diff --git a/JFFLIBRARY_VERSION.txt b/JFFLIBRARY_VERSION.txt index 8bbe6cf..9f55b2c 100755 --- a/JFFLIBRARY_VERSION.txt +++ b/JFFLIBRARY_VERSION.txt @@ -1 +1 @@ -2.2 +3.0 diff --git a/README b/README index 4a7339b..b369d07 100755 --- a/README +++ b/README @@ -14,4 +14,4 @@ JFFExamples - contains usage examples of JFFLibrary components. License : BSD -Supports iOS versions 4.0 and higher. Builds using IOS SDK ver. 5.0 \ No newline at end of file +Supports iOS versions 5.0 and higher. Builds using IOS SDK ver. 7.0 \ No newline at end of file diff --git a/iAsync version.txt b/iAsync version.txt index d3827e7..9f55b2c 100755 --- a/iAsync version.txt +++ b/iAsync version.txt @@ -1 +1 @@ -1.0 +3.0 diff --git a/lib-third-party/libturbojpeg-ios/.gitignore b/lib-third-party/libturbojpeg-ios/.gitignore new file mode 100755 index 0000000..b8e4acb --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/.gitignore @@ -0,0 +1,3 @@ +build/ +Derived Data/ +libturbojpeg/simd-i386/build/ diff --git a/lib-third-party/libturbojpeg-ios/README.txt b/lib-third-party/libturbojpeg-ios/README.txt new file mode 100644 index 0000000..e69de29 diff --git a/lib-third-party/libturbojpeg-ios/TurboAssetLoader/ALAssetRepresentation+turboloader.h b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/ALAssetRepresentation+turboloader.h new file mode 100755 index 0000000..29bf1fe --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/ALAssetRepresentation+turboloader.h @@ -0,0 +1,18 @@ +// +// ALAsset+ALAsset_turboloader.h +// TurboAssetLoader +// +// Created by Johannes Schriewer on 19.12.2012. +// Copyright (c) 2012 Johannes Schriewer. All rights reserved. +// + +#import + +@interface ALAssetRepresentation (DSTTurboLoader) + +- (NSArray *)DSTQuickLoadSizes; +- (CGImageRef)DSTLoadImageOfSize:(CGSize)size; +- (CGSize)DSTQuickLoadSizeNear:(CGSize)desiredSize; +- (CGSize)DSTDimensions; + +@end diff --git a/lib-third-party/libturbojpeg-ios/TurboAssetLoader/ALAssetRepresentation+turboloader.m b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/ALAssetRepresentation+turboloader.m new file mode 100755 index 0000000..1637066 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/ALAssetRepresentation+turboloader.m @@ -0,0 +1,293 @@ +// +// ALAsset+ALAsset_turboloader.m +// TurboAssetLoader +// +// Created by Johannes Schriewer on 19.12.2012. +// Copyright (c) 2012 Johannes Schriewer. All rights reserved. +// + +#import "ALAssetRepresentation+turboloader.h" + +#import "turbojpeg.h" + +#define ACCEPTED_ASPECT_ERROR 0.05 + +static void MemoryPlaneReleaseDataCallback (void *info, const void *data, size_t size) { + free((void *)data); +} + +@implementation ALAssetRepresentation (DSTTurboLoader) + +- (NSArray *)DSTQuickLoadSizes { + CGSize dimensions = [self DSTDimensions]; + + if ([self.UTI isEqualToString:@"public.jpeg"]) { + // ask libjpeg-turbo which sizes it supports natively, others will use Core Graphics to scale down + int numFactors = 0; + tjscalingfactor *factors = tjGetScalingFactors(&numFactors); + + NSMutableArray *result = [NSMutableArray arrayWithCapacity:numFactors]; + for (NSUInteger i = 0; i < numFactors; i++) { + CGFloat zoom = (CGFloat)factors[i].num / (CGFloat)factors[i].denom; + CGSize size = CGSizeMake( + ceilf(dimensions.width * zoom), + ceilf(dimensions.height * zoom) + ); + [result addObject:[NSValue valueWithCGSize:size]]; + } + return [NSArray arrayWithArray:result]; + } + + if ([self.UTI isEqualToString:@"public.png"]) { + // define which sizes we can scale down fast + NSArray *scale = @[ @(1.0), @(1.0/2.0), @(1.0/3.0), @(1.0/4.0), @(1.0/5.0), @(1.0/6.0), @(1.0/7.0), @(1.0/8.0) ]; + NSMutableArray *result = [NSMutableArray arrayWithCapacity:[scale count]]; + for (NSNumber *zoomFactor in scale) { + CGFloat zoom = [zoomFactor floatValue]; + CGSize size = CGSizeMake( + ceilf(dimensions.width * zoom), + ceilf(dimensions.height * zoom) + ); + [result addObject:[NSValue valueWithCGSize:size]]; + } + return [NSArray arrayWithArray:result]; + } + + // Default to full size only + return @[ [NSValue valueWithCGSize:dimensions] ]; +} + +- (CGSize)DSTQuickLoadSizeNear:(CGSize)desiredSize { + CGSize dimensions = [self DSTDimensions]; + int numFactors = 0; + tjscalingfactor *factors = tjGetScalingFactors(&numFactors); + + // Find the nearest possible scaling factor that turbojpeg supports + CGSize delta = CGSizeMake(1000000, 1000000); + CGSize nearest = CGSizeZero; + for (NSUInteger i = 0; i < numFactors; i++) { + CGFloat zoom = (CGFloat)factors[i].num / (CGFloat)factors[i].denom; + CGSize size = CGSizeMake( + ceilf(dimensions.width * zoom), + ceilf(dimensions.height * zoom) + ); + if ((size.width < desiredSize.width) || (size.height < desiredSize.height)) { + continue; + } + if ((size.width == desiredSize.width) && (size.height == desiredSize.height)) { + nearest = size; + break; + } + if (size.width - desiredSize.width < delta.width) { + delta.width = size.width - desiredSize.width; + nearest = size; + } + if (size.height - desiredSize.height < delta.height) { + delta.height = size.height - desiredSize.height; + nearest = size; + } + } + if (nearest.width == 0.0) { + nearest = dimensions; + } + return nearest; +} + +- (CGImageRef)DSTLoadImageOfSize:(CGSize)size { + size = CGSizeMake(ceilf(size.width), ceilf(size.height)); + CGSize dimensions = [self DSTDimensions]; + + // do not stretch images, only zoom + if (dimensions.width > dimensions.height) { + CGFloat imageAspect = dimensions.height / dimensions.width; + CGFloat sizeAspect = size.height / size.width; + if (fabsf(imageAspect - sizeAspect) > ACCEPTED_ASPECT_ERROR) { + // image would be stretched, so we recalculate correct height + size.height = ceilf(imageAspect * size.width); + } + } else { + CGFloat imageAspect = dimensions.width / dimensions.height; + CGFloat sizeAspect = size.width / size.height; + if (fabsf(imageAspect - sizeAspect) > ACCEPTED_ASPECT_ERROR) { + // image would be stretched, so we recalculate correct height + size.width = ceilf(imageAspect * size.height); + } + } + + + if ([self.UTI isEqualToString:@"public.jpeg"]) { + // load image with turbojpeg library near the correct size and then downscale + return [self DSTTurboLoadJPEGImage:size]; + } + if ([self.UTI isEqualToString:@"public.png"]) { + // TODO: load PNG image with libpng + } + + return [self DSTDownscaleImage:[self fullResolutionImage] size:size correctExifRotation:YES]; +} + +#pragma mark - Private +- (CGSize)DSTDimensions { + if ([self respondsToSelector:@selector(dimensions)]) { + CGSize dimensions = self.dimensions; + // looks like an iOS Bug to me: + if (self.orientation == ALAssetOrientationLeftMirrored) { + CGFloat tmp = dimensions.width; + dimensions.width = dimensions.height; + dimensions.height = tmp; + } + return dimensions; + } else { // iOS 5.0 fallback + CGSize dimensions; + + // Exif rotation + switch (self.orientation) { + case ALAssetOrientationUp: + case ALAssetOrientationUpMirrored: + case ALAssetOrientationDown: + case ALAssetOrientationDownMirrored: + dimensions = CGSizeMake([self.metadata[@"PixelWidth"] floatValue], [self.metadata[@"PixelHeight"] floatValue]); + break; + case ALAssetOrientationLeft: + case ALAssetOrientationLeftMirrored: + case ALAssetOrientationRight: + case ALAssetOrientationRightMirrored: + dimensions = CGSizeMake([self.metadata[@"PixelHeight"] floatValue], [self.metadata[@"PixelWidth"] floatValue]); + break; + } + return dimensions; + } +} + +- (CGImageRef)DSTTurboLoadJPEGImage:(CGSize)desiredSize { + NSAssert([self.UTI isEqualToString:@"public.jpeg"], @"Only call for JPEG"); + CGSize nearest = [self DSTQuickLoadSizeNear:desiredSize]; + + // Exif rotation + switch (self.orientation) { + case ALAssetOrientationUp: + case ALAssetOrientationUpMirrored: + case ALAssetOrientationDown: + case ALAssetOrientationDownMirrored: + // do nothing + break; + case ALAssetOrientationLeft: + case ALAssetOrientationLeftMirrored: + case ALAssetOrientationRight: + case ALAssetOrientationRightMirrored: { + // 90 degrees rotated + CGFloat tmp = nearest.width; + nearest.width = nearest.height; + nearest.height = tmp; + break; + } + } + + // decompress image (may be bigger than desired size) + tjhandle handle = tjInitDecompress(); + NSError *error = nil; + uint8_t *buffer = malloc(self.size); + [self getBytes:buffer fromOffset:0 length:self.size error:&error]; + if (error) { + NSLog(@"Error fetching image data: %@", error); + return nil; + } + + uint8_t *imageBuffer = malloc(nearest.width * 4 * nearest.height); + int success = tjDecompress2(handle, buffer, self.size, imageBuffer, nearest.width, nearest.width * 4, nearest.height, TJPF_BGRA, TJFLAG_FASTUPSAMPLE | TJFLAG_FASTDCT); + free(buffer); + if (success < 0) { + NSLog(@"Error while decoding image data: %s", tjGetErrorStr()); + free(imageBuffer); + tjDestroy(handle); + return nil; + } + tjDestroy(handle); + + // Create CGImage from Buffer directly to avoid copy operation to context + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); + CGDataProviderRef rawImageDataProvider = CGDataProviderCreateWithData(nil, imageBuffer, nearest.width * 4 * nearest.height, MemoryPlaneReleaseDataCallback); + CGImageRef image = CGImageCreate(nearest.width, nearest.height, 8, 8 * 4, nearest.width * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little, rawImageDataProvider, NULL, YES, kCGRenderingIntentDefault); + CGDataProviderRelease(rawImageDataProvider); + CGColorSpaceRelease(colorspace); + + if ((self.orientation == ALAssetOrientationUp) && (nearest.width == desiredSize.width) && (nearest.height == desiredSize.height)) { + return image; // no rotation or scaling neccessary + } + + // scaling and orientation correction + CGImageRef result = [self DSTDownscaleImage:image size:desiredSize correctExifRotation:YES]; + CGImageRelease(image); + return result; +} + +- (CGImageRef)DSTDownscaleImage:(CGImageRef)image size:(CGSize)size correctExifRotation:(BOOL)correctRotation { + size = CGSizeMake(ceilf(size.width), ceilf(size.height)); + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); + CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, size.width * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little); + + CGContextSetInterpolationQuality(context, kCGInterpolationLow); + + CGContextTranslateCTM(context, size.width / 2.0, size.height / 2.0); + CGRect imageRect = CGRectMake(-size.width / 2.0, -size.height / 2.0, size.width, size.height); + + if (correctRotation) { + imageRect = [self DSTExifCorrectContext:context contextSize:size]; + } + + CGContextDrawImage(context, imageRect, image); + CGImageRef result = CGBitmapContextCreateImage(context); + CGContextRelease(context); + CGColorSpaceRelease(colorspace); + return result; +} + +- (CGRect)DSTExifCorrectContext:(CGContextRef)context contextSize:(CGSize)size { + CGRect imageRect = CGRectMake(-size.width / 2.0, -size.height / 2.0, size.width, size.height); + + // Exif rotation + switch (self.orientation) { + case ALAssetOrientationUp: + case ALAssetOrientationUpMirrored: + // do nothing + break; + case ALAssetOrientationDown: + case ALAssetOrientationDownMirrored: + // asset on top rotate 180 degrees + CGContextRotateCTM(context, M_PI); + break; + case ALAssetOrientationLeft: + case ALAssetOrientationLeftMirrored: + // asset on left, rotate 90 degrees + imageRect = CGRectMake(-size.height / 2.0, -size.width/ 2.0, size.height, size.width); + CGContextRotateCTM(context, M_PI_2); + break; + case ALAssetOrientationRight: + case ALAssetOrientationRightMirrored: + // asset on left, rotate -90 degrees + imageRect = CGRectMake(-size.height / 2.0, -size.width/ 2.0, size.height, size.width); + CGContextRotateCTM(context, -M_PI_2); + break; + } + + // Exif mirroring + switch (self.orientation) { + case ALAssetOrientationUp: + case ALAssetOrientationDown: + case ALAssetOrientationLeft: + case ALAssetOrientationRight: + // do nothing + break; + case ALAssetOrientationUpMirrored: + case ALAssetOrientationLeftMirrored: + case ALAssetOrientationRightMirrored: + case ALAssetOrientationDownMirrored: + // de-mirror + CGContextScaleCTM(context, -1, 1); + break; + } + + return imageRect; +} + +@end diff --git a/lib-third-party/libturbojpeg-ios/TurboAssetLoader/NSDictionary+ExifMetadataSize.h b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/NSDictionary+ExifMetadataSize.h new file mode 100755 index 0000000..94e5df8 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/NSDictionary+ExifMetadataSize.h @@ -0,0 +1,14 @@ +// +// NSDictionary+ExifMetadataSize.h +// mps +// +// Created by Johannes Schriewer on 16.01.2013. +// Copyright (c) 2013 planetmutlu. All rights reserved. +// + +#import + +@interface NSDictionary (ExifMetadataSize) +- (CGSize)extractEXIFMetadataSize; + +@end diff --git a/lib-third-party/libturbojpeg-ios/TurboAssetLoader/NSDictionary+ExifMetadataSize.m b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/NSDictionary+ExifMetadataSize.m new file mode 100755 index 0000000..20be4de --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/TurboAssetLoader/NSDictionary+ExifMetadataSize.m @@ -0,0 +1,32 @@ +// +// NSDictionary+ExifMetadataSize.m +// mps +// +// Created by Johannes Schriewer on 16.01.2013. +// Copyright (c) 2013 planetmutlu. All rights reserved. +// + +#import "NSDictionary+ExifMetadataSize.h" + +@implementation NSDictionary (ExifMetadataSize) + +- (CGSize)extractEXIFMetadataSize { + switch ([self[@"Orientation"] unsignedIntegerValue]) { + case 1: // straight + case 2: // mirrored + case 3: // top down mirrored + case 4: // top down + return CGSizeMake([self[@"PixelWidth"] floatValue], [self[@"PixelHeight"] floatValue]); + case 5: // rotated left side + case 6: // rotated right side + case 7: // rotated right side mirrored + case 8: // rotated left side mirrored + return CGSizeMake([self[@"PixelHeight"] floatValue], [self[@"PixelWidth"] floatValue]); + default: + NSLog(@"Unknown EXIF rotation"); + return CGSizeMake([self[@"PixelWidth"] floatValue], [self[@"PixelHeight"] floatValue]); + break; + } +} + +@end diff --git a/lib-third-party/libturbojpeg-ios/build.sh b/lib-third-party/libturbojpeg-ios/build.sh new file mode 100755 index 0000000..013b56a --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash +rm -rf "lib" +mkdir -p "lib" +xcodebuild -project libjpeg-turbo-ios.xcodeproj -configuration Release -target turbojpeg -arch "armv7 armv7s" -sdk iphoneos6.0 build || exit $? +xcodebuild -project libjpeg-turbo-simulator.xcodeproj -configuration Release -target turbojpeg -arch i386 -sdk iphonesimulator6.0 build || exit $? + +lipo -output "lib/libturbojpeg-universal.a" -create "lib/libturbojpeg-arm.a" "lib/libturbojpeg-simulator.a" \ No newline at end of file diff --git a/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-arm.a b/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-arm.a new file mode 100644 index 0000000..1e38a34 Binary files /dev/null and b/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-arm.a differ diff --git a/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-simulator.a b/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-simulator.a new file mode 100644 index 0000000..5f79da3 Binary files /dev/null and b/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-simulator.a differ diff --git a/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-universal.a b/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-universal.a new file mode 100644 index 0000000..91cba93 Binary files /dev/null and b/lib-third-party/libturbojpeg-ios/lib/libturbojpeg-universal.a differ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg-turbo-ios.xcodeproj/project.pbxproj b/lib-third-party/libturbojpeg-ios/libjpeg-turbo-ios.xcodeproj/project.pbxproj new file mode 100755 index 0000000..34949f6 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg-turbo-ios.xcodeproj/project.pbxproj @@ -0,0 +1,854 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 423730081646F7F90022C8FB /* jaricom.c in Sources */ = {isa = PBXBuildFile; fileRef = 423730051646F7F90022C8FB /* jaricom.c */; }; + 423730091646F7F90022C8FB /* jcarith.c in Sources */ = {isa = PBXBuildFile; fileRef = 423730061646F7F90022C8FB /* jcarith.c */; }; + 4237300A1646F7F90022C8FB /* jdarith.c in Sources */ = {isa = PBXBuildFile; fileRef = 423730071646F7F90022C8FB /* jdarith.c */; }; + 427BF64A1645BDA500BC3809 /* jcapimin.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FC1645BD3700BC3809 /* jcapimin.c */; }; + 427BF64B1645BDA500BC3809 /* jcapistd.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FD1645BD3700BC3809 /* jcapistd.c */; }; + 427BF64C1645BDA500BC3809 /* jccoefct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FE1645BD3700BC3809 /* jccoefct.c */; }; + 427BF64D1645BDA500BC3809 /* jccolor.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FF1645BD3700BC3809 /* jccolor.c */; }; + 427BF64E1645BDA500BC3809 /* jcdctmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6001645BD3700BC3809 /* jcdctmgr.c */; }; + 427BF64F1645BDA500BC3809 /* jchuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6011645BD3700BC3809 /* jchuff.c */; }; + 427BF6501645BDA500BC3809 /* jcinit.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6031645BD3700BC3809 /* jcinit.c */; }; + 427BF6511645BDA500BC3809 /* jcmainct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6041645BD3700BC3809 /* jcmainct.c */; }; + 427BF6521645BDA500BC3809 /* jcmarker.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6051645BD3700BC3809 /* jcmarker.c */; }; + 427BF6531645BDA500BC3809 /* jcmaster.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6061645BD3700BC3809 /* jcmaster.c */; }; + 427BF6541645BDA500BC3809 /* jcomapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6071645BD3700BC3809 /* jcomapi.c */; }; + 427BF6551645BDA500BC3809 /* jcparam.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6081645BD3700BC3809 /* jcparam.c */; }; + 427BF6561645BDA500BC3809 /* jcphuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6091645BD3700BC3809 /* jcphuff.c */; }; + 427BF6571645BDA500BC3809 /* jcprepct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60A1645BD3700BC3809 /* jcprepct.c */; }; + 427BF6581645BDA500BC3809 /* jcsample.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60B1645BD3700BC3809 /* jcsample.c */; }; + 427BF6591645BDA500BC3809 /* jctrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60C1645BD3700BC3809 /* jctrans.c */; }; + 427BF65A1645BDA500BC3809 /* jdapimin.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60D1645BD3700BC3809 /* jdapimin.c */; }; + 427BF65B1645BDA500BC3809 /* jdapistd.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60E1645BD3700BC3809 /* jdapistd.c */; }; + 427BF65C1645BDA500BC3809 /* jdatadst.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60F1645BD3700BC3809 /* jdatadst.c */; }; + 427BF65D1645BDA500BC3809 /* jdatasrc.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6101645BD3700BC3809 /* jdatasrc.c */; }; + 427BF65E1645BDA500BC3809 /* jdcoefct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6111645BD3700BC3809 /* jdcoefct.c */; }; + 427BF65F1645BDA500BC3809 /* jdcolor.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6121645BD3700BC3809 /* jdcolor.c */; }; + 427BF6601645BDA500BC3809 /* jddctmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6141645BD3700BC3809 /* jddctmgr.c */; }; + 427BF6611645BDA500BC3809 /* jdhuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6151645BD3700BC3809 /* jdhuff.c */; }; + 427BF6621645BDA500BC3809 /* jdinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6171645BD3700BC3809 /* jdinput.c */; }; + 427BF6631645BDA500BC3809 /* jdmainct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6181645BD3700BC3809 /* jdmainct.c */; }; + 427BF6641645BDA500BC3809 /* jdmarker.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6191645BD3700BC3809 /* jdmarker.c */; }; + 427BF6651645BDA500BC3809 /* jdmaster.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61A1645BD3700BC3809 /* jdmaster.c */; }; + 427BF6661645BDA500BC3809 /* jdmerge.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61B1645BD3700BC3809 /* jdmerge.c */; }; + 427BF6671645BDA500BC3809 /* jdphuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61C1645BD3700BC3809 /* jdphuff.c */; }; + 427BF6681645BDA500BC3809 /* jdpostct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61D1645BD3700BC3809 /* jdpostct.c */; }; + 427BF6691645BDA500BC3809 /* jdsample.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61E1645BD3700BC3809 /* jdsample.c */; }; + 427BF66A1645BDA500BC3809 /* jdtrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61F1645BD3700BC3809 /* jdtrans.c */; }; + 427BF66B1645BDA500BC3809 /* jerror.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6201645BD3700BC3809 /* jerror.c */; }; + 427BF66C1645BDA500BC3809 /* jfdctflt.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6221645BD3700BC3809 /* jfdctflt.c */; }; + 427BF66D1645BDA500BC3809 /* jfdctfst.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6231645BD3700BC3809 /* jfdctfst.c */; }; + 427BF66E1645BDA500BC3809 /* jfdctint.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6241645BD3700BC3809 /* jfdctint.c */; }; + 427BF66F1645BDA500BC3809 /* jidctflt.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6251645BD3700BC3809 /* jidctflt.c */; }; + 427BF6701645BDA500BC3809 /* jidctfst.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6261645BD3700BC3809 /* jidctfst.c */; }; + 427BF6711645BDA500BC3809 /* jidctint.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6271645BD3700BC3809 /* jidctint.c */; }; + 427BF6721645BDA500BC3809 /* jidctred.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6281645BD3700BC3809 /* jidctred.c */; }; + 427BF6731645BDA500BC3809 /* jmemmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF62A1645BD3700BC3809 /* jmemmgr.c */; }; + 427BF6741645BDA500BC3809 /* jmemnobs.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF62B1645BD3700BC3809 /* jmemnobs.c */; }; + 427BF6751645BDA500BC3809 /* jquant1.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6311645BD3700BC3809 /* jquant1.c */; }; + 427BF6761645BDA500BC3809 /* jquant2.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6321645BD3700BC3809 /* jquant2.c */; }; + 427BF6771645BDA500BC3809 /* jutils.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6351645BD3700BC3809 /* jutils.c */; }; + 427BF6961645BF4800BC3809 /* jdatadst-tj.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6901645BF4800BC3809 /* jdatadst-tj.c */; }; + 427BF6971645BF4800BC3809 /* jdatasrc-tj.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6911645BF4800BC3809 /* jdatasrc-tj.c */; }; + 427BF6981645BF4800BC3809 /* transupp.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6921645BF4800BC3809 /* transupp.c */; }; + 427BF6991645BF4800BC3809 /* turbojpeg.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6941645BF4800BC3809 /* turbojpeg.c */; }; + 427BF6D11645C1E900BC3809 /* jsimd_arm.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6CF1645C1E900BC3809 /* jsimd_arm.c */; }; + 427BF6D51645D0BB00BC3809 /* libsimd-arm.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 427BF6B11645C08600BC3809 /* libsimd-arm.a */; }; + 427BF7501645DD3300BC3809 /* libjpeg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 427BF63C1645BD8C00BC3809 /* libjpeg.a */; }; + 427BF7591645E10800BC3809 /* jsimd_arm_neon.S in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6CE1645C1E900BC3809 /* jsimd_arm_neon.S */; }; +/* End PBXBuildFile section */ + +/* Begin PBXBuildRule section */ + 427BF7581645E0BF00BC3809 /* PBXBuildRule */ = { + isa = PBXBuildRule; + compilerSpec = com.apple.compilers.proxy.script; + filePatterns = "*.S"; + fileType = pattern.proxy; + isEditable = 1; + outputFiles = ( + "$(OBJECT_FILE_DIR_normal)/$(CURRENT_ARCH)/$(INPUT_FILE_BASE).o", + ); + script = "\ncd \"$INPUT_FILE_DIR\"\n\nfor DIR in $HEADER_SEARCH_PATHS ; do\nINCLUDES=\"$INCLUDES -I$(echo \"$DIR\"|sed -e 's/ /\\\\ /g;')\"\ndone\n\nfor DEFINE in $GCC_PREPROCESSOR_DEFINITIONS ; do\nDEFINES=\"$DEFINES -D$DEFINE\"\ndone;\n\nchmod a+x $SRCROOT/scripts/gas-preprocessor.pl\n\n\"$SRCROOT/scripts/gas-preprocessor.pl\" xcrun llvm-gcc-4.2 -x assembler-with-cpp -arch $CURRENT_ARCH -fmessage-length=0 -pipe -fpascal-strings -O$GCC_OPTIMIZATION_LEVEL $DEFINES -isysroot \"$SDKROOT\" -gdwarf-2 -mthumb -miphoneos-version-min=$IPHONEOS_DEPLOYMENT_TARGET -iquote ./simd-arm-generated-files.hmap -I./simd-arm-own-target-headers.hmap -I./simd-arm-all-target-headers.hmap -iquote ./simd-arm-project-headers.hmap $INCLUDES -I./DerivedSources/armv7 -I./DerivedSources -F.. -c \"$INPUT_FILE_NAME\" -o \"$OBJECT_FILE_DIR_normal/$CURRENT_ARCH/$INPUT_FILE_BASE.o\"\n\n"; + }; +/* End PBXBuildRule section */ + +/* Begin PBXContainerItemProxy section */ + 427BF68D1645BF3600BC3809 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 427BF5DF1645B6F400BC3809 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 427BF63B1645BD8C00BC3809; + remoteInfo = libjpeg; + }; + 427BF6D31645D0B400BC3809 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 427BF5DF1645B6F400BC3809 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 427BF6B01645C08600BC3809; + remoteInfo = "simd-arm"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 423730051646F7F90022C8FB /* jaricom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jaricom.c; path = libjpeg/arithmetric_coding/jaricom.c; sourceTree = ""; }; + 423730061646F7F90022C8FB /* jcarith.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcarith.c; path = libjpeg/arithmetric_coding/jcarith.c; sourceTree = ""; }; + 423730071646F7F90022C8FB /* jdarith.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdarith.c; path = libjpeg/arithmetric_coding/jdarith.c; sourceTree = ""; }; + 427BF5FC1645BD3700BC3809 /* jcapimin.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcapimin.c; path = libjpeg/jcapimin.c; sourceTree = ""; }; + 427BF5FD1645BD3700BC3809 /* jcapistd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcapistd.c; path = libjpeg/jcapistd.c; sourceTree = ""; }; + 427BF5FE1645BD3700BC3809 /* jccoefct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jccoefct.c; path = libjpeg/jccoefct.c; sourceTree = ""; }; + 427BF5FF1645BD3700BC3809 /* jccolor.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jccolor.c; path = libjpeg/jccolor.c; sourceTree = ""; }; + 427BF6001645BD3700BC3809 /* jcdctmgr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcdctmgr.c; path = libjpeg/jcdctmgr.c; sourceTree = ""; }; + 427BF6011645BD3700BC3809 /* jchuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jchuff.c; path = libjpeg/jchuff.c; sourceTree = ""; }; + 427BF6021645BD3700BC3809 /* jchuff.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jchuff.h; path = libjpeg/jchuff.h; sourceTree = ""; }; + 427BF6031645BD3700BC3809 /* jcinit.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcinit.c; path = libjpeg/jcinit.c; sourceTree = ""; }; + 427BF6041645BD3700BC3809 /* jcmainct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcmainct.c; path = libjpeg/jcmainct.c; sourceTree = ""; }; + 427BF6051645BD3700BC3809 /* jcmarker.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcmarker.c; path = libjpeg/jcmarker.c; sourceTree = ""; }; + 427BF6061645BD3700BC3809 /* jcmaster.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcmaster.c; path = libjpeg/jcmaster.c; sourceTree = ""; }; + 427BF6071645BD3700BC3809 /* jcomapi.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcomapi.c; path = libjpeg/jcomapi.c; sourceTree = ""; }; + 427BF6081645BD3700BC3809 /* jcparam.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcparam.c; path = libjpeg/jcparam.c; sourceTree = ""; }; + 427BF6091645BD3700BC3809 /* jcphuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcphuff.c; path = libjpeg/jcphuff.c; sourceTree = ""; }; + 427BF60A1645BD3700BC3809 /* jcprepct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcprepct.c; path = libjpeg/jcprepct.c; sourceTree = ""; }; + 427BF60B1645BD3700BC3809 /* jcsample.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcsample.c; path = libjpeg/jcsample.c; sourceTree = ""; }; + 427BF60C1645BD3700BC3809 /* jctrans.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jctrans.c; path = libjpeg/jctrans.c; sourceTree = ""; }; + 427BF60D1645BD3700BC3809 /* jdapimin.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdapimin.c; path = libjpeg/jdapimin.c; sourceTree = ""; }; + 427BF60E1645BD3700BC3809 /* jdapistd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdapistd.c; path = libjpeg/jdapistd.c; sourceTree = ""; }; + 427BF60F1645BD3700BC3809 /* jdatadst.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdatadst.c; path = libjpeg/jdatadst.c; sourceTree = ""; }; + 427BF6101645BD3700BC3809 /* jdatasrc.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdatasrc.c; path = libjpeg/jdatasrc.c; sourceTree = ""; }; + 427BF6111645BD3700BC3809 /* jdcoefct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdcoefct.c; path = libjpeg/jdcoefct.c; sourceTree = ""; }; + 427BF6121645BD3700BC3809 /* jdcolor.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdcolor.c; path = libjpeg/jdcolor.c; sourceTree = ""; }; + 427BF6131645BD3700BC3809 /* jdct.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jdct.h; path = libjpeg/jdct.h; sourceTree = ""; }; + 427BF6141645BD3700BC3809 /* jddctmgr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jddctmgr.c; path = libjpeg/jddctmgr.c; sourceTree = ""; }; + 427BF6151645BD3700BC3809 /* jdhuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdhuff.c; path = libjpeg/jdhuff.c; sourceTree = ""; }; + 427BF6161645BD3700BC3809 /* jdhuff.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jdhuff.h; path = libjpeg/jdhuff.h; sourceTree = ""; }; + 427BF6171645BD3700BC3809 /* jdinput.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdinput.c; path = libjpeg/jdinput.c; sourceTree = ""; }; + 427BF6181645BD3700BC3809 /* jdmainct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmainct.c; path = libjpeg/jdmainct.c; sourceTree = ""; }; + 427BF6191645BD3700BC3809 /* jdmarker.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmarker.c; path = libjpeg/jdmarker.c; sourceTree = ""; }; + 427BF61A1645BD3700BC3809 /* jdmaster.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmaster.c; path = libjpeg/jdmaster.c; sourceTree = ""; }; + 427BF61B1645BD3700BC3809 /* jdmerge.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmerge.c; path = libjpeg/jdmerge.c; sourceTree = ""; }; + 427BF61C1645BD3700BC3809 /* jdphuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdphuff.c; path = libjpeg/jdphuff.c; sourceTree = ""; }; + 427BF61D1645BD3700BC3809 /* jdpostct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdpostct.c; path = libjpeg/jdpostct.c; sourceTree = ""; }; + 427BF61E1645BD3700BC3809 /* jdsample.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdsample.c; path = libjpeg/jdsample.c; sourceTree = ""; }; + 427BF61F1645BD3700BC3809 /* jdtrans.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdtrans.c; path = libjpeg/jdtrans.c; sourceTree = ""; }; + 427BF6201645BD3700BC3809 /* jerror.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jerror.c; path = libjpeg/jerror.c; sourceTree = ""; }; + 427BF6211645BD3700BC3809 /* jerror.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jerror.h; path = libjpeg/jerror.h; sourceTree = ""; }; + 427BF6221645BD3700BC3809 /* jfdctflt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jfdctflt.c; path = libjpeg/jfdctflt.c; sourceTree = ""; }; + 427BF6231645BD3700BC3809 /* jfdctfst.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jfdctfst.c; path = libjpeg/jfdctfst.c; sourceTree = ""; }; + 427BF6241645BD3700BC3809 /* jfdctint.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jfdctint.c; path = libjpeg/jfdctint.c; sourceTree = ""; }; + 427BF6251645BD3700BC3809 /* jidctflt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctflt.c; path = libjpeg/jidctflt.c; sourceTree = ""; }; + 427BF6261645BD3700BC3809 /* jidctfst.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctfst.c; path = libjpeg/jidctfst.c; sourceTree = ""; }; + 427BF6271645BD3700BC3809 /* jidctint.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctint.c; path = libjpeg/jidctint.c; sourceTree = ""; }; + 427BF6281645BD3700BC3809 /* jidctred.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctred.c; path = libjpeg/jidctred.c; sourceTree = ""; }; + 427BF6291645BD3700BC3809 /* jinclude.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jinclude.h; path = libjpeg/jinclude.h; sourceTree = ""; }; + 427BF62A1645BD3700BC3809 /* jmemmgr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jmemmgr.c; path = libjpeg/jmemmgr.c; sourceTree = ""; }; + 427BF62B1645BD3700BC3809 /* jmemnobs.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jmemnobs.c; path = libjpeg/jmemnobs.c; sourceTree = ""; }; + 427BF62C1645BD3700BC3809 /* jmemsys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jmemsys.h; path = libjpeg/jmemsys.h; sourceTree = ""; }; + 427BF62D1645BD3700BC3809 /* jmorecfg.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jmorecfg.h; path = libjpeg/jmorecfg.h; sourceTree = ""; }; + 427BF62E1645BD3700BC3809 /* jpegcomp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jpegcomp.h; path = libjpeg/jpegcomp.h; sourceTree = ""; }; + 427BF62F1645BD3700BC3809 /* jpegint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jpegint.h; path = libjpeg/jpegint.h; sourceTree = ""; }; + 427BF6301645BD3700BC3809 /* jpeglib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jpeglib.h; path = libjpeg/jpeglib.h; sourceTree = ""; }; + 427BF6311645BD3700BC3809 /* jquant1.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jquant1.c; path = libjpeg/jquant1.c; sourceTree = ""; }; + 427BF6321645BD3700BC3809 /* jquant2.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jquant2.c; path = libjpeg/jquant2.c; sourceTree = ""; }; + 427BF6331645BD3700BC3809 /* jsimd.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jsimd.h; path = libjpeg/jsimd.h; sourceTree = ""; }; + 427BF6341645BD3700BC3809 /* jsimddct.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jsimddct.h; path = libjpeg/jsimddct.h; sourceTree = ""; }; + 427BF6351645BD3700BC3809 /* jutils.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jutils.c; path = libjpeg/jutils.c; sourceTree = ""; }; + 427BF6361645BD3700BC3809 /* jversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jversion.h; path = libjpeg/jversion.h; sourceTree = ""; }; + 427BF63C1645BD8C00BC3809 /* libjpeg.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libjpeg.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 427BF6781645BE0200BC3809 /* jconfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jconfig.h; path = libjpeg/jconfig.h; sourceTree = ""; }; + 427BF6791645BE2E00BC3809 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = config.h; path = libjpeg/config.h; sourceTree = ""; }; + 427BF67A1645BE6000BC3809 /* jccolext.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jccolext.c; path = libjpeg/jccolext.c; sourceTree = ""; }; + 427BF67B1645BE8500BC3809 /* jdcolext.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdcolext.c; path = libjpeg/jdcolext.c; sourceTree = ""; }; + 427BF67C1645BEAA00BC3809 /* jdmrgext.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmrgext.c; path = libjpeg/jdmrgext.c; sourceTree = ""; }; + 427BF6811645BF1200BC3809 /* libturbojpeg.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libturbojpeg.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 427BF6901645BF4800BC3809 /* jdatadst-tj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "jdatadst-tj.c"; path = "libturbojpeg/jdatadst-tj.c"; sourceTree = ""; }; + 427BF6911645BF4800BC3809 /* jdatasrc-tj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "jdatasrc-tj.c"; path = "libturbojpeg/jdatasrc-tj.c"; sourceTree = ""; }; + 427BF6921645BF4800BC3809 /* transupp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = transupp.c; path = libturbojpeg/transupp.c; sourceTree = ""; }; + 427BF6931645BF4800BC3809 /* transupp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = transupp.h; path = libturbojpeg/transupp.h; sourceTree = ""; }; + 427BF6941645BF4800BC3809 /* turbojpeg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = turbojpeg.c; path = libturbojpeg/turbojpeg.c; sourceTree = ""; }; + 427BF6951645BF4800BC3809 /* turbojpeg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = turbojpeg.h; path = libturbojpeg/turbojpeg.h; sourceTree = ""; }; + 427BF69B1645BF7A00BC3809 /* jinclude.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jinclude.h; path = libturbojpeg/jinclude.h; sourceTree = ""; }; + 427BF69C1645BFE000BC3809 /* tjutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tjutil.h; path = libturbojpeg/tjutil.h; sourceTree = ""; }; + 427BF6B11645C08600BC3809 /* libsimd-arm.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libsimd-arm.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 427BF6CC1645C1DB00BC3809 /* jsimd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimd.h; path = libturbojpeg/jsimd.h; sourceTree = ""; }; + 427BF6CD1645C1DB00BC3809 /* jsimddct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimddct.h; path = libturbojpeg/jsimddct.h; sourceTree = ""; }; + 427BF6CE1645C1E900BC3809 /* jsimd_arm_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; name = jsimd_arm_neon.S; path = "libturbojpeg/simd-arm/jsimd_arm_neon.S"; sourceTree = ""; }; + 427BF6CF1645C1E900BC3809 /* jsimd_arm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jsimd_arm.c; path = "libturbojpeg/simd-arm/jsimd_arm.c"; sourceTree = ""; }; + 427BF6D81645D11E00BC3809 /* jcclrmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcclrmmx.asm; path = "libturbojpeg/simd-i386/jcclrmmx.asm"; sourceTree = ""; }; + 427BF6D91645D11E00BC3809 /* jcclrss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcclrss2.asm; path = "libturbojpeg/simd-i386/jcclrss2.asm"; sourceTree = ""; }; + 427BF6DA1645D11E00BC3809 /* jccolmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jccolmmx.asm; path = "libturbojpeg/simd-i386/jccolmmx.asm"; sourceTree = ""; }; + 427BF6DB1645D11E00BC3809 /* jccolss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jccolss2.asm; path = "libturbojpeg/simd-i386/jccolss2.asm"; sourceTree = ""; }; + 427BF6DC1645D11E00BC3809 /* jcgrammx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgrammx.asm; path = "libturbojpeg/simd-i386/jcgrammx.asm"; sourceTree = ""; }; + 427BF6DD1645D11E00BC3809 /* jcgrass2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgrass2.asm; path = "libturbojpeg/simd-i386/jcgrass2.asm"; sourceTree = ""; }; + 427BF6DE1645D11E00BC3809 /* jcgrymmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgrymmx.asm; path = "libturbojpeg/simd-i386/jcgrymmx.asm"; sourceTree = ""; }; + 427BF6DF1645D11E00BC3809 /* jcgryss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgryss2.asm; path = "libturbojpeg/simd-i386/jcgryss2.asm"; sourceTree = ""; }; + 427BF6E01645D11E00BC3809 /* jcolsamp.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = jcolsamp.inc; path = "libturbojpeg/simd-i386/jcolsamp.inc"; sourceTree = ""; }; + 427BF6E11645D11E00BC3809 /* jcqnt3dn.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqnt3dn.asm; path = "libturbojpeg/simd-i386/jcqnt3dn.asm"; sourceTree = ""; }; + 427BF6E21645D11E00BC3809 /* jcqntmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqntmmx.asm; path = "libturbojpeg/simd-i386/jcqntmmx.asm"; sourceTree = ""; }; + 427BF6E31645D11E00BC3809 /* jcqnts2f.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqnts2f.asm; path = "libturbojpeg/simd-i386/jcqnts2f.asm"; sourceTree = ""; }; + 427BF6E41645D11E00BC3809 /* jcqnts2i.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqnts2i.asm; path = "libturbojpeg/simd-i386/jcqnts2i.asm"; sourceTree = ""; }; + 427BF6E51645D11E00BC3809 /* jcqntsse.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqntsse.asm; path = "libturbojpeg/simd-i386/jcqntsse.asm"; sourceTree = ""; }; + 427BF6E61645D11E00BC3809 /* jcsammmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcsammmx.asm; path = "libturbojpeg/simd-i386/jcsammmx.asm"; sourceTree = ""; }; + 427BF6E71645D11E00BC3809 /* jcsamss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcsamss2.asm; path = "libturbojpeg/simd-i386/jcsamss2.asm"; sourceTree = ""; }; + 427BF6E81645D11E00BC3809 /* jdclrmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdclrmmx.asm; path = "libturbojpeg/simd-i386/jdclrmmx.asm"; sourceTree = ""; }; + 427BF6E91645D11E00BC3809 /* jdclrss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdclrss2.asm; path = "libturbojpeg/simd-i386/jdclrss2.asm"; sourceTree = ""; }; + 427BF6EA1645D11E00BC3809 /* jdcolmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdcolmmx.asm; path = "libturbojpeg/simd-i386/jdcolmmx.asm"; sourceTree = ""; }; + 427BF6EB1645D11E00BC3809 /* jdcolss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdcolss2.asm; path = "libturbojpeg/simd-i386/jdcolss2.asm"; sourceTree = ""; }; + 427BF6EC1645D11E00BC3809 /* jdct.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = jdct.inc; path = "libturbojpeg/simd-i386/jdct.inc"; sourceTree = ""; }; + 427BF6ED1645D11E00BC3809 /* jdmermmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmermmx.asm; path = "libturbojpeg/simd-i386/jdmermmx.asm"; sourceTree = ""; }; + 427BF6EE1645D11E00BC3809 /* jdmerss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmerss2.asm; path = "libturbojpeg/simd-i386/jdmerss2.asm"; sourceTree = ""; }; + 427BF6EF1645D11E00BC3809 /* jdmrgmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmrgmmx.asm; path = "libturbojpeg/simd-i386/jdmrgmmx.asm"; sourceTree = ""; }; + 427BF6F01645D11E00BC3809 /* jdmrgss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmrgss2.asm; path = "libturbojpeg/simd-i386/jdmrgss2.asm"; sourceTree = ""; }; + 427BF6F11645D11E00BC3809 /* jdsammmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdsammmx.asm; path = "libturbojpeg/simd-i386/jdsammmx.asm"; sourceTree = ""; }; + 427BF6F21645D11E00BC3809 /* jdsamss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdsamss2.asm; path = "libturbojpeg/simd-i386/jdsamss2.asm"; sourceTree = ""; }; + 427BF6F31645D11E00BC3809 /* jf3dnflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jf3dnflt.asm; path = "libturbojpeg/simd-i386/jf3dnflt.asm"; sourceTree = ""; }; + 427BF6F41645D11E00BC3809 /* jfmmxfst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfmmxfst.asm; path = "libturbojpeg/simd-i386/jfmmxfst.asm"; sourceTree = ""; }; + 427BF6F51645D11E00BC3809 /* jfmmxint.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfmmxint.asm; path = "libturbojpeg/simd-i386/jfmmxint.asm"; sourceTree = ""; }; + 427BF6F61645D11E00BC3809 /* jfss2fst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfss2fst.asm; path = "libturbojpeg/simd-i386/jfss2fst.asm"; sourceTree = ""; }; + 427BF6F71645D11E00BC3809 /* jfss2int.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfss2int.asm; path = "libturbojpeg/simd-i386/jfss2int.asm"; sourceTree = ""; }; + 427BF6F81645D11E00BC3809 /* jfsseflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfsseflt.asm; path = "libturbojpeg/simd-i386/jfsseflt.asm"; sourceTree = ""; }; + 427BF6F91645D11E00BC3809 /* ji3dnflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = ji3dnflt.asm; path = "libturbojpeg/simd-i386/ji3dnflt.asm"; sourceTree = ""; }; + 427BF6FA1645D11E00BC3809 /* jimmxfst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jimmxfst.asm; path = "libturbojpeg/simd-i386/jimmxfst.asm"; sourceTree = ""; }; + 427BF6FB1645D11E00BC3809 /* jimmxint.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jimmxint.asm; path = "libturbojpeg/simd-i386/jimmxint.asm"; sourceTree = ""; }; + 427BF6FC1645D11E00BC3809 /* jimmxred.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jimmxred.asm; path = "libturbojpeg/simd-i386/jimmxred.asm"; sourceTree = ""; }; + 427BF6FD1645D11E00BC3809 /* jiss2flt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2flt.asm; path = "libturbojpeg/simd-i386/jiss2flt.asm"; sourceTree = ""; }; + 427BF6FE1645D11E00BC3809 /* jiss2fst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2fst.asm; path = "libturbojpeg/simd-i386/jiss2fst.asm"; sourceTree = ""; }; + 427BF6FF1645D11E00BC3809 /* jiss2int.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2int.asm; path = "libturbojpeg/simd-i386/jiss2int.asm"; sourceTree = ""; }; + 427BF7001645D11E00BC3809 /* jiss2red.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2red.asm; path = "libturbojpeg/simd-i386/jiss2red.asm"; sourceTree = ""; }; + 427BF7011645D11E00BC3809 /* jisseflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jisseflt.asm; path = "libturbojpeg/simd-i386/jisseflt.asm"; sourceTree = ""; }; + 427BF7021645D11E00BC3809 /* jsimd_i386.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jsimd_i386.c; path = "libturbojpeg/simd-i386/jsimd_i386.c"; sourceTree = ""; }; + 427BF7031645D11E00BC3809 /* jsimd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimd.h; path = "libturbojpeg/simd-i386/jsimd.h"; sourceTree = ""; }; + 427BF7041645D11E00BC3809 /* jsimdcfg.inc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimdcfg.inc.h; path = "libturbojpeg/simd-i386/jsimdcfg.inc.h"; sourceTree = ""; }; + 427BF7051645D11E00BC3809 /* jsimdcpu.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jsimdcpu.asm; path = "libturbojpeg/simd-i386/jsimdcpu.asm"; sourceTree = ""; }; + 427BF7061645D11E00BC3809 /* jsimdext.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = jsimdext.inc; path = "libturbojpeg/simd-i386/jsimdext.inc"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 427BF67E1645BF1200BC3809 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 427BF7501645DD3300BC3809 /* libjpeg.a in Frameworks */, + 427BF6D51645D0BB00BC3809 /* libsimd-arm.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 423730031646F7EC0022C8FB /* arithmetric_coding */ = { + isa = PBXGroup; + children = ( + 423730051646F7F90022C8FB /* jaricom.c */, + 423730061646F7F90022C8FB /* jcarith.c */, + 423730071646F7F90022C8FB /* jdarith.c */, + ); + name = arithmetric_coding; + sourceTree = ""; + }; + 427BF5DD1645B6F400BC3809 = { + isa = PBXGroup; + children = ( + 427BF5FA1645BD0B00BC3809 /* libturbojpeg */, + 427BF5E91645B6F400BC3809 /* Products */, + ); + sourceTree = ""; + }; + 427BF5E91645B6F400BC3809 /* Products */ = { + isa = PBXGroup; + children = ( + 427BF63C1645BD8C00BC3809 /* libjpeg.a */, + 427BF6811645BF1200BC3809 /* libturbojpeg.a */, + 427BF6B11645C08600BC3809 /* libsimd-arm.a */, + ); + name = Products; + sourceTree = ""; + }; + 427BF5F91645BD0000BC3809 /* libjpeg */ = { + isa = PBXGroup; + children = ( + 423730031646F7EC0022C8FB /* arithmetric_coding */, + 427BF6371645BD3C00BC3809 /* header */, + 427BF5FC1645BD3700BC3809 /* jcapimin.c */, + 427BF5FD1645BD3700BC3809 /* jcapistd.c */, + 427BF5FE1645BD3700BC3809 /* jccoefct.c */, + 427BF67A1645BE6000BC3809 /* jccolext.c */, + 427BF5FF1645BD3700BC3809 /* jccolor.c */, + 427BF6001645BD3700BC3809 /* jcdctmgr.c */, + 427BF6011645BD3700BC3809 /* jchuff.c */, + 427BF6031645BD3700BC3809 /* jcinit.c */, + 427BF6041645BD3700BC3809 /* jcmainct.c */, + 427BF6051645BD3700BC3809 /* jcmarker.c */, + 427BF6061645BD3700BC3809 /* jcmaster.c */, + 427BF6071645BD3700BC3809 /* jcomapi.c */, + 427BF6081645BD3700BC3809 /* jcparam.c */, + 427BF6091645BD3700BC3809 /* jcphuff.c */, + 427BF60A1645BD3700BC3809 /* jcprepct.c */, + 427BF60B1645BD3700BC3809 /* jcsample.c */, + 427BF60C1645BD3700BC3809 /* jctrans.c */, + 427BF60D1645BD3700BC3809 /* jdapimin.c */, + 427BF60E1645BD3700BC3809 /* jdapistd.c */, + 427BF60F1645BD3700BC3809 /* jdatadst.c */, + 427BF6101645BD3700BC3809 /* jdatasrc.c */, + 427BF6111645BD3700BC3809 /* jdcoefct.c */, + 427BF67B1645BE8500BC3809 /* jdcolext.c */, + 427BF6121645BD3700BC3809 /* jdcolor.c */, + 427BF6141645BD3700BC3809 /* jddctmgr.c */, + 427BF6151645BD3700BC3809 /* jdhuff.c */, + 427BF6171645BD3700BC3809 /* jdinput.c */, + 427BF6181645BD3700BC3809 /* jdmainct.c */, + 427BF6191645BD3700BC3809 /* jdmarker.c */, + 427BF61A1645BD3700BC3809 /* jdmaster.c */, + 427BF61B1645BD3700BC3809 /* jdmerge.c */, + 427BF67C1645BEAA00BC3809 /* jdmrgext.c */, + 427BF61C1645BD3700BC3809 /* jdphuff.c */, + 427BF61D1645BD3700BC3809 /* jdpostct.c */, + 427BF61E1645BD3700BC3809 /* jdsample.c */, + 427BF61F1645BD3700BC3809 /* jdtrans.c */, + 427BF6201645BD3700BC3809 /* jerror.c */, + 427BF6221645BD3700BC3809 /* jfdctflt.c */, + 427BF6231645BD3700BC3809 /* jfdctfst.c */, + 427BF6241645BD3700BC3809 /* jfdctint.c */, + 427BF6251645BD3700BC3809 /* jidctflt.c */, + 427BF6261645BD3700BC3809 /* jidctfst.c */, + 427BF6271645BD3700BC3809 /* jidctint.c */, + 427BF6281645BD3700BC3809 /* jidctred.c */, + 427BF62A1645BD3700BC3809 /* jmemmgr.c */, + 427BF62B1645BD3700BC3809 /* jmemnobs.c */, + 427BF6311645BD3700BC3809 /* jquant1.c */, + 427BF6321645BD3700BC3809 /* jquant2.c */, + 427BF6351645BD3700BC3809 /* jutils.c */, + ); + name = libjpeg; + sourceTree = ""; + }; + 427BF5FA1645BD0B00BC3809 /* libturbojpeg */ = { + isa = PBXGroup; + children = ( + 427BF69A1645BF4C00BC3809 /* headers */, + 427BF6901645BF4800BC3809 /* jdatadst-tj.c */, + 427BF6911645BF4800BC3809 /* jdatasrc-tj.c */, + 427BF6921645BF4800BC3809 /* transupp.c */, + 427BF6941645BF4800BC3809 /* turbojpeg.c */, + 427BF5F91645BD0000BC3809 /* libjpeg */, + 427BF5FB1645BD1B00BC3809 /* simd */, + ); + name = libturbojpeg; + sourceTree = ""; + }; + 427BF5FB1645BD1B00BC3809 /* simd */ = { + isa = PBXGroup; + children = ( + 427BF6D61645D0DA00BC3809 /* i386 */, + 427BF6BD1645C0D100BC3809 /* arm */, + ); + name = simd; + sourceTree = ""; + }; + 427BF6371645BD3C00BC3809 /* header */ = { + isa = PBXGroup; + children = ( + 427BF6791645BE2E00BC3809 /* config.h */, + 427BF6781645BE0200BC3809 /* jconfig.h */, + 427BF6021645BD3700BC3809 /* jchuff.h */, + 427BF6131645BD3700BC3809 /* jdct.h */, + 427BF6161645BD3700BC3809 /* jdhuff.h */, + 427BF6211645BD3700BC3809 /* jerror.h */, + 427BF6291645BD3700BC3809 /* jinclude.h */, + 427BF62C1645BD3700BC3809 /* jmemsys.h */, + 427BF62D1645BD3700BC3809 /* jmorecfg.h */, + 427BF62E1645BD3700BC3809 /* jpegcomp.h */, + 427BF62F1645BD3700BC3809 /* jpegint.h */, + 427BF6301645BD3700BC3809 /* jpeglib.h */, + 427BF6331645BD3700BC3809 /* jsimd.h */, + 427BF6341645BD3700BC3809 /* jsimddct.h */, + 427BF6361645BD3700BC3809 /* jversion.h */, + ); + name = header; + sourceTree = ""; + }; + 427BF69A1645BF4C00BC3809 /* headers */ = { + isa = PBXGroup; + children = ( + 427BF69B1645BF7A00BC3809 /* jinclude.h */, + 427BF6931645BF4800BC3809 /* transupp.h */, + 427BF6951645BF4800BC3809 /* turbojpeg.h */, + 427BF69C1645BFE000BC3809 /* tjutil.h */, + ); + name = headers; + sourceTree = ""; + }; + 427BF6BD1645C0D100BC3809 /* arm */ = { + isa = PBXGroup; + children = ( + 427BF6CE1645C1E900BC3809 /* jsimd_arm_neon.S */, + 427BF6CF1645C1E900BC3809 /* jsimd_arm.c */, + 427BF6C51645C18400BC3809 /* headers */, + ); + name = arm; + sourceTree = ""; + }; + 427BF6C51645C18400BC3809 /* headers */ = { + isa = PBXGroup; + children = ( + 427BF6CC1645C1DB00BC3809 /* jsimd.h */, + 427BF6CD1645C1DB00BC3809 /* jsimddct.h */, + ); + name = headers; + sourceTree = ""; + }; + 427BF6D61645D0DA00BC3809 /* i386 */ = { + isa = PBXGroup; + children = ( + 427BF6D81645D11E00BC3809 /* jcclrmmx.asm */, + 427BF6D91645D11E00BC3809 /* jcclrss2.asm */, + 427BF6DA1645D11E00BC3809 /* jccolmmx.asm */, + 427BF6DB1645D11E00BC3809 /* jccolss2.asm */, + 427BF6DC1645D11E00BC3809 /* jcgrammx.asm */, + 427BF6DD1645D11E00BC3809 /* jcgrass2.asm */, + 427BF6DE1645D11E00BC3809 /* jcgrymmx.asm */, + 427BF6DF1645D11E00BC3809 /* jcgryss2.asm */, + 427BF6E01645D11E00BC3809 /* jcolsamp.inc */, + 427BF6E11645D11E00BC3809 /* jcqnt3dn.asm */, + 427BF6E21645D11E00BC3809 /* jcqntmmx.asm */, + 427BF6E31645D11E00BC3809 /* jcqnts2f.asm */, + 427BF6E41645D11E00BC3809 /* jcqnts2i.asm */, + 427BF6E51645D11E00BC3809 /* jcqntsse.asm */, + 427BF6E61645D11E00BC3809 /* jcsammmx.asm */, + 427BF6E71645D11E00BC3809 /* jcsamss2.asm */, + 427BF6E81645D11E00BC3809 /* jdclrmmx.asm */, + 427BF6E91645D11E00BC3809 /* jdclrss2.asm */, + 427BF6EA1645D11E00BC3809 /* jdcolmmx.asm */, + 427BF6EB1645D11E00BC3809 /* jdcolss2.asm */, + 427BF6EC1645D11E00BC3809 /* jdct.inc */, + 427BF6ED1645D11E00BC3809 /* jdmermmx.asm */, + 427BF6EE1645D11E00BC3809 /* jdmerss2.asm */, + 427BF6EF1645D11E00BC3809 /* jdmrgmmx.asm */, + 427BF6F01645D11E00BC3809 /* jdmrgss2.asm */, + 427BF6F11645D11E00BC3809 /* jdsammmx.asm */, + 427BF6F21645D11E00BC3809 /* jdsamss2.asm */, + 427BF6F31645D11E00BC3809 /* jf3dnflt.asm */, + 427BF6F41645D11E00BC3809 /* jfmmxfst.asm */, + 427BF6F51645D11E00BC3809 /* jfmmxint.asm */, + 427BF6F61645D11E00BC3809 /* jfss2fst.asm */, + 427BF6F71645D11E00BC3809 /* jfss2int.asm */, + 427BF6F81645D11E00BC3809 /* jfsseflt.asm */, + 427BF6F91645D11E00BC3809 /* ji3dnflt.asm */, + 427BF6FA1645D11E00BC3809 /* jimmxfst.asm */, + 427BF6FB1645D11E00BC3809 /* jimmxint.asm */, + 427BF6FC1645D11E00BC3809 /* jimmxred.asm */, + 427BF6FD1645D11E00BC3809 /* jiss2flt.asm */, + 427BF6FE1645D11E00BC3809 /* jiss2fst.asm */, + 427BF6FF1645D11E00BC3809 /* jiss2int.asm */, + 427BF7001645D11E00BC3809 /* jiss2red.asm */, + 427BF7011645D11E00BC3809 /* jisseflt.asm */, + 427BF7021645D11E00BC3809 /* jsimd_i386.c */, + 427BF7031645D11E00BC3809 /* jsimd.h */, + 427BF7041645D11E00BC3809 /* jsimdcfg.inc.h */, + 427BF7051645D11E00BC3809 /* jsimdcpu.asm */, + 427BF7061645D11E00BC3809 /* jsimdext.inc */, + ); + name = i386; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 427BF63B1645BD8C00BC3809 /* jpeg */ = { + isa = PBXNativeTarget; + buildConfigurationList = 427BF6471645BD8C00BC3809 /* Build configuration list for PBXNativeTarget "jpeg" */; + buildPhases = ( + 427BF6381645BD8C00BC3809 /* Sources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = jpeg; + productName = libjpeg; + productReference = 427BF63C1645BD8C00BC3809 /* libjpeg.a */; + productType = "com.apple.product-type.library.static"; + }; + 427BF6801645BF1200BC3809 /* turbojpeg */ = { + isa = PBXNativeTarget; + buildConfigurationList = 427BF68A1645BF1200BC3809 /* Build configuration list for PBXNativeTarget "turbojpeg" */; + buildPhases = ( + 427BF67D1645BF1200BC3809 /* Sources */, + 427BF67E1645BF1200BC3809 /* Frameworks */, + 427BF7451645DAF900BC3809 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 427BF6D41645D0B400BC3809 /* PBXTargetDependency */, + 427BF68E1645BF3600BC3809 /* PBXTargetDependency */, + ); + name = turbojpeg; + productName = libturbojpeg; + productReference = 427BF6811645BF1200BC3809 /* libturbojpeg.a */; + productType = "com.apple.product-type.library.static"; + }; + 427BF6B01645C08600BC3809 /* simd-arm */ = { + isa = PBXNativeTarget; + buildConfigurationList = 427BF6BA1645C08600BC3809 /* Build configuration list for PBXNativeTarget "simd-arm" */; + buildPhases = ( + 427BF6AD1645C08600BC3809 /* Sources */, + ); + buildRules = ( + 427BF7581645E0BF00BC3809 /* PBXBuildRule */, + ); + dependencies = ( + ); + name = "simd-arm"; + productName = "simd-arm"; + productReference = 427BF6B11645C08600BC3809 /* libsimd-arm.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 427BF5DF1645B6F400BC3809 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0450; + ORGANIZATIONNAME = "Johannes Schriewer"; + }; + buildConfigurationList = 427BF5E21645B6F400BC3809 /* Build configuration list for PBXProject "libjpeg-turbo-ios" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 427BF5DD1645B6F400BC3809; + productRefGroup = 427BF5E91645B6F400BC3809 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 427BF63B1645BD8C00BC3809 /* jpeg */, + 427BF6801645BF1200BC3809 /* turbojpeg */, + 427BF6B01645C08600BC3809 /* simd-arm */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXShellScriptBuildPhase section */ + 427BF7451645DAF900BC3809 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "$(TARGET_BUILD_DIR)/libturbojpeg.a", + ); + outputPaths = ( + "$(SRCROOT)/lib/libturbojpeg-arm.a", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "mkdir -p \"$(dirname \"$SCRIPT_INPUT_FILE_0\")/lib\"\ncp \"$SCRIPT_INPUT_FILE_0\" \"$SCRIPT_OUTPUT_FILE_0\""; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 427BF6381645BD8C00BC3809 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 427BF64A1645BDA500BC3809 /* jcapimin.c in Sources */, + 427BF64B1645BDA500BC3809 /* jcapistd.c in Sources */, + 427BF64C1645BDA500BC3809 /* jccoefct.c in Sources */, + 427BF64D1645BDA500BC3809 /* jccolor.c in Sources */, + 427BF64E1645BDA500BC3809 /* jcdctmgr.c in Sources */, + 427BF64F1645BDA500BC3809 /* jchuff.c in Sources */, + 427BF6501645BDA500BC3809 /* jcinit.c in Sources */, + 427BF6511645BDA500BC3809 /* jcmainct.c in Sources */, + 427BF6521645BDA500BC3809 /* jcmarker.c in Sources */, + 427BF6531645BDA500BC3809 /* jcmaster.c in Sources */, + 427BF6541645BDA500BC3809 /* jcomapi.c in Sources */, + 427BF6551645BDA500BC3809 /* jcparam.c in Sources */, + 427BF6561645BDA500BC3809 /* jcphuff.c in Sources */, + 427BF6571645BDA500BC3809 /* jcprepct.c in Sources */, + 427BF6581645BDA500BC3809 /* jcsample.c in Sources */, + 427BF6591645BDA500BC3809 /* jctrans.c in Sources */, + 427BF65A1645BDA500BC3809 /* jdapimin.c in Sources */, + 427BF65B1645BDA500BC3809 /* jdapistd.c in Sources */, + 427BF65C1645BDA500BC3809 /* jdatadst.c in Sources */, + 427BF65D1645BDA500BC3809 /* jdatasrc.c in Sources */, + 427BF65E1645BDA500BC3809 /* jdcoefct.c in Sources */, + 427BF65F1645BDA500BC3809 /* jdcolor.c in Sources */, + 427BF6601645BDA500BC3809 /* jddctmgr.c in Sources */, + 427BF6611645BDA500BC3809 /* jdhuff.c in Sources */, + 427BF6621645BDA500BC3809 /* jdinput.c in Sources */, + 427BF6631645BDA500BC3809 /* jdmainct.c in Sources */, + 427BF6641645BDA500BC3809 /* jdmarker.c in Sources */, + 427BF6651645BDA500BC3809 /* jdmaster.c in Sources */, + 427BF6661645BDA500BC3809 /* jdmerge.c in Sources */, + 427BF6671645BDA500BC3809 /* jdphuff.c in Sources */, + 427BF6681645BDA500BC3809 /* jdpostct.c in Sources */, + 427BF6691645BDA500BC3809 /* jdsample.c in Sources */, + 427BF66A1645BDA500BC3809 /* jdtrans.c in Sources */, + 427BF66B1645BDA500BC3809 /* jerror.c in Sources */, + 427BF66C1645BDA500BC3809 /* jfdctflt.c in Sources */, + 427BF66D1645BDA500BC3809 /* jfdctfst.c in Sources */, + 427BF66E1645BDA500BC3809 /* jfdctint.c in Sources */, + 427BF66F1645BDA500BC3809 /* jidctflt.c in Sources */, + 427BF6701645BDA500BC3809 /* jidctfst.c in Sources */, + 427BF6711645BDA500BC3809 /* jidctint.c in Sources */, + 427BF6721645BDA500BC3809 /* jidctred.c in Sources */, + 427BF6731645BDA500BC3809 /* jmemmgr.c in Sources */, + 427BF6741645BDA500BC3809 /* jmemnobs.c in Sources */, + 427BF6751645BDA500BC3809 /* jquant1.c in Sources */, + 427BF6761645BDA500BC3809 /* jquant2.c in Sources */, + 427BF6771645BDA500BC3809 /* jutils.c in Sources */, + 423730081646F7F90022C8FB /* jaricom.c in Sources */, + 423730091646F7F90022C8FB /* jcarith.c in Sources */, + 4237300A1646F7F90022C8FB /* jdarith.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 427BF67D1645BF1200BC3809 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 427BF6961645BF4800BC3809 /* jdatadst-tj.c in Sources */, + 427BF6971645BF4800BC3809 /* jdatasrc-tj.c in Sources */, + 427BF6981645BF4800BC3809 /* transupp.c in Sources */, + 427BF6991645BF4800BC3809 /* turbojpeg.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 427BF6AD1645C08600BC3809 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 427BF6D11645C1E900BC3809 /* jsimd_arm.c in Sources */, + 427BF7591645E10800BC3809 /* jsimd_arm_neon.S in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 427BF68E1645BF3600BC3809 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 427BF63B1645BD8C00BC3809 /* jpeg */; + targetProxy = 427BF68D1645BF3600BC3809 /* PBXContainerItemProxy */; + }; + 427BF6D41645D0B400BC3809 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 427BF6B01645C08600BC3809 /* simd-arm */; + targetProxy = 427BF6D31645D0B400BC3809 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 427BF5F41645B6F400BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_UNROLL_LOOPS = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + ONLY_ACTIVE_ARCH = NO; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 427BF5F51645B6F400BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_UNROLL_LOOPS = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 427BF6481645BD8C00BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + armv7, + armv7s, + ); + DSTROOT = /tmp/libjpeg.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 427BF6491645BD8C00BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + armv7, + armv7s, + ); + DSTROOT = /tmp/libjpeg.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 427BF68B1645BF1200BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + armv7, + armv7s, + ); + DSTROOT = /tmp/libturbojpeg.dst; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/libturbojpeg\"", + "\"$(SRCROOT)/libjpeg\"", + ); + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 427BF68C1645BF1200BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + armv7, + armv7s, + ); + DSTROOT = /tmp/libturbojpeg.dst; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/libturbojpeg\"", + "\"$(SRCROOT)/libjpeg\"", + ); + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 427BF6BB1645C08600BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + armv7, + armv7s, + ); + DSTROOT = /tmp/simd_arm.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_WARN_UNINITIALIZED_AUTOS = NO; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/libturbojpeg", + "$(SRCROOT)/libjpeg", + ); + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 427BF6BC1645C08600BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + armv7, + armv7s, + ); + DSTROOT = /tmp/simd_arm.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_WARN_UNINITIALIZED_AUTOS = NO; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/libturbojpeg", + "$(SRCROOT)/libjpeg", + ); + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 427BF5E21645B6F400BC3809 /* Build configuration list for PBXProject "libjpeg-turbo-ios" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF5F41645B6F400BC3809 /* Debug */, + 427BF5F51645B6F400BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 427BF6471645BD8C00BC3809 /* Build configuration list for PBXNativeTarget "jpeg" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF6481645BD8C00BC3809 /* Debug */, + 427BF6491645BD8C00BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 427BF68A1645BF1200BC3809 /* Build configuration list for PBXNativeTarget "turbojpeg" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF68B1645BF1200BC3809 /* Debug */, + 427BF68C1645BF1200BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 427BF6BA1645C08600BC3809 /* Build configuration list for PBXNativeTarget "simd-arm" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF6BB1645C08600BC3809 /* Debug */, + 427BF6BC1645C08600BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 427BF5DF1645B6F400BC3809 /* Project object */; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg-turbo-simulator.xcodeproj/project.pbxproj b/lib-third-party/libturbojpeg-ios/libjpeg-turbo-simulator.xcodeproj/project.pbxproj new file mode 100755 index 0000000..783985a --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg-turbo-simulator.xcodeproj/project.pbxproj @@ -0,0 +1,826 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 42372FFD1646F7C90022C8FB /* jaricom.c in Sources */ = {isa = PBXBuildFile; fileRef = 42372FFA1646F7C90022C8FB /* jaricom.c */; }; + 42372FFE1646F7C90022C8FB /* jcarith.c in Sources */ = {isa = PBXBuildFile; fileRef = 42372FFB1646F7C90022C8FB /* jcarith.c */; }; + 42372FFF1646F7C90022C8FB /* jdarith.c in Sources */ = {isa = PBXBuildFile; fileRef = 42372FFC1646F7C90022C8FB /* jdarith.c */; }; + 427BF64A1645BDA500BC3809 /* jcapimin.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FC1645BD3700BC3809 /* jcapimin.c */; }; + 427BF64B1645BDA500BC3809 /* jcapistd.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FD1645BD3700BC3809 /* jcapistd.c */; }; + 427BF64C1645BDA500BC3809 /* jccoefct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FE1645BD3700BC3809 /* jccoefct.c */; }; + 427BF64D1645BDA500BC3809 /* jccolor.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF5FF1645BD3700BC3809 /* jccolor.c */; }; + 427BF64E1645BDA500BC3809 /* jcdctmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6001645BD3700BC3809 /* jcdctmgr.c */; }; + 427BF64F1645BDA500BC3809 /* jchuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6011645BD3700BC3809 /* jchuff.c */; }; + 427BF6501645BDA500BC3809 /* jcinit.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6031645BD3700BC3809 /* jcinit.c */; }; + 427BF6511645BDA500BC3809 /* jcmainct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6041645BD3700BC3809 /* jcmainct.c */; }; + 427BF6521645BDA500BC3809 /* jcmarker.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6051645BD3700BC3809 /* jcmarker.c */; }; + 427BF6531645BDA500BC3809 /* jcmaster.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6061645BD3700BC3809 /* jcmaster.c */; }; + 427BF6541645BDA500BC3809 /* jcomapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6071645BD3700BC3809 /* jcomapi.c */; }; + 427BF6551645BDA500BC3809 /* jcparam.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6081645BD3700BC3809 /* jcparam.c */; }; + 427BF6561645BDA500BC3809 /* jcphuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6091645BD3700BC3809 /* jcphuff.c */; }; + 427BF6571645BDA500BC3809 /* jcprepct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60A1645BD3700BC3809 /* jcprepct.c */; }; + 427BF6581645BDA500BC3809 /* jcsample.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60B1645BD3700BC3809 /* jcsample.c */; }; + 427BF6591645BDA500BC3809 /* jctrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60C1645BD3700BC3809 /* jctrans.c */; }; + 427BF65A1645BDA500BC3809 /* jdapimin.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60D1645BD3700BC3809 /* jdapimin.c */; }; + 427BF65B1645BDA500BC3809 /* jdapistd.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60E1645BD3700BC3809 /* jdapistd.c */; }; + 427BF65C1645BDA500BC3809 /* jdatadst.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF60F1645BD3700BC3809 /* jdatadst.c */; }; + 427BF65D1645BDA500BC3809 /* jdatasrc.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6101645BD3700BC3809 /* jdatasrc.c */; }; + 427BF65E1645BDA500BC3809 /* jdcoefct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6111645BD3700BC3809 /* jdcoefct.c */; }; + 427BF65F1645BDA500BC3809 /* jdcolor.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6121645BD3700BC3809 /* jdcolor.c */; }; + 427BF6601645BDA500BC3809 /* jddctmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6141645BD3700BC3809 /* jddctmgr.c */; }; + 427BF6611645BDA500BC3809 /* jdhuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6151645BD3700BC3809 /* jdhuff.c */; }; + 427BF6621645BDA500BC3809 /* jdinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6171645BD3700BC3809 /* jdinput.c */; }; + 427BF6631645BDA500BC3809 /* jdmainct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6181645BD3700BC3809 /* jdmainct.c */; }; + 427BF6641645BDA500BC3809 /* jdmarker.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6191645BD3700BC3809 /* jdmarker.c */; }; + 427BF6651645BDA500BC3809 /* jdmaster.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61A1645BD3700BC3809 /* jdmaster.c */; }; + 427BF6661645BDA500BC3809 /* jdmerge.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61B1645BD3700BC3809 /* jdmerge.c */; }; + 427BF6671645BDA500BC3809 /* jdphuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61C1645BD3700BC3809 /* jdphuff.c */; }; + 427BF6681645BDA500BC3809 /* jdpostct.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61D1645BD3700BC3809 /* jdpostct.c */; }; + 427BF6691645BDA500BC3809 /* jdsample.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61E1645BD3700BC3809 /* jdsample.c */; }; + 427BF66A1645BDA500BC3809 /* jdtrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF61F1645BD3700BC3809 /* jdtrans.c */; }; + 427BF66B1645BDA500BC3809 /* jerror.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6201645BD3700BC3809 /* jerror.c */; }; + 427BF66C1645BDA500BC3809 /* jfdctflt.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6221645BD3700BC3809 /* jfdctflt.c */; }; + 427BF66D1645BDA500BC3809 /* jfdctfst.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6231645BD3700BC3809 /* jfdctfst.c */; }; + 427BF66E1645BDA500BC3809 /* jfdctint.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6241645BD3700BC3809 /* jfdctint.c */; }; + 427BF66F1645BDA500BC3809 /* jidctflt.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6251645BD3700BC3809 /* jidctflt.c */; }; + 427BF6701645BDA500BC3809 /* jidctfst.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6261645BD3700BC3809 /* jidctfst.c */; }; + 427BF6711645BDA500BC3809 /* jidctint.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6271645BD3700BC3809 /* jidctint.c */; }; + 427BF6721645BDA500BC3809 /* jidctred.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6281645BD3700BC3809 /* jidctred.c */; }; + 427BF6731645BDA500BC3809 /* jmemmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF62A1645BD3700BC3809 /* jmemmgr.c */; }; + 427BF6741645BDA500BC3809 /* jmemnobs.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF62B1645BD3700BC3809 /* jmemnobs.c */; }; + 427BF6751645BDA500BC3809 /* jquant1.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6311645BD3700BC3809 /* jquant1.c */; }; + 427BF6761645BDA500BC3809 /* jquant2.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6321645BD3700BC3809 /* jquant2.c */; }; + 427BF6771645BDA500BC3809 /* jutils.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6351645BD3700BC3809 /* jutils.c */; }; + 427BF68F1645BF3A00BC3809 /* libjpeg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 427BF63C1645BD8C00BC3809 /* libjpeg.a */; }; + 427BF6961645BF4800BC3809 /* jdatadst-tj.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6901645BF4800BC3809 /* jdatadst-tj.c */; }; + 427BF6971645BF4800BC3809 /* jdatasrc-tj.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6911645BF4800BC3809 /* jdatasrc-tj.c */; }; + 427BF6981645BF4800BC3809 /* transupp.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6921645BF4800BC3809 /* transupp.c */; }; + 427BF6991645BF4800BC3809 /* turbojpeg.c in Sources */ = {isa = PBXBuildFile; fileRef = 427BF6941645BF4800BC3809 /* turbojpeg.c */; }; + 427BF73B1645D62300BC3809 /* libsimd-i386.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 427BF6A11645C04700BC3809 /* libsimd-i386.a */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 427BF68D1645BF3600BC3809 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 427BF5DF1645B6F400BC3809 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 427BF63B1645BD8C00BC3809; + remoteInfo = libjpeg; + }; + 427BF7391645D62000BC3809 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 427BF5DF1645B6F400BC3809 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 427BF6A01645C04700BC3809; + remoteInfo = "simd-i386"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 42372FFA1646F7C90022C8FB /* jaricom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jaricom.c; path = libjpeg/arithmetric_coding/jaricom.c; sourceTree = ""; }; + 42372FFB1646F7C90022C8FB /* jcarith.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcarith.c; path = libjpeg/arithmetric_coding/jcarith.c; sourceTree = ""; }; + 42372FFC1646F7C90022C8FB /* jdarith.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdarith.c; path = libjpeg/arithmetric_coding/jdarith.c; sourceTree = ""; }; + 427BF5FC1645BD3700BC3809 /* jcapimin.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcapimin.c; path = libjpeg/jcapimin.c; sourceTree = ""; }; + 427BF5FD1645BD3700BC3809 /* jcapistd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcapistd.c; path = libjpeg/jcapistd.c; sourceTree = ""; }; + 427BF5FE1645BD3700BC3809 /* jccoefct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jccoefct.c; path = libjpeg/jccoefct.c; sourceTree = ""; }; + 427BF5FF1645BD3700BC3809 /* jccolor.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jccolor.c; path = libjpeg/jccolor.c; sourceTree = ""; }; + 427BF6001645BD3700BC3809 /* jcdctmgr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcdctmgr.c; path = libjpeg/jcdctmgr.c; sourceTree = ""; }; + 427BF6011645BD3700BC3809 /* jchuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jchuff.c; path = libjpeg/jchuff.c; sourceTree = ""; }; + 427BF6021645BD3700BC3809 /* jchuff.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jchuff.h; path = libjpeg/jchuff.h; sourceTree = ""; }; + 427BF6031645BD3700BC3809 /* jcinit.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcinit.c; path = libjpeg/jcinit.c; sourceTree = ""; }; + 427BF6041645BD3700BC3809 /* jcmainct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcmainct.c; path = libjpeg/jcmainct.c; sourceTree = ""; }; + 427BF6051645BD3700BC3809 /* jcmarker.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcmarker.c; path = libjpeg/jcmarker.c; sourceTree = ""; }; + 427BF6061645BD3700BC3809 /* jcmaster.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcmaster.c; path = libjpeg/jcmaster.c; sourceTree = ""; }; + 427BF6071645BD3700BC3809 /* jcomapi.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcomapi.c; path = libjpeg/jcomapi.c; sourceTree = ""; }; + 427BF6081645BD3700BC3809 /* jcparam.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcparam.c; path = libjpeg/jcparam.c; sourceTree = ""; }; + 427BF6091645BD3700BC3809 /* jcphuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcphuff.c; path = libjpeg/jcphuff.c; sourceTree = ""; }; + 427BF60A1645BD3700BC3809 /* jcprepct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcprepct.c; path = libjpeg/jcprepct.c; sourceTree = ""; }; + 427BF60B1645BD3700BC3809 /* jcsample.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jcsample.c; path = libjpeg/jcsample.c; sourceTree = ""; }; + 427BF60C1645BD3700BC3809 /* jctrans.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jctrans.c; path = libjpeg/jctrans.c; sourceTree = ""; }; + 427BF60D1645BD3700BC3809 /* jdapimin.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdapimin.c; path = libjpeg/jdapimin.c; sourceTree = ""; }; + 427BF60E1645BD3700BC3809 /* jdapistd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdapistd.c; path = libjpeg/jdapistd.c; sourceTree = ""; }; + 427BF60F1645BD3700BC3809 /* jdatadst.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdatadst.c; path = libjpeg/jdatadst.c; sourceTree = ""; }; + 427BF6101645BD3700BC3809 /* jdatasrc.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdatasrc.c; path = libjpeg/jdatasrc.c; sourceTree = ""; }; + 427BF6111645BD3700BC3809 /* jdcoefct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdcoefct.c; path = libjpeg/jdcoefct.c; sourceTree = ""; }; + 427BF6121645BD3700BC3809 /* jdcolor.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdcolor.c; path = libjpeg/jdcolor.c; sourceTree = ""; }; + 427BF6131645BD3700BC3809 /* jdct.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jdct.h; path = libjpeg/jdct.h; sourceTree = ""; }; + 427BF6141645BD3700BC3809 /* jddctmgr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jddctmgr.c; path = libjpeg/jddctmgr.c; sourceTree = ""; }; + 427BF6151645BD3700BC3809 /* jdhuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdhuff.c; path = libjpeg/jdhuff.c; sourceTree = ""; }; + 427BF6161645BD3700BC3809 /* jdhuff.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jdhuff.h; path = libjpeg/jdhuff.h; sourceTree = ""; }; + 427BF6171645BD3700BC3809 /* jdinput.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdinput.c; path = libjpeg/jdinput.c; sourceTree = ""; }; + 427BF6181645BD3700BC3809 /* jdmainct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmainct.c; path = libjpeg/jdmainct.c; sourceTree = ""; }; + 427BF6191645BD3700BC3809 /* jdmarker.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmarker.c; path = libjpeg/jdmarker.c; sourceTree = ""; }; + 427BF61A1645BD3700BC3809 /* jdmaster.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmaster.c; path = libjpeg/jdmaster.c; sourceTree = ""; }; + 427BF61B1645BD3700BC3809 /* jdmerge.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmerge.c; path = libjpeg/jdmerge.c; sourceTree = ""; }; + 427BF61C1645BD3700BC3809 /* jdphuff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdphuff.c; path = libjpeg/jdphuff.c; sourceTree = ""; }; + 427BF61D1645BD3700BC3809 /* jdpostct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdpostct.c; path = libjpeg/jdpostct.c; sourceTree = ""; }; + 427BF61E1645BD3700BC3809 /* jdsample.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdsample.c; path = libjpeg/jdsample.c; sourceTree = ""; }; + 427BF61F1645BD3700BC3809 /* jdtrans.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdtrans.c; path = libjpeg/jdtrans.c; sourceTree = ""; }; + 427BF6201645BD3700BC3809 /* jerror.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jerror.c; path = libjpeg/jerror.c; sourceTree = ""; }; + 427BF6211645BD3700BC3809 /* jerror.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jerror.h; path = libjpeg/jerror.h; sourceTree = ""; }; + 427BF6221645BD3700BC3809 /* jfdctflt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jfdctflt.c; path = libjpeg/jfdctflt.c; sourceTree = ""; }; + 427BF6231645BD3700BC3809 /* jfdctfst.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jfdctfst.c; path = libjpeg/jfdctfst.c; sourceTree = ""; }; + 427BF6241645BD3700BC3809 /* jfdctint.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jfdctint.c; path = libjpeg/jfdctint.c; sourceTree = ""; }; + 427BF6251645BD3700BC3809 /* jidctflt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctflt.c; path = libjpeg/jidctflt.c; sourceTree = ""; }; + 427BF6261645BD3700BC3809 /* jidctfst.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctfst.c; path = libjpeg/jidctfst.c; sourceTree = ""; }; + 427BF6271645BD3700BC3809 /* jidctint.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctint.c; path = libjpeg/jidctint.c; sourceTree = ""; }; + 427BF6281645BD3700BC3809 /* jidctred.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jidctred.c; path = libjpeg/jidctred.c; sourceTree = ""; }; + 427BF6291645BD3700BC3809 /* jinclude.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jinclude.h; path = libjpeg/jinclude.h; sourceTree = ""; }; + 427BF62A1645BD3700BC3809 /* jmemmgr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jmemmgr.c; path = libjpeg/jmemmgr.c; sourceTree = ""; }; + 427BF62B1645BD3700BC3809 /* jmemnobs.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jmemnobs.c; path = libjpeg/jmemnobs.c; sourceTree = ""; }; + 427BF62C1645BD3700BC3809 /* jmemsys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jmemsys.h; path = libjpeg/jmemsys.h; sourceTree = ""; }; + 427BF62D1645BD3700BC3809 /* jmorecfg.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jmorecfg.h; path = libjpeg/jmorecfg.h; sourceTree = ""; }; + 427BF62E1645BD3700BC3809 /* jpegcomp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jpegcomp.h; path = libjpeg/jpegcomp.h; sourceTree = ""; }; + 427BF62F1645BD3700BC3809 /* jpegint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jpegint.h; path = libjpeg/jpegint.h; sourceTree = ""; }; + 427BF6301645BD3700BC3809 /* jpeglib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jpeglib.h; path = libjpeg/jpeglib.h; sourceTree = ""; }; + 427BF6311645BD3700BC3809 /* jquant1.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jquant1.c; path = libjpeg/jquant1.c; sourceTree = ""; }; + 427BF6321645BD3700BC3809 /* jquant2.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jquant2.c; path = libjpeg/jquant2.c; sourceTree = ""; }; + 427BF6331645BD3700BC3809 /* jsimd.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jsimd.h; path = libjpeg/jsimd.h; sourceTree = ""; }; + 427BF6341645BD3700BC3809 /* jsimddct.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jsimddct.h; path = libjpeg/jsimddct.h; sourceTree = ""; }; + 427BF6351645BD3700BC3809 /* jutils.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jutils.c; path = libjpeg/jutils.c; sourceTree = ""; }; + 427BF6361645BD3700BC3809 /* jversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = jversion.h; path = libjpeg/jversion.h; sourceTree = ""; }; + 427BF63C1645BD8C00BC3809 /* libjpeg.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libjpeg.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 427BF6781645BE0200BC3809 /* jconfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jconfig.h; path = libjpeg/jconfig.h; sourceTree = ""; }; + 427BF6791645BE2E00BC3809 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = config.h; path = libjpeg/config.h; sourceTree = ""; }; + 427BF67A1645BE6000BC3809 /* jccolext.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jccolext.c; path = libjpeg/jccolext.c; sourceTree = ""; }; + 427BF67B1645BE8500BC3809 /* jdcolext.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdcolext.c; path = libjpeg/jdcolext.c; sourceTree = ""; }; + 427BF67C1645BEAA00BC3809 /* jdmrgext.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = jdmrgext.c; path = libjpeg/jdmrgext.c; sourceTree = ""; }; + 427BF6811645BF1200BC3809 /* libturbojpeg.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libturbojpeg.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 427BF6901645BF4800BC3809 /* jdatadst-tj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "jdatadst-tj.c"; path = "libturbojpeg/jdatadst-tj.c"; sourceTree = ""; }; + 427BF6911645BF4800BC3809 /* jdatasrc-tj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "jdatasrc-tj.c"; path = "libturbojpeg/jdatasrc-tj.c"; sourceTree = ""; }; + 427BF6921645BF4800BC3809 /* transupp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = transupp.c; path = libturbojpeg/transupp.c; sourceTree = ""; }; + 427BF6931645BF4800BC3809 /* transupp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = transupp.h; path = libturbojpeg/transupp.h; sourceTree = ""; }; + 427BF6941645BF4800BC3809 /* turbojpeg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = turbojpeg.c; path = libturbojpeg/turbojpeg.c; sourceTree = ""; }; + 427BF6951645BF4800BC3809 /* turbojpeg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = turbojpeg.h; path = libturbojpeg/turbojpeg.h; sourceTree = ""; }; + 427BF69B1645BF7A00BC3809 /* jinclude.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jinclude.h; path = libturbojpeg/jinclude.h; sourceTree = ""; }; + 427BF69C1645BFE000BC3809 /* tjutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tjutil.h; path = libturbojpeg/tjutil.h; sourceTree = ""; }; + 427BF6A11645C04700BC3809 /* libsimd-i386.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libsimd-i386.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 427BF6CC1645C1DB00BC3809 /* jsimd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimd.h; path = libturbojpeg/jsimd.h; sourceTree = ""; }; + 427BF6CD1645C1DB00BC3809 /* jsimddct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimddct.h; path = libturbojpeg/jsimddct.h; sourceTree = ""; }; + 427BF6CE1645C1E900BC3809 /* jsimd_arm_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; name = jsimd_arm_neon.S; path = "libturbojpeg/simd-arm/jsimd_arm_neon.S"; sourceTree = ""; }; + 427BF6CF1645C1E900BC3809 /* jsimd_arm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jsimd_arm.c; path = "libturbojpeg/simd-arm/jsimd_arm.c"; sourceTree = ""; }; + 427BF6D81645D11E00BC3809 /* jcclrmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcclrmmx.asm; path = "libturbojpeg/simd-i386/jcclrmmx.asm"; sourceTree = ""; }; + 427BF6D91645D11E00BC3809 /* jcclrss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcclrss2.asm; path = "libturbojpeg/simd-i386/jcclrss2.asm"; sourceTree = ""; }; + 427BF6DA1645D11E00BC3809 /* jccolmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jccolmmx.asm; path = "libturbojpeg/simd-i386/jccolmmx.asm"; sourceTree = ""; }; + 427BF6DB1645D11E00BC3809 /* jccolss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jccolss2.asm; path = "libturbojpeg/simd-i386/jccolss2.asm"; sourceTree = ""; }; + 427BF6DC1645D11E00BC3809 /* jcgrammx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgrammx.asm; path = "libturbojpeg/simd-i386/jcgrammx.asm"; sourceTree = ""; }; + 427BF6DD1645D11E00BC3809 /* jcgrass2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgrass2.asm; path = "libturbojpeg/simd-i386/jcgrass2.asm"; sourceTree = ""; }; + 427BF6DE1645D11E00BC3809 /* jcgrymmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgrymmx.asm; path = "libturbojpeg/simd-i386/jcgrymmx.asm"; sourceTree = ""; }; + 427BF6DF1645D11E00BC3809 /* jcgryss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcgryss2.asm; path = "libturbojpeg/simd-i386/jcgryss2.asm"; sourceTree = ""; }; + 427BF6E01645D11E00BC3809 /* jcolsamp.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = jcolsamp.inc; path = "libturbojpeg/simd-i386/jcolsamp.inc"; sourceTree = ""; }; + 427BF6E11645D11E00BC3809 /* jcqnt3dn.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqnt3dn.asm; path = "libturbojpeg/simd-i386/jcqnt3dn.asm"; sourceTree = ""; }; + 427BF6E21645D11E00BC3809 /* jcqntmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqntmmx.asm; path = "libturbojpeg/simd-i386/jcqntmmx.asm"; sourceTree = ""; }; + 427BF6E31645D11E00BC3809 /* jcqnts2f.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqnts2f.asm; path = "libturbojpeg/simd-i386/jcqnts2f.asm"; sourceTree = ""; }; + 427BF6E41645D11E00BC3809 /* jcqnts2i.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqnts2i.asm; path = "libturbojpeg/simd-i386/jcqnts2i.asm"; sourceTree = ""; }; + 427BF6E51645D11E00BC3809 /* jcqntsse.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcqntsse.asm; path = "libturbojpeg/simd-i386/jcqntsse.asm"; sourceTree = ""; }; + 427BF6E61645D11E00BC3809 /* jcsammmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcsammmx.asm; path = "libturbojpeg/simd-i386/jcsammmx.asm"; sourceTree = ""; }; + 427BF6E71645D11E00BC3809 /* jcsamss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jcsamss2.asm; path = "libturbojpeg/simd-i386/jcsamss2.asm"; sourceTree = ""; }; + 427BF6E81645D11E00BC3809 /* jdclrmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdclrmmx.asm; path = "libturbojpeg/simd-i386/jdclrmmx.asm"; sourceTree = ""; }; + 427BF6E91645D11E00BC3809 /* jdclrss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdclrss2.asm; path = "libturbojpeg/simd-i386/jdclrss2.asm"; sourceTree = ""; }; + 427BF6EA1645D11E00BC3809 /* jdcolmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdcolmmx.asm; path = "libturbojpeg/simd-i386/jdcolmmx.asm"; sourceTree = ""; }; + 427BF6EB1645D11E00BC3809 /* jdcolss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdcolss2.asm; path = "libturbojpeg/simd-i386/jdcolss2.asm"; sourceTree = ""; }; + 427BF6EC1645D11E00BC3809 /* jdct.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = jdct.inc; path = "libturbojpeg/simd-i386/jdct.inc"; sourceTree = ""; }; + 427BF6ED1645D11E00BC3809 /* jdmermmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmermmx.asm; path = "libturbojpeg/simd-i386/jdmermmx.asm"; sourceTree = ""; }; + 427BF6EE1645D11E00BC3809 /* jdmerss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmerss2.asm; path = "libturbojpeg/simd-i386/jdmerss2.asm"; sourceTree = ""; }; + 427BF6EF1645D11E00BC3809 /* jdmrgmmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmrgmmx.asm; path = "libturbojpeg/simd-i386/jdmrgmmx.asm"; sourceTree = ""; }; + 427BF6F01645D11E00BC3809 /* jdmrgss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdmrgss2.asm; path = "libturbojpeg/simd-i386/jdmrgss2.asm"; sourceTree = ""; }; + 427BF6F11645D11E00BC3809 /* jdsammmx.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdsammmx.asm; path = "libturbojpeg/simd-i386/jdsammmx.asm"; sourceTree = ""; }; + 427BF6F21645D11E00BC3809 /* jdsamss2.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jdsamss2.asm; path = "libturbojpeg/simd-i386/jdsamss2.asm"; sourceTree = ""; }; + 427BF6F31645D11E00BC3809 /* jf3dnflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jf3dnflt.asm; path = "libturbojpeg/simd-i386/jf3dnflt.asm"; sourceTree = ""; }; + 427BF6F41645D11E00BC3809 /* jfmmxfst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfmmxfst.asm; path = "libturbojpeg/simd-i386/jfmmxfst.asm"; sourceTree = ""; }; + 427BF6F51645D11E00BC3809 /* jfmmxint.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfmmxint.asm; path = "libturbojpeg/simd-i386/jfmmxint.asm"; sourceTree = ""; }; + 427BF6F61645D11E00BC3809 /* jfss2fst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfss2fst.asm; path = "libturbojpeg/simd-i386/jfss2fst.asm"; sourceTree = ""; }; + 427BF6F71645D11E00BC3809 /* jfss2int.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfss2int.asm; path = "libturbojpeg/simd-i386/jfss2int.asm"; sourceTree = ""; }; + 427BF6F81645D11E00BC3809 /* jfsseflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jfsseflt.asm; path = "libturbojpeg/simd-i386/jfsseflt.asm"; sourceTree = ""; }; + 427BF6F91645D11E00BC3809 /* ji3dnflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = ji3dnflt.asm; path = "libturbojpeg/simd-i386/ji3dnflt.asm"; sourceTree = ""; }; + 427BF6FA1645D11E00BC3809 /* jimmxfst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jimmxfst.asm; path = "libturbojpeg/simd-i386/jimmxfst.asm"; sourceTree = ""; }; + 427BF6FB1645D11E00BC3809 /* jimmxint.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jimmxint.asm; path = "libturbojpeg/simd-i386/jimmxint.asm"; sourceTree = ""; }; + 427BF6FC1645D11E00BC3809 /* jimmxred.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jimmxred.asm; path = "libturbojpeg/simd-i386/jimmxred.asm"; sourceTree = ""; }; + 427BF6FD1645D11E00BC3809 /* jiss2flt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2flt.asm; path = "libturbojpeg/simd-i386/jiss2flt.asm"; sourceTree = ""; }; + 427BF6FE1645D11E00BC3809 /* jiss2fst.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2fst.asm; path = "libturbojpeg/simd-i386/jiss2fst.asm"; sourceTree = ""; }; + 427BF6FF1645D11E00BC3809 /* jiss2int.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2int.asm; path = "libturbojpeg/simd-i386/jiss2int.asm"; sourceTree = ""; }; + 427BF7001645D11E00BC3809 /* jiss2red.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jiss2red.asm; path = "libturbojpeg/simd-i386/jiss2red.asm"; sourceTree = ""; }; + 427BF7011645D11E00BC3809 /* jisseflt.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jisseflt.asm; path = "libturbojpeg/simd-i386/jisseflt.asm"; sourceTree = ""; }; + 427BF7021645D11E00BC3809 /* jsimd_i386.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jsimd_i386.c; path = "libturbojpeg/simd-i386/jsimd_i386.c"; sourceTree = ""; }; + 427BF7031645D11E00BC3809 /* jsimd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimd.h; path = "libturbojpeg/simd-i386/jsimd.h"; sourceTree = ""; }; + 427BF7041645D11E00BC3809 /* jsimdcfg.inc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsimdcfg.inc.h; path = "libturbojpeg/simd-i386/jsimdcfg.inc.h"; sourceTree = ""; }; + 427BF7051645D11E00BC3809 /* jsimdcpu.asm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm.asm; name = jsimdcpu.asm; path = "libturbojpeg/simd-i386/jsimdcpu.asm"; sourceTree = ""; }; + 427BF7061645D11E00BC3809 /* jsimdext.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = jsimdext.inc; path = "libturbojpeg/simd-i386/jsimdext.inc"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 427BF67E1645BF1200BC3809 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 427BF68F1645BF3A00BC3809 /* libjpeg.a in Frameworks */, + 427BF73B1645D62300BC3809 /* libsimd-i386.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 42372FF81646F7B40022C8FB /* arithmetric_coding */ = { + isa = PBXGroup; + children = ( + 42372FFA1646F7C90022C8FB /* jaricom.c */, + 42372FFB1646F7C90022C8FB /* jcarith.c */, + 42372FFC1646F7C90022C8FB /* jdarith.c */, + ); + name = arithmetric_coding; + sourceTree = ""; + }; + 427BF5DD1645B6F400BC3809 = { + isa = PBXGroup; + children = ( + 427BF5FA1645BD0B00BC3809 /* libturbojpeg */, + 427BF5E91645B6F400BC3809 /* Products */, + ); + sourceTree = ""; + }; + 427BF5E91645B6F400BC3809 /* Products */ = { + isa = PBXGroup; + children = ( + 427BF63C1645BD8C00BC3809 /* libjpeg.a */, + 427BF6811645BF1200BC3809 /* libturbojpeg.a */, + 427BF6A11645C04700BC3809 /* libsimd-i386.a */, + ); + name = Products; + sourceTree = ""; + }; + 427BF5F91645BD0000BC3809 /* libjpeg */ = { + isa = PBXGroup; + children = ( + 42372FF81646F7B40022C8FB /* arithmetric_coding */, + 427BF6371645BD3C00BC3809 /* header */, + 427BF5FC1645BD3700BC3809 /* jcapimin.c */, + 427BF5FD1645BD3700BC3809 /* jcapistd.c */, + 427BF5FE1645BD3700BC3809 /* jccoefct.c */, + 427BF67A1645BE6000BC3809 /* jccolext.c */, + 427BF5FF1645BD3700BC3809 /* jccolor.c */, + 427BF6001645BD3700BC3809 /* jcdctmgr.c */, + 427BF6011645BD3700BC3809 /* jchuff.c */, + 427BF6031645BD3700BC3809 /* jcinit.c */, + 427BF6041645BD3700BC3809 /* jcmainct.c */, + 427BF6051645BD3700BC3809 /* jcmarker.c */, + 427BF6061645BD3700BC3809 /* jcmaster.c */, + 427BF6071645BD3700BC3809 /* jcomapi.c */, + 427BF6081645BD3700BC3809 /* jcparam.c */, + 427BF6091645BD3700BC3809 /* jcphuff.c */, + 427BF60A1645BD3700BC3809 /* jcprepct.c */, + 427BF60B1645BD3700BC3809 /* jcsample.c */, + 427BF60C1645BD3700BC3809 /* jctrans.c */, + 427BF60D1645BD3700BC3809 /* jdapimin.c */, + 427BF60E1645BD3700BC3809 /* jdapistd.c */, + 427BF60F1645BD3700BC3809 /* jdatadst.c */, + 427BF6101645BD3700BC3809 /* jdatasrc.c */, + 427BF6111645BD3700BC3809 /* jdcoefct.c */, + 427BF67B1645BE8500BC3809 /* jdcolext.c */, + 427BF6121645BD3700BC3809 /* jdcolor.c */, + 427BF6141645BD3700BC3809 /* jddctmgr.c */, + 427BF6151645BD3700BC3809 /* jdhuff.c */, + 427BF6171645BD3700BC3809 /* jdinput.c */, + 427BF6181645BD3700BC3809 /* jdmainct.c */, + 427BF6191645BD3700BC3809 /* jdmarker.c */, + 427BF61A1645BD3700BC3809 /* jdmaster.c */, + 427BF61B1645BD3700BC3809 /* jdmerge.c */, + 427BF67C1645BEAA00BC3809 /* jdmrgext.c */, + 427BF61C1645BD3700BC3809 /* jdphuff.c */, + 427BF61D1645BD3700BC3809 /* jdpostct.c */, + 427BF61E1645BD3700BC3809 /* jdsample.c */, + 427BF61F1645BD3700BC3809 /* jdtrans.c */, + 427BF6201645BD3700BC3809 /* jerror.c */, + 427BF6221645BD3700BC3809 /* jfdctflt.c */, + 427BF6231645BD3700BC3809 /* jfdctfst.c */, + 427BF6241645BD3700BC3809 /* jfdctint.c */, + 427BF6251645BD3700BC3809 /* jidctflt.c */, + 427BF6261645BD3700BC3809 /* jidctfst.c */, + 427BF6271645BD3700BC3809 /* jidctint.c */, + 427BF6281645BD3700BC3809 /* jidctred.c */, + 427BF62A1645BD3700BC3809 /* jmemmgr.c */, + 427BF62B1645BD3700BC3809 /* jmemnobs.c */, + 427BF6311645BD3700BC3809 /* jquant1.c */, + 427BF6321645BD3700BC3809 /* jquant2.c */, + 427BF6351645BD3700BC3809 /* jutils.c */, + ); + name = libjpeg; + sourceTree = ""; + }; + 427BF5FA1645BD0B00BC3809 /* libturbojpeg */ = { + isa = PBXGroup; + children = ( + 427BF69A1645BF4C00BC3809 /* headers */, + 427BF6901645BF4800BC3809 /* jdatadst-tj.c */, + 427BF6911645BF4800BC3809 /* jdatasrc-tj.c */, + 427BF6921645BF4800BC3809 /* transupp.c */, + 427BF6941645BF4800BC3809 /* turbojpeg.c */, + 427BF5F91645BD0000BC3809 /* libjpeg */, + 427BF5FB1645BD1B00BC3809 /* simd */, + ); + name = libturbojpeg; + sourceTree = ""; + }; + 427BF5FB1645BD1B00BC3809 /* simd */ = { + isa = PBXGroup; + children = ( + 427BF6D61645D0DA00BC3809 /* i386 */, + 427BF6BD1645C0D100BC3809 /* arm */, + ); + name = simd; + sourceTree = ""; + }; + 427BF6371645BD3C00BC3809 /* header */ = { + isa = PBXGroup; + children = ( + 427BF6791645BE2E00BC3809 /* config.h */, + 427BF6781645BE0200BC3809 /* jconfig.h */, + 427BF6021645BD3700BC3809 /* jchuff.h */, + 427BF6131645BD3700BC3809 /* jdct.h */, + 427BF6161645BD3700BC3809 /* jdhuff.h */, + 427BF6211645BD3700BC3809 /* jerror.h */, + 427BF6291645BD3700BC3809 /* jinclude.h */, + 427BF62C1645BD3700BC3809 /* jmemsys.h */, + 427BF62D1645BD3700BC3809 /* jmorecfg.h */, + 427BF62E1645BD3700BC3809 /* jpegcomp.h */, + 427BF62F1645BD3700BC3809 /* jpegint.h */, + 427BF6301645BD3700BC3809 /* jpeglib.h */, + 427BF6331645BD3700BC3809 /* jsimd.h */, + 427BF6341645BD3700BC3809 /* jsimddct.h */, + 427BF6361645BD3700BC3809 /* jversion.h */, + ); + name = header; + sourceTree = ""; + }; + 427BF69A1645BF4C00BC3809 /* headers */ = { + isa = PBXGroup; + children = ( + 427BF69B1645BF7A00BC3809 /* jinclude.h */, + 427BF6931645BF4800BC3809 /* transupp.h */, + 427BF6951645BF4800BC3809 /* turbojpeg.h */, + 427BF69C1645BFE000BC3809 /* tjutil.h */, + ); + name = headers; + sourceTree = ""; + }; + 427BF6BD1645C0D100BC3809 /* arm */ = { + isa = PBXGroup; + children = ( + 427BF6CE1645C1E900BC3809 /* jsimd_arm_neon.S */, + 427BF6CF1645C1E900BC3809 /* jsimd_arm.c */, + 427BF6C51645C18400BC3809 /* headers */, + ); + name = arm; + sourceTree = ""; + }; + 427BF6C51645C18400BC3809 /* headers */ = { + isa = PBXGroup; + children = ( + 427BF6CC1645C1DB00BC3809 /* jsimd.h */, + 427BF6CD1645C1DB00BC3809 /* jsimddct.h */, + ); + name = headers; + sourceTree = ""; + }; + 427BF6D61645D0DA00BC3809 /* i386 */ = { + isa = PBXGroup; + children = ( + 427BF6D81645D11E00BC3809 /* jcclrmmx.asm */, + 427BF6D91645D11E00BC3809 /* jcclrss2.asm */, + 427BF6DA1645D11E00BC3809 /* jccolmmx.asm */, + 427BF6DB1645D11E00BC3809 /* jccolss2.asm */, + 427BF6DC1645D11E00BC3809 /* jcgrammx.asm */, + 427BF6DD1645D11E00BC3809 /* jcgrass2.asm */, + 427BF6DE1645D11E00BC3809 /* jcgrymmx.asm */, + 427BF6DF1645D11E00BC3809 /* jcgryss2.asm */, + 427BF6E01645D11E00BC3809 /* jcolsamp.inc */, + 427BF6E11645D11E00BC3809 /* jcqnt3dn.asm */, + 427BF6E21645D11E00BC3809 /* jcqntmmx.asm */, + 427BF6E31645D11E00BC3809 /* jcqnts2f.asm */, + 427BF6E41645D11E00BC3809 /* jcqnts2i.asm */, + 427BF6E51645D11E00BC3809 /* jcqntsse.asm */, + 427BF6E61645D11E00BC3809 /* jcsammmx.asm */, + 427BF6E71645D11E00BC3809 /* jcsamss2.asm */, + 427BF6E81645D11E00BC3809 /* jdclrmmx.asm */, + 427BF6E91645D11E00BC3809 /* jdclrss2.asm */, + 427BF6EA1645D11E00BC3809 /* jdcolmmx.asm */, + 427BF6EB1645D11E00BC3809 /* jdcolss2.asm */, + 427BF6EC1645D11E00BC3809 /* jdct.inc */, + 427BF6ED1645D11E00BC3809 /* jdmermmx.asm */, + 427BF6EE1645D11E00BC3809 /* jdmerss2.asm */, + 427BF6EF1645D11E00BC3809 /* jdmrgmmx.asm */, + 427BF6F01645D11E00BC3809 /* jdmrgss2.asm */, + 427BF6F11645D11E00BC3809 /* jdsammmx.asm */, + 427BF6F21645D11E00BC3809 /* jdsamss2.asm */, + 427BF6F31645D11E00BC3809 /* jf3dnflt.asm */, + 427BF6F41645D11E00BC3809 /* jfmmxfst.asm */, + 427BF6F51645D11E00BC3809 /* jfmmxint.asm */, + 427BF6F61645D11E00BC3809 /* jfss2fst.asm */, + 427BF6F71645D11E00BC3809 /* jfss2int.asm */, + 427BF6F81645D11E00BC3809 /* jfsseflt.asm */, + 427BF6F91645D11E00BC3809 /* ji3dnflt.asm */, + 427BF6FA1645D11E00BC3809 /* jimmxfst.asm */, + 427BF6FB1645D11E00BC3809 /* jimmxint.asm */, + 427BF6FC1645D11E00BC3809 /* jimmxred.asm */, + 427BF6FD1645D11E00BC3809 /* jiss2flt.asm */, + 427BF6FE1645D11E00BC3809 /* jiss2fst.asm */, + 427BF6FF1645D11E00BC3809 /* jiss2int.asm */, + 427BF7001645D11E00BC3809 /* jiss2red.asm */, + 427BF7011645D11E00BC3809 /* jisseflt.asm */, + 427BF7021645D11E00BC3809 /* jsimd_i386.c */, + 427BF7031645D11E00BC3809 /* jsimd.h */, + 427BF7041645D11E00BC3809 /* jsimdcfg.inc.h */, + 427BF7051645D11E00BC3809 /* jsimdcpu.asm */, + 427BF7061645D11E00BC3809 /* jsimdext.inc */, + ); + name = i386; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 427BF63B1645BD8C00BC3809 /* jpeg */ = { + isa = PBXNativeTarget; + buildConfigurationList = 427BF6471645BD8C00BC3809 /* Build configuration list for PBXNativeTarget "jpeg" */; + buildPhases = ( + 427BF6381645BD8C00BC3809 /* Sources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = jpeg; + productName = libjpeg; + productReference = 427BF63C1645BD8C00BC3809 /* libjpeg.a */; + productType = "com.apple.product-type.library.static"; + }; + 427BF6801645BF1200BC3809 /* turbojpeg */ = { + isa = PBXNativeTarget; + buildConfigurationList = 427BF68A1645BF1200BC3809 /* Build configuration list for PBXNativeTarget "turbojpeg" */; + buildPhases = ( + 427BF67D1645BF1200BC3809 /* Sources */, + 427BF67E1645BF1200BC3809 /* Frameworks */, + 427BF7571645DF4700BC3809 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 427BF73A1645D62000BC3809 /* PBXTargetDependency */, + 427BF68E1645BF3600BC3809 /* PBXTargetDependency */, + ); + name = turbojpeg; + productName = libturbojpeg; + productReference = 427BF6811645BF1200BC3809 /* libturbojpeg.a */; + productType = "com.apple.product-type.library.static"; + }; + 427BF6A01645C04700BC3809 /* simd-i386 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 427BF6AA1645C04700BC3809 /* Build configuration list for PBXNativeTarget "simd-i386" */; + buildPhases = ( + 420375E416469FCE00899EA2 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "simd-i386"; + productName = "simd-i386"; + productReference = 427BF6A11645C04700BC3809 /* libsimd-i386.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 427BF5DF1645B6F400BC3809 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0450; + ORGANIZATIONNAME = "Johannes Schriewer"; + }; + buildConfigurationList = 427BF5E21645B6F400BC3809 /* Build configuration list for PBXProject "libjpeg-turbo-simulator" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 427BF5DD1645B6F400BC3809; + productRefGroup = 427BF5E91645B6F400BC3809 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 427BF63B1645BD8C00BC3809 /* jpeg */, + 427BF6801645BF1200BC3809 /* turbojpeg */, + 427BF6A01645C04700BC3809 /* simd-i386 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXShellScriptBuildPhase section */ + 420375E416469FCE00899EA2 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "$(SRCROOT)/libturbojpeg/simd-i386/build/libsimd-i386.a", + ); + outputPaths = ( + "$(TARGET_BUILD_DIR)/libsimd-i386.a", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/bash; + shellScript = "cd \"$SRCROOT/libturbojpeg/simd-i386\"\nmake clean\nmake\n\nmkdir -p \"$(dirname \"$SCRIPT_INPUT_FILE_0\")/lib\"\ncp \"$SCRIPT_INPUT_FILE_0\" \"$SCRIPT_OUTPUT_FILE_0\""; + showEnvVarsInLog = 0; + }; + 427BF7571645DF4700BC3809 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "$(TARGET_BUILD_DIR)/libturbojpeg.a", + ); + outputPaths = ( + "$(SRCROOT)/lib/libturbojpeg-simulator.a", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "mkdir -p \"$(dirname \"$SCRIPT_INPUT_FILE_0\")/lib\"\ncp \"$SCRIPT_INPUT_FILE_0\" \"$SCRIPT_OUTPUT_FILE_0\""; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 427BF6381645BD8C00BC3809 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 427BF64A1645BDA500BC3809 /* jcapimin.c in Sources */, + 427BF64B1645BDA500BC3809 /* jcapistd.c in Sources */, + 427BF64C1645BDA500BC3809 /* jccoefct.c in Sources */, + 427BF64D1645BDA500BC3809 /* jccolor.c in Sources */, + 427BF64E1645BDA500BC3809 /* jcdctmgr.c in Sources */, + 427BF64F1645BDA500BC3809 /* jchuff.c in Sources */, + 427BF6501645BDA500BC3809 /* jcinit.c in Sources */, + 427BF6511645BDA500BC3809 /* jcmainct.c in Sources */, + 427BF6521645BDA500BC3809 /* jcmarker.c in Sources */, + 427BF6531645BDA500BC3809 /* jcmaster.c in Sources */, + 427BF6541645BDA500BC3809 /* jcomapi.c in Sources */, + 427BF6551645BDA500BC3809 /* jcparam.c in Sources */, + 427BF6561645BDA500BC3809 /* jcphuff.c in Sources */, + 427BF6571645BDA500BC3809 /* jcprepct.c in Sources */, + 427BF6581645BDA500BC3809 /* jcsample.c in Sources */, + 427BF6591645BDA500BC3809 /* jctrans.c in Sources */, + 427BF65A1645BDA500BC3809 /* jdapimin.c in Sources */, + 427BF65B1645BDA500BC3809 /* jdapistd.c in Sources */, + 427BF65C1645BDA500BC3809 /* jdatadst.c in Sources */, + 427BF65D1645BDA500BC3809 /* jdatasrc.c in Sources */, + 427BF65E1645BDA500BC3809 /* jdcoefct.c in Sources */, + 427BF65F1645BDA500BC3809 /* jdcolor.c in Sources */, + 427BF6601645BDA500BC3809 /* jddctmgr.c in Sources */, + 427BF6611645BDA500BC3809 /* jdhuff.c in Sources */, + 427BF6621645BDA500BC3809 /* jdinput.c in Sources */, + 427BF6631645BDA500BC3809 /* jdmainct.c in Sources */, + 427BF6641645BDA500BC3809 /* jdmarker.c in Sources */, + 427BF6651645BDA500BC3809 /* jdmaster.c in Sources */, + 427BF6661645BDA500BC3809 /* jdmerge.c in Sources */, + 427BF6671645BDA500BC3809 /* jdphuff.c in Sources */, + 427BF6681645BDA500BC3809 /* jdpostct.c in Sources */, + 427BF6691645BDA500BC3809 /* jdsample.c in Sources */, + 427BF66A1645BDA500BC3809 /* jdtrans.c in Sources */, + 427BF66B1645BDA500BC3809 /* jerror.c in Sources */, + 427BF66C1645BDA500BC3809 /* jfdctflt.c in Sources */, + 427BF66D1645BDA500BC3809 /* jfdctfst.c in Sources */, + 427BF66E1645BDA500BC3809 /* jfdctint.c in Sources */, + 427BF66F1645BDA500BC3809 /* jidctflt.c in Sources */, + 427BF6701645BDA500BC3809 /* jidctfst.c in Sources */, + 427BF6711645BDA500BC3809 /* jidctint.c in Sources */, + 427BF6721645BDA500BC3809 /* jidctred.c in Sources */, + 427BF6731645BDA500BC3809 /* jmemmgr.c in Sources */, + 427BF6741645BDA500BC3809 /* jmemnobs.c in Sources */, + 427BF6751645BDA500BC3809 /* jquant1.c in Sources */, + 427BF6761645BDA500BC3809 /* jquant2.c in Sources */, + 427BF6771645BDA500BC3809 /* jutils.c in Sources */, + 42372FFD1646F7C90022C8FB /* jaricom.c in Sources */, + 42372FFE1646F7C90022C8FB /* jcarith.c in Sources */, + 42372FFF1646F7C90022C8FB /* jdarith.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 427BF67D1645BF1200BC3809 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 427BF6961645BF4800BC3809 /* jdatadst-tj.c in Sources */, + 427BF6971645BF4800BC3809 /* jdatasrc-tj.c in Sources */, + 427BF6981645BF4800BC3809 /* transupp.c in Sources */, + 427BF6991645BF4800BC3809 /* turbojpeg.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 427BF68E1645BF3600BC3809 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 427BF63B1645BD8C00BC3809 /* jpeg */; + targetProxy = 427BF68D1645BF3600BC3809 /* PBXContainerItemProxy */; + }; + 427BF73A1645D62000BC3809 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 427BF6A01645C04700BC3809 /* simd-i386 */; + targetProxy = 427BF7391645D62000BC3809 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 427BF5F41645B6F400BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 427BF5F51645B6F400BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 427BF6481645BD8C00BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = i386; + DSTROOT = /tmp/libjpeg.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = i386; + }; + name = Debug; + }; + 427BF6491645BD8C00BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = i386; + DSTROOT = /tmp/libjpeg.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = i386; + }; + name = Release; + }; + 427BF68B1645BF1200BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = i386; + DSTROOT = /tmp/libturbojpeg.dst; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/libturbojpeg\"", + "\"$(SRCROOT)/libjpeg\"", + ); + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = i386; + }; + name = Debug; + }; + 427BF68C1645BF1200BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = i386; + DSTROOT = /tmp/libturbojpeg.dst; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/libturbojpeg\"", + "\"$(SRCROOT)/libjpeg\"", + ); + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = i386; + }; + name = Release; + }; + 427BF6AB1645C04700BC3809 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = i386; + DSTROOT = /tmp/simd_i386.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_WARN_UNINITIALIZED_AUTOS = NO; + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = i386; + }; + name = Debug; + }; + 427BF6AC1645C04700BC3809 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = i386; + DSTROOT = /tmp/simd_i386.dst; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_WARN_UNINITIALIZED_AUTOS = NO; + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = i386; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 427BF5E21645B6F400BC3809 /* Build configuration list for PBXProject "libjpeg-turbo-simulator" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF5F41645B6F400BC3809 /* Debug */, + 427BF5F51645B6F400BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 427BF6471645BD8C00BC3809 /* Build configuration list for PBXNativeTarget "jpeg" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF6481645BD8C00BC3809 /* Debug */, + 427BF6491645BD8C00BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 427BF68A1645BF1200BC3809 /* Build configuration list for PBXNativeTarget "turbojpeg" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF68B1645BF1200BC3809 /* Debug */, + 427BF68C1645BF1200BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 427BF6AA1645C04700BC3809 /* Build configuration list for PBXNativeTarget "simd-i386" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 427BF6AB1645C04700BC3809 /* Debug */, + 427BF6AC1645C04700BC3809 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 427BF5DF1645B6F400BC3809 /* Project object */; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jaricom.c b/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jaricom.c new file mode 100755 index 0000000..f43e2ea --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jaricom.c @@ -0,0 +1,153 @@ +/* + * jaricom.c + * + * Developed 1997-2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains probability estimation tables for common use in + * arithmetic entropy encoding and decoding routines. + * + * This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1 + * and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec + * (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82). + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + +/* The following #define specifies the packing of the four components + * into the compact INT32 representation. + * Note that this formula must match the actual arithmetic encoder + * and decoder implementation. The implementation has to be changed + * if this formula is changed. + * The current organization is leaned on Markus Kuhn's JBIG + * implementation (jbig_tab.c). + */ + +#define V(i,a,b,c,d) (((INT32)a << 16) | ((INT32)c << 8) | ((INT32)d << 7) | b) + +const INT32 jpeg_aritab[113+1] = { +/* + * Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS + */ + V( 0, 0x5a1d, 1, 1, 1 ), + V( 1, 0x2586, 14, 2, 0 ), + V( 2, 0x1114, 16, 3, 0 ), + V( 3, 0x080b, 18, 4, 0 ), + V( 4, 0x03d8, 20, 5, 0 ), + V( 5, 0x01da, 23, 6, 0 ), + V( 6, 0x00e5, 25, 7, 0 ), + V( 7, 0x006f, 28, 8, 0 ), + V( 8, 0x0036, 30, 9, 0 ), + V( 9, 0x001a, 33, 10, 0 ), + V( 10, 0x000d, 35, 11, 0 ), + V( 11, 0x0006, 9, 12, 0 ), + V( 12, 0x0003, 10, 13, 0 ), + V( 13, 0x0001, 12, 13, 0 ), + V( 14, 0x5a7f, 15, 15, 1 ), + V( 15, 0x3f25, 36, 16, 0 ), + V( 16, 0x2cf2, 38, 17, 0 ), + V( 17, 0x207c, 39, 18, 0 ), + V( 18, 0x17b9, 40, 19, 0 ), + V( 19, 0x1182, 42, 20, 0 ), + V( 20, 0x0cef, 43, 21, 0 ), + V( 21, 0x09a1, 45, 22, 0 ), + V( 22, 0x072f, 46, 23, 0 ), + V( 23, 0x055c, 48, 24, 0 ), + V( 24, 0x0406, 49, 25, 0 ), + V( 25, 0x0303, 51, 26, 0 ), + V( 26, 0x0240, 52, 27, 0 ), + V( 27, 0x01b1, 54, 28, 0 ), + V( 28, 0x0144, 56, 29, 0 ), + V( 29, 0x00f5, 57, 30, 0 ), + V( 30, 0x00b7, 59, 31, 0 ), + V( 31, 0x008a, 60, 32, 0 ), + V( 32, 0x0068, 62, 33, 0 ), + V( 33, 0x004e, 63, 34, 0 ), + V( 34, 0x003b, 32, 35, 0 ), + V( 35, 0x002c, 33, 9, 0 ), + V( 36, 0x5ae1, 37, 37, 1 ), + V( 37, 0x484c, 64, 38, 0 ), + V( 38, 0x3a0d, 65, 39, 0 ), + V( 39, 0x2ef1, 67, 40, 0 ), + V( 40, 0x261f, 68, 41, 0 ), + V( 41, 0x1f33, 69, 42, 0 ), + V( 42, 0x19a8, 70, 43, 0 ), + V( 43, 0x1518, 72, 44, 0 ), + V( 44, 0x1177, 73, 45, 0 ), + V( 45, 0x0e74, 74, 46, 0 ), + V( 46, 0x0bfb, 75, 47, 0 ), + V( 47, 0x09f8, 77, 48, 0 ), + V( 48, 0x0861, 78, 49, 0 ), + V( 49, 0x0706, 79, 50, 0 ), + V( 50, 0x05cd, 48, 51, 0 ), + V( 51, 0x04de, 50, 52, 0 ), + V( 52, 0x040f, 50, 53, 0 ), + V( 53, 0x0363, 51, 54, 0 ), + V( 54, 0x02d4, 52, 55, 0 ), + V( 55, 0x025c, 53, 56, 0 ), + V( 56, 0x01f8, 54, 57, 0 ), + V( 57, 0x01a4, 55, 58, 0 ), + V( 58, 0x0160, 56, 59, 0 ), + V( 59, 0x0125, 57, 60, 0 ), + V( 60, 0x00f6, 58, 61, 0 ), + V( 61, 0x00cb, 59, 62, 0 ), + V( 62, 0x00ab, 61, 63, 0 ), + V( 63, 0x008f, 61, 32, 0 ), + V( 64, 0x5b12, 65, 65, 1 ), + V( 65, 0x4d04, 80, 66, 0 ), + V( 66, 0x412c, 81, 67, 0 ), + V( 67, 0x37d8, 82, 68, 0 ), + V( 68, 0x2fe8, 83, 69, 0 ), + V( 69, 0x293c, 84, 70, 0 ), + V( 70, 0x2379, 86, 71, 0 ), + V( 71, 0x1edf, 87, 72, 0 ), + V( 72, 0x1aa9, 87, 73, 0 ), + V( 73, 0x174e, 72, 74, 0 ), + V( 74, 0x1424, 72, 75, 0 ), + V( 75, 0x119c, 74, 76, 0 ), + V( 76, 0x0f6b, 74, 77, 0 ), + V( 77, 0x0d51, 75, 78, 0 ), + V( 78, 0x0bb6, 77, 79, 0 ), + V( 79, 0x0a40, 77, 48, 0 ), + V( 80, 0x5832, 80, 81, 1 ), + V( 81, 0x4d1c, 88, 82, 0 ), + V( 82, 0x438e, 89, 83, 0 ), + V( 83, 0x3bdd, 90, 84, 0 ), + V( 84, 0x34ee, 91, 85, 0 ), + V( 85, 0x2eae, 92, 86, 0 ), + V( 86, 0x299a, 93, 87, 0 ), + V( 87, 0x2516, 86, 71, 0 ), + V( 88, 0x5570, 88, 89, 1 ), + V( 89, 0x4ca9, 95, 90, 0 ), + V( 90, 0x44d9, 96, 91, 0 ), + V( 91, 0x3e22, 97, 92, 0 ), + V( 92, 0x3824, 99, 93, 0 ), + V( 93, 0x32b4, 99, 94, 0 ), + V( 94, 0x2e17, 93, 86, 0 ), + V( 95, 0x56a8, 95, 96, 1 ), + V( 96, 0x4f46, 101, 97, 0 ), + V( 97, 0x47e5, 102, 98, 0 ), + V( 98, 0x41cf, 103, 99, 0 ), + V( 99, 0x3c3d, 104, 100, 0 ), + V( 100, 0x375e, 99, 93, 0 ), + V( 101, 0x5231, 105, 102, 0 ), + V( 102, 0x4c0f, 106, 103, 0 ), + V( 103, 0x4639, 107, 104, 0 ), + V( 104, 0x415e, 103, 99, 0 ), + V( 105, 0x5627, 105, 106, 1 ), + V( 106, 0x50e7, 108, 107, 0 ), + V( 107, 0x4b85, 109, 103, 0 ), + V( 108, 0x5597, 110, 109, 0 ), + V( 109, 0x504f, 111, 107, 0 ), + V( 110, 0x5a10, 110, 111, 1 ), + V( 111, 0x5522, 112, 109, 0 ), + V( 112, 0x59eb, 112, 111, 1 ), +/* + * This last entry is used for fixed probability estimate of 0.5 + * as recommended in Section 10.3 Table 5 of ITU-T Rec. T.851. + */ + V( 113, 0x5a1d, 113, 113, 0 ) +}; diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jcarith.c b/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jcarith.c new file mode 100755 index 0000000..a9ca1c3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jcarith.c @@ -0,0 +1,925 @@ +/* + * jcarith.c + * + * Developed 1997-2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains portable arithmetic entropy encoding routines for JPEG + * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81). + * + * Both sequential and progressive modes are supported in this single module. + * + * Suspension is not currently supported in this module. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* Expanded entropy encoder object for arithmetic encoding. */ + +typedef struct { + struct jpeg_entropy_encoder pub; /* public fields */ + + INT32 c; /* C register, base of coding interval, layout as in sec. D.1.3 */ + INT32 a; /* A register, normalized size of coding interval */ + INT32 sc; /* counter for stacked 0xFF values which might overflow */ + INT32 zc; /* counter for pending 0x00 output values which might * + * be discarded at the end ("Pacman" termination) */ + int ct; /* bit shift counter, determines when next byte will be written */ + int buffer; /* buffer for most recent output byte != 0xFF */ + + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ + int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ + + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + int next_restart_num; /* next restart number to write (0-7) */ + + /* Pointers to statistics areas (these workspaces have image lifespan) */ + unsigned char * dc_stats[NUM_ARITH_TBLS]; + unsigned char * ac_stats[NUM_ARITH_TBLS]; + + /* Statistics bin for coding with fixed probability 0.5 */ + unsigned char fixed_bin[4]; +} arith_entropy_encoder; + +typedef arith_entropy_encoder * arith_entropy_ptr; + +/* The following two definitions specify the allocation chunk size + * for the statistics area. + * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least + * 49 statistics bins for DC, and 245 statistics bins for AC coding. + * + * We use a compact representation with 1 byte per statistics bin, + * thus the numbers directly represent byte sizes. + * This 1 byte per statistics bin contains the meaning of the MPS + * (more probable symbol) in the highest bit (mask 0x80), and the + * index into the probability estimation state machine table + * in the lower bits (mask 0x7F). + */ + +#define DC_STAT_BINS 64 +#define AC_STAT_BINS 256 + +/* NOTE: Uncomment the following #define if you want to use the + * given formula for calculating the AC conditioning parameter Kx + * for spectral selection progressive coding in section G.1.3.2 + * of the spec (Kx = Kmin + SRL (8 + Se - Kmin) 4). + * Although the spec and P&M authors claim that this "has proven + * to give good results for 8 bit precision samples", I'm not + * convinced yet that this is really beneficial. + * Early tests gave only very marginal compression enhancements + * (a few - around 5 or so - bytes even for very large files), + * which would turn out rather negative if we'd suppress the + * DAC (Define Arithmetic Conditioning) marker segments for + * the default parameters in the future. + * Note that currently the marker writing module emits 12-byte + * DAC segments for a full-component scan in a color image. + * This is not worth worrying about IMHO. However, since the + * spec defines the default values to be used if the tables + * are omitted (unlike Huffman tables, which are required + * anyway), one might optimize this behaviour in the future, + * and then it would be disadvantageous to use custom tables if + * they don't provide sufficient gain to exceed the DAC size. + * + * On the other hand, I'd consider it as a reasonable result + * that the conditioning has no significant influence on the + * compression performance. This means that the basic + * statistical model is already rather stable. + * + * Thus, at the moment, we use the default conditioning values + * anyway, and do not use the custom formula. + * +#define CALCULATE_SPECTRAL_CONDITIONING + */ + +/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32. + * We assume that int right shift is unsigned if INT32 right shift is, + * which should be safe. + */ + +#ifdef RIGHT_SHIFT_IS_UNSIGNED +#define ISHIFT_TEMPS int ishift_temp; +#define IRIGHT_SHIFT(x,shft) \ + ((ishift_temp = (x)) < 0 ? \ + (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \ + (ishift_temp >> (shft))) +#else +#define ISHIFT_TEMPS +#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) +#endif + + +LOCAL(void) +emit_byte (int val, j_compress_ptr cinfo) +/* Write next output byte; we do not support suspension in this module. */ +{ + struct jpeg_destination_mgr * dest = cinfo->dest; + + *dest->next_output_byte++ = (JOCTET) val; + if (--dest->free_in_buffer == 0) + if (! (*dest->empty_output_buffer) (cinfo)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); +} + + +/* + * Finish up at the end of an arithmetic-compressed scan. + */ + +METHODDEF(void) +finish_pass (j_compress_ptr cinfo) +{ + arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; + INT32 temp; + + /* Section D.1.8: Termination of encoding */ + + /* Find the e->c in the coding interval with the largest + * number of trailing zero bits */ + if ((temp = (e->a - 1 + e->c) & 0xFFFF0000L) < e->c) + e->c = temp + 0x8000L; + else + e->c = temp; + /* Send remaining bytes to output */ + e->c <<= e->ct; + if (e->c & 0xF8000000L) { + /* One final overflow has to be handled */ + if (e->buffer >= 0) { + if (e->zc) + do emit_byte(0x00, cinfo); + while (--e->zc); + emit_byte(e->buffer + 1, cinfo); + if (e->buffer + 1 == 0xFF) + emit_byte(0x00, cinfo); + } + e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ + e->sc = 0; + } else { + if (e->buffer == 0) + ++e->zc; + else if (e->buffer >= 0) { + if (e->zc) + do emit_byte(0x00, cinfo); + while (--e->zc); + emit_byte(e->buffer, cinfo); + } + if (e->sc) { + if (e->zc) + do emit_byte(0x00, cinfo); + while (--e->zc); + do { + emit_byte(0xFF, cinfo); + emit_byte(0x00, cinfo); + } while (--e->sc); + } + } + /* Output final bytes only if they are not 0x00 */ + if (e->c & 0x7FFF800L) { + if (e->zc) /* output final pending zero bytes */ + do emit_byte(0x00, cinfo); + while (--e->zc); + emit_byte((e->c >> 19) & 0xFF, cinfo); + if (((e->c >> 19) & 0xFF) == 0xFF) + emit_byte(0x00, cinfo); + if (e->c & 0x7F800L) { + emit_byte((e->c >> 11) & 0xFF, cinfo); + if (((e->c >> 11) & 0xFF) == 0xFF) + emit_byte(0x00, cinfo); + } + } +} + + +/* + * The core arithmetic encoding routine (common in JPEG and JBIG). + * This needs to go as fast as possible. + * Machine-dependent optimization facilities + * are not utilized in this portable implementation. + * However, this code should be fairly efficient and + * may be a good base for further optimizations anyway. + * + * Parameter 'val' to be encoded may be 0 or 1 (binary decision). + * + * Note: I've added full "Pacman" termination support to the + * byte output routines, which is equivalent to the optional + * Discard_final_zeros procedure (Figure D.15) in the spec. + * Thus, we always produce the shortest possible output + * stream compliant to the spec (no trailing zero bytes, + * except for FF stuffing). + * + * I've also introduced a new scheme for accessing + * the probability estimation state machine table, + * derived from Markus Kuhn's JBIG implementation. + */ + +LOCAL(void) +arith_encode (j_compress_ptr cinfo, unsigned char *st, int val) +{ + register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; + register unsigned char nl, nm; + register INT32 qe, temp; + register int sv; + + /* Fetch values from our compact representation of Table D.2: + * Qe values and probability estimation state machine + */ + sv = *st; + qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ + nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ + nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ + + /* Encode & estimation procedures per sections D.1.4 & D.1.5 */ + e->a -= qe; + if (val != (sv >> 7)) { + /* Encode the less probable symbol */ + if (e->a >= qe) { + /* If the interval size (qe) for the less probable symbol (LPS) + * is larger than the interval size for the MPS, then exchange + * the two symbols for coding efficiency, otherwise code the LPS + * as usual: */ + e->c += e->a; + e->a = qe; + } + *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ + } else { + /* Encode the more probable symbol */ + if (e->a >= 0x8000L) + return; /* A >= 0x8000 -> ready, no renormalization required */ + if (e->a < qe) { + /* If the interval size (qe) for the less probable symbol (LPS) + * is larger than the interval size for the MPS, then exchange + * the two symbols for coding efficiency: */ + e->c += e->a; + e->a = qe; + } + *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ + } + + /* Renormalization & data output per section D.1.6 */ + do { + e->a <<= 1; + e->c <<= 1; + if (--e->ct == 0) { + /* Another byte is ready for output */ + temp = e->c >> 19; + if (temp > 0xFF) { + /* Handle overflow over all stacked 0xFF bytes */ + if (e->buffer >= 0) { + if (e->zc) + do emit_byte(0x00, cinfo); + while (--e->zc); + emit_byte(e->buffer + 1, cinfo); + if (e->buffer + 1 == 0xFF) + emit_byte(0x00, cinfo); + } + e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ + e->sc = 0; + /* Note: The 3 spacer bits in the C register guarantee + * that the new buffer byte can't be 0xFF here + * (see page 160 in the P&M JPEG book). */ + e->buffer = temp & 0xFF; /* new output byte, might overflow later */ + } else if (temp == 0xFF) { + ++e->sc; /* stack 0xFF byte (which might overflow later) */ + } else { + /* Output all stacked 0xFF bytes, they will not overflow any more */ + if (e->buffer == 0) + ++e->zc; + else if (e->buffer >= 0) { + if (e->zc) + do emit_byte(0x00, cinfo); + while (--e->zc); + emit_byte(e->buffer, cinfo); + } + if (e->sc) { + if (e->zc) + do emit_byte(0x00, cinfo); + while (--e->zc); + do { + emit_byte(0xFF, cinfo); + emit_byte(0x00, cinfo); + } while (--e->sc); + } + e->buffer = temp & 0xFF; /* new output byte (can still overflow) */ + } + e->c &= 0x7FFFFL; + e->ct += 8; + } + } while (e->a < 0x8000L); +} + + +/* + * Emit a restart marker & resynchronize predictions. + */ + +LOCAL(void) +emit_restart (j_compress_ptr cinfo, int restart_num) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + int ci; + jpeg_component_info * compptr; + + finish_pass(cinfo); + + emit_byte(0xFF, cinfo); + emit_byte(JPEG_RST0 + restart_num, cinfo); + + /* Re-initialize statistics areas */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* DC needs no table for refinement scan */ + if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) { + MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS); + /* Reset DC predictions to 0 */ + entropy->last_dc_val[ci] = 0; + entropy->dc_context[ci] = 0; + } + /* AC needs no table when not present */ + if (cinfo->progressive_mode == 0 || cinfo->Se) { + MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS); + } + } + + /* Reset arithmetic encoding variables */ + entropy->c = 0; + entropy->a = 0x10000L; + entropy->sc = 0; + entropy->zc = 0; + entropy->ct = 11; + entropy->buffer = -1; /* empty */ +} + + +/* + * MCU encoding for DC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + JBLOCKROW block; + unsigned char *st; + int blkn, ci, tbl; + int v, v2, m; + ISHIFT_TEMPS + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + emit_restart(cinfo, entropy->next_restart_num); + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + tbl = cinfo->cur_comp_info[ci]->dc_tbl_no; + + /* Compute the DC value after the required point transform by Al. + * This is simply an arithmetic right shift. + */ + m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al); + + /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */ + + /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ + st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; + + /* Figure F.4: Encode_DC_DIFF */ + if ((v = m - entropy->last_dc_val[ci]) == 0) { + arith_encode(cinfo, st, 0); + entropy->dc_context[ci] = 0; /* zero diff category */ + } else { + entropy->last_dc_val[ci] = m; + arith_encode(cinfo, st, 1); + /* Figure F.6: Encoding nonzero value v */ + /* Figure F.7: Encoding the sign of v */ + if (v > 0) { + arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ + st += 2; /* Table F.4: SP = S0 + 2 */ + entropy->dc_context[ci] = 4; /* small positive diff category */ + } else { + v = -v; + arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ + st += 3; /* Table F.4: SN = S0 + 3 */ + entropy->dc_context[ci] = 8; /* small negative diff category */ + } + /* Figure F.8: Encoding the magnitude category of v */ + m = 0; + if (v -= 1) { + arith_encode(cinfo, st, 1); + m = 1; + v2 = v; + st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ + while (v2 >>= 1) { + arith_encode(cinfo, st, 1); + m <<= 1; + st += 1; + } + } + arith_encode(cinfo, st, 0); + /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ + if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) + entropy->dc_context[ci] = 0; /* zero diff category */ + else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) + entropy->dc_context[ci] += 8; /* large diff category */ + /* Figure F.9: Encoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + arith_encode(cinfo, st, (m & v) ? 1 : 0); + } + } + + return TRUE; +} + + +/* + * MCU encoding for AC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + JBLOCKROW block; + unsigned char *st; + int tbl, k, ke; + int v, v2, m; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + emit_restart(cinfo, entropy->next_restart_num); + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + /* Encode the MCU data block */ + block = MCU_data[0]; + tbl = cinfo->cur_comp_info[0]->ac_tbl_no; + + /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ + + /* Establish EOB (end-of-block) index */ + for (ke = cinfo->Se; ke > 0; ke--) + /* We must apply the point transform by Al. For AC coefficients this + * is an integer division with rounding towards 0. To do this portably + * in C, we shift after obtaining the absolute value. + */ + if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) { + if (v >>= cinfo->Al) break; + } else { + v = -v; + if (v >>= cinfo->Al) break; + } + + /* Figure F.5: Encode_AC_Coefficients */ + for (k = cinfo->Ss; k <= ke; k++) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + arith_encode(cinfo, st, 0); /* EOB decision */ + for (;;) { + if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { + if (v >>= cinfo->Al) { + arith_encode(cinfo, st + 1, 1); + arith_encode(cinfo, entropy->fixed_bin, 0); + break; + } + } else { + v = -v; + if (v >>= cinfo->Al) { + arith_encode(cinfo, st + 1, 1); + arith_encode(cinfo, entropy->fixed_bin, 1); + break; + } + } + arith_encode(cinfo, st + 1, 0); st += 3; k++; + } + st += 2; + /* Figure F.8: Encoding the magnitude category of v */ + m = 0; + if (v -= 1) { + arith_encode(cinfo, st, 1); + m = 1; + v2 = v; + if (v2 >>= 1) { + arith_encode(cinfo, st, 1); + m <<= 1; + st = entropy->ac_stats[tbl] + + (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); + while (v2 >>= 1) { + arith_encode(cinfo, st, 1); + m <<= 1; + st += 1; + } + } + } + arith_encode(cinfo, st, 0); + /* Figure F.9: Encoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + arith_encode(cinfo, st, (m & v) ? 1 : 0); + } + /* Encode EOB decision only if k <= cinfo->Se */ + if (k <= cinfo->Se) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + arith_encode(cinfo, st, 1); + } + + return TRUE; +} + + +/* + * MCU encoding for DC successive approximation refinement scan. + */ + +METHODDEF(boolean) +encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + unsigned char *st; + int Al, blkn; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + emit_restart(cinfo, entropy->next_restart_num); + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + st = entropy->fixed_bin; /* use fixed probability estimation */ + Al = cinfo->Al; + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + /* We simply emit the Al'th bit of the DC coefficient value. */ + arith_encode(cinfo, st, (MCU_data[blkn][0][0] >> Al) & 1); + } + + return TRUE; +} + + +/* + * MCU encoding for AC successive approximation refinement scan. + */ + +METHODDEF(boolean) +encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + JBLOCKROW block; + unsigned char *st; + int tbl, k, ke, kex; + int v; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + emit_restart(cinfo, entropy->next_restart_num); + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + /* Encode the MCU data block */ + block = MCU_data[0]; + tbl = cinfo->cur_comp_info[0]->ac_tbl_no; + + /* Section G.1.3.3: Encoding of AC coefficients */ + + /* Establish EOB (end-of-block) index */ + for (ke = cinfo->Se; ke > 0; ke--) + /* We must apply the point transform by Al. For AC coefficients this + * is an integer division with rounding towards 0. To do this portably + * in C, we shift after obtaining the absolute value. + */ + if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) { + if (v >>= cinfo->Al) break; + } else { + v = -v; + if (v >>= cinfo->Al) break; + } + + /* Establish EOBx (previous stage end-of-block) index */ + for (kex = ke; kex > 0; kex--) + if ((v = (*block)[jpeg_natural_order[kex]]) >= 0) { + if (v >>= cinfo->Ah) break; + } else { + v = -v; + if (v >>= cinfo->Ah) break; + } + + /* Figure G.10: Encode_AC_Coefficients_SA */ + for (k = cinfo->Ss; k <= ke; k++) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + if (k > kex) + arith_encode(cinfo, st, 0); /* EOB decision */ + for (;;) { + if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { + if (v >>= cinfo->Al) { + if (v >> 1) /* previously nonzero coef */ + arith_encode(cinfo, st + 2, (v & 1)); + else { /* newly nonzero coef */ + arith_encode(cinfo, st + 1, 1); + arith_encode(cinfo, entropy->fixed_bin, 0); + } + break; + } + } else { + v = -v; + if (v >>= cinfo->Al) { + if (v >> 1) /* previously nonzero coef */ + arith_encode(cinfo, st + 2, (v & 1)); + else { /* newly nonzero coef */ + arith_encode(cinfo, st + 1, 1); + arith_encode(cinfo, entropy->fixed_bin, 1); + } + break; + } + } + arith_encode(cinfo, st + 1, 0); st += 3; k++; + } + } + /* Encode EOB decision only if k <= cinfo->Se */ + if (k <= cinfo->Se) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + arith_encode(cinfo, st, 1); + } + + return TRUE; +} + + +/* + * Encode and output one MCU's worth of arithmetic-compressed coefficients. + */ + +METHODDEF(boolean) +encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + jpeg_component_info * compptr; + JBLOCKROW block; + unsigned char *st; + int blkn, ci, tbl, k, ke; + int v, v2, m; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + emit_restart(cinfo, entropy->next_restart_num); + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + + /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */ + + tbl = compptr->dc_tbl_no; + + /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ + st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; + + /* Figure F.4: Encode_DC_DIFF */ + if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) { + arith_encode(cinfo, st, 0); + entropy->dc_context[ci] = 0; /* zero diff category */ + } else { + entropy->last_dc_val[ci] = (*block)[0]; + arith_encode(cinfo, st, 1); + /* Figure F.6: Encoding nonzero value v */ + /* Figure F.7: Encoding the sign of v */ + if (v > 0) { + arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ + st += 2; /* Table F.4: SP = S0 + 2 */ + entropy->dc_context[ci] = 4; /* small positive diff category */ + } else { + v = -v; + arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ + st += 3; /* Table F.4: SN = S0 + 3 */ + entropy->dc_context[ci] = 8; /* small negative diff category */ + } + /* Figure F.8: Encoding the magnitude category of v */ + m = 0; + if (v -= 1) { + arith_encode(cinfo, st, 1); + m = 1; + v2 = v; + st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ + while (v2 >>= 1) { + arith_encode(cinfo, st, 1); + m <<= 1; + st += 1; + } + } + arith_encode(cinfo, st, 0); + /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ + if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) + entropy->dc_context[ci] = 0; /* zero diff category */ + else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) + entropy->dc_context[ci] += 8; /* large diff category */ + /* Figure F.9: Encoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + arith_encode(cinfo, st, (m & v) ? 1 : 0); + } + + /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ + + tbl = compptr->ac_tbl_no; + + /* Establish EOB (end-of-block) index */ + for (ke = DCTSIZE2 - 1; ke > 0; ke--) + if ((*block)[jpeg_natural_order[ke]]) break; + + /* Figure F.5: Encode_AC_Coefficients */ + for (k = 1; k <= ke; k++) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + arith_encode(cinfo, st, 0); /* EOB decision */ + while ((v = (*block)[jpeg_natural_order[k]]) == 0) { + arith_encode(cinfo, st + 1, 0); st += 3; k++; + } + arith_encode(cinfo, st + 1, 1); + /* Figure F.6: Encoding nonzero value v */ + /* Figure F.7: Encoding the sign of v */ + if (v > 0) { + arith_encode(cinfo, entropy->fixed_bin, 0); + } else { + v = -v; + arith_encode(cinfo, entropy->fixed_bin, 1); + } + st += 2; + /* Figure F.8: Encoding the magnitude category of v */ + m = 0; + if (v -= 1) { + arith_encode(cinfo, st, 1); + m = 1; + v2 = v; + if (v2 >>= 1) { + arith_encode(cinfo, st, 1); + m <<= 1; + st = entropy->ac_stats[tbl] + + (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); + while (v2 >>= 1) { + arith_encode(cinfo, st, 1); + m <<= 1; + st += 1; + } + } + } + arith_encode(cinfo, st, 0); + /* Figure F.9: Encoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + arith_encode(cinfo, st, (m & v) ? 1 : 0); + } + /* Encode EOB decision only if k <= DCTSIZE2 - 1 */ + if (k <= DCTSIZE2 - 1) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + arith_encode(cinfo, st, 1); + } + } + + return TRUE; +} + + +/* + * Initialize for an arithmetic-compressed scan. + */ + +METHODDEF(void) +start_pass (j_compress_ptr cinfo, boolean gather_statistics) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + int ci, tbl; + jpeg_component_info * compptr; + + if (gather_statistics) + /* Make sure to avoid that in the master control logic! + * We are fully adaptive here and need no extra + * statistics gathering pass! + */ + ERREXIT(cinfo, JERR_NOT_COMPILED); + + /* We assume jcmaster.c already validated the progressive scan parameters. */ + + /* Select execution routines */ + if (cinfo->progressive_mode) { + if (cinfo->Ah == 0) { + if (cinfo->Ss == 0) + entropy->pub.encode_mcu = encode_mcu_DC_first; + else + entropy->pub.encode_mcu = encode_mcu_AC_first; + } else { + if (cinfo->Ss == 0) + entropy->pub.encode_mcu = encode_mcu_DC_refine; + else + entropy->pub.encode_mcu = encode_mcu_AC_refine; + } + } else + entropy->pub.encode_mcu = encode_mcu; + + /* Allocate & initialize requested statistics areas */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* DC needs no table for refinement scan */ + if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) { + tbl = compptr->dc_tbl_no; + if (tbl < 0 || tbl >= NUM_ARITH_TBLS) + ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); + if (entropy->dc_stats[tbl] == NULL) + entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS); + MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS); + /* Initialize DC predictions to 0 */ + entropy->last_dc_val[ci] = 0; + entropy->dc_context[ci] = 0; + } + /* AC needs no table when not present */ + if (cinfo->progressive_mode == 0 || cinfo->Se) { + tbl = compptr->ac_tbl_no; + if (tbl < 0 || tbl >= NUM_ARITH_TBLS) + ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); + if (entropy->ac_stats[tbl] == NULL) + entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS); + MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS); +#ifdef CALCULATE_SPECTRAL_CONDITIONING + if (cinfo->progressive_mode) + /* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */ + cinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4); +#endif + } + } + + /* Initialize arithmetic encoding variables */ + entropy->c = 0; + entropy->a = 0x10000L; + entropy->sc = 0; + entropy->zc = 0; + entropy->ct = 11; + entropy->buffer = -1; /* empty */ + + /* Initialize restart stuff */ + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num = 0; +} + + +/* + * Module initialization routine for arithmetic entropy encoding. + */ + +GLOBAL(void) +jinit_arith_encoder (j_compress_ptr cinfo) +{ + arith_entropy_ptr entropy; + int i; + + entropy = (arith_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(arith_entropy_encoder)); + cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; + entropy->pub.start_pass = start_pass; + entropy->pub.finish_pass = finish_pass; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_ARITH_TBLS; i++) { + entropy->dc_stats[i] = NULL; + entropy->ac_stats[i] = NULL; + } + + /* Initialize index for fixed probability estimation */ + entropy->fixed_bin[0] = 113; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jdarith.c b/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jdarith.c new file mode 100755 index 0000000..d556733 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/arithmetric_coding/jdarith.c @@ -0,0 +1,761 @@ +/* + * jdarith.c + * + * Developed 1997-2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains portable arithmetic entropy decoding routines for JPEG + * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81). + * + * Both sequential and progressive modes are supported in this single module. + * + * Suspension is not currently supported in this module. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* Expanded entropy decoder object for arithmetic decoding. */ + +typedef struct { + struct jpeg_entropy_decoder pub; /* public fields */ + + INT32 c; /* C register, base of coding interval + input bit buffer */ + INT32 a; /* A register, normalized size of coding interval */ + int ct; /* bit shift counter, # of bits left in bit buffer part of C */ + /* init: ct = -16 */ + /* run: ct = 0..7 */ + /* error: ct = -1 */ + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ + int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ + + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + + /* Pointers to statistics areas (these workspaces have image lifespan) */ + unsigned char * dc_stats[NUM_ARITH_TBLS]; + unsigned char * ac_stats[NUM_ARITH_TBLS]; + + /* Statistics bin for coding with fixed probability 0.5 */ + unsigned char fixed_bin[4]; +} arith_entropy_decoder; + +typedef arith_entropy_decoder * arith_entropy_ptr; + +/* The following two definitions specify the allocation chunk size + * for the statistics area. + * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least + * 49 statistics bins for DC, and 245 statistics bins for AC coding. + * + * We use a compact representation with 1 byte per statistics bin, + * thus the numbers directly represent byte sizes. + * This 1 byte per statistics bin contains the meaning of the MPS + * (more probable symbol) in the highest bit (mask 0x80), and the + * index into the probability estimation state machine table + * in the lower bits (mask 0x7F). + */ + +#define DC_STAT_BINS 64 +#define AC_STAT_BINS 256 + + +LOCAL(int) +get_byte (j_decompress_ptr cinfo) +/* Read next input byte; we do not support suspension in this module. */ +{ + struct jpeg_source_mgr * src = cinfo->src; + + if (src->bytes_in_buffer == 0) + if (! (*src->fill_input_buffer) (cinfo)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + src->bytes_in_buffer--; + return GETJOCTET(*src->next_input_byte++); +} + + +/* + * The core arithmetic decoding routine (common in JPEG and JBIG). + * This needs to go as fast as possible. + * Machine-dependent optimization facilities + * are not utilized in this portable implementation. + * However, this code should be fairly efficient and + * may be a good base for further optimizations anyway. + * + * Return value is 0 or 1 (binary decision). + * + * Note: I've changed the handling of the code base & bit + * buffer register C compared to other implementations + * based on the standards layout & procedures. + * While it also contains both the actual base of the + * coding interval (16 bits) and the next-bits buffer, + * the cut-point between these two parts is floating + * (instead of fixed) with the bit shift counter CT. + * Thus, we also need only one (variable instead of + * fixed size) shift for the LPS/MPS decision, and + * we can get away with any renormalization update + * of C (except for new data insertion, of course). + * + * I've also introduced a new scheme for accessing + * the probability estimation state machine table, + * derived from Markus Kuhn's JBIG implementation. + */ + +LOCAL(int) +arith_decode (j_decompress_ptr cinfo, unsigned char *st) +{ + register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; + register unsigned char nl, nm; + register INT32 qe, temp; + register int sv, data; + + /* Renormalization & data input per section D.2.6 */ + while (e->a < 0x8000L) { + if (--e->ct < 0) { + /* Need to fetch next data byte */ + if (cinfo->unread_marker) + data = 0; /* stuff zero data */ + else { + data = get_byte(cinfo); /* read next input byte */ + if (data == 0xFF) { /* zero stuff or marker code */ + do data = get_byte(cinfo); + while (data == 0xFF); /* swallow extra 0xFF bytes */ + if (data == 0) + data = 0xFF; /* discard stuffed zero byte */ + else { + /* Note: Different from the Huffman decoder, hitting + * a marker while processing the compressed data + * segment is legal in arithmetic coding. + * The convention is to supply zero data + * then until decoding is complete. + */ + cinfo->unread_marker = data; + data = 0; + } + } + } + e->c = (e->c << 8) | data; /* insert data into C register */ + if ((e->ct += 8) < 0) /* update bit shift counter */ + /* Need more initial bytes */ + if (++e->ct == 0) + /* Got 2 initial bytes -> re-init A and exit loop */ + e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */ + } + e->a <<= 1; + } + + /* Fetch values from our compact representation of Table D.2: + * Qe values and probability estimation state machine + */ + sv = *st; + qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ + nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ + nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ + + /* Decode & estimation procedures per sections D.2.4 & D.2.5 */ + temp = e->a - qe; + e->a = temp; + temp <<= e->ct; + if (e->c >= temp) { + e->c -= temp; + /* Conditional LPS (less probable symbol) exchange */ + if (e->a < qe) { + e->a = qe; + *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ + } else { + e->a = qe; + *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ + sv ^= 0x80; /* Exchange LPS/MPS */ + } + } else if (e->a < 0x8000L) { + /* Conditional MPS (more probable symbol) exchange */ + if (e->a < qe) { + *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ + sv ^= 0x80; /* Exchange LPS/MPS */ + } else { + *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ + } + } + + return sv >> 7; +} + + +/* + * Check for a restart marker & resynchronize decoder. + */ + +LOCAL(void) +process_restart (j_decompress_ptr cinfo) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + int ci; + jpeg_component_info * compptr; + + /* Advance past the RSTn marker */ + if (! (*cinfo->marker->read_restart_marker) (cinfo)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + + /* Re-initialize statistics areas */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) { + MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS); + /* Reset DC predictions to 0 */ + entropy->last_dc_val[ci] = 0; + entropy->dc_context[ci] = 0; + } + if (! cinfo->progressive_mode || cinfo->Ss) { + MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS); + } + } + + /* Reset arithmetic decoding variables */ + entropy->c = 0; + entropy->a = 0; + entropy->ct = -16; /* force reading 2 initial bytes to fill C */ + + /* Reset restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; +} + + +/* + * Arithmetic MCU decoding. + * Each of these routines decodes and returns one MCU's worth of + * arithmetic-compressed coefficients. + * The coefficients are reordered from zigzag order into natural array order, + * but are not dequantized. + * + * The i'th block of the MCU is stored into the block pointed to by + * MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER. + */ + +/* + * MCU decoding for DC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + JBLOCKROW block; + unsigned char *st; + int blkn, ci, tbl, sign; + int v, m; + + /* Process restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + process_restart(cinfo); + entropy->restarts_to_go--; + } + + if (entropy->ct == -1) return TRUE; /* if error do nothing */ + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + tbl = cinfo->cur_comp_info[ci]->dc_tbl_no; + + /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */ + + /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ + st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; + + /* Figure F.19: Decode_DC_DIFF */ + if (arith_decode(cinfo, st) == 0) + entropy->dc_context[ci] = 0; + else { + /* Figure F.21: Decoding nonzero value v */ + /* Figure F.22: Decoding the sign of v */ + sign = arith_decode(cinfo, st + 1); + st += 2; st += sign; + /* Figure F.23: Decoding the magnitude category of v */ + if ((m = arith_decode(cinfo, st)) != 0) { + st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ + while (arith_decode(cinfo, st)) { + if ((m <<= 1) == 0x8000) { + WARNMS(cinfo, JWRN_ARITH_BAD_CODE); + entropy->ct = -1; /* magnitude overflow */ + return TRUE; + } + st += 1; + } + } + /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ + if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) + entropy->dc_context[ci] = 0; /* zero diff category */ + else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) + entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ + else + entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ + v = m; + /* Figure F.24: Decoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + if (arith_decode(cinfo, st)) v |= m; + v += 1; if (sign) v = -v; + entropy->last_dc_val[ci] += v; + } + + /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */ + (*block)[0] = (JCOEF) (entropy->last_dc_val[ci] << cinfo->Al); + } + + return TRUE; +} + + +/* + * MCU decoding for AC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + JBLOCKROW block; + unsigned char *st; + int tbl, sign, k; + int v, m; + + /* Process restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + process_restart(cinfo); + entropy->restarts_to_go--; + } + + if (entropy->ct == -1) return TRUE; /* if error do nothing */ + + /* There is always only one block per MCU */ + block = MCU_data[0]; + tbl = cinfo->cur_comp_info[0]->ac_tbl_no; + + /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ + + /* Figure F.20: Decode_AC_coefficients */ + for (k = cinfo->Ss; k <= cinfo->Se; k++) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + if (arith_decode(cinfo, st)) break; /* EOB flag */ + while (arith_decode(cinfo, st + 1) == 0) { + st += 3; k++; + if (k > cinfo->Se) { + WARNMS(cinfo, JWRN_ARITH_BAD_CODE); + entropy->ct = -1; /* spectral overflow */ + return TRUE; + } + } + /* Figure F.21: Decoding nonzero value v */ + /* Figure F.22: Decoding the sign of v */ + sign = arith_decode(cinfo, entropy->fixed_bin); + st += 2; + /* Figure F.23: Decoding the magnitude category of v */ + if ((m = arith_decode(cinfo, st)) != 0) { + if (arith_decode(cinfo, st)) { + m <<= 1; + st = entropy->ac_stats[tbl] + + (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); + while (arith_decode(cinfo, st)) { + if ((m <<= 1) == 0x8000) { + WARNMS(cinfo, JWRN_ARITH_BAD_CODE); + entropy->ct = -1; /* magnitude overflow */ + return TRUE; + } + st += 1; + } + } + } + v = m; + /* Figure F.24: Decoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + if (arith_decode(cinfo, st)) v |= m; + v += 1; if (sign) v = -v; + /* Scale and output coefficient in natural (dezigzagged) order */ + (*block)[jpeg_natural_order[k]] = (JCOEF) (v << cinfo->Al); + } + + return TRUE; +} + + +/* + * MCU decoding for DC successive approximation refinement scan. + */ + +METHODDEF(boolean) +decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + unsigned char *st; + int p1, blkn; + + /* Process restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + process_restart(cinfo); + entropy->restarts_to_go--; + } + + st = entropy->fixed_bin; /* use fixed probability estimation */ + p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + /* Encoded data is simply the next bit of the two's-complement DC value */ + if (arith_decode(cinfo, st)) + MCU_data[blkn][0][0] |= p1; + } + + return TRUE; +} + + +/* + * MCU decoding for AC successive approximation refinement scan. + */ + +METHODDEF(boolean) +decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + JBLOCKROW block; + JCOEFPTR thiscoef; + unsigned char *st; + int tbl, k, kex; + int p1, m1; + + /* Process restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + process_restart(cinfo); + entropy->restarts_to_go--; + } + + if (entropy->ct == -1) return TRUE; /* if error do nothing */ + + /* There is always only one block per MCU */ + block = MCU_data[0]; + tbl = cinfo->cur_comp_info[0]->ac_tbl_no; + + p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ + m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ + + /* Establish EOBx (previous stage end-of-block) index */ + for (kex = cinfo->Se; kex > 0; kex--) + if ((*block)[jpeg_natural_order[kex]]) break; + + for (k = cinfo->Ss; k <= cinfo->Se; k++) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + if (k > kex) + if (arith_decode(cinfo, st)) break; /* EOB flag */ + for (;;) { + thiscoef = *block + jpeg_natural_order[k]; + if (*thiscoef) { /* previously nonzero coef */ + if (arith_decode(cinfo, st + 2)) { + if (*thiscoef < 0) + *thiscoef += m1; + else + *thiscoef += p1; + } + break; + } + if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */ + if (arith_decode(cinfo, entropy->fixed_bin)) + *thiscoef = m1; + else + *thiscoef = p1; + break; + } + st += 3; k++; + if (k > cinfo->Se) { + WARNMS(cinfo, JWRN_ARITH_BAD_CODE); + entropy->ct = -1; /* spectral overflow */ + return TRUE; + } + } + } + + return TRUE; +} + + +/* + * Decode one MCU's worth of arithmetic-compressed coefficients. + */ + +METHODDEF(boolean) +decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + jpeg_component_info * compptr; + JBLOCKROW block; + unsigned char *st; + int blkn, ci, tbl, sign, k; + int v, m; + + /* Process restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + process_restart(cinfo); + entropy->restarts_to_go--; + } + + if (entropy->ct == -1) return TRUE; /* if error do nothing */ + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + + /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */ + + tbl = compptr->dc_tbl_no; + + /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ + st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; + + /* Figure F.19: Decode_DC_DIFF */ + if (arith_decode(cinfo, st) == 0) + entropy->dc_context[ci] = 0; + else { + /* Figure F.21: Decoding nonzero value v */ + /* Figure F.22: Decoding the sign of v */ + sign = arith_decode(cinfo, st + 1); + st += 2; st += sign; + /* Figure F.23: Decoding the magnitude category of v */ + if ((m = arith_decode(cinfo, st)) != 0) { + st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ + while (arith_decode(cinfo, st)) { + if ((m <<= 1) == 0x8000) { + WARNMS(cinfo, JWRN_ARITH_BAD_CODE); + entropy->ct = -1; /* magnitude overflow */ + return TRUE; + } + st += 1; + } + } + /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ + if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) + entropy->dc_context[ci] = 0; /* zero diff category */ + else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) + entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ + else + entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ + v = m; + /* Figure F.24: Decoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + if (arith_decode(cinfo, st)) v |= m; + v += 1; if (sign) v = -v; + entropy->last_dc_val[ci] += v; + } + + (*block)[0] = (JCOEF) entropy->last_dc_val[ci]; + + /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ + + tbl = compptr->ac_tbl_no; + + /* Figure F.20: Decode_AC_coefficients */ + for (k = 1; k <= DCTSIZE2 - 1; k++) { + st = entropy->ac_stats[tbl] + 3 * (k - 1); + if (arith_decode(cinfo, st)) break; /* EOB flag */ + while (arith_decode(cinfo, st + 1) == 0) { + st += 3; k++; + if (k > DCTSIZE2 - 1) { + WARNMS(cinfo, JWRN_ARITH_BAD_CODE); + entropy->ct = -1; /* spectral overflow */ + return TRUE; + } + } + /* Figure F.21: Decoding nonzero value v */ + /* Figure F.22: Decoding the sign of v */ + sign = arith_decode(cinfo, entropy->fixed_bin); + st += 2; + /* Figure F.23: Decoding the magnitude category of v */ + if ((m = arith_decode(cinfo, st)) != 0) { + if (arith_decode(cinfo, st)) { + m <<= 1; + st = entropy->ac_stats[tbl] + + (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); + while (arith_decode(cinfo, st)) { + if ((m <<= 1) == 0x8000) { + WARNMS(cinfo, JWRN_ARITH_BAD_CODE); + entropy->ct = -1; /* magnitude overflow */ + return TRUE; + } + st += 1; + } + } + } + v = m; + /* Figure F.24: Decoding the magnitude bit pattern of v */ + st += 14; + while (m >>= 1) + if (arith_decode(cinfo, st)) v |= m; + v += 1; if (sign) v = -v; + (*block)[jpeg_natural_order[k]] = (JCOEF) v; + } + } + + return TRUE; +} + + +/* + * Initialize for an arithmetic-compressed scan. + */ + +METHODDEF(void) +start_pass (j_decompress_ptr cinfo) +{ + arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; + int ci, tbl; + jpeg_component_info * compptr; + + if (cinfo->progressive_mode) { + /* Validate progressive scan parameters */ + if (cinfo->Ss == 0) { + if (cinfo->Se != 0) + goto bad; + } else { + /* need not check Ss/Se < 0 since they came from unsigned bytes */ + if (cinfo->Se < cinfo->Ss || cinfo->Se > DCTSIZE2 - 1) + goto bad; + /* AC scans may have only one component */ + if (cinfo->comps_in_scan != 1) + goto bad; + } + if (cinfo->Ah != 0) { + /* Successive approximation refinement scan: must have Al = Ah-1. */ + if (cinfo->Ah-1 != cinfo->Al) + goto bad; + } + if (cinfo->Al > 13) { /* need not check for < 0 */ + bad: + ERREXIT4(cinfo, JERR_BAD_PROGRESSION, + cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); + } + /* Update progression status, and verify that scan order is legal. + * Note that inter-scan inconsistencies are treated as warnings + * not fatal errors ... not clear if this is right way to behave. + */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + int coefi, cindex = cinfo->cur_comp_info[ci]->component_index; + int *coef_bit_ptr = & cinfo->coef_bits[cindex][0]; + if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ + WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); + for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { + int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; + if (cinfo->Ah != expected) + WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); + coef_bit_ptr[coefi] = cinfo->Al; + } + } + /* Select MCU decoding routine */ + if (cinfo->Ah == 0) { + if (cinfo->Ss == 0) + entropy->pub.decode_mcu = decode_mcu_DC_first; + else + entropy->pub.decode_mcu = decode_mcu_AC_first; + } else { + if (cinfo->Ss == 0) + entropy->pub.decode_mcu = decode_mcu_DC_refine; + else + entropy->pub.decode_mcu = decode_mcu_AC_refine; + } + } else { + /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. + * This ought to be an error condition, but we make it a warning. + */ + if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 || + (cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1)) + WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); + /* Select MCU decoding routine */ + entropy->pub.decode_mcu = decode_mcu; + } + + /* Allocate & initialize requested statistics areas */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) { + tbl = compptr->dc_tbl_no; + if (tbl < 0 || tbl >= NUM_ARITH_TBLS) + ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); + if (entropy->dc_stats[tbl] == NULL) + entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS); + MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS); + /* Initialize DC predictions to 0 */ + entropy->last_dc_val[ci] = 0; + entropy->dc_context[ci] = 0; + } + if (! cinfo->progressive_mode || cinfo->Ss) { + tbl = compptr->ac_tbl_no; + if (tbl < 0 || tbl >= NUM_ARITH_TBLS) + ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); + if (entropy->ac_stats[tbl] == NULL) + entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS); + MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS); + } + } + + /* Initialize arithmetic decoding variables */ + entropy->c = 0; + entropy->a = 0; + entropy->ct = -16; /* force reading 2 initial bytes to fill C */ + + /* Initialize restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; +} + + +/* + * Module initialization routine for arithmetic entropy decoding. + */ + +GLOBAL(void) +jinit_arith_decoder (j_decompress_ptr cinfo) +{ + arith_entropy_ptr entropy; + int i; + + entropy = (arith_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(arith_entropy_decoder)); + cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; + entropy->pub.start_pass = start_pass; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_ARITH_TBLS; i++) { + entropy->dc_stats[i] = NULL; + entropy->ac_stats[i] = NULL; + } + + /* Initialize index for fixed probability estimation */ + entropy->fixed_bin[0] = 113; + + if (cinfo->progressive_mode) { + /* Create progression status table */ + int *coef_bit_ptr, ci; + cinfo->coef_bits = (int (*)[DCTSIZE2]) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components*DCTSIZE2*SIZEOF(int)); + coef_bit_ptr = & cinfo->coef_bits[0][0]; + for (ci = 0; ci < cinfo->num_components; ci++) + for (i = 0; i < DCTSIZE2; i++) + *coef_bit_ptr++ = -1; + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/config.h b/lib-third-party/libturbojpeg-ios/libjpeg/config.h new file mode 100755 index 0000000..58bd0fc --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/config.h @@ -0,0 +1,137 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Build number */ +#define BUILD "20121103" + +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 + +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_JNI_H */ + +/* Define to 1 if you have the `memcpy' function. */ +#define HAVE_MEMCPY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define if your compiler supports prototypes */ +#define HAVE_PROTOTYPES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if the system has the type `unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 + +/* Define to 1 if the system has the type `unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 + +/* Compiler does not support pointers to undefined structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* How to obtain function inlining. */ +#define INLINE __attribute__((always_inline)) + +/* libjpeg API version */ +#define JPEG_LIB_VERSION 62 + +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 1.2.80 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define if you have BSD-like bzero and bcopy */ +/* #undef NEED_BSD_STRINGS */ + +/* Define if you need short function names */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ + +/* Define if you have sys/types.h */ +#define NEED_SYS_TYPES_H 1 + +/* Name of package */ +#define PACKAGE "libjpeg-turbo" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libjpeg-turbo" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libjpeg-turbo 1.2.80" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libjpeg-turbo" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.2.80" + +/* Define if shift is unsigned */ +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.2.80" + +/* Use accelerated SIMD routines. */ +#define WITH_SIMD 1 + +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +/* # undef __CHAR_UNSIGNED__ */ +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcapimin.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcapimin.c new file mode 100755 index 0000000..20ba9e9 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcapimin.c @@ -0,0 +1,292 @@ +/* + * jcapimin.c + * + * Copyright (C) 1994-1998, Thomas G. Lane. + * Modified 2003-2010 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the compression half + * of the JPEG library. These are the "minimum" API routines that may be + * needed in either the normal full-compression case or the transcoding-only + * case. + * + * Most of the routines intended to be called directly by an application + * are in this file or in jcapistd.c. But also see jcparam.c for + * parameter-setup helper routines, jcomapi.c for routines shared by + * compression and decompression, and jctrans.c for the transcoding case. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* + * Initialization of a JPEG compression object. + * The error manager must already be set up (in case memory manager fails). + */ + +GLOBAL(void) +jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) +{ + int i; + + /* Guard against version mismatches between library and caller. */ + cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ + if (version != JPEG_LIB_VERSION) + ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); + if (structsize != SIZEOF(struct jpeg_compress_struct)) + ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, + (int) SIZEOF(struct jpeg_compress_struct), (int) structsize); + + /* For debugging purposes, we zero the whole master structure. + * But the application has already set the err pointer, and may have set + * client_data, so we have to save and restore those fields. + * Note: if application hasn't set client_data, tools like Purify may + * complain here. + */ + { + struct jpeg_error_mgr * err = cinfo->err; + void * client_data = cinfo->client_data; /* ignore Purify complaint here */ + MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct)); + cinfo->err = err; + cinfo->client_data = client_data; + } + cinfo->is_decompressor = FALSE; + + /* Initialize a memory manager instance for this object */ + jinit_memory_mgr((j_common_ptr) cinfo); + + /* Zero out pointers to permanent structures. */ + cinfo->progress = NULL; + cinfo->dest = NULL; + + cinfo->comp_info = NULL; + + for (i = 0; i < NUM_QUANT_TBLS; i++) { + cinfo->quant_tbl_ptrs[i] = NULL; +#if JPEG_LIB_VERSION >= 70 + cinfo->q_scale_factor[i] = 100; +#endif + } + + for (i = 0; i < NUM_HUFF_TBLS; i++) { + cinfo->dc_huff_tbl_ptrs[i] = NULL; + cinfo->ac_huff_tbl_ptrs[i] = NULL; + } + +#if JPEG_LIB_VERSION >= 80 + /* Must do it here for emit_dqt in case jpeg_write_tables is used */ + cinfo->block_size = DCTSIZE; + cinfo->natural_order = jpeg_natural_order; + cinfo->lim_Se = DCTSIZE2-1; +#endif + + cinfo->script_space = NULL; + + cinfo->input_gamma = 1.0; /* in case application forgets */ + + /* OK, I'm ready */ + cinfo->global_state = CSTATE_START; +} + + +/* + * Destruction of a JPEG compression object + */ + +GLOBAL(void) +jpeg_destroy_compress (j_compress_ptr cinfo) +{ + jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ +} + + +/* + * Abort processing of a JPEG compression operation, + * but don't destroy the object itself. + */ + +GLOBAL(void) +jpeg_abort_compress (j_compress_ptr cinfo) +{ + jpeg_abort((j_common_ptr) cinfo); /* use common routine */ +} + + +/* + * Forcibly suppress or un-suppress all quantization and Huffman tables. + * Marks all currently defined tables as already written (if suppress) + * or not written (if !suppress). This will control whether they get emitted + * by a subsequent jpeg_start_compress call. + * + * This routine is exported for use by applications that want to produce + * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but + * since it is called by jpeg_start_compress, we put it here --- otherwise + * jcparam.o would be linked whether the application used it or not. + */ + +GLOBAL(void) +jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress) +{ + int i; + JQUANT_TBL * qtbl; + JHUFF_TBL * htbl; + + for (i = 0; i < NUM_QUANT_TBLS; i++) { + if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL) + qtbl->sent_table = suppress; + } + + for (i = 0; i < NUM_HUFF_TBLS; i++) { + if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL) + htbl->sent_table = suppress; + if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL) + htbl->sent_table = suppress; + } +} + + +/* + * Finish JPEG compression. + * + * If a multipass operating mode was selected, this may do a great deal of + * work including most of the actual output. + */ + +GLOBAL(void) +jpeg_finish_compress (j_compress_ptr cinfo) +{ + JDIMENSION iMCU_row; + + if (cinfo->global_state == CSTATE_SCANNING || + cinfo->global_state == CSTATE_RAW_OK) { + /* Terminate first pass */ + if (cinfo->next_scanline < cinfo->image_height) + ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); + (*cinfo->master->finish_pass) (cinfo); + } else if (cinfo->global_state != CSTATE_WRCOEFS) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Perform any remaining passes */ + while (! cinfo->master->is_last_pass) { + (*cinfo->master->prepare_for_pass) (cinfo); + for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) iMCU_row; + cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + /* We bypass the main controller and invoke coef controller directly; + * all work is being done from the coefficient buffer. + */ + if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } + (*cinfo->master->finish_pass) (cinfo); + } + /* Write EOI, do final cleanup */ + (*cinfo->marker->write_file_trailer) (cinfo); + (*cinfo->dest->term_destination) (cinfo); + /* We can use jpeg_abort to release memory and reset global_state */ + jpeg_abort((j_common_ptr) cinfo); +} + + +/* + * Write a special marker. + * This is only recommended for writing COM or APPn markers. + * Must be called after jpeg_start_compress() and before + * first call to jpeg_write_scanlines() or jpeg_write_raw_data(). + */ + +GLOBAL(void) +jpeg_write_marker (j_compress_ptr cinfo, int marker, + const JOCTET *dataptr, unsigned int datalen) +{ + JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); + + if (cinfo->next_scanline != 0 || + (cinfo->global_state != CSTATE_SCANNING && + cinfo->global_state != CSTATE_RAW_OK && + cinfo->global_state != CSTATE_WRCOEFS)) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + (*cinfo->marker->write_marker_header) (cinfo, marker, datalen); + write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */ + while (datalen--) { + (*write_marker_byte) (cinfo, *dataptr); + dataptr++; + } +} + +/* Same, but piecemeal. */ + +GLOBAL(void) +jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen) +{ + if (cinfo->next_scanline != 0 || + (cinfo->global_state != CSTATE_SCANNING && + cinfo->global_state != CSTATE_RAW_OK && + cinfo->global_state != CSTATE_WRCOEFS)) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + (*cinfo->marker->write_marker_header) (cinfo, marker, datalen); +} + +GLOBAL(void) +jpeg_write_m_byte (j_compress_ptr cinfo, int val) +{ + (*cinfo->marker->write_marker_byte) (cinfo, val); +} + + +/* + * Alternate compression function: just write an abbreviated table file. + * Before calling this, all parameters and a data destination must be set up. + * + * To produce a pair of files containing abbreviated tables and abbreviated + * image data, one would proceed as follows: + * + * initialize JPEG object + * set JPEG parameters + * set destination to table file + * jpeg_write_tables(cinfo); + * set destination to image file + * jpeg_start_compress(cinfo, FALSE); + * write data... + * jpeg_finish_compress(cinfo); + * + * jpeg_write_tables has the side effect of marking all tables written + * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress + * will not re-emit the tables unless it is passed write_all_tables=TRUE. + */ + +GLOBAL(void) +jpeg_write_tables (j_compress_ptr cinfo) +{ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* (Re)initialize error mgr and destination modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->dest->init_destination) (cinfo); + /* Initialize the marker writer ... bit of a crock to do it here. */ + jinit_marker_writer(cinfo); + /* Write them tables! */ + (*cinfo->marker->write_tables_only) (cinfo); + /* And clean up. */ + (*cinfo->dest->term_destination) (cinfo); + /* + * In library releases up through v6a, we called jpeg_abort() here to free + * any working memory allocated by the destination manager and marker + * writer. Some applications had a problem with that: they allocated space + * of their own from the library memory manager, and didn't want it to go + * away during write_tables. So now we do nothing. This will cause a + * memory leak if an app calls write_tables repeatedly without doing a full + * compression cycle or otherwise resetting the JPEG object. However, that + * seems less bad than unexpectedly freeing memory in the normal case. + * An app that prefers the old behavior can call jpeg_abort for itself after + * each call to jpeg_write_tables(). + */ +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcapistd.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcapistd.c new file mode 100755 index 0000000..c0320b1 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcapistd.c @@ -0,0 +1,161 @@ +/* + * jcapistd.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the compression half + * of the JPEG library. These are the "standard" API routines that are + * used in the normal full-compression case. They are not used by a + * transcoding-only application. Note that if an application links in + * jpeg_start_compress, it will end up linking in the entire compressor. + * We thus must separate this file from jcapimin.c to avoid linking the + * whole compression library into a transcoder. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* + * Compression initialization. + * Before calling this, all parameters and a data destination must be set up. + * + * We require a write_all_tables parameter as a failsafe check when writing + * multiple datastreams from the same compression object. Since prior runs + * will have left all the tables marked sent_table=TRUE, a subsequent run + * would emit an abbreviated stream (no tables) by default. This may be what + * is wanted, but for safety's sake it should not be the default behavior: + * programmers should have to make a deliberate choice to emit abbreviated + * images. Therefore the documentation and examples should encourage people + * to pass write_all_tables=TRUE; then it will take active thought to do the + * wrong thing. + */ + +GLOBAL(void) +jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) +{ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + if (write_all_tables) + jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ + + /* (Re)initialize error mgr and destination modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->dest->init_destination) (cinfo); + /* Perform master selection of active modules */ + jinit_compress_master(cinfo); + /* Set up for the first pass */ + (*cinfo->master->prepare_for_pass) (cinfo); + /* Ready for application to drive first pass through jpeg_write_scanlines + * or jpeg_write_raw_data. + */ + cinfo->next_scanline = 0; + cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING); +} + + +/* + * Write some scanlines of data to the JPEG compressor. + * + * The return value will be the number of lines actually written. + * This should be less than the supplied num_lines only in case that + * the data destination module has requested suspension of the compressor, + * or if more than image_height scanlines are passed in. + * + * Note: we warn about excess calls to jpeg_write_scanlines() since + * this likely signals an application programmer error. However, + * excess scanlines passed in the last valid call are *silently* ignored, + * so that the application need not adjust num_lines for end-of-image + * when using a multiple-scanline buffer. + */ + +GLOBAL(JDIMENSION) +jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, + JDIMENSION num_lines) +{ + JDIMENSION row_ctr, rows_left; + + if (cinfo->global_state != CSTATE_SCANNING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->next_scanline >= cinfo->image_height) + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->next_scanline; + cinfo->progress->pass_limit = (long) cinfo->image_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Give master control module another chance if this is first call to + * jpeg_write_scanlines. This lets output of the frame/scan headers be + * delayed so that application can write COM, etc, markers between + * jpeg_start_compress and jpeg_write_scanlines. + */ + if (cinfo->master->call_pass_startup) + (*cinfo->master->pass_startup) (cinfo); + + /* Ignore any extra scanlines at bottom of image. */ + rows_left = cinfo->image_height - cinfo->next_scanline; + if (num_lines > rows_left) + num_lines = rows_left; + + row_ctr = 0; + (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines); + cinfo->next_scanline += row_ctr; + return row_ctr; +} + + +/* + * Alternate entry point to write raw data. + * Processes exactly one iMCU row per call, unless suspended. + */ + +GLOBAL(JDIMENSION) +jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, + JDIMENSION num_lines) +{ + JDIMENSION lines_per_iMCU_row; + + if (cinfo->global_state != CSTATE_RAW_OK) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->next_scanline >= cinfo->image_height) { + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + return 0; + } + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->next_scanline; + cinfo->progress->pass_limit = (long) cinfo->image_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Give master control module another chance if this is first call to + * jpeg_write_raw_data. This lets output of the frame/scan headers be + * delayed so that application can write COM, etc, markers between + * jpeg_start_compress and jpeg_write_raw_data. + */ + if (cinfo->master->call_pass_startup) + (*cinfo->master->pass_startup) (cinfo); + + /* Verify that at least one iMCU row has been passed. */ + lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE; + if (num_lines < lines_per_iMCU_row) + ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* Directly compress the row. */ + if (! (*cinfo->coef->compress_data) (cinfo, data)) { + /* If compressor did not consume the whole row, suspend processing. */ + return 0; + } + + /* OK, we processed one iMCU row. */ + cinfo->next_scanline += lines_per_iMCU_row; + return lines_per_iMCU_row; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jccoefct.c b/lib-third-party/libturbojpeg-ios/libjpeg/jccoefct.c new file mode 100755 index 0000000..1963ddb --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jccoefct.c @@ -0,0 +1,449 @@ +/* + * jccoefct.c + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the coefficient buffer controller for compression. + * This controller is the top level of the JPEG compressor proper. + * The coefficient buffer lies between forward-DCT and entropy encoding steps. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* We use a full-image coefficient buffer when doing Huffman optimization, + * and also for writing multiple-scan JPEG files. In all cases, the DCT + * step is run during the first pass, and subsequent passes need only read + * the buffered coefficients. + */ +#ifdef ENTROPY_OPT_SUPPORTED +#define FULL_COEF_BUFFER_SUPPORTED +#else +#ifdef C_MULTISCAN_FILES_SUPPORTED +#define FULL_COEF_BUFFER_SUPPORTED +#endif +#endif + + +/* Private buffer controller object */ + +typedef struct { + struct jpeg_c_coef_controller pub; /* public fields */ + + JDIMENSION iMCU_row_num; /* iMCU row # within image */ + JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ + int MCU_vert_offset; /* counts MCU rows within iMCU row */ + int MCU_rows_per_iMCU_row; /* number of such rows needed */ + + /* For single-pass compression, it's sufficient to buffer just one MCU + * (although this may prove a bit slow in practice). We allocate a + * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each + * MCU constructed and sent. (On 80x86, the workspace is FAR even though + * it's not really very big; this is to keep the module interfaces unchanged + * when a large coefficient buffer is necessary.) + * In multi-pass modes, this array points to the current MCU's blocks + * within the virtual arrays. + */ + JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; + + /* In multi-pass modes, we need a virtual block array for each component. */ + jvirt_barray_ptr whole_image[MAX_COMPONENTS]; +} my_coef_controller; + +typedef my_coef_controller * my_coef_ptr; + + +/* Forward declarations */ +METHODDEF(boolean) compress_data + JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); +#ifdef FULL_COEF_BUFFER_SUPPORTED +METHODDEF(boolean) compress_first_pass + JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); +METHODDEF(boolean) compress_output + JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); +#endif + + +LOCAL(void) +start_iMCU_row (j_compress_ptr cinfo) +/* Reset within-iMCU-row counters for a new row */ +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* In an interleaved scan, an MCU row is the same as an iMCU row. + * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. + * But at the bottom of the image, process only what's left. + */ + if (cinfo->comps_in_scan > 1) { + coef->MCU_rows_per_iMCU_row = 1; + } else { + if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; + else + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; + } + + coef->mcu_ctr = 0; + coef->MCU_vert_offset = 0; +} + + +/* + * Initialize for a processing pass. + */ + +METHODDEF(void) +start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + coef->iMCU_row_num = 0; + start_iMCU_row(cinfo); + + switch (pass_mode) { + case JBUF_PASS_THRU: + if (coef->whole_image[0] != NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + coef->pub.compress_data = compress_data; + break; +#ifdef FULL_COEF_BUFFER_SUPPORTED + case JBUF_SAVE_AND_PASS: + if (coef->whole_image[0] == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + coef->pub.compress_data = compress_first_pass; + break; + case JBUF_CRANK_DEST: + if (coef->whole_image[0] == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + coef->pub.compress_data = compress_output; + break; +#endif + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } +} + + +/* + * Process some data in the single-pass case. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the image. + * Returns TRUE if the iMCU row is completed, FALSE if suspended. + * + * NB: input_buf contains a plane for each component in image, + * which we index according to the component's SOF position. + */ + +METHODDEF(boolean) +compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + int blkn, bi, ci, yindex, yoffset, blockcnt; + JDIMENSION ypos, xpos; + jpeg_component_info *compptr; + + /* Loop to write as much as one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col; + MCU_col_num++) { + /* Determine where data comes from in input_buf and do the DCT thing. + * Each call on forward_DCT processes a horizontal row of DCT blocks + * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks + * sequentially. Dummy blocks at the right or bottom edge are filled in + * specially. The data in them does not matter for image reconstruction, + * so we fill them with values that will encode to the smallest amount of + * data, viz: all zeroes in the AC entries, DC entries equal to previous + * block's DC value. (Thanks to Thomas Kinsman for this idea.) + */ + blkn = 0; + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width + : compptr->last_col_width; + xpos = MCU_col_num * compptr->MCU_sample_width; + ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */ + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + if (coef->iMCU_row_num < last_iMCU_row || + yoffset+yindex < compptr->last_row_height) { + (*cinfo->fdct->forward_DCT) (cinfo, compptr, + input_buf[compptr->component_index], + coef->MCU_buffer[blkn], + ypos, xpos, (JDIMENSION) blockcnt); + if (blockcnt < compptr->MCU_width) { + /* Create some dummy blocks at the right edge of the image. */ + jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt], + (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK)); + for (bi = blockcnt; bi < compptr->MCU_width; bi++) { + coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0]; + } + } + } else { + /* Create a row of dummy blocks at the bottom of the image. */ + jzero_far((void FAR *) coef->MCU_buffer[blkn], + compptr->MCU_width * SIZEOF(JBLOCK)); + for (bi = 0; bi < compptr->MCU_width; bi++) { + coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0]; + } + } + blkn += compptr->MCU_width; + ypos += DCTSIZE; + } + } + /* Try to write the MCU. In event of a suspension failure, we will + * re-DCT the MCU on restart (a bit inefficient, could be fixed...) + */ + if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->mcu_ctr = MCU_col_num; + return FALSE; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->mcu_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + coef->iMCU_row_num++; + start_iMCU_row(cinfo); + return TRUE; +} + + +#ifdef FULL_COEF_BUFFER_SUPPORTED + +/* + * Process some data in the first pass of a multi-pass case. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the image. + * This amount of data is read from the source buffer, DCT'd and quantized, + * and saved into the virtual arrays. We also generate suitable dummy blocks + * as needed at the right and lower edges. (The dummy blocks are constructed + * in the virtual arrays, which have been padded appropriately.) This makes + * it possible for subsequent passes not to worry about real vs. dummy blocks. + * + * We must also emit the data to the entropy encoder. This is conveniently + * done by calling compress_output() after we've loaded the current strip + * of the virtual arrays. + * + * NB: input_buf contains a plane for each component in image. All + * components are DCT'd and loaded into the virtual arrays in this pass. + * However, it may be that only a subset of the components are emitted to + * the entropy encoder during this first pass; be careful about looking + * at the scan-dependent variables (MCU dimensions, etc). + */ + +METHODDEF(boolean) +compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + JDIMENSION blocks_across, MCUs_across, MCUindex; + int bi, ci, h_samp_factor, block_row, block_rows, ndummy; + JCOEF lastDC; + jpeg_component_info *compptr; + JBLOCKARRAY buffer; + JBLOCKROW thisblockrow, lastblockrow; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Align the virtual buffer for this component. */ + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + coef->iMCU_row_num * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, TRUE); + /* Count non-dummy DCT block rows in this iMCU row. */ + if (coef->iMCU_row_num < last_iMCU_row) + block_rows = compptr->v_samp_factor; + else { + /* NB: can't use last_row_height here, since may not be set! */ + block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (block_rows == 0) block_rows = compptr->v_samp_factor; + } + blocks_across = compptr->width_in_blocks; + h_samp_factor = compptr->h_samp_factor; + /* Count number of dummy blocks to be added at the right margin. */ + ndummy = (int) (blocks_across % h_samp_factor); + if (ndummy > 0) + ndummy = h_samp_factor - ndummy; + /* Perform DCT for all non-dummy blocks in this iMCU row. Each call + * on forward_DCT processes a complete horizontal row of DCT blocks. + */ + for (block_row = 0; block_row < block_rows; block_row++) { + thisblockrow = buffer[block_row]; + (*cinfo->fdct->forward_DCT) (cinfo, compptr, + input_buf[ci], thisblockrow, + (JDIMENSION) (block_row * DCTSIZE), + (JDIMENSION) 0, blocks_across); + if (ndummy > 0) { + /* Create dummy blocks at the right edge of the image. */ + thisblockrow += blocks_across; /* => first dummy block */ + jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); + lastDC = thisblockrow[-1][0]; + for (bi = 0; bi < ndummy; bi++) { + thisblockrow[bi][0] = lastDC; + } + } + } + /* If at end of image, create dummy block rows as needed. + * The tricky part here is that within each MCU, we want the DC values + * of the dummy blocks to match the last real block's DC value. + * This squeezes a few more bytes out of the resulting file... + */ + if (coef->iMCU_row_num == last_iMCU_row) { + blocks_across += ndummy; /* include lower right corner */ + MCUs_across = blocks_across / h_samp_factor; + for (block_row = block_rows; block_row < compptr->v_samp_factor; + block_row++) { + thisblockrow = buffer[block_row]; + lastblockrow = buffer[block_row-1]; + jzero_far((void FAR *) thisblockrow, + (size_t) (blocks_across * SIZEOF(JBLOCK))); + for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { + lastDC = lastblockrow[h_samp_factor-1][0]; + for (bi = 0; bi < h_samp_factor; bi++) { + thisblockrow[bi][0] = lastDC; + } + thisblockrow += h_samp_factor; /* advance to next MCU in row */ + lastblockrow += h_samp_factor; + } + } + } + } + /* NB: compress_output will increment iMCU_row_num if successful. + * A suspension return will result in redoing all the work above next time. + */ + + /* Emit data to the entropy encoder, sharing code with subsequent passes */ + return compress_output(cinfo, input_buf); +} + + +/* + * Process some data in subsequent passes of a multi-pass case. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the scan. + * The data is obtained from the virtual arrays and fed to the entropy coder. + * Returns TRUE if the iMCU row is completed, FALSE if suspended. + * + * NB: input_buf is ignored; it is likely to be a NULL pointer. + */ + +METHODDEF(boolean) +compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + int blkn, ci, xindex, yindex, yoffset; + JDIMENSION start_col; + JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; + JBLOCKROW buffer_ptr; + jpeg_component_info *compptr; + + /* Align the virtual buffers for the components used in this scan. + * NB: during first pass, this is safe only because the buffers will + * already be aligned properly, so jmemmgr.c won't need to do any I/O. + */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + buffer[ci] = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], + coef->iMCU_row_num * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } + + /* Loop to process one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; + MCU_col_num++) { + /* Construct list of pointers to DCT blocks belonging to this MCU */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + start_col = MCU_col_num * compptr->MCU_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + buffer_ptr = buffer[ci][yindex+yoffset] + start_col; + for (xindex = 0; xindex < compptr->MCU_width; xindex++) { + coef->MCU_buffer[blkn++] = buffer_ptr++; + } + } + } + /* Try to write the MCU. */ + if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->mcu_ctr = MCU_col_num; + return FALSE; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->mcu_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + coef->iMCU_row_num++; + start_iMCU_row(cinfo); + return TRUE; +} + +#endif /* FULL_COEF_BUFFER_SUPPORTED */ + + +/* + * Initialize coefficient buffer controller. + */ + +GLOBAL(void) +jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer) +{ + my_coef_ptr coef; + + coef = (my_coef_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_coef_controller)); + cinfo->coef = (struct jpeg_c_coef_controller *) coef; + coef->pub.start_pass = start_pass_coef; + + /* Create the coefficient buffer. */ + if (need_full_buffer) { +#ifdef FULL_COEF_BUFFER_SUPPORTED + /* Allocate a full-image virtual array for each component, */ + /* padded to a multiple of samp_factor DCT blocks in each direction. */ + int ci; + jpeg_component_info *compptr; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + (JDIMENSION) jround_up((long) compptr->width_in_blocks, + (long) compptr->h_samp_factor), + (JDIMENSION) jround_up((long) compptr->height_in_blocks, + (long) compptr->v_samp_factor), + (JDIMENSION) compptr->v_samp_factor); + } +#else + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); +#endif + } else { + /* We only need a single-MCU buffer. */ + JBLOCKROW buffer; + int i; + + buffer = (JBLOCKROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { + coef->MCU_buffer[i] = buffer + i; + } + coef->whole_image[0] = NULL; /* flag for no virtual arrays */ + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jccolext.c b/lib-third-party/libturbojpeg-ios/libjpeg/jccolext.c new file mode 100755 index 0000000..dbac84a --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jccolext.c @@ -0,0 +1,146 @@ +/* + * jccolext.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * Copyright (C) 2009-2012, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains input colorspace conversion routines. + */ + + +/* This file is included by jccolor.c */ + + +/* + * Convert some rows of samples to the JPEG colorspace. + * + * Note that we change from the application's interleaved-pixel format + * to our internal noninterleaved, one-plane-per-component format. + * The input buffer is therefore three times as wide as the output buffer. + * + * A starting row offset is provided only for the output buffer. The caller + * can easily adjust the passed input_buf value to accommodate any row + * offset required on that side. + */ + +INLINE +LOCAL(void) +rgb_ycc_convert_internal (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int r, g, b; + register INT32 * ctab = cconvert->rgb_ycc_tab; + register JSAMPROW inptr; + register JSAMPROW outptr0, outptr1, outptr2; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr0 = output_buf[0][output_row]; + outptr1 = output_buf[1][output_row]; + outptr2 = output_buf[2][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + r = GETJSAMPLE(inptr[RGB_RED]); + g = GETJSAMPLE(inptr[RGB_GREEN]); + b = GETJSAMPLE(inptr[RGB_BLUE]); + inptr += RGB_PIXELSIZE; + /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations + * must be too; we do not need an explicit range-limiting operation. + * Hence the value being shifted is never negative, and we don't + * need the general RIGHT_SHIFT macro. + */ + /* Y */ + outptr0[col] = (JSAMPLE) + ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) + >> SCALEBITS); + /* Cb */ + outptr1[col] = (JSAMPLE) + ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) + >> SCALEBITS); + /* Cr */ + outptr2[col] = (JSAMPLE) + ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) + >> SCALEBITS); + } + } +} + + +/**************** Cases other than RGB -> YCbCr **************/ + + +/* + * Convert some rows of samples to the JPEG colorspace. + * This version handles RGB->grayscale conversion, which is the same + * as the RGB->Y portion of RGB->YCbCr. + * We assume rgb_ycc_start has been called (we only use the Y tables). + */ + +INLINE +LOCAL(void) +rgb_gray_convert_internal (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int r, g, b; + register INT32 * ctab = cconvert->rgb_ycc_tab; + register JSAMPROW inptr; + register JSAMPROW outptr; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr = output_buf[0][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + r = GETJSAMPLE(inptr[RGB_RED]); + g = GETJSAMPLE(inptr[RGB_GREEN]); + b = GETJSAMPLE(inptr[RGB_BLUE]); + inptr += RGB_PIXELSIZE; + /* Y */ + outptr[col] = (JSAMPLE) + ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) + >> SCALEBITS); + } + } +} + + +/* + * Convert some rows of samples to the JPEG colorspace. + * This version handles extended RGB->plain RGB conversion + */ + +INLINE +LOCAL(void) +rgb_rgb_convert_internal (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + register JSAMPROW inptr; + register JSAMPROW outptr0, outptr1, outptr2; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr0 = output_buf[0][output_row]; + outptr1 = output_buf[1][output_row]; + outptr2 = output_buf[2][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + outptr0[col] = GETJSAMPLE(inptr[RGB_RED]); + outptr1[col] = GETJSAMPLE(inptr[RGB_GREEN]); + outptr2[col] = GETJSAMPLE(inptr[RGB_BLUE]); + inptr += RGB_PIXELSIZE; + } + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jccolor.c b/lib-third-party/libturbojpeg-ios/libjpeg/jccolor.c new file mode 100755 index 0000000..3a0772b --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jccolor.c @@ -0,0 +1,661 @@ +/* + * jccolor.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2009-2012, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains input colorspace conversion routines. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jsimd.h" +#include "config.h" + + +/* Private subobject */ + +typedef struct { + struct jpeg_color_converter pub; /* public fields */ + + /* Private state for RGB->YCC conversion */ + INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */ +} my_color_converter; + +typedef my_color_converter * my_cconvert_ptr; + + +/**************** RGB -> YCbCr conversion: most common case **************/ + +/* + * YCbCr is defined per CCIR 601-1, except that Cb and Cr are + * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. + * The conversion equations to be implemented are therefore + * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) + * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, + * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and + * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0) + * were not represented exactly. Now we sacrifice exact representation of + * maximum red and maximum blue in order to get exact grayscales. + * + * To avoid floating-point arithmetic, we represent the fractional constants + * as integers scaled up by 2^16 (about 4 digits precision); we have to divide + * the products by 2^16, with appropriate rounding, to get the correct answer. + * + * For even more speed, we avoid doing any multiplications in the inner loop + * by precalculating the constants times R,G,B for all possible values. + * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); + * for 12-bit samples it is still acceptable. It's not very reasonable for + * 16-bit samples, but if you want lossless storage you shouldn't be changing + * colorspace anyway. + * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included + * in the tables to save adding them separately in the inner loop. + */ + +#define SCALEBITS 16 /* speediest right-shift on some machines */ +#define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS) +#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) +#define FIX(x) ((INT32) ((x) * (1L< Y section */ +#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ +#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ +#define R_CB_OFF (3*(MAXJSAMPLE+1)) +#define G_CB_OFF (4*(MAXJSAMPLE+1)) +#define B_CB_OFF (5*(MAXJSAMPLE+1)) +#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ +#define G_CR_OFF (6*(MAXJSAMPLE+1)) +#define B_CR_OFF (7*(MAXJSAMPLE+1)) +#define TABLE_SIZE (8*(MAXJSAMPLE+1)) + + +/* Include inline routines for colorspace extensions */ + +#include "jccolext.c" +#undef RGB_RED +#undef RGB_GREEN +#undef RGB_BLUE +#undef RGB_PIXELSIZE + +#define RGB_RED EXT_RGB_RED +#define RGB_GREEN EXT_RGB_GREEN +#define RGB_BLUE EXT_RGB_BLUE +#define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +#define rgb_ycc_convert_internal extrgb_ycc_convert_internal +#define rgb_gray_convert_internal extrgb_gray_convert_internal +#define rgb_rgb_convert_internal extrgb_rgb_convert_internal +#include "jccolext.c" +#undef RGB_RED +#undef RGB_GREEN +#undef RGB_BLUE +#undef RGB_PIXELSIZE +#undef rgb_ycc_convert_internal +#undef rgb_gray_convert_internal +#undef rgb_rgb_convert_internal + +#define RGB_RED EXT_RGBX_RED +#define RGB_GREEN EXT_RGBX_GREEN +#define RGB_BLUE EXT_RGBX_BLUE +#define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +#define rgb_ycc_convert_internal extrgbx_ycc_convert_internal +#define rgb_gray_convert_internal extrgbx_gray_convert_internal +#define rgb_rgb_convert_internal extrgbx_rgb_convert_internal +#include "jccolext.c" +#undef RGB_RED +#undef RGB_GREEN +#undef RGB_BLUE +#undef RGB_PIXELSIZE +#undef rgb_ycc_convert_internal +#undef rgb_gray_convert_internal +#undef rgb_rgb_convert_internal + +#define RGB_RED EXT_BGR_RED +#define RGB_GREEN EXT_BGR_GREEN +#define RGB_BLUE EXT_BGR_BLUE +#define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +#define rgb_ycc_convert_internal extbgr_ycc_convert_internal +#define rgb_gray_convert_internal extbgr_gray_convert_internal +#define rgb_rgb_convert_internal extbgr_rgb_convert_internal +#include "jccolext.c" +#undef RGB_RED +#undef RGB_GREEN +#undef RGB_BLUE +#undef RGB_PIXELSIZE +#undef rgb_ycc_convert_internal +#undef rgb_gray_convert_internal +#undef rgb_rgb_convert_internal + +#define RGB_RED EXT_BGRX_RED +#define RGB_GREEN EXT_BGRX_GREEN +#define RGB_BLUE EXT_BGRX_BLUE +#define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +#define rgb_ycc_convert_internal extbgrx_ycc_convert_internal +#define rgb_gray_convert_internal extbgrx_gray_convert_internal +#define rgb_rgb_convert_internal extbgrx_rgb_convert_internal +#include "jccolext.c" +#undef RGB_RED +#undef RGB_GREEN +#undef RGB_BLUE +#undef RGB_PIXELSIZE +#undef rgb_ycc_convert_internal +#undef rgb_gray_convert_internal +#undef rgb_rgb_convert_internal + +#define RGB_RED EXT_XBGR_RED +#define RGB_GREEN EXT_XBGR_GREEN +#define RGB_BLUE EXT_XBGR_BLUE +#define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +#define rgb_ycc_convert_internal extxbgr_ycc_convert_internal +#define rgb_gray_convert_internal extxbgr_gray_convert_internal +#define rgb_rgb_convert_internal extxbgr_rgb_convert_internal +#include "jccolext.c" +#undef RGB_RED +#undef RGB_GREEN +#undef RGB_BLUE +#undef RGB_PIXELSIZE +#undef rgb_ycc_convert_internal +#undef rgb_gray_convert_internal +#undef rgb_rgb_convert_internal + +#define RGB_RED EXT_XRGB_RED +#define RGB_GREEN EXT_XRGB_GREEN +#define RGB_BLUE EXT_XRGB_BLUE +#define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +#define rgb_ycc_convert_internal extxrgb_ycc_convert_internal +#define rgb_gray_convert_internal extxrgb_gray_convert_internal +#define rgb_rgb_convert_internal extxrgb_rgb_convert_internal +#include "jccolext.c" +#undef RGB_RED +#undef RGB_GREEN +#undef RGB_BLUE +#undef RGB_PIXELSIZE +#undef rgb_ycc_convert_internal +#undef rgb_gray_convert_internal +#undef rgb_rgb_convert_internal + + +/* + * Initialize for RGB->YCC colorspace conversion. + */ + +METHODDEF(void) +rgb_ycc_start (j_compress_ptr cinfo) +{ + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + INT32 * rgb_ycc_tab; + INT32 i; + + /* Allocate and fill in the conversion tables. */ + cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (TABLE_SIZE * SIZEOF(INT32))); + + for (i = 0; i <= MAXJSAMPLE; i++) { + rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; + rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; + rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; + rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; + rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; + /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. + * This ensures that the maximum output will round to MAXJSAMPLE + * not MAXJSAMPLE+1, and thus that we don't have to range-limit. + */ + rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; +/* B=>Cb and R=>Cr tables are the same + rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; +*/ + rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; + rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; + } +} + + +/* + * Convert some rows of samples to the JPEG colorspace. + */ + +METHODDEF(void) +rgb_ycc_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + switch (cinfo->in_color_space) { + case JCS_EXT_RGB: + extrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + extrgbx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_BGR: + extbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + extbgrx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + extxbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + extxrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + default: + rgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + } +} + + +/**************** Cases other than RGB -> YCbCr **************/ + + +/* + * Convert some rows of samples to the JPEG colorspace. + */ + +METHODDEF(void) +rgb_gray_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + switch (cinfo->in_color_space) { + case JCS_EXT_RGB: + extrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + extrgbx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_BGR: + extbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + extbgrx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + extxbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + extxrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + default: + rgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + } +} + + +/* + * Extended RGB to plain RGB conversion + */ + +METHODDEF(void) +rgb_rgb_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + switch (cinfo->in_color_space) { + case JCS_EXT_RGB: + extrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + extrgbx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_BGR: + extbgr_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + extbgrx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + extxbgr_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + extxrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + default: + rgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, + num_rows); + break; + } +} + + +/* + * Convert some rows of samples to the JPEG colorspace. + * This version handles Adobe-style CMYK->YCCK conversion, + * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same + * conversion as above, while passing K (black) unchanged. + * We assume rgb_ycc_start has been called. + */ + +METHODDEF(void) +cmyk_ycck_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int r, g, b; + register INT32 * ctab = cconvert->rgb_ycc_tab; + register JSAMPROW inptr; + register JSAMPROW outptr0, outptr1, outptr2, outptr3; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr0 = output_buf[0][output_row]; + outptr1 = output_buf[1][output_row]; + outptr2 = output_buf[2][output_row]; + outptr3 = output_buf[3][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + r = MAXJSAMPLE - GETJSAMPLE(inptr[0]); + g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); + b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); + /* K passes through as-is */ + outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ + inptr += 4; + /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations + * must be too; we do not need an explicit range-limiting operation. + * Hence the value being shifted is never negative, and we don't + * need the general RIGHT_SHIFT macro. + */ + /* Y */ + outptr0[col] = (JSAMPLE) + ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) + >> SCALEBITS); + /* Cb */ + outptr1[col] = (JSAMPLE) + ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) + >> SCALEBITS); + /* Cr */ + outptr2[col] = (JSAMPLE) + ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) + >> SCALEBITS); + } + } +} + + +/* + * Convert some rows of samples to the JPEG colorspace. + * This version handles grayscale output with no conversion. + * The source can be either plain grayscale or YCbCr (since Y == gray). + */ + +METHODDEF(void) +grayscale_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + register JSAMPROW inptr; + register JSAMPROW outptr; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + int instride = cinfo->input_components; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr = output_buf[0][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ + inptr += instride; + } + } +} + + +/* + * Convert some rows of samples to the JPEG colorspace. + * This version handles multi-component colorspaces without conversion. + * We assume input_components == num_components. + */ + +METHODDEF(void) +null_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + register JSAMPROW inptr; + register JSAMPROW outptr; + register JDIMENSION col; + register int ci; + int nc = cinfo->num_components; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + /* It seems fastest to make a separate pass for each component. */ + for (ci = 0; ci < nc; ci++) { + inptr = *input_buf; + outptr = output_buf[ci][output_row]; + for (col = 0; col < num_cols; col++) { + outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ + inptr += nc; + } + } + input_buf++; + output_row++; + } +} + + +/* + * Empty method for start_pass. + */ + +METHODDEF(void) +null_method (j_compress_ptr cinfo) +{ + /* no work needed */ +} + + +/* + * Module initialization routine for input colorspace conversion. + */ + +GLOBAL(void) +jinit_color_converter (j_compress_ptr cinfo) +{ + my_cconvert_ptr cconvert; + + cconvert = (my_cconvert_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_color_converter)); + cinfo->cconvert = (struct jpeg_color_converter *) cconvert; + /* set start_pass to null method until we find out differently */ + cconvert->pub.start_pass = null_method; + + /* Make sure input_components agrees with in_color_space */ + switch (cinfo->in_color_space) { + case JCS_GRAYSCALE: + if (cinfo->input_components != 1) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + + case JCS_RGB: + case JCS_EXT_RGB: + case JCS_EXT_RGBX: + case JCS_EXT_BGR: + case JCS_EXT_BGRX: + case JCS_EXT_XBGR: + case JCS_EXT_XRGB: + case JCS_EXT_RGBA: + case JCS_EXT_BGRA: + case JCS_EXT_ABGR: + case JCS_EXT_ARGB: + if (cinfo->input_components != rgb_pixelsize[cinfo->in_color_space]) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + + case JCS_YCbCr: + if (cinfo->input_components != 3) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + + case JCS_CMYK: + case JCS_YCCK: + if (cinfo->input_components != 4) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + + default: /* JCS_UNKNOWN can be anything */ + if (cinfo->input_components < 1) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + } + + /* Check num_components, set conversion method based on requested space */ + switch (cinfo->jpeg_color_space) { + case JCS_GRAYSCALE: + if (cinfo->num_components != 1) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_GRAYSCALE) + cconvert->pub.color_convert = grayscale_convert; + else if (cinfo->in_color_space == JCS_RGB || + cinfo->in_color_space == JCS_EXT_RGB || + cinfo->in_color_space == JCS_EXT_RGBX || + cinfo->in_color_space == JCS_EXT_BGR || + cinfo->in_color_space == JCS_EXT_BGRX || + cinfo->in_color_space == JCS_EXT_XBGR || + cinfo->in_color_space == JCS_EXT_XRGB || + cinfo->in_color_space == JCS_EXT_RGBA || + cinfo->in_color_space == JCS_EXT_BGRA || + cinfo->in_color_space == JCS_EXT_ABGR || + cinfo->in_color_space == JCS_EXT_ARGB) { + if (jsimd_can_rgb_gray()) + cconvert->pub.color_convert = jsimd_rgb_gray_convert; + else { + cconvert->pub.start_pass = rgb_ycc_start; + cconvert->pub.color_convert = rgb_gray_convert; + } + } else if (cinfo->in_color_space == JCS_YCbCr) + cconvert->pub.color_convert = grayscale_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_RGB: + if (cinfo->num_components != 3) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (rgb_red[cinfo->in_color_space] == 0 && + rgb_green[cinfo->in_color_space] == 1 && + rgb_blue[cinfo->in_color_space] == 2 && + rgb_pixelsize[cinfo->in_color_space] == 3) + cconvert->pub.color_convert = null_convert; + else if (cinfo->in_color_space == JCS_RGB || + cinfo->in_color_space == JCS_EXT_RGB || + cinfo->in_color_space == JCS_EXT_RGBX || + cinfo->in_color_space == JCS_EXT_BGR || + cinfo->in_color_space == JCS_EXT_BGRX || + cinfo->in_color_space == JCS_EXT_XBGR || + cinfo->in_color_space == JCS_EXT_XRGB || + cinfo->in_color_space == JCS_EXT_RGBA || + cinfo->in_color_space == JCS_EXT_BGRA || + cinfo->in_color_space == JCS_EXT_ABGR || + cinfo->in_color_space == JCS_EXT_ARGB) + cconvert->pub.color_convert = rgb_rgb_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_YCbCr: + if (cinfo->num_components != 3) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_RGB || + cinfo->in_color_space == JCS_EXT_RGB || + cinfo->in_color_space == JCS_EXT_RGBX || + cinfo->in_color_space == JCS_EXT_BGR || + cinfo->in_color_space == JCS_EXT_BGRX || + cinfo->in_color_space == JCS_EXT_XBGR || + cinfo->in_color_space == JCS_EXT_XRGB || + cinfo->in_color_space == JCS_EXT_RGBA || + cinfo->in_color_space == JCS_EXT_BGRA || + cinfo->in_color_space == JCS_EXT_ABGR || + cinfo->in_color_space == JCS_EXT_ARGB) { + if (jsimd_can_rgb_ycc()) + cconvert->pub.color_convert = jsimd_rgb_ycc_convert; + else { + cconvert->pub.start_pass = rgb_ycc_start; + cconvert->pub.color_convert = rgb_ycc_convert; + } + } else if (cinfo->in_color_space == JCS_YCbCr) + cconvert->pub.color_convert = null_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_CMYK: + if (cinfo->num_components != 4) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_CMYK) + cconvert->pub.color_convert = null_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_YCCK: + if (cinfo->num_components != 4) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_CMYK) { + cconvert->pub.start_pass = rgb_ycc_start; + cconvert->pub.color_convert = cmyk_ycck_convert; + } else if (cinfo->in_color_space == JCS_YCCK) + cconvert->pub.color_convert = null_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + default: /* allow null conversion of JCS_UNKNOWN */ + if (cinfo->jpeg_color_space != cinfo->in_color_space || + cinfo->num_components != cinfo->input_components) + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + cconvert->pub.color_convert = null_convert; + break; + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcdctmgr.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcdctmgr.c new file mode 100755 index 0000000..12f8872 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcdctmgr.c @@ -0,0 +1,642 @@ +/* + * jcdctmgr.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2011 D. R. Commander + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the forward-DCT management logic. + * This code selects a particular DCT implementation to be used, + * and it performs related housekeeping chores including coefficient + * quantization. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ +#include "jsimddct.h" + + +/* Private subobject for this module */ + +typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data)); +typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data)); + +typedef JMETHOD(void, convsamp_method_ptr, + (JSAMPARRAY sample_data, JDIMENSION start_col, + DCTELEM * workspace)); +typedef JMETHOD(void, float_convsamp_method_ptr, + (JSAMPARRAY sample_data, JDIMENSION start_col, + FAST_FLOAT *workspace)); + +typedef JMETHOD(void, quantize_method_ptr, + (JCOEFPTR coef_block, DCTELEM * divisors, + DCTELEM * workspace)); +typedef JMETHOD(void, float_quantize_method_ptr, + (JCOEFPTR coef_block, FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *); + +typedef struct { + struct jpeg_forward_dct pub; /* public fields */ + + /* Pointer to the DCT routine actually in use */ + forward_DCT_method_ptr dct; + convsamp_method_ptr convsamp; + quantize_method_ptr quantize; + + /* The actual post-DCT divisors --- not identical to the quant table + * entries, because of scaling (especially for an unnormalized DCT). + * Each table is given in normal array order. + */ + DCTELEM * divisors[NUM_QUANT_TBLS]; + + /* work area for FDCT subroutine */ + DCTELEM * workspace; + +#ifdef DCT_FLOAT_SUPPORTED + /* Same as above for the floating-point case. */ + float_DCT_method_ptr float_dct; + float_convsamp_method_ptr float_convsamp; + float_quantize_method_ptr float_quantize; + FAST_FLOAT * float_divisors[NUM_QUANT_TBLS]; + FAST_FLOAT * float_workspace; +#endif +} my_fdct_controller; + +typedef my_fdct_controller * my_fdct_ptr; + + +/* + * Find the highest bit in an integer through binary search. + */ +LOCAL(int) +flss (UINT16 val) +{ + int bit; + + bit = 16; + + if (!val) + return 0; + + if (!(val & 0xff00)) { + bit -= 8; + val <<= 8; + } + if (!(val & 0xf000)) { + bit -= 4; + val <<= 4; + } + if (!(val & 0xc000)) { + bit -= 2; + val <<= 2; + } + if (!(val & 0x8000)) { + bit -= 1; + val <<= 1; + } + + return bit; +} + +/* + * Compute values to do a division using reciprocal. + * + * This implementation is based on an algorithm described in + * "How to optimize for the Pentium family of microprocessors" + * (http://www.agner.org/assem/). + * More information about the basic algorithm can be found in + * the paper "Integer Division Using Reciprocals" by Robert Alverson. + * + * The basic idea is to replace x/d by x * d^-1. In order to store + * d^-1 with enough precision we shift it left a few places. It turns + * out that this algoright gives just enough precision, and also fits + * into DCTELEM: + * + * b = (the number of significant bits in divisor) - 1 + * r = (word size) + b + * f = 2^r / divisor + * + * f will not be an integer for most cases, so we need to compensate + * for the rounding error introduced: + * + * no fractional part: + * + * result = input >> r + * + * fractional part of f < 0.5: + * + * round f down to nearest integer + * result = ((input + 1) * f) >> r + * + * fractional part of f > 0.5: + * + * round f up to nearest integer + * result = (input * f) >> r + * + * This is the original algorithm that gives truncated results. But we + * want properly rounded results, so we replace "input" with + * "input + divisor/2". + * + * In order to allow SIMD implementations we also tweak the values to + * allow the same calculation to be made at all times: + * + * dctbl[0] = f rounded to nearest integer + * dctbl[1] = divisor / 2 (+ 1 if fractional part of f < 0.5) + * dctbl[2] = 1 << ((word size) * 2 - r) + * dctbl[3] = r - (word size) + * + * dctbl[2] is for stupid instruction sets where the shift operation + * isn't member wise (e.g. MMX). + * + * The reason dctbl[2] and dctbl[3] reduce the shift with (word size) + * is that most SIMD implementations have a "multiply and store top + * half" operation. + * + * Lastly, we store each of the values in their own table instead + * of in a consecutive manner, yet again in order to allow SIMD + * routines. + */ +LOCAL(int) +compute_reciprocal (UINT16 divisor, DCTELEM * dtbl) +{ + UDCTELEM2 fq, fr; + UDCTELEM c; + int b, r; + + b = flss(divisor) - 1; + r = sizeof(DCTELEM) * 8 + b; + + fq = ((UDCTELEM2)1 << r) / divisor; + fr = ((UDCTELEM2)1 << r) % divisor; + + c = divisor / 2; /* for rounding */ + + if (fr == 0) { /* divisor is power of two */ + /* fq will be one bit too large to fit in DCTELEM, so adjust */ + fq >>= 1; + r--; + } else if (fr <= (divisor / 2U)) { /* fractional part is < 0.5 */ + c++; + } else { /* fractional part is > 0.5 */ + fq++; + } + + dtbl[DCTSIZE2 * 0] = (DCTELEM) fq; /* reciprocal */ + dtbl[DCTSIZE2 * 1] = (DCTELEM) c; /* correction + roundfactor */ + dtbl[DCTSIZE2 * 2] = (DCTELEM) (1 << (sizeof(DCTELEM)*8*2 - r)); /* scale */ + dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */ + + if(r <= 16) return 0; + else return 1; +} + +/* + * Initialize for a processing pass. + * Verify that all referenced Q-tables are present, and set up + * the divisor table for each one. + * In the current implementation, DCT of all components is done during + * the first pass, even if only some components will be output in the + * first scan. Hence all components should be examined here. + */ + +METHODDEF(void) +start_pass_fdctmgr (j_compress_ptr cinfo) +{ + my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; + int ci, qtblno, i; + jpeg_component_info *compptr; + JQUANT_TBL * qtbl; + DCTELEM * dtbl; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + qtblno = compptr->quant_tbl_no; + /* Make sure specified quantization table is present */ + if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || + cinfo->quant_tbl_ptrs[qtblno] == NULL) + ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); + qtbl = cinfo->quant_tbl_ptrs[qtblno]; + /* Compute divisors for this quant table */ + /* We may do this more than once for same table, but it's not a big deal */ + switch (cinfo->dct_method) { +#ifdef DCT_ISLOW_SUPPORTED + case JDCT_ISLOW: + /* For LL&M IDCT method, divisors are equal to raw quantization + * coefficients multiplied by 8 (to counteract scaling). + */ + if (fdct->divisors[qtblno] == NULL) { + fdct->divisors[qtblno] = (DCTELEM *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); + } + dtbl = fdct->divisors[qtblno]; + for (i = 0; i < DCTSIZE2; i++) { + if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) + && fdct->quantize == jsimd_quantize) + fdct->quantize = quantize; + } + break; +#endif +#ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + { + /* For AA&N IDCT method, divisors are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + * We apply a further scale factor of 8. + */ +#define CONST_BITS 14 + static const INT16 aanscales[DCTSIZE2] = { + /* precomputed values scaled up by 14 bits */ + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, + 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, + 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, + 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, + 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 + }; + SHIFT_TEMPS + + if (fdct->divisors[qtblno] == NULL) { + fdct->divisors[qtblno] = (DCTELEM *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); + } + dtbl = fdct->divisors[qtblno]; + for (i = 0; i < DCTSIZE2; i++) { + if(!compute_reciprocal( + DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], + (INT32) aanscales[i]), + CONST_BITS-3), &dtbl[i]) + && fdct->quantize == jsimd_quantize) + fdct->quantize = quantize; + } + } + break; +#endif +#ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + { + /* For float AA&N IDCT method, divisors are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + * We apply a further scale factor of 8. + * What's actually stored is 1/divisor so that the inner loop can + * use a multiplication rather than a division. + */ + FAST_FLOAT * fdtbl; + int row, col; + static const double aanscalefactor[DCTSIZE] = { + 1.0, 1.387039845, 1.306562965, 1.175875602, + 1.0, 0.785694958, 0.541196100, 0.275899379 + }; + + if (fdct->float_divisors[qtblno] == NULL) { + fdct->float_divisors[qtblno] = (FAST_FLOAT *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + DCTSIZE2 * SIZEOF(FAST_FLOAT)); + } + fdtbl = fdct->float_divisors[qtblno]; + i = 0; + for (row = 0; row < DCTSIZE; row++) { + for (col = 0; col < DCTSIZE; col++) { + fdtbl[i] = (FAST_FLOAT) + (1.0 / (((double) qtbl->quantval[i] * + aanscalefactor[row] * aanscalefactor[col] * 8.0))); + i++; + } + } + } + break; +#endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + } +} + + +/* + * Load data into workspace, applying unsigned->signed conversion. + */ + +METHODDEF(void) +convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM * workspace) +{ + register DCTELEM *workspaceptr; + register JSAMPROW elemptr; + register int elemr; + + workspaceptr = workspace; + for (elemr = 0; elemr < DCTSIZE; elemr++) { + elemptr = sample_data[elemr] + start_col; + +#if DCTSIZE == 8 /* unroll the inner loop */ + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; +#else + { + register int elemc; + for (elemc = DCTSIZE; elemc > 0; elemc--) + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + } +#endif + } +} + + +/* + * Quantize/descale the coefficients, and store into coef_blocks[]. + */ + +METHODDEF(void) +quantize (JCOEFPTR coef_block, DCTELEM * divisors, DCTELEM * workspace) +{ + int i; + DCTELEM temp; + UDCTELEM recip, corr, shift; + UDCTELEM2 product; + JCOEFPTR output_ptr = coef_block; + + for (i = 0; i < DCTSIZE2; i++) { + temp = workspace[i]; + recip = divisors[i + DCTSIZE2 * 0]; + corr = divisors[i + DCTSIZE2 * 1]; + shift = divisors[i + DCTSIZE2 * 3]; + + if (temp < 0) { + temp = -temp; + product = (UDCTELEM2)(temp + corr) * recip; + product >>= shift + sizeof(DCTELEM)*8; + temp = product; + temp = -temp; + } else { + product = (UDCTELEM2)(temp + corr) * recip; + product >>= shift + sizeof(DCTELEM)*8; + temp = product; + } + + output_ptr[i] = (JCOEF) temp; + } +} + + +/* + * Perform forward DCT on one or more blocks of a component. + * + * The input samples are taken from the sample_data[] array starting at + * position start_row/start_col, and moving to the right for any additional + * blocks. The quantized coefficients are returned in coef_blocks[]. + */ + +METHODDEF(void) +forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY sample_data, JBLOCKROW coef_blocks, + JDIMENSION start_row, JDIMENSION start_col, + JDIMENSION num_blocks) +/* This version is used for integer DCT implementations. */ +{ + /* This routine is heavily used, so it's worth coding it tightly. */ + my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; + DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no]; + DCTELEM * workspace; + JDIMENSION bi; + + /* Make sure the compiler doesn't look up these every pass */ + forward_DCT_method_ptr do_dct = fdct->dct; + convsamp_method_ptr do_convsamp = fdct->convsamp; + quantize_method_ptr do_quantize = fdct->quantize; + workspace = fdct->workspace; + + sample_data += start_row; /* fold in the vertical offset once */ + + for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { + /* Load data into workspace, applying unsigned->signed conversion */ + (*do_convsamp) (sample_data, start_col, workspace); + + /* Perform the DCT */ + (*do_dct) (workspace); + + /* Quantize/descale the coefficients, and store into coef_blocks[] */ + (*do_quantize) (coef_blocks[bi], divisors, workspace); + } +} + + +#ifdef DCT_FLOAT_SUPPORTED + + +METHODDEF(void) +convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, FAST_FLOAT * workspace) +{ + register FAST_FLOAT *workspaceptr; + register JSAMPROW elemptr; + register int elemr; + + workspaceptr = workspace; + for (elemr = 0; elemr < DCTSIZE; elemr++) { + elemptr = sample_data[elemr] + start_col; +#if DCTSIZE == 8 /* unroll the inner loop */ + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); +#else + { + register int elemc; + for (elemc = DCTSIZE; elemc > 0; elemc--) + *workspaceptr++ = (FAST_FLOAT) + (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + } +#endif + } +} + + +METHODDEF(void) +quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, FAST_FLOAT * workspace) +{ + register FAST_FLOAT temp; + register int i; + register JCOEFPTR output_ptr = coef_block; + + for (i = 0; i < DCTSIZE2; i++) { + /* Apply the quantization and scaling factor */ + temp = workspace[i] * divisors[i]; + + /* Round to nearest integer. + * Since C does not specify the direction of rounding for negative + * quotients, we have to force the dividend positive for portability. + * The maximum coefficient size is +-16K (for 12-bit data), so this + * code should work for either 16-bit or 32-bit ints. + */ + output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384); + } +} + + +METHODDEF(void) +forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY sample_data, JBLOCKROW coef_blocks, + JDIMENSION start_row, JDIMENSION start_col, + JDIMENSION num_blocks) +/* This version is used for floating-point DCT implementations. */ +{ + /* This routine is heavily used, so it's worth coding it tightly. */ + my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; + FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no]; + FAST_FLOAT * workspace; + JDIMENSION bi; + + + /* Make sure the compiler doesn't look up these every pass */ + float_DCT_method_ptr do_dct = fdct->float_dct; + float_convsamp_method_ptr do_convsamp = fdct->float_convsamp; + float_quantize_method_ptr do_quantize = fdct->float_quantize; + workspace = fdct->float_workspace; + + sample_data += start_row; /* fold in the vertical offset once */ + + for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { + /* Load data into workspace, applying unsigned->signed conversion */ + (*do_convsamp) (sample_data, start_col, workspace); + + /* Perform the DCT */ + (*do_dct) (workspace); + + /* Quantize/descale the coefficients, and store into coef_blocks[] */ + (*do_quantize) (coef_blocks[bi], divisors, workspace); + } +} + +#endif /* DCT_FLOAT_SUPPORTED */ + + +/* + * Initialize FDCT manager. + */ + +GLOBAL(void) +jinit_forward_dct (j_compress_ptr cinfo) +{ + my_fdct_ptr fdct; + int i; + + fdct = (my_fdct_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_fdct_controller)); + cinfo->fdct = (struct jpeg_forward_dct *) fdct; + fdct->pub.start_pass = start_pass_fdctmgr; + + /* First determine the DCT... */ + switch (cinfo->dct_method) { +#ifdef DCT_ISLOW_SUPPORTED + case JDCT_ISLOW: + fdct->pub.forward_DCT = forward_DCT; + if (jsimd_can_fdct_islow()) + fdct->dct = jsimd_fdct_islow; + else + fdct->dct = jpeg_fdct_islow; + break; +#endif +#ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + fdct->pub.forward_DCT = forward_DCT; + if (jsimd_can_fdct_ifast()) + fdct->dct = jsimd_fdct_ifast; + else + fdct->dct = jpeg_fdct_ifast; + break; +#endif +#ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + fdct->pub.forward_DCT = forward_DCT_float; + if (jsimd_can_fdct_float()) + fdct->float_dct = jsimd_fdct_float; + else + fdct->float_dct = jpeg_fdct_float; + break; +#endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + + /* ...then the supporting stages. */ + switch (cinfo->dct_method) { +#ifdef DCT_ISLOW_SUPPORTED + case JDCT_ISLOW: +#endif +#ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: +#endif +#if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED) + if (jsimd_can_convsamp()) + fdct->convsamp = jsimd_convsamp; + else + fdct->convsamp = convsamp; + if (jsimd_can_quantize()) + fdct->quantize = jsimd_quantize; + else + fdct->quantize = quantize; + break; +#endif +#ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + if (jsimd_can_convsamp_float()) + fdct->float_convsamp = jsimd_convsamp_float; + else + fdct->float_convsamp = convsamp_float; + if (jsimd_can_quantize_float()) + fdct->float_quantize = jsimd_quantize_float; + else + fdct->float_quantize = quantize_float; + break; +#endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + + /* Allocate workspace memory */ +#ifdef DCT_FLOAT_SUPPORTED + if (cinfo->dct_method == JDCT_FLOAT) + fdct->float_workspace = (FAST_FLOAT *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(FAST_FLOAT) * DCTSIZE2); + else +#endif + fdct->workspace = (DCTELEM *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(DCTELEM) * DCTSIZE2); + + /* Mark divisor tables unallocated */ + for (i = 0; i < NUM_QUANT_TBLS; i++) { + fdct->divisors[i] = NULL; +#ifdef DCT_FLOAT_SUPPORTED + fdct->float_divisors[i] = NULL; +#endif + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jchuff.c b/lib-third-party/libturbojpeg-ios/libjpeg/jchuff.c new file mode 100755 index 0000000..fd4fa46 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jchuff.c @@ -0,0 +1,1026 @@ +/* + * jchuff.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright (C) 2009-2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy encoding routines. + * + * Much of the complexity here has to do with supporting output suspension. + * If the data destination module demands suspension, we want to be able to + * back up to the start of the current MCU. To do this, we copy state + * variables into local working storage, and update them back to the + * permanent JPEG objects only upon successful completion of an MCU. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jchuff.h" /* Declarations shared with jcphuff.c */ +#include + +static unsigned char jpeg_nbits_table[65536]; +static int jpeg_nbits_table_init = 0; + +#ifndef min + #define min(a,b) ((a)<(b)?(a):(b)) +#endif + + +/* Expanded entropy encoder object for Huffman encoding. + * + * The savable_state subrecord contains fields that change within an MCU, + * but must not be updated permanently until we complete the MCU. + */ + +typedef struct { + size_t put_buffer; /* current bit-accumulation buffer */ + int put_bits; /* # of bits now in it */ + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ +} savable_state; + +/* This macro is to work around compilers with missing or broken + * structure assignment. You'll need to fix this code if you have + * such a compiler and you change MAX_COMPS_IN_SCAN. + */ + +#ifndef NO_STRUCT_ASSIGN +#define ASSIGN_STATE(dest,src) ((dest) = (src)) +#else +#if MAX_COMPS_IN_SCAN == 4 +#define ASSIGN_STATE(dest,src) \ + ((dest).put_buffer = (src).put_buffer, \ + (dest).put_bits = (src).put_bits, \ + (dest).last_dc_val[0] = (src).last_dc_val[0], \ + (dest).last_dc_val[1] = (src).last_dc_val[1], \ + (dest).last_dc_val[2] = (src).last_dc_val[2], \ + (dest).last_dc_val[3] = (src).last_dc_val[3]) +#endif +#endif + + +typedef struct { + struct jpeg_entropy_encoder pub; /* public fields */ + + savable_state saved; /* Bit buffer & DC state at start of MCU */ + + /* These fields are NOT loaded into local working state. */ + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + int next_restart_num; /* next restart number to write (0-7) */ + + /* Pointers to derived tables (these workspaces have image lifespan) */ + c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; + c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]; + +#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */ + long * dc_count_ptrs[NUM_HUFF_TBLS]; + long * ac_count_ptrs[NUM_HUFF_TBLS]; +#endif +} huff_entropy_encoder; + +typedef huff_entropy_encoder * huff_entropy_ptr; + +/* Working state while writing an MCU. + * This struct contains all the fields that are needed by subroutines. + */ + +typedef struct { + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + savable_state cur; /* Current bit buffer & DC state */ + j_compress_ptr cinfo; /* dump_buffer needs access to this */ +} working_state; + + +/* Forward declarations */ +METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo)); +#ifdef ENTROPY_OPT_SUPPORTED +METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo)); +#endif + + +/* + * Initialize for a Huffman-compressed scan. + * If gather_statistics is TRUE, we do not output anything during the scan, + * just count the Huffman symbols used and generate Huffman code tables. + */ + +METHODDEF(void) +start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci, dctbl, actbl; + jpeg_component_info * compptr; + + if (gather_statistics) { +#ifdef ENTROPY_OPT_SUPPORTED + entropy->pub.encode_mcu = encode_mcu_gather; + entropy->pub.finish_pass = finish_pass_gather; +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else { + entropy->pub.encode_mcu = encode_mcu_huff; + entropy->pub.finish_pass = finish_pass_huff; + } + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + dctbl = compptr->dc_tbl_no; + actbl = compptr->ac_tbl_no; + if (gather_statistics) { +#ifdef ENTROPY_OPT_SUPPORTED + /* Check for invalid table indexes */ + /* (make_c_derived_tbl does this in the other path) */ + if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); + if (actbl < 0 || actbl >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); + /* Allocate and zero the statistics tables */ + /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ + if (entropy->dc_count_ptrs[dctbl] == NULL) + entropy->dc_count_ptrs[dctbl] = (long *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 257 * SIZEOF(long)); + MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long)); + if (entropy->ac_count_ptrs[actbl] == NULL) + entropy->ac_count_ptrs[actbl] = (long *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 257 * SIZEOF(long)); + MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long)); +#endif + } else { + /* Compute derived values for Huffman tables */ + /* We may do this more than once for a table, but it's not expensive */ + jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl, + & entropy->dc_derived_tbls[dctbl]); + jpeg_make_c_derived_tbl(cinfo, FALSE, actbl, + & entropy->ac_derived_tbls[actbl]); + } + /* Initialize DC predictions to 0 */ + entropy->saved.last_dc_val[ci] = 0; + } + + /* Initialize bit buffer to empty */ + entropy->saved.put_buffer = 0; + entropy->saved.put_bits = 0; + + /* Initialize restart stuff */ + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num = 0; +} + + +/* + * Compute the derived values for a Huffman table. + * This routine also performs some validation checks on the table. + * + * Note this is also used by jcphuff.c. + */ + +GLOBAL(void) +jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno, + c_derived_tbl ** pdtbl) +{ + JHUFF_TBL *htbl; + c_derived_tbl *dtbl; + int p, i, l, lastp, si, maxsymbol; + char huffsize[257]; + unsigned int huffcode[257]; + unsigned int code; + + /* Note that huffsize[] and huffcode[] are filled in code-length order, + * paralleling the order of the symbols themselves in htbl->huffval[]. + */ + + /* Find the input Huffman table */ + if (tblno < 0 || tblno >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); + htbl = + isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno]; + if (htbl == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); + + /* Allocate a workspace if we haven't already done so. */ + if (*pdtbl == NULL) + *pdtbl = (c_derived_tbl *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(c_derived_tbl)); + dtbl = *pdtbl; + + /* Figure C.1: make table of Huffman code length for each symbol */ + + p = 0; + for (l = 1; l <= 16; l++) { + i = (int) htbl->bits[l]; + if (i < 0 || p + i > 256) /* protect against table overrun */ + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + while (i--) + huffsize[p++] = (char) l; + } + huffsize[p] = 0; + lastp = p; + + /* Figure C.2: generate the codes themselves */ + /* We also validate that the counts represent a legal Huffman code tree. */ + + code = 0; + si = huffsize[0]; + p = 0; + while (huffsize[p]) { + while (((int) huffsize[p]) == si) { + huffcode[p++] = code; + code++; + } + /* code is now 1 more than the last code used for codelength si; but + * it must still fit in si bits, since no code is allowed to be all ones. + */ + if (((INT32) code) >= (((INT32) 1) << si)) + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + code <<= 1; + si++; + } + + /* Figure C.3: generate encoding tables */ + /* These are code and size indexed by symbol value */ + + /* Set all codeless symbols to have code length 0; + * this lets us detect duplicate VAL entries here, and later + * allows emit_bits to detect any attempt to emit such symbols. + */ + MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi)); + + /* This is also a convenient place to check for out-of-range + * and duplicated VAL entries. We allow 0..255 for AC symbols + * but only 0..15 for DC. (We could constrain them further + * based on data depth and mode, but this seems enough.) + */ + maxsymbol = isDC ? 15 : 255; + + for (p = 0; p < lastp; p++) { + i = htbl->huffval[p]; + if (i < 0 || i > maxsymbol || dtbl->ehufsi[i]) + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + dtbl->ehufco[i] = huffcode[p]; + dtbl->ehufsi[i] = huffsize[p]; + } + + if(!jpeg_nbits_table_init) { + for(i = 0; i < 65536; i++) { + int nbits = 0, temp = i; + while (temp) {temp >>= 1; nbits++;} + jpeg_nbits_table[i] = nbits; + } + jpeg_nbits_table_init = 1; + } +} + + +/* Outputting bytes to the file */ + +/* Emit a byte, taking 'action' if must suspend. */ +#define emit_byte(state,val,action) \ + { *(state)->next_output_byte++ = (JOCTET) (val); \ + if (--(state)->free_in_buffer == 0) \ + if (! dump_buffer(state)) \ + { action; } } + + +LOCAL(boolean) +dump_buffer (working_state * state) +/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */ +{ + struct jpeg_destination_mgr * dest = state->cinfo->dest; + + dest->free_in_buffer = state->free_in_buffer; + + if (! (*dest->empty_output_buffer) (state->cinfo)) + return FALSE; + /* After a successful buffer dump, must reset buffer pointers */ + state->next_output_byte = dest->next_output_byte; + state->free_in_buffer = dest->free_in_buffer; + return TRUE; +} + + +/* Outputting bits to the file */ + +/* These macros perform the same task as the emit_bits() function in the + * original libjpeg code. In addition to reducing overhead by explicitly + * inlining the code, additional performance is achieved by taking into + * account the size of the bit buffer and waiting until it is almost full + * before emptying it. This mostly benefits 64-bit platforms, since 6 + * bytes can be stored in a 64-bit bit buffer before it has to be emptied. + */ + +#define EMIT_BYTE() { \ + JOCTET c; \ + put_bits -= 8; \ + c = (JOCTET)GETJOCTET(put_buffer >> put_bits); \ + *buffer++ = c; \ + if (c == 0xFF) /* need to stuff a zero byte? */ \ + *buffer++ = 0; \ + } + +#define PUT_BITS(code, size) { \ + put_bits += size; \ + put_buffer = (put_buffer << size) | code; \ +} + +#define CHECKBUF15() { \ + if (put_bits > 15) { \ + EMIT_BYTE() \ + EMIT_BYTE() \ + } \ +} + +#define CHECKBUF31() { \ + if (put_bits > 31) { \ + EMIT_BYTE() \ + EMIT_BYTE() \ + EMIT_BYTE() \ + EMIT_BYTE() \ + } \ +} + +#define CHECKBUF47() { \ + if (put_bits > 47) { \ + EMIT_BYTE() \ + EMIT_BYTE() \ + EMIT_BYTE() \ + EMIT_BYTE() \ + EMIT_BYTE() \ + EMIT_BYTE() \ + } \ +} + +#if __WORDSIZE==64 || defined(_WIN64) + +#define EMIT_BITS(code, size) { \ + CHECKBUF47() \ + PUT_BITS(code, size) \ +} + +#define EMIT_CODE(code, size) { \ + temp2 &= (((INT32) 1)<free_in_buffer < BUFSIZE) { \ + localbuf = 1; \ + buffer = _buffer; \ + } \ + else buffer = state->next_output_byte; \ + } + +#define STORE_BUFFER() { \ + if (localbuf) { \ + bytes = buffer - _buffer; \ + buffer = _buffer; \ + while (bytes > 0) { \ + bytestocopy = min(bytes, state->free_in_buffer); \ + MEMCOPY(state->next_output_byte, buffer, bytestocopy); \ + state->next_output_byte += bytestocopy; \ + buffer += bytestocopy; \ + state->free_in_buffer -= bytestocopy; \ + if (state->free_in_buffer == 0) \ + if (! dump_buffer(state)) return FALSE; \ + bytes -= bytestocopy; \ + } \ + } \ + else { \ + state->free_in_buffer -= (buffer - state->next_output_byte); \ + state->next_output_byte = buffer; \ + } \ + } + + +LOCAL(boolean) +flush_bits (working_state * state) +{ + JOCTET _buffer[BUFSIZE], *buffer; + size_t put_buffer; int put_bits; + size_t bytes, bytestocopy; int localbuf = 0; + + put_buffer = state->cur.put_buffer; + put_bits = state->cur.put_bits; + LOAD_BUFFER() + + /* fill any partial byte with ones */ + PUT_BITS(0x7F, 7) + while (put_bits >= 8) EMIT_BYTE() + + state->cur.put_buffer = 0; /* and reset bit-buffer to empty */ + state->cur.put_bits = 0; + STORE_BUFFER() + + return TRUE; +} + + +/* Encode a single block's worth of coefficients */ + +LOCAL(boolean) +encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, + c_derived_tbl *dctbl, c_derived_tbl *actbl) +{ + int temp, temp2, temp3; + int nbits; + int r, code, size; + JOCTET _buffer[BUFSIZE], *buffer; + size_t put_buffer; int put_bits; + int code_0xf0 = actbl->ehufco[0xf0], size_0xf0 = actbl->ehufsi[0xf0]; + size_t bytes, bytestocopy; int localbuf = 0; + + put_buffer = state->cur.put_buffer; + put_bits = state->cur.put_bits; + LOAD_BUFFER() + + /* Encode the DC coefficient difference per section F.1.2.1 */ + + temp = temp2 = block[0] - last_dc_val; + + /* This is a well-known technique for obtaining the absolute value without a + * branch. It is derived from an assembly language technique presented in + * "How to Optimize for the Pentium Processors", Copyright (c) 1996, 1997 by + * Agner Fog. + */ + temp3 = temp >> (CHAR_BIT * sizeof(int) - 1); + temp ^= temp3; + temp -= temp3; + + /* For a negative input, want temp2 = bitwise complement of abs(input) */ + /* This code assumes we are on a two's complement machine */ + temp2 += temp3; + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = jpeg_nbits_table[temp]; + + /* Emit the Huffman-coded symbol for the number of bits */ + code = dctbl->ehufco[nbits]; + size = dctbl->ehufsi[nbits]; + PUT_BITS(code, size) + CHECKBUF15() + + /* Mask off any extra bits in code */ + temp2 &= (((INT32) 1)<> (CHAR_BIT * sizeof(int) - 1); \ + temp ^= temp3; \ + temp -= temp3; \ + temp2 += temp3; \ + nbits = jpeg_nbits_table[temp]; \ + /* if run length > 15, must emit special run-length-16 codes (0xF0) */ \ + while (r > 15) { \ + EMIT_BITS(code_0xf0, size_0xf0) \ + r -= 16; \ + } \ + /* Emit Huffman symbol for run length / number of bits */ \ + temp3 = (r << 4) + nbits; \ + code = actbl->ehufco[temp3]; \ + size = actbl->ehufsi[temp3]; \ + EMIT_CODE(code, size) \ + r = 0; \ + } \ +} + + /* One iteration for each value in jpeg_natural_order[] */ + kloop(1); kloop(8); kloop(16); kloop(9); kloop(2); kloop(3); + kloop(10); kloop(17); kloop(24); kloop(32); kloop(25); kloop(18); + kloop(11); kloop(4); kloop(5); kloop(12); kloop(19); kloop(26); + kloop(33); kloop(40); kloop(48); kloop(41); kloop(34); kloop(27); + kloop(20); kloop(13); kloop(6); kloop(7); kloop(14); kloop(21); + kloop(28); kloop(35); kloop(42); kloop(49); kloop(56); kloop(57); + kloop(50); kloop(43); kloop(36); kloop(29); kloop(22); kloop(15); + kloop(23); kloop(30); kloop(37); kloop(44); kloop(51); kloop(58); + kloop(59); kloop(52); kloop(45); kloop(38); kloop(31); kloop(39); + kloop(46); kloop(53); kloop(60); kloop(61); kloop(54); kloop(47); + kloop(55); kloop(62); kloop(63); + + /* If the last coef(s) were zero, emit an end-of-block code */ + if (r > 0) { + code = actbl->ehufco[0]; + size = actbl->ehufsi[0]; + EMIT_BITS(code, size) + } + + state->cur.put_buffer = put_buffer; + state->cur.put_bits = put_bits; + STORE_BUFFER() + + return TRUE; +} + + +/* + * Emit a restart marker & resynchronize predictions. + */ + +LOCAL(boolean) +emit_restart (working_state * state, int restart_num) +{ + int ci; + + if (! flush_bits(state)) + return FALSE; + + emit_byte(state, 0xFF, return FALSE); + emit_byte(state, JPEG_RST0 + restart_num, return FALSE); + + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < state->cinfo->comps_in_scan; ci++) + state->cur.last_dc_val[ci] = 0; + + /* The restart counter is not updated until we successfully write the MCU. */ + + return TRUE; +} + + +/* + * Encode and output one MCU's worth of Huffman-compressed coefficients. + */ + +METHODDEF(boolean) +encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + working_state state; + int blkn, ci; + jpeg_component_info * compptr; + + /* Load up working state */ + state.next_output_byte = cinfo->dest->next_output_byte; + state.free_in_buffer = cinfo->dest->free_in_buffer; + ASSIGN_STATE(state.cur, entropy->saved); + state.cinfo = cinfo; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! emit_restart(&state, entropy->next_restart_num)) + return FALSE; + } + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + if (! encode_one_block(&state, + MCU_data[blkn][0], state.cur.last_dc_val[ci], + entropy->dc_derived_tbls[compptr->dc_tbl_no], + entropy->ac_derived_tbls[compptr->ac_tbl_no])) + return FALSE; + /* Update last_dc_val */ + state.cur.last_dc_val[ci] = MCU_data[blkn][0][0]; + } + + /* Completed MCU, so update state */ + cinfo->dest->next_output_byte = state.next_output_byte; + cinfo->dest->free_in_buffer = state.free_in_buffer; + ASSIGN_STATE(entropy->saved, state.cur); + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; +} + + +/* + * Finish up at the end of a Huffman-compressed scan. + */ + +METHODDEF(void) +finish_pass_huff (j_compress_ptr cinfo) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + working_state state; + + /* Load up working state ... flush_bits needs it */ + state.next_output_byte = cinfo->dest->next_output_byte; + state.free_in_buffer = cinfo->dest->free_in_buffer; + ASSIGN_STATE(state.cur, entropy->saved); + state.cinfo = cinfo; + + /* Flush out the last data */ + if (! flush_bits(&state)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + + /* Update state */ + cinfo->dest->next_output_byte = state.next_output_byte; + cinfo->dest->free_in_buffer = state.free_in_buffer; + ASSIGN_STATE(entropy->saved, state.cur); +} + + +/* + * Huffman coding optimization. + * + * We first scan the supplied data and count the number of uses of each symbol + * that is to be Huffman-coded. (This process MUST agree with the code above.) + * Then we build a Huffman coding tree for the observed counts. + * Symbols which are not needed at all for the particular image are not + * assigned any code, which saves space in the DHT marker as well as in + * the compressed data. + */ + +#ifdef ENTROPY_OPT_SUPPORTED + + +/* Process a single block's worth of coefficients */ + +LOCAL(void) +htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, + long dc_counts[], long ac_counts[]) +{ + register int temp; + register int nbits; + register int k, r; + + /* Encode the DC coefficient difference per section F.1.2.1 */ + + temp = block[0] - last_dc_val; + if (temp < 0) + temp = -temp; + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 0; + while (temp) { + nbits++; + temp >>= 1; + } + /* Check for out-of-range coefficient values. + * Since we're encoding a difference, the range limit is twice as much. + */ + if (nbits > MAX_COEF_BITS+1) + ERREXIT(cinfo, JERR_BAD_DCT_COEF); + + /* Count the Huffman symbol for the number of bits */ + dc_counts[nbits]++; + + /* Encode the AC coefficients per section F.1.2.2 */ + + r = 0; /* r = run length of zeros */ + + for (k = 1; k < DCTSIZE2; k++) { + if ((temp = block[jpeg_natural_order[k]]) == 0) { + r++; + } else { + /* if run length > 15, must emit special run-length-16 codes (0xF0) */ + while (r > 15) { + ac_counts[0xF0]++; + r -= 16; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + if (temp < 0) + temp = -temp; + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 1; /* there must be at least one 1 bit */ + while ((temp >>= 1)) + nbits++; + /* Check for out-of-range coefficient values */ + if (nbits > MAX_COEF_BITS) + ERREXIT(cinfo, JERR_BAD_DCT_COEF); + + /* Count Huffman symbol for run length / number of bits */ + ac_counts[(r << 4) + nbits]++; + + r = 0; + } + } + + /* If the last coef(s) were zero, emit an end-of-block code */ + if (r > 0) + ac_counts[0]++; +} + + +/* + * Trial-encode one MCU's worth of Huffman-compressed coefficients. + * No data is actually output, so no suspension return is possible. + */ + +METHODDEF(boolean) +encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int blkn, ci; + jpeg_component_info * compptr; + + /* Take care of restart intervals if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) + entropy->saved.last_dc_val[ci] = 0; + /* Update restart state */ + entropy->restarts_to_go = cinfo->restart_interval; + } + entropy->restarts_to_go--; + } + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci], + entropy->dc_count_ptrs[compptr->dc_tbl_no], + entropy->ac_count_ptrs[compptr->ac_tbl_no]); + entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0]; + } + + return TRUE; +} + + +/* + * Generate the best Huffman code table for the given counts, fill htbl. + * Note this is also used by jcphuff.c. + * + * The JPEG standard requires that no symbol be assigned a codeword of all + * one bits (so that padding bits added at the end of a compressed segment + * can't look like a valid code). Because of the canonical ordering of + * codewords, this just means that there must be an unused slot in the + * longest codeword length category. Section K.2 of the JPEG spec suggests + * reserving such a slot by pretending that symbol 256 is a valid symbol + * with count 1. In theory that's not optimal; giving it count zero but + * including it in the symbol set anyway should give a better Huffman code. + * But the theoretically better code actually seems to come out worse in + * practice, because it produces more all-ones bytes (which incur stuffed + * zero bytes in the final file). In any case the difference is tiny. + * + * The JPEG standard requires Huffman codes to be no more than 16 bits long. + * If some symbols have a very small but nonzero probability, the Huffman tree + * must be adjusted to meet the code length restriction. We currently use + * the adjustment method suggested in JPEG section K.2. This method is *not* + * optimal; it may not choose the best possible limited-length code. But + * typically only very-low-frequency symbols will be given less-than-optimal + * lengths, so the code is almost optimal. Experimental comparisons against + * an optimal limited-length-code algorithm indicate that the difference is + * microscopic --- usually less than a hundredth of a percent of total size. + * So the extra complexity of an optimal algorithm doesn't seem worthwhile. + */ + +GLOBAL(void) +jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]) +{ +#define MAX_CLEN 32 /* assumed maximum initial code length */ + UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */ + int codesize[257]; /* codesize[k] = code length of symbol k */ + int others[257]; /* next symbol in current branch of tree */ + int c1, c2; + int p, i, j; + long v; + + /* This algorithm is explained in section K.2 of the JPEG standard */ + + MEMZERO(bits, SIZEOF(bits)); + MEMZERO(codesize, SIZEOF(codesize)); + for (i = 0; i < 257; i++) + others[i] = -1; /* init links to empty */ + + freq[256] = 1; /* make sure 256 has a nonzero count */ + /* Including the pseudo-symbol 256 in the Huffman procedure guarantees + * that no real symbol is given code-value of all ones, because 256 + * will be placed last in the largest codeword category. + */ + + /* Huffman's basic algorithm to assign optimal code lengths to symbols */ + + for (;;) { + /* Find the smallest nonzero frequency, set c1 = its symbol */ + /* In case of ties, take the larger symbol number */ + c1 = -1; + v = 1000000000L; + for (i = 0; i <= 256; i++) { + if (freq[i] && freq[i] <= v) { + v = freq[i]; + c1 = i; + } + } + + /* Find the next smallest nonzero frequency, set c2 = its symbol */ + /* In case of ties, take the larger symbol number */ + c2 = -1; + v = 1000000000L; + for (i = 0; i <= 256; i++) { + if (freq[i] && freq[i] <= v && i != c1) { + v = freq[i]; + c2 = i; + } + } + + /* Done if we've merged everything into one frequency */ + if (c2 < 0) + break; + + /* Else merge the two counts/trees */ + freq[c1] += freq[c2]; + freq[c2] = 0; + + /* Increment the codesize of everything in c1's tree branch */ + codesize[c1]++; + while (others[c1] >= 0) { + c1 = others[c1]; + codesize[c1]++; + } + + others[c1] = c2; /* chain c2 onto c1's tree branch */ + + /* Increment the codesize of everything in c2's tree branch */ + codesize[c2]++; + while (others[c2] >= 0) { + c2 = others[c2]; + codesize[c2]++; + } + } + + /* Now count the number of symbols of each code length */ + for (i = 0; i <= 256; i++) { + if (codesize[i]) { + /* The JPEG standard seems to think that this can't happen, */ + /* but I'm paranoid... */ + if (codesize[i] > MAX_CLEN) + ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW); + + bits[codesize[i]]++; + } + } + + /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure + * Huffman procedure assigned any such lengths, we must adjust the coding. + * Here is what the JPEG spec says about how this next bit works: + * Since symbols are paired for the longest Huffman code, the symbols are + * removed from this length category two at a time. The prefix for the pair + * (which is one bit shorter) is allocated to one of the pair; then, + * skipping the BITS entry for that prefix length, a code word from the next + * shortest nonzero BITS entry is converted into a prefix for two code words + * one bit longer. + */ + + for (i = MAX_CLEN; i > 16; i--) { + while (bits[i] > 0) { + j = i - 2; /* find length of new prefix to be used */ + while (bits[j] == 0) + j--; + + bits[i] -= 2; /* remove two symbols */ + bits[i-1]++; /* one goes in this length */ + bits[j+1] += 2; /* two new symbols in this length */ + bits[j]--; /* symbol of this length is now a prefix */ + } + } + + /* Remove the count for the pseudo-symbol 256 from the largest codelength */ + while (bits[i] == 0) /* find largest codelength still in use */ + i--; + bits[i]--; + + /* Return final symbol counts (only for lengths 0..16) */ + MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits)); + + /* Return a list of the symbols sorted by code length */ + /* It's not real clear to me why we don't need to consider the codelength + * changes made above, but the JPEG spec seems to think this works. + */ + p = 0; + for (i = 1; i <= MAX_CLEN; i++) { + for (j = 0; j <= 255; j++) { + if (codesize[j] == i) { + htbl->huffval[p] = (UINT8) j; + p++; + } + } + } + + /* Set sent_table FALSE so updated table will be written to JPEG file. */ + htbl->sent_table = FALSE; +} + + +/* + * Finish up a statistics-gathering pass and create the new Huffman tables. + */ + +METHODDEF(void) +finish_pass_gather (j_compress_ptr cinfo) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci, dctbl, actbl; + jpeg_component_info * compptr; + JHUFF_TBL **htblptr; + boolean did_dc[NUM_HUFF_TBLS]; + boolean did_ac[NUM_HUFF_TBLS]; + + /* It's important not to apply jpeg_gen_optimal_table more than once + * per table, because it clobbers the input frequency counts! + */ + MEMZERO(did_dc, SIZEOF(did_dc)); + MEMZERO(did_ac, SIZEOF(did_ac)); + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + dctbl = compptr->dc_tbl_no; + actbl = compptr->ac_tbl_no; + if (! did_dc[dctbl]) { + htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl]; + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]); + did_dc[dctbl] = TRUE; + } + if (! did_ac[actbl]) { + htblptr = & cinfo->ac_huff_tbl_ptrs[actbl]; + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]); + did_ac[actbl] = TRUE; + } + } +} + + +#endif /* ENTROPY_OPT_SUPPORTED */ + + +/* + * Module initialization routine for Huffman entropy encoding. + */ + +GLOBAL(void) +jinit_huff_encoder (j_compress_ptr cinfo) +{ + huff_entropy_ptr entropy; + int i; + + entropy = (huff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(huff_entropy_encoder)); + cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; + entropy->pub.start_pass = start_pass_huff; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; +#ifdef ENTROPY_OPT_SUPPORTED + entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL; +#endif + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jchuff.h b/lib-third-party/libturbojpeg-ios/libjpeg/jchuff.h new file mode 100755 index 0000000..a9599fc --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jchuff.h @@ -0,0 +1,47 @@ +/* + * jchuff.h + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains declarations for Huffman entropy encoding routines + * that are shared between the sequential encoder (jchuff.c) and the + * progressive encoder (jcphuff.c). No other modules need to see these. + */ + +/* The legal range of a DCT coefficient is + * -1024 .. +1023 for 8-bit data; + * -16384 .. +16383 for 12-bit data. + * Hence the magnitude should always fit in 10 or 14 bits respectively. + */ + +#if BITS_IN_JSAMPLE == 8 +#define MAX_COEF_BITS 10 +#else +#define MAX_COEF_BITS 14 +#endif + +/* Derived data constructed for each Huffman table */ + +typedef struct { + unsigned int ehufco[256]; /* code for each symbol */ + char ehufsi[256]; /* length of code for each symbol */ + /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */ +} c_derived_tbl; + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_make_c_derived_tbl jMkCDerived +#define jpeg_gen_optimal_table jGenOptTbl +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +/* Expand a Huffman table definition into the derived format */ +EXTERN(void) jpeg_make_c_derived_tbl + JPP((j_compress_ptr cinfo, boolean isDC, int tblno, + c_derived_tbl ** pdtbl)); + +/* Generate an optimal table definition given the specified counts */ +EXTERN(void) jpeg_gen_optimal_table + JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])); diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcinit.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcinit.c new file mode 100755 index 0000000..de0ade2 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcinit.c @@ -0,0 +1,76 @@ +/* + * jcinit.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains initialization logic for the JPEG compressor. + * This routine is in charge of selecting the modules to be executed and + * making an initialization call to each one. + * + * Logically, this code belongs in jcmaster.c. It's split out because + * linking this routine implies linking the entire compression library. + * For a transcoding-only application, we want to be able to use jcmaster.c + * without linking in the whole library. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* + * Master selection of compression modules. + * This is done once at the start of processing an image. We determine + * which modules will be used and give them appropriate initialization calls. + */ + +GLOBAL(void) +jinit_compress_master (j_compress_ptr cinfo) +{ + /* Initialize master control (includes parameter checking/processing) */ + jinit_c_master_control(cinfo, FALSE /* full compression */); + + /* Preprocessing */ + if (! cinfo->raw_data_in) { + jinit_color_converter(cinfo); + jinit_downsampler(cinfo); + jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); + } + /* Forward DCT */ + jinit_forward_dct(cinfo); + /* Entropy encoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { +#ifdef C_ARITH_CODING_SUPPORTED + jinit_arith_encoder(cinfo); +#else + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); +#endif + } else { + if (cinfo->progressive_mode) { +#ifdef C_PROGRESSIVE_SUPPORTED + jinit_phuff_encoder(cinfo); +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else + jinit_huff_encoder(cinfo); + } + + /* Need a full-image coefficient buffer in any multi-pass mode. */ + jinit_c_coef_controller(cinfo, + (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding)); + jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); + + jinit_marker_writer(cinfo); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Write the datastream header (SOI) immediately. + * Frame and scan headers are postponed till later. + * This lets application insert special markers after the SOI. + */ + (*cinfo->marker->write_file_header) (cinfo); +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcmainct.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcmainct.c new file mode 100755 index 0000000..bd0051a --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcmainct.c @@ -0,0 +1,293 @@ +/* + * jcmainct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the main buffer controller for compression. + * The main buffer lies between the pre-processor and the JPEG + * compressor proper; it holds downsampled data in the JPEG colorspace. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* Note: currently, there is no operating mode in which a full-image buffer + * is needed at this step. If there were, that mode could not be used with + * "raw data" input, since this module is bypassed in that case. However, + * we've left the code here for possible use in special applications. + */ +#undef FULL_MAIN_BUFFER_SUPPORTED + + +/* Private buffer controller object */ + +typedef struct { + struct jpeg_c_main_controller pub; /* public fields */ + + JDIMENSION cur_iMCU_row; /* number of current iMCU row */ + JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */ + boolean suspended; /* remember if we suspended output */ + J_BUF_MODE pass_mode; /* current operating mode */ + + /* If using just a strip buffer, this points to the entire set of buffers + * (we allocate one for each component). In the full-image case, this + * points to the currently accessible strips of the virtual arrays. + */ + JSAMPARRAY buffer[MAX_COMPONENTS]; + +#ifdef FULL_MAIN_BUFFER_SUPPORTED + /* If using full-image storage, this array holds pointers to virtual-array + * control blocks for each component. Unused if not full-image storage. + */ + jvirt_sarray_ptr whole_image[MAX_COMPONENTS]; +#endif +} my_main_controller; + +typedef my_main_controller * my_main_ptr; + + +/* Forward declarations */ +METHODDEF(void) process_data_simple_main + JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, + JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); +#ifdef FULL_MAIN_BUFFER_SUPPORTED +METHODDEF(void) process_data_buffer_main + JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, + JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); +#endif + + +/* + * Initialize for a processing pass. + */ + +METHODDEF(void) +start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode) +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + + /* Do nothing in raw-data mode. */ + if (cinfo->raw_data_in) + return; + + main_ptr->cur_iMCU_row = 0; /* initialize counters */ + main_ptr->rowgroup_ctr = 0; + main_ptr->suspended = FALSE; + main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */ + + switch (pass_mode) { + case JBUF_PASS_THRU: +#ifdef FULL_MAIN_BUFFER_SUPPORTED + if (main_ptr->whole_image[0] != NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); +#endif + main_ptr->pub.process_data = process_data_simple_main; + break; +#ifdef FULL_MAIN_BUFFER_SUPPORTED + case JBUF_SAVE_SOURCE: + case JBUF_CRANK_DEST: + case JBUF_SAVE_AND_PASS: + if (main_ptr->whole_image[0] == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + main_ptr->pub.process_data = process_data_buffer_main; + break; +#endif + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } +} + + +/* + * Process some data. + * This routine handles the simple pass-through mode, + * where we have only a strip buffer. + */ + +METHODDEF(void) +process_data_simple_main (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail) +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + + while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) { + /* Read input data if we haven't filled the main buffer yet */ + if (main_ptr->rowgroup_ctr < DCTSIZE) + (*cinfo->prep->pre_process_data) (cinfo, + input_buf, in_row_ctr, in_rows_avail, + main_ptr->buffer, &main_ptr->rowgroup_ctr, + (JDIMENSION) DCTSIZE); + + /* If we don't have a full iMCU row buffered, return to application for + * more data. Note that preprocessor will always pad to fill the iMCU row + * at the bottom of the image. + */ + if (main_ptr->rowgroup_ctr != DCTSIZE) + return; + + /* Send the completed row to the compressor */ + if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) { + /* If compressor did not consume the whole row, then we must need to + * suspend processing and return to the application. In this situation + * we pretend we didn't yet consume the last input row; otherwise, if + * it happened to be the last row of the image, the application would + * think we were done. + */ + if (! main_ptr->suspended) { + (*in_row_ctr)--; + main_ptr->suspended = TRUE; + } + return; + } + /* We did finish the row. Undo our little suspension hack if a previous + * call suspended; then mark the main buffer empty. + */ + if (main_ptr->suspended) { + (*in_row_ctr)++; + main_ptr->suspended = FALSE; + } + main_ptr->rowgroup_ctr = 0; + main_ptr->cur_iMCU_row++; + } +} + + +#ifdef FULL_MAIN_BUFFER_SUPPORTED + +/* + * Process some data. + * This routine handles all of the modes that use a full-size buffer. + */ + +METHODDEF(void) +process_data_buffer_main (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail) +{ + my_main_ptr main = (my_main_ptr) cinfo->main; + int ci; + jpeg_component_info *compptr; + boolean writing = (main_ptr->pass_mode != JBUF_CRANK_DEST); + + while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) { + /* Realign the virtual buffers if at the start of an iMCU row. */ + if (main_ptr->rowgroup_ctr == 0) { + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + main_ptr->buffer[ci] = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, main_ptr->whole_image[ci], + main_ptr->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE), + (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing); + } + /* In a read pass, pretend we just read some source data. */ + if (! writing) { + *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE; + main_ptr->rowgroup_ctr = DCTSIZE; + } + } + + /* If a write pass, read input data until the current iMCU row is full. */ + /* Note: preprocessor will pad if necessary to fill the last iMCU row. */ + if (writing) { + (*cinfo->prep->pre_process_data) (cinfo, + input_buf, in_row_ctr, in_rows_avail, + main_ptr->buffer, &main_ptr->rowgroup_ctr, + (JDIMENSION) DCTSIZE); + /* Return to application if we need more data to fill the iMCU row. */ + if (main_ptr->rowgroup_ctr < DCTSIZE) + return; + } + + /* Emit data, unless this is a sink-only pass. */ + if (main_ptr->pass_mode != JBUF_SAVE_SOURCE) { + if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) { + /* If compressor did not consume the whole row, then we must need to + * suspend processing and return to the application. In this situation + * we pretend we didn't yet consume the last input row; otherwise, if + * it happened to be the last row of the image, the application would + * think we were done. + */ + if (! main_ptr->suspended) { + (*in_row_ctr)--; + main_ptr->suspended = TRUE; + } + return; + } + /* We did finish the row. Undo our little suspension hack if a previous + * call suspended; then mark the main buffer empty. + */ + if (main_ptr->suspended) { + (*in_row_ctr)++; + main_ptr->suspended = FALSE; + } + } + + /* If get here, we are done with this iMCU row. Mark buffer empty. */ + main_ptr->rowgroup_ctr = 0; + main_ptr->cur_iMCU_row++; + } +} + +#endif /* FULL_MAIN_BUFFER_SUPPORTED */ + + +/* + * Initialize main buffer controller. + */ + +GLOBAL(void) +jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer) +{ + my_main_ptr main_ptr; + int ci; + jpeg_component_info *compptr; + + main_ptr = (my_main_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_main_controller)); + cinfo->main = (struct jpeg_c_main_controller *) main_ptr; + main_ptr->pub.start_pass = start_pass_main; + + /* We don't need to create a buffer in raw-data mode. */ + if (cinfo->raw_data_in) + return; + + /* Create the buffer. It holds downsampled data, so each component + * may be of a different size. + */ + if (need_full_buffer) { +#ifdef FULL_MAIN_BUFFER_SUPPORTED + /* Allocate a full-image virtual array for each component */ + /* Note we pad the bottom to a multiple of the iMCU height */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + main_ptr->whole_image[ci] = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + compptr->width_in_blocks * DCTSIZE, + (JDIMENSION) jround_up((long) compptr->height_in_blocks, + (long) compptr->v_samp_factor) * DCTSIZE, + (JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); + } +#else + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); +#endif + } else { +#ifdef FULL_MAIN_BUFFER_SUPPORTED + main_ptr->whole_image[0] = NULL; /* flag for no virtual arrays */ +#endif + /* Allocate a strip buffer for each component */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + compptr->width_in_blocks * DCTSIZE, + (JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); + } + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcmarker.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcmarker.c new file mode 100755 index 0000000..b1c1e45 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcmarker.c @@ -0,0 +1,666 @@ +/* + * jcmarker.c + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write JPEG datastream markers. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jpegcomp.h" + + +typedef enum { /* JPEG marker codes */ + M_SOF0 = 0xc0, + M_SOF1 = 0xc1, + M_SOF2 = 0xc2, + M_SOF3 = 0xc3, + + M_SOF5 = 0xc5, + M_SOF6 = 0xc6, + M_SOF7 = 0xc7, + + M_JPG = 0xc8, + M_SOF9 = 0xc9, + M_SOF10 = 0xca, + M_SOF11 = 0xcb, + + M_SOF13 = 0xcd, + M_SOF14 = 0xce, + M_SOF15 = 0xcf, + + M_DHT = 0xc4, + + M_DAC = 0xcc, + + M_RST0 = 0xd0, + M_RST1 = 0xd1, + M_RST2 = 0xd2, + M_RST3 = 0xd3, + M_RST4 = 0xd4, + M_RST5 = 0xd5, + M_RST6 = 0xd6, + M_RST7 = 0xd7, + + M_SOI = 0xd8, + M_EOI = 0xd9, + M_SOS = 0xda, + M_DQT = 0xdb, + M_DNL = 0xdc, + M_DRI = 0xdd, + M_DHP = 0xde, + M_EXP = 0xdf, + + M_APP0 = 0xe0, + M_APP1 = 0xe1, + M_APP2 = 0xe2, + M_APP3 = 0xe3, + M_APP4 = 0xe4, + M_APP5 = 0xe5, + M_APP6 = 0xe6, + M_APP7 = 0xe7, + M_APP8 = 0xe8, + M_APP9 = 0xe9, + M_APP10 = 0xea, + M_APP11 = 0xeb, + M_APP12 = 0xec, + M_APP13 = 0xed, + M_APP14 = 0xee, + M_APP15 = 0xef, + + M_JPG0 = 0xf0, + M_JPG13 = 0xfd, + M_COM = 0xfe, + + M_TEM = 0x01, + + M_ERROR = 0x100 +} JPEG_MARKER; + + +/* Private state */ + +typedef struct { + struct jpeg_marker_writer pub; /* public fields */ + + unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */ +} my_marker_writer; + +typedef my_marker_writer * my_marker_ptr; + + +/* + * Basic output routines. + * + * Note that we do not support suspension while writing a marker. + * Therefore, an application using suspension must ensure that there is + * enough buffer space for the initial markers (typ. 600-700 bytes) before + * calling jpeg_start_compress, and enough space to write the trailing EOI + * (a few bytes) before calling jpeg_finish_compress. Multipass compression + * modes are not supported at all with suspension, so those two are the only + * points where markers will be written. + */ + +LOCAL(void) +emit_byte (j_compress_ptr cinfo, int val) +/* Emit a byte */ +{ + struct jpeg_destination_mgr * dest = cinfo->dest; + + *(dest->next_output_byte)++ = (JOCTET) val; + if (--dest->free_in_buffer == 0) { + if (! (*dest->empty_output_buffer) (cinfo)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } +} + + +LOCAL(void) +emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark) +/* Emit a marker code */ +{ + emit_byte(cinfo, 0xFF); + emit_byte(cinfo, (int) mark); +} + + +LOCAL(void) +emit_2bytes (j_compress_ptr cinfo, int value) +/* Emit a 2-byte integer; these are always MSB first in JPEG files */ +{ + emit_byte(cinfo, (value >> 8) & 0xFF); + emit_byte(cinfo, value & 0xFF); +} + + +/* + * Routines to write specific marker types. + */ + +LOCAL(int) +emit_dqt (j_compress_ptr cinfo, int index) +/* Emit a DQT marker */ +/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */ +{ + JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index]; + int prec; + int i; + + if (qtbl == NULL) + ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index); + + prec = 0; + for (i = 0; i < DCTSIZE2; i++) { + if (qtbl->quantval[i] > 255) + prec = 1; + } + + if (! qtbl->sent_table) { + emit_marker(cinfo, M_DQT); + + emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2); + + emit_byte(cinfo, index + (prec<<4)); + + for (i = 0; i < DCTSIZE2; i++) { + /* The table entries must be emitted in zigzag order. */ + unsigned int qval = qtbl->quantval[jpeg_natural_order[i]]; + if (prec) + emit_byte(cinfo, (int) (qval >> 8)); + emit_byte(cinfo, (int) (qval & 0xFF)); + } + + qtbl->sent_table = TRUE; + } + + return prec; +} + + +LOCAL(void) +emit_dht (j_compress_ptr cinfo, int index, boolean is_ac) +/* Emit a DHT marker */ +{ + JHUFF_TBL * htbl; + int length, i; + + if (is_ac) { + htbl = cinfo->ac_huff_tbl_ptrs[index]; + index += 0x10; /* output index has AC bit set */ + } else { + htbl = cinfo->dc_huff_tbl_ptrs[index]; + } + + if (htbl == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index); + + if (! htbl->sent_table) { + emit_marker(cinfo, M_DHT); + + length = 0; + for (i = 1; i <= 16; i++) + length += htbl->bits[i]; + + emit_2bytes(cinfo, length + 2 + 1 + 16); + emit_byte(cinfo, index); + + for (i = 1; i <= 16; i++) + emit_byte(cinfo, htbl->bits[i]); + + for (i = 0; i < length; i++) + emit_byte(cinfo, htbl->huffval[i]); + + htbl->sent_table = TRUE; + } +} + + +LOCAL(void) +emit_dac (j_compress_ptr cinfo) +/* Emit a DAC marker */ +/* Since the useful info is so small, we want to emit all the tables in */ +/* one DAC marker. Therefore this routine does its own scan of the table. */ +{ +#ifdef C_ARITH_CODING_SUPPORTED + char dc_in_use[NUM_ARITH_TBLS]; + char ac_in_use[NUM_ARITH_TBLS]; + int length, i; + jpeg_component_info *compptr; + + for (i = 0; i < NUM_ARITH_TBLS; i++) + dc_in_use[i] = ac_in_use[i] = 0; + + for (i = 0; i < cinfo->comps_in_scan; i++) { + compptr = cinfo->cur_comp_info[i]; + dc_in_use[compptr->dc_tbl_no] = 1; + ac_in_use[compptr->ac_tbl_no] = 1; + } + + length = 0; + for (i = 0; i < NUM_ARITH_TBLS; i++) + length += dc_in_use[i] + ac_in_use[i]; + + emit_marker(cinfo, M_DAC); + + emit_2bytes(cinfo, length*2 + 2); + + for (i = 0; i < NUM_ARITH_TBLS; i++) { + if (dc_in_use[i]) { + emit_byte(cinfo, i); + emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4)); + } + if (ac_in_use[i]) { + emit_byte(cinfo, i + 0x10); + emit_byte(cinfo, cinfo->arith_ac_K[i]); + } + } +#endif /* C_ARITH_CODING_SUPPORTED */ +} + + +LOCAL(void) +emit_dri (j_compress_ptr cinfo) +/* Emit a DRI marker */ +{ + emit_marker(cinfo, M_DRI); + + emit_2bytes(cinfo, 4); /* fixed length */ + + emit_2bytes(cinfo, (int) cinfo->restart_interval); +} + + +LOCAL(void) +emit_sof (j_compress_ptr cinfo, JPEG_MARKER code) +/* Emit a SOF marker */ +{ + int ci; + jpeg_component_info *compptr; + + emit_marker(cinfo, code); + + emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */ + + /* Make sure image isn't bigger than SOF field can handle */ + if ((long) cinfo->_jpeg_height > 65535L || + (long) cinfo->_jpeg_width > 65535L) + ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535); + + emit_byte(cinfo, cinfo->data_precision); + emit_2bytes(cinfo, (int) cinfo->_jpeg_height); + emit_2bytes(cinfo, (int) cinfo->_jpeg_width); + + emit_byte(cinfo, cinfo->num_components); + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + emit_byte(cinfo, compptr->component_id); + emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor); + emit_byte(cinfo, compptr->quant_tbl_no); + } +} + + +LOCAL(void) +emit_sos (j_compress_ptr cinfo) +/* Emit a SOS marker */ +{ + int i, td, ta; + jpeg_component_info *compptr; + + emit_marker(cinfo, M_SOS); + + emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */ + + emit_byte(cinfo, cinfo->comps_in_scan); + + for (i = 0; i < cinfo->comps_in_scan; i++) { + compptr = cinfo->cur_comp_info[i]; + emit_byte(cinfo, compptr->component_id); + td = compptr->dc_tbl_no; + ta = compptr->ac_tbl_no; + if (cinfo->progressive_mode) { + /* Progressive mode: only DC or only AC tables are used in one scan; + * furthermore, Huffman coding of DC refinement uses no table at all. + * We emit 0 for unused field(s); this is recommended by the P&M text + * but does not seem to be specified in the standard. + */ + if (cinfo->Ss == 0) { + ta = 0; /* DC scan */ + if (cinfo->Ah != 0 && !cinfo->arith_code) + td = 0; /* no DC table either */ + } else { + td = 0; /* AC scan */ + } + } + emit_byte(cinfo, (td << 4) + ta); + } + + emit_byte(cinfo, cinfo->Ss); + emit_byte(cinfo, cinfo->Se); + emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al); +} + + +LOCAL(void) +emit_jfif_app0 (j_compress_ptr cinfo) +/* Emit a JFIF-compliant APP0 marker */ +{ + /* + * Length of APP0 block (2 bytes) + * Block ID (4 bytes - ASCII "JFIF") + * Zero byte (1 byte to terminate the ID string) + * Version Major, Minor (2 bytes - major first) + * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm) + * Xdpu (2 bytes - dots per unit horizontal) + * Ydpu (2 bytes - dots per unit vertical) + * Thumbnail X size (1 byte) + * Thumbnail Y size (1 byte) + */ + + emit_marker(cinfo, M_APP0); + + emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */ + + emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */ + emit_byte(cinfo, 0x46); + emit_byte(cinfo, 0x49); + emit_byte(cinfo, 0x46); + emit_byte(cinfo, 0); + emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */ + emit_byte(cinfo, cinfo->JFIF_minor_version); + emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */ + emit_2bytes(cinfo, (int) cinfo->X_density); + emit_2bytes(cinfo, (int) cinfo->Y_density); + emit_byte(cinfo, 0); /* No thumbnail image */ + emit_byte(cinfo, 0); +} + + +LOCAL(void) +emit_adobe_app14 (j_compress_ptr cinfo) +/* Emit an Adobe APP14 marker */ +{ + /* + * Length of APP14 block (2 bytes) + * Block ID (5 bytes - ASCII "Adobe") + * Version Number (2 bytes - currently 100) + * Flags0 (2 bytes - currently 0) + * Flags1 (2 bytes - currently 0) + * Color transform (1 byte) + * + * Although Adobe TN 5116 mentions Version = 101, all the Adobe files + * now in circulation seem to use Version = 100, so that's what we write. + * + * We write the color transform byte as 1 if the JPEG color space is + * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with + * whether the encoder performed a transformation, which is pretty useless. + */ + + emit_marker(cinfo, M_APP14); + + emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */ + + emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */ + emit_byte(cinfo, 0x64); + emit_byte(cinfo, 0x6F); + emit_byte(cinfo, 0x62); + emit_byte(cinfo, 0x65); + emit_2bytes(cinfo, 100); /* Version */ + emit_2bytes(cinfo, 0); /* Flags0 */ + emit_2bytes(cinfo, 0); /* Flags1 */ + switch (cinfo->jpeg_color_space) { + case JCS_YCbCr: + emit_byte(cinfo, 1); /* Color transform = 1 */ + break; + case JCS_YCCK: + emit_byte(cinfo, 2); /* Color transform = 2 */ + break; + default: + emit_byte(cinfo, 0); /* Color transform = 0 */ + break; + } +} + + +/* + * These routines allow writing an arbitrary marker with parameters. + * The only intended use is to emit COM or APPn markers after calling + * write_file_header and before calling write_frame_header. + * Other uses are not guaranteed to produce desirable results. + * Counting the parameter bytes properly is the caller's responsibility. + */ + +METHODDEF(void) +write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen) +/* Emit an arbitrary marker header */ +{ + if (datalen > (unsigned int) 65533) /* safety check */ + ERREXIT(cinfo, JERR_BAD_LENGTH); + + emit_marker(cinfo, (JPEG_MARKER) marker); + + emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */ +} + +METHODDEF(void) +write_marker_byte (j_compress_ptr cinfo, int val) +/* Emit one byte of marker parameters following write_marker_header */ +{ + emit_byte(cinfo, val); +} + + +/* + * Write datastream header. + * This consists of an SOI and optional APPn markers. + * We recommend use of the JFIF marker, but not the Adobe marker, + * when using YCbCr or grayscale data. The JFIF marker should NOT + * be used for any other JPEG colorspace. The Adobe marker is helpful + * to distinguish RGB, CMYK, and YCCK colorspaces. + * Note that an application can write additional header markers after + * jpeg_start_compress returns. + */ + +METHODDEF(void) +write_file_header (j_compress_ptr cinfo) +{ + my_marker_ptr marker = (my_marker_ptr) cinfo->marker; + + emit_marker(cinfo, M_SOI); /* first the SOI */ + + /* SOI is defined to reset restart interval to 0 */ + marker->last_restart_interval = 0; + + if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */ + emit_jfif_app0(cinfo); + if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */ + emit_adobe_app14(cinfo); +} + + +/* + * Write frame header. + * This consists of DQT and SOFn markers. + * Note that we do not emit the SOF until we have emitted the DQT(s). + * This avoids compatibility problems with incorrect implementations that + * try to error-check the quant table numbers as soon as they see the SOF. + */ + +METHODDEF(void) +write_frame_header (j_compress_ptr cinfo) +{ + int ci, prec; + boolean is_baseline; + jpeg_component_info *compptr; + + /* Emit DQT for each quantization table. + * Note that emit_dqt() suppresses any duplicate tables. + */ + prec = 0; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + prec += emit_dqt(cinfo, compptr->quant_tbl_no); + } + /* now prec is nonzero iff there are any 16-bit quant tables. */ + + /* Check for a non-baseline specification. + * Note we assume that Huffman table numbers won't be changed later. + */ + if (cinfo->arith_code || cinfo->progressive_mode || + cinfo->data_precision != 8) { + is_baseline = FALSE; + } else { + is_baseline = TRUE; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1) + is_baseline = FALSE; + } + if (prec && is_baseline) { + is_baseline = FALSE; + /* If it's baseline except for quantizer size, warn the user */ + TRACEMS(cinfo, 0, JTRC_16BIT_TABLES); + } + } + + /* Emit the proper SOF marker */ + if (cinfo->arith_code) { + emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */ + } else { + if (cinfo->progressive_mode) + emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */ + else if (is_baseline) + emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */ + else + emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */ + } +} + + +/* + * Write scan header. + * This consists of DHT or DAC markers, optional DRI, and SOS. + * Compressed data will be written following the SOS. + */ + +METHODDEF(void) +write_scan_header (j_compress_ptr cinfo) +{ + my_marker_ptr marker = (my_marker_ptr) cinfo->marker; + int i; + jpeg_component_info *compptr; + + if (cinfo->arith_code) { + /* Emit arith conditioning info. We may have some duplication + * if the file has multiple scans, but it's so small it's hardly + * worth worrying about. + */ + emit_dac(cinfo); + } else { + /* Emit Huffman tables. + * Note that emit_dht() suppresses any duplicate tables. + */ + for (i = 0; i < cinfo->comps_in_scan; i++) { + compptr = cinfo->cur_comp_info[i]; + if (cinfo->progressive_mode) { + /* Progressive mode: only DC or only AC tables are used in one scan */ + if (cinfo->Ss == 0) { + if (cinfo->Ah == 0) /* DC needs no table for refinement scan */ + emit_dht(cinfo, compptr->dc_tbl_no, FALSE); + } else { + emit_dht(cinfo, compptr->ac_tbl_no, TRUE); + } + } else { + /* Sequential mode: need both DC and AC tables */ + emit_dht(cinfo, compptr->dc_tbl_no, FALSE); + emit_dht(cinfo, compptr->ac_tbl_no, TRUE); + } + } + } + + /* Emit DRI if required --- note that DRI value could change for each scan. + * We avoid wasting space with unnecessary DRIs, however. + */ + if (cinfo->restart_interval != marker->last_restart_interval) { + emit_dri(cinfo); + marker->last_restart_interval = cinfo->restart_interval; + } + + emit_sos(cinfo); +} + + +/* + * Write datastream trailer. + */ + +METHODDEF(void) +write_file_trailer (j_compress_ptr cinfo) +{ + emit_marker(cinfo, M_EOI); +} + + +/* + * Write an abbreviated table-specification datastream. + * This consists of SOI, DQT and DHT tables, and EOI. + * Any table that is defined and not marked sent_table = TRUE will be + * emitted. Note that all tables will be marked sent_table = TRUE at exit. + */ + +METHODDEF(void) +write_tables_only (j_compress_ptr cinfo) +{ + int i; + + emit_marker(cinfo, M_SOI); + + for (i = 0; i < NUM_QUANT_TBLS; i++) { + if (cinfo->quant_tbl_ptrs[i] != NULL) + (void) emit_dqt(cinfo, i); + } + + if (! cinfo->arith_code) { + for (i = 0; i < NUM_HUFF_TBLS; i++) { + if (cinfo->dc_huff_tbl_ptrs[i] != NULL) + emit_dht(cinfo, i, FALSE); + if (cinfo->ac_huff_tbl_ptrs[i] != NULL) + emit_dht(cinfo, i, TRUE); + } + } + + emit_marker(cinfo, M_EOI); +} + + +/* + * Initialize the marker writer module. + */ + +GLOBAL(void) +jinit_marker_writer (j_compress_ptr cinfo) +{ + my_marker_ptr marker; + + /* Create the subobject */ + marker = (my_marker_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_marker_writer)); + cinfo->marker = (struct jpeg_marker_writer *) marker; + /* Initialize method pointers */ + marker->pub.write_file_header = write_file_header; + marker->pub.write_frame_header = write_frame_header; + marker->pub.write_scan_header = write_scan_header; + marker->pub.write_file_trailer = write_file_trailer; + marker->pub.write_tables_only = write_tables_only; + marker->pub.write_marker_header = write_marker_header; + marker->pub.write_marker_byte = write_marker_byte; + /* Initialize private state */ + marker->last_restart_interval = 0; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcmaster.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcmaster.c new file mode 100755 index 0000000..3ca346c --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcmaster.c @@ -0,0 +1,624 @@ +/* + * jcmaster.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Modified 2003-2010 by Guido Vollbeding. + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains master control logic for the JPEG compressor. + * These routines are concerned with parameter validation, initial setup, + * and inter-pass control (determining the number of passes and the work + * to be done in each pass). + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jpegcomp.h" + + +/* Private state */ + +typedef enum { + main_pass, /* input data, also do first output step */ + huff_opt_pass, /* Huffman code optimization pass */ + output_pass /* data output pass */ +} c_pass_type; + +typedef struct { + struct jpeg_comp_master pub; /* public fields */ + + c_pass_type pass_type; /* the type of the current pass */ + + int pass_number; /* # of passes completed */ + int total_passes; /* total # of passes needed */ + + int scan_number; /* current index in scan_info[] */ +} my_comp_master; + +typedef my_comp_master * my_master_ptr; + + +/* + * Support routines that do various essential calculations. + */ + +#if JPEG_LIB_VERSION >= 70 +/* + * Compute JPEG image dimensions and related values. + * NOTE: this is exported for possible use by application. + * Hence it mustn't do anything that can't be done twice. + */ + +GLOBAL(void) +jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo) +/* Do computations that are needed before master selection phase */ +{ + /* Hardwire it to "no scaling" */ + cinfo->jpeg_width = cinfo->image_width; + cinfo->jpeg_height = cinfo->image_height; + cinfo->min_DCT_h_scaled_size = DCTSIZE; + cinfo->min_DCT_v_scaled_size = DCTSIZE; +} +#endif + + +LOCAL(void) +initial_setup (j_compress_ptr cinfo, boolean transcode_only) +/* Do computations that are needed before master selection phase */ +{ + int ci; + jpeg_component_info *compptr; + long samplesperrow; + JDIMENSION jd_samplesperrow; + +#if JPEG_LIB_VERSION >= 70 +#if JPEG_LIB_VERSION >= 80 + if (!transcode_only) +#endif + jpeg_calc_jpeg_dimensions(cinfo); +#endif + + /* Sanity check on image dimensions */ + if (cinfo->_jpeg_height <= 0 || cinfo->_jpeg_width <= 0 + || cinfo->num_components <= 0 || cinfo->input_components <= 0) + ERREXIT(cinfo, JERR_EMPTY_IMAGE); + + /* Make sure image isn't bigger than I can handle */ + if ((long) cinfo->_jpeg_height > (long) JPEG_MAX_DIMENSION || + (long) cinfo->_jpeg_width > (long) JPEG_MAX_DIMENSION) + ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); + + /* Width of an input scanline must be representable as JDIMENSION. */ + samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components; + jd_samplesperrow = (JDIMENSION) samplesperrow; + if ((long) jd_samplesperrow != samplesperrow) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + + /* For now, precision must match compiled-in value... */ + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + + /* Check that number of components won't exceed internal array sizes */ + if (cinfo->num_components > MAX_COMPONENTS) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPONENTS); + + /* Compute maximum sampling factors; check factor validity */ + cinfo->max_h_samp_factor = 1; + cinfo->max_v_samp_factor = 1; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || + compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) + ERREXIT(cinfo, JERR_BAD_SAMPLING); + cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, + compptr->h_samp_factor); + cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, + compptr->v_samp_factor); + } + + /* Compute dimensions of components */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Fill in the correct component_index value; don't rely on application */ + compptr->component_index = ci; + /* For compression, we never do DCT scaling. */ +#if JPEG_LIB_VERSION >= 70 + compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; +#else + compptr->DCT_scaled_size = DCTSIZE; +#endif + /* Size in DCT blocks */ + compptr->width_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, + (long) (cinfo->max_h_samp_factor * DCTSIZE)); + compptr->height_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, + (long) (cinfo->max_v_samp_factor * DCTSIZE)); + /* Size in samples */ + compptr->downsampled_width = (JDIMENSION) + jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, + (long) cinfo->max_h_samp_factor); + compptr->downsampled_height = (JDIMENSION) + jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, + (long) cinfo->max_v_samp_factor); + /* Mark component needed (this flag isn't actually used for compression) */ + compptr->component_needed = TRUE; + } + + /* Compute number of fully interleaved MCU rows (number of times that + * main controller will call coefficient controller). + */ + cinfo->total_iMCU_rows = (JDIMENSION) + jdiv_round_up((long) cinfo->_jpeg_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); +} + + +#ifdef C_MULTISCAN_FILES_SUPPORTED + +LOCAL(void) +validate_script (j_compress_ptr cinfo) +/* Verify that the scan script in cinfo->scan_info[] is valid; also + * determine whether it uses progressive JPEG, and set cinfo->progressive_mode. + */ +{ + const jpeg_scan_info * scanptr; + int scanno, ncomps, ci, coefi, thisi; + int Ss, Se, Ah, Al; + boolean component_sent[MAX_COMPONENTS]; +#ifdef C_PROGRESSIVE_SUPPORTED + int * last_bitpos_ptr; + int last_bitpos[MAX_COMPONENTS][DCTSIZE2]; + /* -1 until that coefficient has been seen; then last Al for it */ +#endif + + if (cinfo->num_scans <= 0) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0); + + /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1; + * for progressive JPEG, no scan can have this. + */ + scanptr = cinfo->scan_info; + if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) { +#ifdef C_PROGRESSIVE_SUPPORTED + cinfo->progressive_mode = TRUE; + last_bitpos_ptr = & last_bitpos[0][0]; + for (ci = 0; ci < cinfo->num_components; ci++) + for (coefi = 0; coefi < DCTSIZE2; coefi++) + *last_bitpos_ptr++ = -1; +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else { + cinfo->progressive_mode = FALSE; + for (ci = 0; ci < cinfo->num_components; ci++) + component_sent[ci] = FALSE; + } + + for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) { + /* Validate component indexes */ + ncomps = scanptr->comps_in_scan; + if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN); + for (ci = 0; ci < ncomps; ci++) { + thisi = scanptr->component_index[ci]; + if (thisi < 0 || thisi >= cinfo->num_components) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); + /* Components must appear in SOF order within each scan */ + if (ci > 0 && thisi <= scanptr->component_index[ci-1]) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); + } + /* Validate progression parameters */ + Ss = scanptr->Ss; + Se = scanptr->Se; + Ah = scanptr->Ah; + Al = scanptr->Al; + if (cinfo->progressive_mode) { +#ifdef C_PROGRESSIVE_SUPPORTED + /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that + * seems wrong: the upper bound ought to depend on data precision. + * Perhaps they really meant 0..N+1 for N-bit precision. + * Here we allow 0..10 for 8-bit data; Al larger than 10 results in + * out-of-range reconstructed DC values during the first DC scan, + * which might cause problems for some decoders. + */ +#if BITS_IN_JSAMPLE == 8 +#define MAX_AH_AL 10 +#else +#define MAX_AH_AL 13 +#endif + if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || + Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + if (Ss == 0) { + if (Se != 0) /* DC and AC together not OK */ + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } else { + if (ncomps != 1) /* AC scans must be for only one component */ + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } + for (ci = 0; ci < ncomps; ci++) { + last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0]; + if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */ + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + for (coefi = Ss; coefi <= Se; coefi++) { + if (last_bitpos_ptr[coefi] < 0) { + /* first scan of this coefficient */ + if (Ah != 0) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } else { + /* not first scan */ + if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } + last_bitpos_ptr[coefi] = Al; + } + } +#endif + } else { + /* For sequential JPEG, all progression parameters must be these: */ + if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + /* Make sure components are not sent twice */ + for (ci = 0; ci < ncomps; ci++) { + thisi = scanptr->component_index[ci]; + if (component_sent[thisi]) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); + component_sent[thisi] = TRUE; + } + } + } + + /* Now verify that everything got sent. */ + if (cinfo->progressive_mode) { +#ifdef C_PROGRESSIVE_SUPPORTED + /* For progressive mode, we only check that at least some DC data + * got sent for each component; the spec does not require that all bits + * of all coefficients be transmitted. Would it be wiser to enforce + * transmission of all coefficient bits?? + */ + for (ci = 0; ci < cinfo->num_components; ci++) { + if (last_bitpos[ci][0] < 0) + ERREXIT(cinfo, JERR_MISSING_DATA); + } +#endif + } else { + for (ci = 0; ci < cinfo->num_components; ci++) { + if (! component_sent[ci]) + ERREXIT(cinfo, JERR_MISSING_DATA); + } + } +} + +#endif /* C_MULTISCAN_FILES_SUPPORTED */ + + +LOCAL(void) +select_scan_parameters (j_compress_ptr cinfo) +/* Set up the scan parameters for the current scan */ +{ + int ci; + +#ifdef C_MULTISCAN_FILES_SUPPORTED + if (cinfo->scan_info != NULL) { + /* Prepare for current scan --- the script is already validated */ + my_master_ptr master = (my_master_ptr) cinfo->master; + const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number; + + cinfo->comps_in_scan = scanptr->comps_in_scan; + for (ci = 0; ci < scanptr->comps_in_scan; ci++) { + cinfo->cur_comp_info[ci] = + &cinfo->comp_info[scanptr->component_index[ci]]; + } + cinfo->Ss = scanptr->Ss; + cinfo->Se = scanptr->Se; + cinfo->Ah = scanptr->Ah; + cinfo->Al = scanptr->Al; + } + else +#endif + { + /* Prepare for single sequential-JPEG scan containing all components */ + if (cinfo->num_components > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPS_IN_SCAN); + cinfo->comps_in_scan = cinfo->num_components; + for (ci = 0; ci < cinfo->num_components; ci++) { + cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; + } + cinfo->Ss = 0; + cinfo->Se = DCTSIZE2-1; + cinfo->Ah = 0; + cinfo->Al = 0; + } +} + + +LOCAL(void) +per_scan_setup (j_compress_ptr cinfo) +/* Do computations that are needed before processing a JPEG scan */ +/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */ +{ + int ci, mcublks, tmp; + jpeg_component_info *compptr; + + if (cinfo->comps_in_scan == 1) { + + /* Noninterleaved (single-component) scan */ + compptr = cinfo->cur_comp_info[0]; + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = compptr->width_in_blocks; + cinfo->MCU_rows_in_scan = compptr->height_in_blocks; + + /* For noninterleaved scan, always one block per MCU */ + compptr->MCU_width = 1; + compptr->MCU_height = 1; + compptr->MCU_blocks = 1; + compptr->MCU_sample_width = DCTSIZE; + compptr->last_col_width = 1; + /* For noninterleaved scans, it is convenient to define last_row_height + * as the number of block rows present in the last iMCU row. + */ + tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (tmp == 0) tmp = compptr->v_samp_factor; + compptr->last_row_height = tmp; + + /* Prepare array describing MCU composition */ + cinfo->blocks_in_MCU = 1; + cinfo->MCU_membership[0] = 0; + + } else { + + /* Interleaved (multi-component) scan */ + if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, + MAX_COMPS_IN_SCAN); + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = (JDIMENSION) + jdiv_round_up((long) cinfo->_jpeg_width, + (long) (cinfo->max_h_samp_factor*DCTSIZE)); + cinfo->MCU_rows_in_scan = (JDIMENSION) + jdiv_round_up((long) cinfo->_jpeg_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); + + cinfo->blocks_in_MCU = 0; + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Sampling factors give # of blocks of component in each MCU */ + compptr->MCU_width = compptr->h_samp_factor; + compptr->MCU_height = compptr->v_samp_factor; + compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; + compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE; + /* Figure number of non-dummy blocks in last MCU column & row */ + tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); + if (tmp == 0) tmp = compptr->MCU_width; + compptr->last_col_width = tmp; + tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); + if (tmp == 0) tmp = compptr->MCU_height; + compptr->last_row_height = tmp; + /* Prepare array describing MCU composition */ + mcublks = compptr->MCU_blocks; + if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) + ERREXIT(cinfo, JERR_BAD_MCU_SIZE); + while (mcublks-- > 0) { + cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; + } + } + + } + + /* Convert restart specified in rows to actual MCU count. */ + /* Note that count must fit in 16 bits, so we provide limiting. */ + if (cinfo->restart_in_rows > 0) { + long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row; + cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L); + } +} + + +/* + * Per-pass setup. + * This is called at the beginning of each pass. We determine which modules + * will be active during this pass and give them appropriate start_pass calls. + * We also set is_last_pass to indicate whether any more passes will be + * required. + */ + +METHODDEF(void) +prepare_for_pass (j_compress_ptr cinfo) +{ + my_master_ptr master = (my_master_ptr) cinfo->master; + + switch (master->pass_type) { + case main_pass: + /* Initial pass: will collect input data, and do either Huffman + * optimization or data output for the first scan. + */ + select_scan_parameters(cinfo); + per_scan_setup(cinfo); + if (! cinfo->raw_data_in) { + (*cinfo->cconvert->start_pass) (cinfo); + (*cinfo->downsample->start_pass) (cinfo); + (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU); + } + (*cinfo->fdct->start_pass) (cinfo); + (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding); + (*cinfo->coef->start_pass) (cinfo, + (master->total_passes > 1 ? + JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); + (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); + if (cinfo->optimize_coding) { + /* No immediate data output; postpone writing frame/scan headers */ + master->pub.call_pass_startup = FALSE; + } else { + /* Will write frame/scan headers at first jpeg_write_scanlines call */ + master->pub.call_pass_startup = TRUE; + } + break; +#ifdef ENTROPY_OPT_SUPPORTED + case huff_opt_pass: + /* Do Huffman optimization for a scan after the first one. */ + select_scan_parameters(cinfo); + per_scan_setup(cinfo); + if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) { + (*cinfo->entropy->start_pass) (cinfo, TRUE); + (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); + master->pub.call_pass_startup = FALSE; + break; + } + /* Special case: Huffman DC refinement scans need no Huffman table + * and therefore we can skip the optimization pass for them. + */ + master->pass_type = output_pass; + master->pass_number++; + /*FALLTHROUGH*/ +#endif + case output_pass: + /* Do a data-output pass. */ + /* We need not repeat per-scan setup if prior optimization pass did it. */ + if (! cinfo->optimize_coding) { + select_scan_parameters(cinfo); + per_scan_setup(cinfo); + } + (*cinfo->entropy->start_pass) (cinfo, FALSE); + (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); + /* We emit frame/scan headers now */ + if (master->scan_number == 0) + (*cinfo->marker->write_frame_header) (cinfo); + (*cinfo->marker->write_scan_header) (cinfo); + master->pub.call_pass_startup = FALSE; + break; + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + } + + master->pub.is_last_pass = (master->pass_number == master->total_passes-1); + + /* Set up progress monitor's pass info if present */ + if (cinfo->progress != NULL) { + cinfo->progress->completed_passes = master->pass_number; + cinfo->progress->total_passes = master->total_passes; + } +} + + +/* + * Special start-of-pass hook. + * This is called by jpeg_write_scanlines if call_pass_startup is TRUE. + * In single-pass processing, we need this hook because we don't want to + * write frame/scan headers during jpeg_start_compress; we want to let the + * application write COM markers etc. between jpeg_start_compress and the + * jpeg_write_scanlines loop. + * In multi-pass processing, this routine is not used. + */ + +METHODDEF(void) +pass_startup (j_compress_ptr cinfo) +{ + cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */ + + (*cinfo->marker->write_frame_header) (cinfo); + (*cinfo->marker->write_scan_header) (cinfo); +} + + +/* + * Finish up at end of pass. + */ + +METHODDEF(void) +finish_pass_master (j_compress_ptr cinfo) +{ + my_master_ptr master = (my_master_ptr) cinfo->master; + + /* The entropy coder always needs an end-of-pass call, + * either to analyze statistics or to flush its output buffer. + */ + (*cinfo->entropy->finish_pass) (cinfo); + + /* Update state for next pass */ + switch (master->pass_type) { + case main_pass: + /* next pass is either output of scan 0 (after optimization) + * or output of scan 1 (if no optimization). + */ + master->pass_type = output_pass; + if (! cinfo->optimize_coding) + master->scan_number++; + break; + case huff_opt_pass: + /* next pass is always output of current scan */ + master->pass_type = output_pass; + break; + case output_pass: + /* next pass is either optimization or output of next scan */ + if (cinfo->optimize_coding) + master->pass_type = huff_opt_pass; + master->scan_number++; + break; + } + + master->pass_number++; +} + + +/* + * Initialize master compression control. + */ + +GLOBAL(void) +jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) +{ + my_master_ptr master; + + master = (my_master_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_comp_master)); + cinfo->master = (struct jpeg_comp_master *) master; + master->pub.prepare_for_pass = prepare_for_pass; + master->pub.pass_startup = pass_startup; + master->pub.finish_pass = finish_pass_master; + master->pub.is_last_pass = FALSE; + + /* Validate parameters, determine derived values */ + initial_setup(cinfo, transcode_only); + + if (cinfo->scan_info != NULL) { +#ifdef C_MULTISCAN_FILES_SUPPORTED + validate_script(cinfo); +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else { + cinfo->progressive_mode = FALSE; + cinfo->num_scans = 1; + } + + if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */ + cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */ + + /* Initialize my private state */ + if (transcode_only) { + /* no main pass in transcoding */ + if (cinfo->optimize_coding) + master->pass_type = huff_opt_pass; + else + master->pass_type = output_pass; + } else { + /* for normal compression, first pass is always this type: */ + master->pass_type = main_pass; + } + master->scan_number = 0; + master->pass_number = 0; + if (cinfo->optimize_coding) + master->total_passes = cinfo->num_scans * 2; + else + master->total_passes = cinfo->num_scans; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcomapi.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcomapi.c new file mode 100755 index 0000000..9b1fa75 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcomapi.c @@ -0,0 +1,106 @@ +/* + * jcomapi.c + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface routines that are used for both + * compression and decompression. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* + * Abort processing of a JPEG compression or decompression operation, + * but don't destroy the object itself. + * + * For this, we merely clean up all the nonpermanent memory pools. + * Note that temp files (virtual arrays) are not allowed to belong to + * the permanent pool, so we will be able to close all temp files here. + * Closing a data source or destination, if necessary, is the application's + * responsibility. + */ + +GLOBAL(void) +jpeg_abort (j_common_ptr cinfo) +{ + int pool; + + /* Do nothing if called on a not-initialized or destroyed JPEG object. */ + if (cinfo->mem == NULL) + return; + + /* Releasing pools in reverse order might help avoid fragmentation + * with some (brain-damaged) malloc libraries. + */ + for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { + (*cinfo->mem->free_pool) (cinfo, pool); + } + + /* Reset overall state for possible reuse of object */ + if (cinfo->is_decompressor) { + cinfo->global_state = DSTATE_START; + /* Try to keep application from accessing now-deleted marker list. + * A bit kludgy to do it here, but this is the most central place. + */ + ((j_decompress_ptr) cinfo)->marker_list = NULL; + } else { + cinfo->global_state = CSTATE_START; + } +} + + +/* + * Destruction of a JPEG object. + * + * Everything gets deallocated except the master jpeg_compress_struct itself + * and the error manager struct. Both of these are supplied by the application + * and must be freed, if necessary, by the application. (Often they are on + * the stack and so don't need to be freed anyway.) + * Closing a data source or destination, if necessary, is the application's + * responsibility. + */ + +GLOBAL(void) +jpeg_destroy (j_common_ptr cinfo) +{ + /* We need only tell the memory manager to release everything. */ + /* NB: mem pointer is NULL if memory mgr failed to initialize. */ + if (cinfo->mem != NULL) + (*cinfo->mem->self_destruct) (cinfo); + cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ + cinfo->global_state = 0; /* mark it destroyed */ +} + + +/* + * Convenience routines for allocating quantization and Huffman tables. + * (Would jutils.c be a more reasonable place to put these?) + */ + +GLOBAL(JQUANT_TBL *) +jpeg_alloc_quant_table (j_common_ptr cinfo) +{ + JQUANT_TBL *tbl; + + tbl = (JQUANT_TBL *) + (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); + tbl->sent_table = FALSE; /* make sure this is false in any new table */ + return tbl; +} + + +GLOBAL(JHUFF_TBL *) +jpeg_alloc_huff_table (j_common_ptr cinfo) +{ + JHUFF_TBL *tbl; + + tbl = (JHUFF_TBL *) + (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); + tbl->sent_table = FALSE; /* make sure this is false in any new table */ + return tbl; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jconfig.h b/lib-third-party/libturbojpeg-ios/libjpeg/jconfig.h new file mode 100755 index 0000000..29aa100 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jconfig.h @@ -0,0 +1,58 @@ +/* jconfig.h. Generated from jconfig.h.in by configure. */ +/* Version ID for the JPEG library. + * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". + */ +#define JPEG_LIB_VERSION 62 + +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 1.2.80 + +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 + +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 + +/* Compiler supports function prototypes. */ +#define HAVE_PROTOTYPES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Compiler supports 'unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 + +/* Compiler supports 'unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 + +/* Compiler does not support pointers to unspecified structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* Compiler has rather than standard . */ +/* #undef NEED_BSD_STRINGS */ + +/* Linker requires that global names be unique in first 15 characters. */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ + +/* Need to include in order to obtain size_t. */ +#define NEED_SYS_TYPES_H 1 + +/* Broken compiler shifts signed values as an unsigned shift. */ +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ + +/* Use accelerated SIMD routines. */ +#define WITH_SIMD 1 + +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +/* # undef __CHAR_UNSIGNED__ */ +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcparam.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcparam.c new file mode 100755 index 0000000..557fdc9 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcparam.c @@ -0,0 +1,649 @@ +/* + * jcparam.c + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Modified 2003-2008 by Guido Vollbeding. + * Copyright (C) 2009-2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains optional default-setting code for the JPEG compressor. + * Applications do not have to use this file, but those that don't use it + * must know a lot more about the innards of the JPEG code. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* + * Quantization table setup routines + */ + +GLOBAL(void) +jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, + const unsigned int *basic_table, + int scale_factor, boolean force_baseline) +/* Define a quantization table equal to the basic_table times + * a scale factor (given as a percentage). + * If force_baseline is TRUE, the computed quantization table entries + * are limited to 1..255 for JPEG baseline compatibility. + */ +{ + JQUANT_TBL ** qtblptr; + int i; + long temp; + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS) + ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl); + + qtblptr = & cinfo->quant_tbl_ptrs[which_tbl]; + + if (*qtblptr == NULL) + *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo); + + for (i = 0; i < DCTSIZE2; i++) { + temp = ((long) basic_table[i] * scale_factor + 50L) / 100L; + /* limit the values to the valid range */ + if (temp <= 0L) temp = 1L; + if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */ + if (force_baseline && temp > 255L) + temp = 255L; /* limit to baseline range if requested */ + (*qtblptr)->quantval[i] = (UINT16) temp; + } + + /* Initialize sent_table FALSE so table will be written to JPEG file. */ + (*qtblptr)->sent_table = FALSE; +} + + +/* These are the sample quantization tables given in JPEG spec section K.1. + * The spec says that the values given produce "good" quality, and + * when divided by 2, "very good" quality. + */ +static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { + 16, 11, 10, 16, 24, 40, 51, 61, + 12, 12, 14, 19, 26, 58, 60, 55, + 14, 13, 16, 24, 40, 57, 69, 56, + 14, 17, 22, 29, 51, 87, 80, 62, + 18, 22, 37, 56, 68, 109, 103, 77, + 24, 35, 55, 64, 81, 104, 113, 92, + 49, 64, 78, 87, 103, 121, 120, 101, + 72, 92, 95, 98, 112, 100, 103, 99 +}; +static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { + 17, 18, 24, 47, 99, 99, 99, 99, + 18, 21, 26, 66, 99, 99, 99, 99, + 24, 26, 56, 99, 99, 99, 99, 99, + 47, 66, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99 +}; + + +#if JPEG_LIB_VERSION >= 70 +GLOBAL(void) +jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) +/* Set or change the 'quality' (quantization) setting, using default tables + * and straight percentage-scaling quality scales. + * This entry point allows different scalings for luminance and chrominance. + */ +{ + /* Set up two quantization tables using the specified scaling */ + jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, + cinfo->q_scale_factor[0], force_baseline); + jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, + cinfo->q_scale_factor[1], force_baseline); +} +#endif + + +GLOBAL(void) +jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, + boolean force_baseline) +/* Set or change the 'quality' (quantization) setting, using default tables + * and a straight percentage-scaling quality scale. In most cases it's better + * to use jpeg_set_quality (below); this entry point is provided for + * applications that insist on a linear percentage scaling. + */ +{ + /* Set up two quantization tables using the specified scaling */ + jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, + scale_factor, force_baseline); + jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, + scale_factor, force_baseline); +} + + +GLOBAL(int) +jpeg_quality_scaling (int quality) +/* Convert a user-specified quality rating to a percentage scaling factor + * for an underlying quantization table, using our recommended scaling curve. + * The input 'quality' factor should be 0 (terrible) to 100 (very good). + */ +{ + /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */ + if (quality <= 0) quality = 1; + if (quality > 100) quality = 100; + + /* The basic table is used as-is (scaling 100) for a quality of 50. + * Qualities 50..100 are converted to scaling percentage 200 - 2*Q; + * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table + * to make all the table entries 1 (hence, minimum quantization loss). + * Qualities 1..50 are converted to scaling percentage 5000/Q. + */ + if (quality < 50) + quality = 5000 / quality; + else + quality = 200 - quality*2; + + return quality; +} + + +GLOBAL(void) +jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) +/* Set or change the 'quality' (quantization) setting, using default tables. + * This is the standard quality-adjusting entry point for typical user + * interfaces; only those who want detailed control over quantization tables + * would use the preceding three routines directly. + */ +{ + /* Convert user 0-100 rating to percentage scaling */ + quality = jpeg_quality_scaling(quality); + + /* Set up standard quality tables */ + jpeg_set_linear_quality(cinfo, quality, force_baseline); +} + + +/* + * Huffman table setup routines + */ + +LOCAL(void) +add_huff_table (j_compress_ptr cinfo, + JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) +/* Define a Huffman table */ +{ + int nsymbols, len; + + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + + /* Copy the number-of-symbols-of-each-code-length counts */ + MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); + + /* Validate the counts. We do this here mainly so we can copy the right + * number of symbols from the val[] array, without risking marching off + * the end of memory. jchuff.c will do a more thorough test later. + */ + nsymbols = 0; + for (len = 1; len <= 16; len++) + nsymbols += bits[len]; + if (nsymbols < 1 || nsymbols > 256) + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + + MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8)); + + /* Initialize sent_table FALSE so table will be written to JPEG file. */ + (*htblptr)->sent_table = FALSE; +} + + +LOCAL(void) +std_huff_tables (j_compress_ptr cinfo) +/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ +/* IMPORTANT: these are only valid for 8-bit data precision! */ +{ + static const UINT8 bits_dc_luminance[17] = + { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; + static const UINT8 val_dc_luminance[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + + static const UINT8 bits_dc_chrominance[17] = + { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; + static const UINT8 val_dc_chrominance[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + + static const UINT8 bits_ac_luminance[17] = + { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; + static const UINT8 val_ac_luminance[] = + { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, + 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, + 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, + 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, + 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, + 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, + 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, + 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa }; + + static const UINT8 bits_ac_chrominance[17] = + { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; + static const UINT8 val_ac_chrominance[] = + { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, + 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, + 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, + 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, + 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, + 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, + 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, + 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, + 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, + 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa }; + + add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0], + bits_dc_luminance, val_dc_luminance); + add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0], + bits_ac_luminance, val_ac_luminance); + add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1], + bits_dc_chrominance, val_dc_chrominance); + add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1], + bits_ac_chrominance, val_ac_chrominance); +} + + +/* + * Default parameter setup for compression. + * + * Applications that don't choose to use this routine must do their + * own setup of all these parameters. Alternately, you can call this + * to establish defaults and then alter parameters selectively. This + * is the recommended approach since, if we add any new parameters, + * your code will still work (they'll be set to reasonable defaults). + */ + +GLOBAL(void) +jpeg_set_defaults (j_compress_ptr cinfo) +{ + int i; + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* Allocate comp_info array large enough for maximum component count. + * Array is made permanent in case application wants to compress + * multiple images at same param settings. + */ + if (cinfo->comp_info == NULL) + cinfo->comp_info = (jpeg_component_info *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + MAX_COMPONENTS * SIZEOF(jpeg_component_info)); + + /* Initialize everything not dependent on the color space */ + +#if JPEG_LIB_VERSION >= 70 + cinfo->scale_num = 1; /* 1:1 scaling */ + cinfo->scale_denom = 1; +#endif + cinfo->data_precision = BITS_IN_JSAMPLE; + /* Set up two quantization tables using default quality of 75 */ + jpeg_set_quality(cinfo, 75, TRUE); + /* Set up two Huffman tables */ + std_huff_tables(cinfo); + + /* Initialize default arithmetic coding conditioning */ + for (i = 0; i < NUM_ARITH_TBLS; i++) { + cinfo->arith_dc_L[i] = 0; + cinfo->arith_dc_U[i] = 1; + cinfo->arith_ac_K[i] = 5; + } + + /* Default is no multiple-scan output */ + cinfo->scan_info = NULL; + cinfo->num_scans = 0; + + /* Expect normal source image, not raw downsampled data */ + cinfo->raw_data_in = FALSE; + + /* Use Huffman coding, not arithmetic coding, by default */ + cinfo->arith_code = FALSE; + + /* By default, don't do extra passes to optimize entropy coding */ + cinfo->optimize_coding = FALSE; + /* The standard Huffman tables are only valid for 8-bit data precision. + * If the precision is higher, force optimization on so that usable + * tables will be computed. This test can be removed if default tables + * are supplied that are valid for the desired precision. + */ + if (cinfo->data_precision > 8) + cinfo->optimize_coding = TRUE; + + /* By default, use the simpler non-cosited sampling alignment */ + cinfo->CCIR601_sampling = FALSE; + +#if JPEG_LIB_VERSION >= 70 + /* By default, apply fancy downsampling */ + cinfo->do_fancy_downsampling = TRUE; +#endif + + /* No input smoothing */ + cinfo->smoothing_factor = 0; + + /* DCT algorithm preference */ + cinfo->dct_method = JDCT_DEFAULT; + + /* No restart markers */ + cinfo->restart_interval = 0; + cinfo->restart_in_rows = 0; + + /* Fill in default JFIF marker parameters. Note that whether the marker + * will actually be written is determined by jpeg_set_colorspace. + * + * By default, the library emits JFIF version code 1.01. + * An application that wants to emit JFIF 1.02 extension markers should set + * JFIF_minor_version to 2. We could probably get away with just defaulting + * to 1.02, but there may still be some decoders in use that will complain + * about that; saying 1.01 should minimize compatibility problems. + */ + cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */ + cinfo->JFIF_minor_version = 1; + cinfo->density_unit = 0; /* Pixel size is unknown by default */ + cinfo->X_density = 1; /* Pixel aspect ratio is square by default */ + cinfo->Y_density = 1; + + /* Choose JPEG colorspace based on input space, set defaults accordingly */ + + jpeg_default_colorspace(cinfo); +} + + +/* + * Select an appropriate JPEG colorspace for in_color_space. + */ + +GLOBAL(void) +jpeg_default_colorspace (j_compress_ptr cinfo) +{ + switch (cinfo->in_color_space) { + case JCS_GRAYSCALE: + jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); + break; + case JCS_RGB: + case JCS_EXT_RGB: + case JCS_EXT_RGBX: + case JCS_EXT_BGR: + case JCS_EXT_BGRX: + case JCS_EXT_XBGR: + case JCS_EXT_XRGB: + case JCS_EXT_RGBA: + case JCS_EXT_BGRA: + case JCS_EXT_ABGR: + case JCS_EXT_ARGB: + jpeg_set_colorspace(cinfo, JCS_YCbCr); + break; + case JCS_YCbCr: + jpeg_set_colorspace(cinfo, JCS_YCbCr); + break; + case JCS_CMYK: + jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */ + break; + case JCS_YCCK: + jpeg_set_colorspace(cinfo, JCS_YCCK); + break; + case JCS_UNKNOWN: + jpeg_set_colorspace(cinfo, JCS_UNKNOWN); + break; + default: + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + } +} + + +/* + * Set the JPEG colorspace, and choose colorspace-dependent default values. + */ + +GLOBAL(void) +jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) +{ + jpeg_component_info * compptr; + int ci; + +#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \ + (compptr = &cinfo->comp_info[index], \ + compptr->component_id = (id), \ + compptr->h_samp_factor = (hsamp), \ + compptr->v_samp_factor = (vsamp), \ + compptr->quant_tbl_no = (quant), \ + compptr->dc_tbl_no = (dctbl), \ + compptr->ac_tbl_no = (actbl) ) + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* For all colorspaces, we use Q and Huff tables 0 for luminance components, + * tables 1 for chrominance components. + */ + + cinfo->jpeg_color_space = colorspace; + + cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */ + cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */ + + switch (colorspace) { + case JCS_GRAYSCALE: + cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ + cinfo->num_components = 1; + /* JFIF specifies component ID 1 */ + SET_COMP(0, 1, 1,1, 0, 0,0); + break; + case JCS_RGB: + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ + cinfo->num_components = 3; + SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0); + SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); + SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0); + break; + case JCS_YCbCr: + cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ + cinfo->num_components = 3; + /* JFIF specifies component IDs 1,2,3 */ + /* We default to 2x2 subsamples of chrominance */ + SET_COMP(0, 1, 2,2, 0, 0,0); + SET_COMP(1, 2, 1,1, 1, 1,1); + SET_COMP(2, 3, 1,1, 1, 1,1); + break; + case JCS_CMYK: + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */ + cinfo->num_components = 4; + SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0); + SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0); + SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0); + SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0); + break; + case JCS_YCCK: + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */ + cinfo->num_components = 4; + SET_COMP(0, 1, 2,2, 0, 0,0); + SET_COMP(1, 2, 1,1, 1, 1,1); + SET_COMP(2, 3, 1,1, 1, 1,1); + SET_COMP(3, 4, 2,2, 0, 0,0); + break; + case JCS_UNKNOWN: + cinfo->num_components = cinfo->input_components; + if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPONENTS); + for (ci = 0; ci < cinfo->num_components; ci++) { + SET_COMP(ci, ci, 1,1, 0, 0,0); + } + break; + default: + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + } +} + + +#ifdef C_PROGRESSIVE_SUPPORTED + +LOCAL(jpeg_scan_info *) +fill_a_scan (jpeg_scan_info * scanptr, int ci, + int Ss, int Se, int Ah, int Al) +/* Support routine: generate one scan for specified component */ +{ + scanptr->comps_in_scan = 1; + scanptr->component_index[0] = ci; + scanptr->Ss = Ss; + scanptr->Se = Se; + scanptr->Ah = Ah; + scanptr->Al = Al; + scanptr++; + return scanptr; +} + +LOCAL(jpeg_scan_info *) +fill_scans (jpeg_scan_info * scanptr, int ncomps, + int Ss, int Se, int Ah, int Al) +/* Support routine: generate one scan for each component */ +{ + int ci; + + for (ci = 0; ci < ncomps; ci++) { + scanptr->comps_in_scan = 1; + scanptr->component_index[0] = ci; + scanptr->Ss = Ss; + scanptr->Se = Se; + scanptr->Ah = Ah; + scanptr->Al = Al; + scanptr++; + } + return scanptr; +} + +LOCAL(jpeg_scan_info *) +fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al) +/* Support routine: generate interleaved DC scan if possible, else N scans */ +{ + int ci; + + if (ncomps <= MAX_COMPS_IN_SCAN) { + /* Single interleaved DC scan */ + scanptr->comps_in_scan = ncomps; + for (ci = 0; ci < ncomps; ci++) + scanptr->component_index[ci] = ci; + scanptr->Ss = scanptr->Se = 0; + scanptr->Ah = Ah; + scanptr->Al = Al; + scanptr++; + } else { + /* Noninterleaved DC scan for each component */ + scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al); + } + return scanptr; +} + + +/* + * Create a recommended progressive-JPEG script. + * cinfo->num_components and cinfo->jpeg_color_space must be correct. + */ + +GLOBAL(void) +jpeg_simple_progression (j_compress_ptr cinfo) +{ + int ncomps = cinfo->num_components; + int nscans; + jpeg_scan_info * scanptr; + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* Figure space needed for script. Calculation must match code below! */ + if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { + /* Custom script for YCbCr color images. */ + nscans = 10; + } else { + /* All-purpose script for other color spaces. */ + if (ncomps > MAX_COMPS_IN_SCAN) + nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */ + else + nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */ + } + + /* Allocate space for script. + * We need to put it in the permanent pool in case the application performs + * multiple compressions without changing the settings. To avoid a memory + * leak if jpeg_simple_progression is called repeatedly for the same JPEG + * object, we try to re-use previously allocated space, and we allocate + * enough space to handle YCbCr even if initially asked for grayscale. + */ + if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) { + cinfo->script_space_size = MAX(nscans, 10); + cinfo->script_space = (jpeg_scan_info *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + cinfo->script_space_size * SIZEOF(jpeg_scan_info)); + } + scanptr = cinfo->script_space; + cinfo->scan_info = scanptr; + cinfo->num_scans = nscans; + + if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { + /* Custom script for YCbCr color images. */ + /* Initial DC scan */ + scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); + /* Initial AC scan: get some luma data out in a hurry */ + scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2); + /* Chroma data is too small to be worth expending many scans on */ + scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1); + scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1); + /* Complete spectral selection for luma AC */ + scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2); + /* Refine next bit of luma AC */ + scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1); + /* Finish DC successive approximation */ + scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); + /* Finish AC successive approximation */ + scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0); + scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0); + /* Luma bottom bit comes last since it's usually largest scan */ + scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0); + } else { + /* All-purpose script for other color spaces. */ + /* Successive approximation first pass */ + scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); + scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2); + scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2); + /* Successive approximation second pass */ + scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1); + /* Successive approximation final pass */ + scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); + scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0); + } +} + +#endif /* C_PROGRESSIVE_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcphuff.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcphuff.c new file mode 100755 index 0000000..3102871 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcphuff.c @@ -0,0 +1,831 @@ +/* + * jcphuff.c + * + * Copyright (C) 1995-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy encoding routines for progressive JPEG. + * + * We do not support output suspension in this module, since the library + * currently does not allow multiple-scan files to be written with output + * suspension. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jchuff.h" /* Declarations shared with jchuff.c */ + +#ifdef C_PROGRESSIVE_SUPPORTED + +/* Expanded entropy encoder object for progressive Huffman encoding. */ + +typedef struct { + struct jpeg_entropy_encoder pub; /* public fields */ + + /* Mode flag: TRUE for optimization, FALSE for actual data output */ + boolean gather_statistics; + + /* Bit-level coding status. + * next_output_byte/free_in_buffer are local copies of cinfo->dest fields. + */ + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + INT32 put_buffer; /* current bit-accumulation buffer */ + int put_bits; /* # of bits now in it */ + j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */ + + /* Coding status for DC components */ + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ + + /* Coding status for AC components */ + int ac_tbl_no; /* the table number of the single component */ + unsigned int EOBRUN; /* run length of EOBs */ + unsigned int BE; /* # of buffered correction bits before MCU */ + char * bit_buffer; /* buffer for correction bits (1 per char) */ + /* packing correction bits tightly would save some space but cost time... */ + + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + int next_restart_num; /* next restart number to write (0-7) */ + + /* Pointers to derived tables (these workspaces have image lifespan). + * Since any one scan codes only DC or only AC, we only need one set + * of tables, not one for DC and one for AC. + */ + c_derived_tbl * derived_tbls[NUM_HUFF_TBLS]; + + /* Statistics tables for optimization; again, one set is enough */ + long * count_ptrs[NUM_HUFF_TBLS]; +} phuff_entropy_encoder; + +typedef phuff_entropy_encoder * phuff_entropy_ptr; + +/* MAX_CORR_BITS is the number of bits the AC refinement correction-bit + * buffer can hold. Larger sizes may slightly improve compression, but + * 1000 is already well into the realm of overkill. + * The minimum safe size is 64 bits. + */ + +#define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */ + +/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32. + * We assume that int right shift is unsigned if INT32 right shift is, + * which should be safe. + */ + +#ifdef RIGHT_SHIFT_IS_UNSIGNED +#define ISHIFT_TEMPS int ishift_temp; +#define IRIGHT_SHIFT(x,shft) \ + ((ishift_temp = (x)) < 0 ? \ + (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \ + (ishift_temp >> (shft))) +#else +#define ISHIFT_TEMPS +#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) +#endif + +/* Forward declarations */ +METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo)); +METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo)); + + +/* + * Initialize for a Huffman-compressed scan using progressive JPEG. + */ + +METHODDEF(void) +start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + boolean is_DC_band; + int ci, tbl; + jpeg_component_info * compptr; + + entropy->cinfo = cinfo; + entropy->gather_statistics = gather_statistics; + + is_DC_band = (cinfo->Ss == 0); + + /* We assume jcmaster.c already validated the scan parameters. */ + + /* Select execution routines */ + if (cinfo->Ah == 0) { + if (is_DC_band) + entropy->pub.encode_mcu = encode_mcu_DC_first; + else + entropy->pub.encode_mcu = encode_mcu_AC_first; + } else { + if (is_DC_band) + entropy->pub.encode_mcu = encode_mcu_DC_refine; + else { + entropy->pub.encode_mcu = encode_mcu_AC_refine; + /* AC refinement needs a correction bit buffer */ + if (entropy->bit_buffer == NULL) + entropy->bit_buffer = (char *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + MAX_CORR_BITS * SIZEOF(char)); + } + } + if (gather_statistics) + entropy->pub.finish_pass = finish_pass_gather_phuff; + else + entropy->pub.finish_pass = finish_pass_phuff; + + /* Only DC coefficients may be interleaved, so cinfo->comps_in_scan = 1 + * for AC coefficients. + */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Initialize DC predictions to 0 */ + entropy->last_dc_val[ci] = 0; + /* Get table index */ + if (is_DC_band) { + if (cinfo->Ah != 0) /* DC refinement needs no table */ + continue; + tbl = compptr->dc_tbl_no; + } else { + entropy->ac_tbl_no = tbl = compptr->ac_tbl_no; + } + if (gather_statistics) { + /* Check for invalid table index */ + /* (make_c_derived_tbl does this in the other path) */ + if (tbl < 0 || tbl >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl); + /* Allocate and zero the statistics tables */ + /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ + if (entropy->count_ptrs[tbl] == NULL) + entropy->count_ptrs[tbl] = (long *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 257 * SIZEOF(long)); + MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long)); + } else { + /* Compute derived values for Huffman table */ + /* We may do this more than once for a table, but it's not expensive */ + jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl, + & entropy->derived_tbls[tbl]); + } + } + + /* Initialize AC stuff */ + entropy->EOBRUN = 0; + entropy->BE = 0; + + /* Initialize bit buffer to empty */ + entropy->put_buffer = 0; + entropy->put_bits = 0; + + /* Initialize restart stuff */ + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num = 0; +} + + +/* Outputting bytes to the file. + * NB: these must be called only when actually outputting, + * that is, entropy->gather_statistics == FALSE. + */ + +/* Emit a byte */ +#define emit_byte(entropy,val) \ + { *(entropy)->next_output_byte++ = (JOCTET) (val); \ + if (--(entropy)->free_in_buffer == 0) \ + dump_buffer(entropy); } + + +LOCAL(void) +dump_buffer (phuff_entropy_ptr entropy) +/* Empty the output buffer; we do not support suspension in this module. */ +{ + struct jpeg_destination_mgr * dest = entropy->cinfo->dest; + + if (! (*dest->empty_output_buffer) (entropy->cinfo)) + ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND); + /* After a successful buffer dump, must reset buffer pointers */ + entropy->next_output_byte = dest->next_output_byte; + entropy->free_in_buffer = dest->free_in_buffer; +} + + +/* Outputting bits to the file */ + +/* Only the right 24 bits of put_buffer are used; the valid bits are + * left-justified in this part. At most 16 bits can be passed to emit_bits + * in one call, and we never retain more than 7 bits in put_buffer + * between calls, so 24 bits are sufficient. + */ + +LOCAL(void) +emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size) +/* Emit some bits, unless we are in gather mode */ +{ + /* This routine is heavily used, so it's worth coding tightly. */ + register INT32 put_buffer = (INT32) code; + register int put_bits = entropy->put_bits; + + /* if size is 0, caller used an invalid Huffman table entry */ + if (size == 0) + ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); + + if (entropy->gather_statistics) + return; /* do nothing if we're only getting stats */ + + put_buffer &= (((INT32) 1)<put_buffer; /* and merge with old buffer contents */ + + while (put_bits >= 8) { + int c = (int) ((put_buffer >> 16) & 0xFF); + + emit_byte(entropy, c); + if (c == 0xFF) { /* need to stuff a zero byte? */ + emit_byte(entropy, 0); + } + put_buffer <<= 8; + put_bits -= 8; + } + + entropy->put_buffer = put_buffer; /* update variables */ + entropy->put_bits = put_bits; +} + + +LOCAL(void) +flush_bits (phuff_entropy_ptr entropy) +{ + emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */ + entropy->put_buffer = 0; /* and reset bit-buffer to empty */ + entropy->put_bits = 0; +} + + +/* + * Emit (or just count) a Huffman symbol. + */ + +LOCAL(void) +emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol) +{ + if (entropy->gather_statistics) + entropy->count_ptrs[tbl_no][symbol]++; + else { + c_derived_tbl * tbl = entropy->derived_tbls[tbl_no]; + emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]); + } +} + + +/* + * Emit bits from a correction bit buffer. + */ + +LOCAL(void) +emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart, + unsigned int nbits) +{ + if (entropy->gather_statistics) + return; /* no real work */ + + while (nbits > 0) { + emit_bits(entropy, (unsigned int) (*bufstart), 1); + bufstart++; + nbits--; + } +} + + +/* + * Emit any pending EOBRUN symbol. + */ + +LOCAL(void) +emit_eobrun (phuff_entropy_ptr entropy) +{ + register int temp, nbits; + + if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */ + temp = entropy->EOBRUN; + nbits = 0; + while ((temp >>= 1)) + nbits++; + /* safety check: shouldn't happen given limited correction-bit buffer */ + if (nbits > 14) + ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); + + emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4); + if (nbits) + emit_bits(entropy, entropy->EOBRUN, nbits); + + entropy->EOBRUN = 0; + + /* Emit any buffered correction bits */ + emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE); + entropy->BE = 0; + } +} + + +/* + * Emit a restart marker & resynchronize predictions. + */ + +LOCAL(void) +emit_restart (phuff_entropy_ptr entropy, int restart_num) +{ + int ci; + + emit_eobrun(entropy); + + if (! entropy->gather_statistics) { + flush_bits(entropy); + emit_byte(entropy, 0xFF); + emit_byte(entropy, JPEG_RST0 + restart_num); + } + + if (entropy->cinfo->Ss == 0) { + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++) + entropy->last_dc_val[ci] = 0; + } else { + /* Re-initialize all AC-related fields to 0 */ + entropy->EOBRUN = 0; + entropy->BE = 0; + } +} + + +/* + * MCU encoding for DC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp, temp2; + register int nbits; + int blkn, ci; + int Al = cinfo->Al; + JBLOCKROW block; + jpeg_component_info * compptr; + ISHIFT_TEMPS + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + + /* Compute the DC value after the required point transform by Al. + * This is simply an arithmetic right shift. + */ + temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al); + + /* DC differences are figured on the point-transformed values. */ + temp = temp2 - entropy->last_dc_val[ci]; + entropy->last_dc_val[ci] = temp2; + + /* Encode the DC coefficient difference per section G.1.2.1 */ + temp2 = temp; + if (temp < 0) { + temp = -temp; /* temp is abs value of input */ + /* For a negative input, want temp2 = bitwise complement of abs(input) */ + /* This code assumes we are on a two's complement machine */ + temp2--; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 0; + while (temp) { + nbits++; + temp >>= 1; + } + /* Check for out-of-range coefficient values. + * Since we're encoding a difference, the range limit is twice as much. + */ + if (nbits > MAX_COEF_BITS+1) + ERREXIT(cinfo, JERR_BAD_DCT_COEF); + + /* Count/emit the Huffman-coded symbol for the number of bits */ + emit_symbol(entropy, compptr->dc_tbl_no, nbits); + + /* Emit that number of bits of the value, if positive, */ + /* or the complement of its magnitude, if negative. */ + if (nbits) /* emit_bits rejects calls with size 0 */ + emit_bits(entropy, (unsigned int) temp2, nbits); + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; +} + + +/* + * MCU encoding for AC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp, temp2; + register int nbits; + register int r, k; + int Se = cinfo->Se; + int Al = cinfo->Al; + JBLOCKROW block; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data block */ + block = MCU_data[0]; + + /* Encode the AC coefficients per section G.1.2.2, fig. G.3 */ + + r = 0; /* r = run length of zeros */ + + for (k = cinfo->Ss; k <= Se; k++) { + if ((temp = (*block)[jpeg_natural_order[k]]) == 0) { + r++; + continue; + } + /* We must apply the point transform by Al. For AC coefficients this + * is an integer division with rounding towards 0. To do this portably + * in C, we shift after obtaining the absolute value; so the code is + * interwoven with finding the abs value (temp) and output bits (temp2). + */ + if (temp < 0) { + temp = -temp; /* temp is abs value of input */ + temp >>= Al; /* apply the point transform */ + /* For a negative coef, want temp2 = bitwise complement of abs(coef) */ + temp2 = ~temp; + } else { + temp >>= Al; /* apply the point transform */ + temp2 = temp; + } + /* Watch out for case that nonzero coef is zero after point transform */ + if (temp == 0) { + r++; + continue; + } + + /* Emit any pending EOBRUN */ + if (entropy->EOBRUN > 0) + emit_eobrun(entropy); + /* if run length > 15, must emit special run-length-16 codes (0xF0) */ + while (r > 15) { + emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); + r -= 16; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 1; /* there must be at least one 1 bit */ + while ((temp >>= 1)) + nbits++; + /* Check for out-of-range coefficient values */ + if (nbits > MAX_COEF_BITS) + ERREXIT(cinfo, JERR_BAD_DCT_COEF); + + /* Count/emit Huffman symbol for run length / number of bits */ + emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits); + + /* Emit that number of bits of the value, if positive, */ + /* or the complement of its magnitude, if negative. */ + emit_bits(entropy, (unsigned int) temp2, nbits); + + r = 0; /* reset zero run length */ + } + + if (r > 0) { /* If there are trailing zeroes, */ + entropy->EOBRUN++; /* count an EOB */ + if (entropy->EOBRUN == 0x7FFF) + emit_eobrun(entropy); /* force it out to avoid overflow */ + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; +} + + +/* + * MCU encoding for DC successive approximation refinement scan. + * Note: we assume such scans can be multi-component, although the spec + * is not very clear on the point. + */ + +METHODDEF(boolean) +encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp; + int blkn; + int Al = cinfo->Al; + JBLOCKROW block; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + + /* We simply emit the Al'th bit of the DC coefficient value. */ + temp = (*block)[0]; + emit_bits(entropy, (unsigned int) (temp >> Al), 1); + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; +} + + +/* + * MCU encoding for AC successive approximation refinement scan. + */ + +METHODDEF(boolean) +encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp; + register int r, k; + int EOB; + char *BR_buffer; + unsigned int BR; + int Se = cinfo->Se; + int Al = cinfo->Al; + JBLOCKROW block; + int absvalues[DCTSIZE2]; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data block */ + block = MCU_data[0]; + + /* It is convenient to make a pre-pass to determine the transformed + * coefficients' absolute values and the EOB position. + */ + EOB = 0; + for (k = cinfo->Ss; k <= Se; k++) { + temp = (*block)[jpeg_natural_order[k]]; + /* We must apply the point transform by Al. For AC coefficients this + * is an integer division with rounding towards 0. To do this portably + * in C, we shift after obtaining the absolute value. + */ + if (temp < 0) + temp = -temp; /* temp is abs value of input */ + temp >>= Al; /* apply the point transform */ + absvalues[k] = temp; /* save abs value for main pass */ + if (temp == 1) + EOB = k; /* EOB = index of last newly-nonzero coef */ + } + + /* Encode the AC coefficients per section G.1.2.3, fig. G.7 */ + + r = 0; /* r = run length of zeros */ + BR = 0; /* BR = count of buffered bits added now */ + BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */ + + for (k = cinfo->Ss; k <= Se; k++) { + if ((temp = absvalues[k]) == 0) { + r++; + continue; + } + + /* Emit any required ZRLs, but not if they can be folded into EOB */ + while (r > 15 && k <= EOB) { + /* emit any pending EOBRUN and the BE correction bits */ + emit_eobrun(entropy); + /* Emit ZRL */ + emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); + r -= 16; + /* Emit buffered correction bits that must be associated with ZRL */ + emit_buffered_bits(entropy, BR_buffer, BR); + BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ + BR = 0; + } + + /* If the coef was previously nonzero, it only needs a correction bit. + * NOTE: a straight translation of the spec's figure G.7 would suggest + * that we also need to test r > 15. But if r > 15, we can only get here + * if k > EOB, which implies that this coefficient is not 1. + */ + if (temp > 1) { + /* The correction bit is the next bit of the absolute value. */ + BR_buffer[BR++] = (char) (temp & 1); + continue; + } + + /* Emit any pending EOBRUN and the BE correction bits */ + emit_eobrun(entropy); + + /* Count/emit Huffman symbol for run length / number of bits */ + emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1); + + /* Emit output bit for newly-nonzero coef */ + temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1; + emit_bits(entropy, (unsigned int) temp, 1); + + /* Emit buffered correction bits that must be associated with this code */ + emit_buffered_bits(entropy, BR_buffer, BR); + BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ + BR = 0; + r = 0; /* reset zero run length */ + } + + if (r > 0 || BR > 0) { /* If there are trailing zeroes, */ + entropy->EOBRUN++; /* count an EOB */ + entropy->BE += BR; /* concat my correction bits to older ones */ + /* We force out the EOB if we risk either: + * 1. overflow of the EOB counter; + * 2. overflow of the correction bit buffer during the next MCU. + */ + if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1)) + emit_eobrun(entropy); + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; +} + + +/* + * Finish up at the end of a Huffman-compressed progressive scan. + */ + +METHODDEF(void) +finish_pass_phuff (j_compress_ptr cinfo) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Flush out any buffered data */ + emit_eobrun(entropy); + flush_bits(entropy); + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; +} + + +/* + * Finish up a statistics-gathering pass and create the new Huffman tables. + */ + +METHODDEF(void) +finish_pass_gather_phuff (j_compress_ptr cinfo) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + boolean is_DC_band; + int ci, tbl; + jpeg_component_info * compptr; + JHUFF_TBL **htblptr; + boolean did[NUM_HUFF_TBLS]; + + /* Flush out buffered data (all we care about is counting the EOB symbol) */ + emit_eobrun(entropy); + + is_DC_band = (cinfo->Ss == 0); + + /* It's important not to apply jpeg_gen_optimal_table more than once + * per table, because it clobbers the input frequency counts! + */ + MEMZERO(did, SIZEOF(did)); + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + if (is_DC_band) { + if (cinfo->Ah != 0) /* DC refinement needs no table */ + continue; + tbl = compptr->dc_tbl_no; + } else { + tbl = compptr->ac_tbl_no; + } + if (! did[tbl]) { + if (is_DC_band) + htblptr = & cinfo->dc_huff_tbl_ptrs[tbl]; + else + htblptr = & cinfo->ac_huff_tbl_ptrs[tbl]; + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]); + did[tbl] = TRUE; + } + } +} + + +/* + * Module initialization routine for progressive Huffman entropy encoding. + */ + +GLOBAL(void) +jinit_phuff_encoder (j_compress_ptr cinfo) +{ + phuff_entropy_ptr entropy; + int i; + + entropy = (phuff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(phuff_entropy_encoder)); + cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; + entropy->pub.start_pass = start_pass_phuff; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->derived_tbls[i] = NULL; + entropy->count_ptrs[i] = NULL; + } + entropy->bit_buffer = NULL; /* needed only in AC refinement scan */ +} + +#endif /* C_PROGRESSIVE_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcprepct.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcprepct.c new file mode 100755 index 0000000..fa93333 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcprepct.c @@ -0,0 +1,354 @@ +/* + * jcprepct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the compression preprocessing controller. + * This controller manages the color conversion, downsampling, + * and edge expansion steps. + * + * Most of the complexity here is associated with buffering input rows + * as required by the downsampler. See the comments at the head of + * jcsample.c for the downsampler's needs. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* At present, jcsample.c can request context rows only for smoothing. + * In the future, we might also need context rows for CCIR601 sampling + * or other more-complex downsampling procedures. The code to support + * context rows should be compiled only if needed. + */ +#ifdef INPUT_SMOOTHING_SUPPORTED +#define CONTEXT_ROWS_SUPPORTED +#endif + + +/* + * For the simple (no-context-row) case, we just need to buffer one + * row group's worth of pixels for the downsampling step. At the bottom of + * the image, we pad to a full row group by replicating the last pixel row. + * The downsampler's last output row is then replicated if needed to pad + * out to a full iMCU row. + * + * When providing context rows, we must buffer three row groups' worth of + * pixels. Three row groups are physically allocated, but the row pointer + * arrays are made five row groups high, with the extra pointers above and + * below "wrapping around" to point to the last and first real row groups. + * This allows the downsampler to access the proper context rows. + * At the top and bottom of the image, we create dummy context rows by + * copying the first or last real pixel row. This copying could be avoided + * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the + * trouble on the compression side. + */ + + +/* Private buffer controller object */ + +typedef struct { + struct jpeg_c_prep_controller pub; /* public fields */ + + /* Downsampling input buffer. This buffer holds color-converted data + * until we have enough to do a downsample step. + */ + JSAMPARRAY color_buf[MAX_COMPONENTS]; + + JDIMENSION rows_to_go; /* counts rows remaining in source image */ + int next_buf_row; /* index of next row to store in color_buf */ + +#ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */ + int this_row_group; /* starting row index of group to process */ + int next_buf_stop; /* downsample when we reach this index */ +#endif +} my_prep_controller; + +typedef my_prep_controller * my_prep_ptr; + + +/* + * Initialize for a processing pass. + */ + +METHODDEF(void) +start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode) +{ + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + + if (pass_mode != JBUF_PASS_THRU) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + /* Initialize total-height counter for detecting bottom of image */ + prep->rows_to_go = cinfo->image_height; + /* Mark the conversion buffer empty */ + prep->next_buf_row = 0; +#ifdef CONTEXT_ROWS_SUPPORTED + /* Preset additional state variables for context mode. + * These aren't used in non-context mode, so we needn't test which mode. + */ + prep->this_row_group = 0; + /* Set next_buf_stop to stop after two row groups have been read in. */ + prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; +#endif +} + + +/* + * Expand an image vertically from height input_rows to height output_rows, + * by duplicating the bottom row. + */ + +LOCAL(void) +expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, + int input_rows, int output_rows) +{ + register int row; + + for (row = input_rows; row < output_rows; row++) { + jcopy_sample_rows(image_data, input_rows-1, image_data, row, + 1, num_cols); + } +} + + +/* + * Process some data in the simple no-context case. + * + * Preprocessor output data is counted in "row groups". A row group + * is defined to be v_samp_factor sample rows of each component. + * Downsampling will produce this much data from each max_v_samp_factor + * input rows. + */ + +METHODDEF(void) +pre_process_data (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail, + JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, + JDIMENSION out_row_groups_avail) +{ + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + int numrows, ci; + JDIMENSION inrows; + jpeg_component_info * compptr; + + while (*in_row_ctr < in_rows_avail && + *out_row_group_ctr < out_row_groups_avail) { + /* Do color conversion to fill the conversion buffer. */ + inrows = in_rows_avail - *in_row_ctr; + numrows = cinfo->max_v_samp_factor - prep->next_buf_row; + numrows = (int) MIN((JDIMENSION) numrows, inrows); + (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, + prep->color_buf, + (JDIMENSION) prep->next_buf_row, + numrows); + *in_row_ctr += numrows; + prep->next_buf_row += numrows; + prep->rows_to_go -= numrows; + /* If at bottom of image, pad to fill the conversion buffer. */ + if (prep->rows_to_go == 0 && + prep->next_buf_row < cinfo->max_v_samp_factor) { + for (ci = 0; ci < cinfo->num_components; ci++) { + expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, + prep->next_buf_row, cinfo->max_v_samp_factor); + } + prep->next_buf_row = cinfo->max_v_samp_factor; + } + /* If we've filled the conversion buffer, empty it. */ + if (prep->next_buf_row == cinfo->max_v_samp_factor) { + (*cinfo->downsample->downsample) (cinfo, + prep->color_buf, (JDIMENSION) 0, + output_buf, *out_row_group_ctr); + prep->next_buf_row = 0; + (*out_row_group_ctr)++; + } + /* If at bottom of image, pad the output to a full iMCU height. + * Note we assume the caller is providing a one-iMCU-height output buffer! + */ + if (prep->rows_to_go == 0 && + *out_row_group_ctr < out_row_groups_avail) { + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + expand_bottom_edge(output_buf[ci], + compptr->width_in_blocks * DCTSIZE, + (int) (*out_row_group_ctr * compptr->v_samp_factor), + (int) (out_row_groups_avail * compptr->v_samp_factor)); + } + *out_row_group_ctr = out_row_groups_avail; + break; /* can exit outer loop without test */ + } + } +} + + +#ifdef CONTEXT_ROWS_SUPPORTED + +/* + * Process some data in the context case. + */ + +METHODDEF(void) +pre_process_context (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail, + JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, + JDIMENSION out_row_groups_avail) +{ + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + int numrows, ci; + int buf_height = cinfo->max_v_samp_factor * 3; + JDIMENSION inrows; + + while (*out_row_group_ctr < out_row_groups_avail) { + if (*in_row_ctr < in_rows_avail) { + /* Do color conversion to fill the conversion buffer. */ + inrows = in_rows_avail - *in_row_ctr; + numrows = prep->next_buf_stop - prep->next_buf_row; + numrows = (int) MIN((JDIMENSION) numrows, inrows); + (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, + prep->color_buf, + (JDIMENSION) prep->next_buf_row, + numrows); + /* Pad at top of image, if first time through */ + if (prep->rows_to_go == cinfo->image_height) { + for (ci = 0; ci < cinfo->num_components; ci++) { + int row; + for (row = 1; row <= cinfo->max_v_samp_factor; row++) { + jcopy_sample_rows(prep->color_buf[ci], 0, + prep->color_buf[ci], -row, + 1, cinfo->image_width); + } + } + } + *in_row_ctr += numrows; + prep->next_buf_row += numrows; + prep->rows_to_go -= numrows; + } else { + /* Return for more data, unless we are at the bottom of the image. */ + if (prep->rows_to_go != 0) + break; + /* When at bottom of image, pad to fill the conversion buffer. */ + if (prep->next_buf_row < prep->next_buf_stop) { + for (ci = 0; ci < cinfo->num_components; ci++) { + expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, + prep->next_buf_row, prep->next_buf_stop); + } + prep->next_buf_row = prep->next_buf_stop; + } + } + /* If we've gotten enough data, downsample a row group. */ + if (prep->next_buf_row == prep->next_buf_stop) { + (*cinfo->downsample->downsample) (cinfo, + prep->color_buf, + (JDIMENSION) prep->this_row_group, + output_buf, *out_row_group_ctr); + (*out_row_group_ctr)++; + /* Advance pointers with wraparound as necessary. */ + prep->this_row_group += cinfo->max_v_samp_factor; + if (prep->this_row_group >= buf_height) + prep->this_row_group = 0; + if (prep->next_buf_row >= buf_height) + prep->next_buf_row = 0; + prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; + } + } +} + + +/* + * Create the wrapped-around downsampling input buffer needed for context mode. + */ + +LOCAL(void) +create_context_buffer (j_compress_ptr cinfo) +{ + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + int rgroup_height = cinfo->max_v_samp_factor; + int ci, i; + jpeg_component_info * compptr; + JSAMPARRAY true_buffer, fake_buffer; + + /* Grab enough space for fake row pointers for all the components; + * we need five row groups' worth of pointers for each component. + */ + fake_buffer = (JSAMPARRAY) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (cinfo->num_components * 5 * rgroup_height) * + SIZEOF(JSAMPROW)); + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Allocate the actual buffer space (3 row groups) for this component. + * We make the buffer wide enough to allow the downsampler to edge-expand + * horizontally within the buffer, if it so chooses. + */ + true_buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * + cinfo->max_h_samp_factor) / compptr->h_samp_factor), + (JDIMENSION) (3 * rgroup_height)); + /* Copy true buffer row pointers into the middle of the fake row array */ + MEMCOPY(fake_buffer + rgroup_height, true_buffer, + 3 * rgroup_height * SIZEOF(JSAMPROW)); + /* Fill in the above and below wraparound pointers */ + for (i = 0; i < rgroup_height; i++) { + fake_buffer[i] = true_buffer[2 * rgroup_height + i]; + fake_buffer[4 * rgroup_height + i] = true_buffer[i]; + } + prep->color_buf[ci] = fake_buffer + rgroup_height; + fake_buffer += 5 * rgroup_height; /* point to space for next component */ + } +} + +#endif /* CONTEXT_ROWS_SUPPORTED */ + + +/* + * Initialize preprocessing controller. + */ + +GLOBAL(void) +jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) +{ + my_prep_ptr prep; + int ci; + jpeg_component_info * compptr; + + if (need_full_buffer) /* safety check */ + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + prep = (my_prep_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_prep_controller)); + cinfo->prep = (struct jpeg_c_prep_controller *) prep; + prep->pub.start_pass = start_pass_prep; + + /* Allocate the color conversion buffer. + * We make the buffer wide enough to allow the downsampler to edge-expand + * horizontally within the buffer, if it so chooses. + */ + if (cinfo->downsample->need_context_rows) { + /* Set up to provide context rows */ +#ifdef CONTEXT_ROWS_SUPPORTED + prep->pub.pre_process_data = pre_process_context; + create_context_buffer(cinfo); +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else { + /* No context, just make it tall enough for one row group */ + prep->pub.pre_process_data = pre_process_data; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * + cinfo->max_h_samp_factor) / compptr->h_samp_factor), + (JDIMENSION) cinfo->max_v_samp_factor); + } + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jcsample.c b/lib-third-party/libturbojpeg-ios/libjpeg/jcsample.c new file mode 100755 index 0000000..eea376f --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jcsample.c @@ -0,0 +1,527 @@ +/* + * jcsample.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * Copyright 2009 Pierre Ossman for Cendio AB + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains downsampling routines. + * + * Downsampling input data is counted in "row groups". A row group + * is defined to be max_v_samp_factor pixel rows of each component, + * from which the downsampler produces v_samp_factor sample rows. + * A single row group is processed in each call to the downsampler module. + * + * The downsampler is responsible for edge-expansion of its output data + * to fill an integral number of DCT blocks horizontally. The source buffer + * may be modified if it is helpful for this purpose (the source buffer is + * allocated wide enough to correspond to the desired output width). + * The caller (the prep controller) is responsible for vertical padding. + * + * The downsampler may request "context rows" by setting need_context_rows + * during startup. In this case, the input arrays will contain at least + * one row group's worth of pixels above and below the passed-in data; + * the caller will create dummy rows at image top and bottom by replicating + * the first or last real pixel row. + * + * An excellent reference for image resampling is + * Digital Image Warping, George Wolberg, 1990. + * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. + * + * The downsampling algorithm used here is a simple average of the source + * pixels covered by the output pixel. The hi-falutin sampling literature + * refers to this as a "box filter". In general the characteristics of a box + * filter are not very good, but for the specific cases we normally use (1:1 + * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not + * nearly so bad. If you intend to use other sampling ratios, you'd be well + * advised to improve this code. + * + * A simple input-smoothing capability is provided. This is mainly intended + * for cleaning up color-dithered GIF input files (if you find it inadequate, + * we suggest using an external filtering program such as pnmconvol). When + * enabled, each input pixel P is replaced by a weighted sum of itself and its + * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF, + * where SF = (smoothing_factor / 1024). + * Currently, smoothing is only supported for 2h2v sampling factors. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jsimd.h" + + +/* Pointer to routine to downsample a single component */ +typedef JMETHOD(void, downsample1_ptr, + (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +/* Private subobject */ + +typedef struct { + struct jpeg_downsampler pub; /* public fields */ + + /* Downsampling method pointers, one per component */ + downsample1_ptr methods[MAX_COMPONENTS]; +} my_downsampler; + +typedef my_downsampler * my_downsample_ptr; + + +/* + * Initialize for a downsampling pass. + */ + +METHODDEF(void) +start_pass_downsample (j_compress_ptr cinfo) +{ + /* no work for now */ +} + + +/* + * Expand a component horizontally from width input_cols to width output_cols, + * by duplicating the rightmost samples. + */ + +LOCAL(void) +expand_right_edge (JSAMPARRAY image_data, int num_rows, + JDIMENSION input_cols, JDIMENSION output_cols) +{ + register JSAMPROW ptr; + register JSAMPLE pixval; + register int count; + int row; + int numcols = (int) (output_cols - input_cols); + + if (numcols > 0) { + for (row = 0; row < num_rows; row++) { + ptr = image_data[row] + input_cols; + pixval = ptr[-1]; /* don't need GETJSAMPLE() here */ + for (count = numcols; count > 0; count--) + *ptr++ = pixval; + } + } +} + + +/* + * Do downsampling for a whole row group (all components). + * + * In this version we simply downsample each component independently. + */ + +METHODDEF(void) +sep_downsample (j_compress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_index, + JSAMPIMAGE output_buf, JDIMENSION out_row_group_index) +{ + my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample; + int ci; + jpeg_component_info * compptr; + JSAMPARRAY in_ptr, out_ptr; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + in_ptr = input_buf[ci] + in_row_index; + out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); + (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); + } +} + + +/* + * Downsample pixel values of a single component. + * One row group is processed per call. + * This version handles arbitrary integral sampling ratios, without smoothing. + * Note that this version is not actually used for customary sampling ratios. + */ + +METHODDEF(void) +int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; + JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + JSAMPROW inptr, outptr; + INT32 outvalue; + + h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; + v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; + numpix = h_expand * v_expand; + numpix2 = numpix/2; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data, cinfo->max_v_samp_factor, + cinfo->image_width, output_cols * h_expand); + + inrow = 0; + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + for (outcol = 0, outcol_h = 0; outcol < output_cols; + outcol++, outcol_h += h_expand) { + outvalue = 0; + for (v = 0; v < v_expand; v++) { + inptr = input_data[inrow+v] + outcol_h; + for (h = 0; h < h_expand; h++) { + outvalue += (INT32) GETJSAMPLE(*inptr++); + } + } + *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix); + } + inrow += v_expand; + } +} + + +/* + * Downsample pixel values of a single component. + * This version handles the special case of a full-size component, + * without smoothing. + */ + +METHODDEF(void) +fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + /* Copy the data */ + jcopy_sample_rows(input_data, 0, output_data, 0, + cinfo->max_v_samp_factor, cinfo->image_width); + /* Edge-expand */ + expand_right_edge(output_data, cinfo->max_v_samp_factor, + cinfo->image_width, compptr->width_in_blocks * DCTSIZE); +} + + +/* + * Downsample pixel values of a single component. + * This version handles the common case of 2:1 horizontal and 1:1 vertical, + * without smoothing. + * + * A note about the "bias" calculations: when rounding fractional values to + * integer, we do not want to always round 0.5 up to the next integer. + * If we did that, we'd introduce a noticeable bias towards larger values. + * Instead, this code is arranged so that 0.5 will be rounded up or down at + * alternate pixel locations (a simple ordered dither pattern). + */ + +METHODDEF(void) +h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + int outrow; + JDIMENSION outcol; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr, outptr; + register int bias; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data, cinfo->max_v_samp_factor, + cinfo->image_width, output_cols * 2); + + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr = input_data[outrow]; + bias = 0; /* bias = 0,1,0,1,... for successive samples */ + for (outcol = 0; outcol < output_cols; outcol++) { + *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) + + bias) >> 1); + bias ^= 1; /* 0=>1, 1=>0 */ + inptr += 2; + } + } +} + + +/* + * Downsample pixel values of a single component. + * This version handles the standard case of 2:1 horizontal and 2:1 vertical, + * without smoothing. + */ + +METHODDEF(void) +h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + int inrow, outrow; + JDIMENSION outcol; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr0, inptr1, outptr; + register int bias; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data, cinfo->max_v_samp_factor, + cinfo->image_width, output_cols * 2); + + inrow = 0; + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr0 = input_data[inrow]; + inptr1 = input_data[inrow+1]; + bias = 1; /* bias = 1,2,1,2,... for successive samples */ + for (outcol = 0; outcol < output_cols; outcol++) { + *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) + + bias) >> 2); + bias ^= 3; /* 1=>2, 2=>1 */ + inptr0 += 2; inptr1 += 2; + } + inrow += 2; + } +} + + +#ifdef INPUT_SMOOTHING_SUPPORTED + +/* + * Downsample pixel values of a single component. + * This version handles the standard case of 2:1 horizontal and 2:1 vertical, + * with smoothing. One row of context is required. + */ + +METHODDEF(void) +h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + int inrow, outrow; + JDIMENSION colctr; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr; + INT32 membersum, neighsum, memberscale, neighscale; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, + cinfo->image_width, output_cols * 2); + + /* We don't bother to form the individual "smoothed" input pixel values; + * we can directly compute the output which is the average of the four + * smoothed values. Each of the four member pixels contributes a fraction + * (1-8*SF) to its own smoothed image and a fraction SF to each of the three + * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final + * output. The four corner-adjacent neighbor pixels contribute a fraction + * SF to just one smoothed pixel, or SF/4 to the final output; while the + * eight edge-adjacent neighbors contribute SF to each of two smoothed + * pixels, or SF/2 overall. In order to use integer arithmetic, these + * factors are scaled by 2^16 = 65536. + * Also recall that SF = smoothing_factor / 1024. + */ + + memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */ + neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */ + + inrow = 0; + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr0 = input_data[inrow]; + inptr1 = input_data[inrow+1]; + above_ptr = input_data[inrow-1]; + below_ptr = input_data[inrow+2]; + + /* Special case for first column: pretend column -1 is same as column 0 */ + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + + GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]); + neighsum += neighsum; + neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]); + membersum = membersum * memberscale + neighsum * neighscale; + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; + + for (colctr = output_cols - 2; colctr > 0; colctr--) { + /* sum of pixels directly mapped to this output element */ + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); + /* sum of edge-neighbor pixels */ + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) + + GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]); + /* The edge-neighbors count twice as much as corner-neighbors */ + neighsum += neighsum; + /* Add in the corner-neighbors */ + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) + + GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]); + /* form final output scaled up by 2^16 */ + membersum = membersum * memberscale + neighsum * neighscale; + /* round, descale and output it */ + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; + } + + /* Special case for last column */ + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]); + neighsum += neighsum; + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]); + membersum = membersum * memberscale + neighsum * neighscale; + *outptr = (JSAMPLE) ((membersum + 32768) >> 16); + + inrow += 2; + } +} + + +/* + * Downsample pixel values of a single component. + * This version handles the special case of a full-size component, + * with smoothing. One row of context is required. + */ + +METHODDEF(void) +fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + int outrow; + JDIMENSION colctr; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr, above_ptr, below_ptr, outptr; + INT32 membersum, neighsum, memberscale, neighscale; + int colsum, lastcolsum, nextcolsum; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, + cinfo->image_width, output_cols); + + /* Each of the eight neighbor pixels contributes a fraction SF to the + * smoothed pixel, while the main pixel contributes (1-8*SF). In order + * to use integer arithmetic, these factors are multiplied by 2^16 = 65536. + * Also recall that SF = smoothing_factor / 1024. + */ + + memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */ + neighscale = cinfo->smoothing_factor * 64; /* scaled SF */ + + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr = input_data[outrow]; + above_ptr = input_data[outrow-1]; + below_ptr = input_data[outrow+1]; + + /* Special case for first column */ + colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) + + GETJSAMPLE(*inptr); + membersum = GETJSAMPLE(*inptr++); + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + + GETJSAMPLE(*inptr); + neighsum = colsum + (colsum - membersum) + nextcolsum; + membersum = membersum * memberscale + neighsum * neighscale; + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + lastcolsum = colsum; colsum = nextcolsum; + + for (colctr = output_cols - 2; colctr > 0; colctr--) { + membersum = GETJSAMPLE(*inptr++); + above_ptr++; below_ptr++; + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + + GETJSAMPLE(*inptr); + neighsum = lastcolsum + (colsum - membersum) + nextcolsum; + membersum = membersum * memberscale + neighsum * neighscale; + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + lastcolsum = colsum; colsum = nextcolsum; + } + + /* Special case for last column */ + membersum = GETJSAMPLE(*inptr); + neighsum = lastcolsum + (colsum - membersum) + colsum; + membersum = membersum * memberscale + neighsum * neighscale; + *outptr = (JSAMPLE) ((membersum + 32768) >> 16); + + } +} + +#endif /* INPUT_SMOOTHING_SUPPORTED */ + + +/* + * Module initialization routine for downsampling. + * Note that we must select a routine for each component. + */ + +GLOBAL(void) +jinit_downsampler (j_compress_ptr cinfo) +{ + my_downsample_ptr downsample; + int ci; + jpeg_component_info * compptr; + boolean smoothok = TRUE; + + downsample = (my_downsample_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_downsampler)); + cinfo->downsample = (struct jpeg_downsampler *) downsample; + downsample->pub.start_pass = start_pass_downsample; + downsample->pub.downsample = sep_downsample; + downsample->pub.need_context_rows = FALSE; + + if (cinfo->CCIR601_sampling) + ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); + + /* Verify we can handle the sampling factors, and set up method pointers */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->h_samp_factor == cinfo->max_h_samp_factor && + compptr->v_samp_factor == cinfo->max_v_samp_factor) { +#ifdef INPUT_SMOOTHING_SUPPORTED + if (cinfo->smoothing_factor) { + downsample->methods[ci] = fullsize_smooth_downsample; + downsample->pub.need_context_rows = TRUE; + } else +#endif + downsample->methods[ci] = fullsize_downsample; + } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && + compptr->v_samp_factor == cinfo->max_v_samp_factor) { + smoothok = FALSE; + if (jsimd_can_h2v1_downsample()) + downsample->methods[ci] = jsimd_h2v1_downsample; + else + downsample->methods[ci] = h2v1_downsample; + } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && + compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { +#ifdef INPUT_SMOOTHING_SUPPORTED + if (cinfo->smoothing_factor) { + downsample->methods[ci] = h2v2_smooth_downsample; + downsample->pub.need_context_rows = TRUE; + } else +#endif + if (jsimd_can_h2v2_downsample()) + downsample->methods[ci] = jsimd_h2v2_downsample; + else + downsample->methods[ci] = h2v2_downsample; + } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && + (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { + smoothok = FALSE; + downsample->methods[ci] = int_downsample; + } else + ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); + } + +#ifdef INPUT_SMOOTHING_SUPPORTED + if (cinfo->smoothing_factor && !smoothok) + TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); +#endif +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jctrans.c b/lib-third-party/libturbojpeg-ios/libjpeg/jctrans.c new file mode 100755 index 0000000..916e872 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jctrans.c @@ -0,0 +1,399 @@ +/* + * jctrans.c + * + * Copyright (C) 1995-1998, Thomas G. Lane. + * Modified 2000-2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains library routines for transcoding compression, + * that is, writing raw DCT coefficient arrays to an output JPEG file. + * The routines in jcapimin.c will also be needed by a transcoder. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* Forward declarations */ +LOCAL(void) transencode_master_selection + JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); +LOCAL(void) transencode_coef_controller + JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); + + +/* + * Compression initialization for writing raw-coefficient data. + * Before calling this, all parameters and a data destination must be set up. + * Call jpeg_finish_compress() to actually write the data. + * + * The number of passed virtual arrays must match cinfo->num_components. + * Note that the virtual arrays need not be filled or even realized at + * the time write_coefficients is called; indeed, if the virtual arrays + * were requested from this compression object's memory manager, they + * typically will be realized during this routine and filled afterwards. + */ + +GLOBAL(void) +jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays) +{ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Mark all tables to be written */ + jpeg_suppress_tables(cinfo, FALSE); + /* (Re)initialize error mgr and destination modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->dest->init_destination) (cinfo); + /* Perform master selection of active modules */ + transencode_master_selection(cinfo, coef_arrays); + /* Wait for jpeg_finish_compress() call */ + cinfo->next_scanline = 0; /* so jpeg_write_marker works */ + cinfo->global_state = CSTATE_WRCOEFS; +} + + +/* + * Initialize the compression object with default parameters, + * then copy from the source object all parameters needed for lossless + * transcoding. Parameters that can be varied without loss (such as + * scan script and Huffman optimization) are left in their default states. + */ + +GLOBAL(void) +jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, + j_compress_ptr dstinfo) +{ + JQUANT_TBL ** qtblptr; + jpeg_component_info *incomp, *outcomp; + JQUANT_TBL *c_quant, *slot_quant; + int tblno, ci, coefi; + + /* Safety check to ensure start_compress not called yet. */ + if (dstinfo->global_state != CSTATE_START) + ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state); + /* Copy fundamental image dimensions */ + dstinfo->image_width = srcinfo->image_width; + dstinfo->image_height = srcinfo->image_height; + dstinfo->input_components = srcinfo->num_components; + dstinfo->in_color_space = srcinfo->jpeg_color_space; +#if JPEG_LIB_VERSION >= 70 + dstinfo->jpeg_width = srcinfo->output_width; + dstinfo->jpeg_height = srcinfo->output_height; + dstinfo->min_DCT_h_scaled_size = srcinfo->min_DCT_h_scaled_size; + dstinfo->min_DCT_v_scaled_size = srcinfo->min_DCT_v_scaled_size; +#endif + /* Initialize all parameters to default values */ + jpeg_set_defaults(dstinfo); + /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. + * Fix it to get the right header markers for the image colorspace. + */ + jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space); + dstinfo->data_precision = srcinfo->data_precision; + dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling; + /* Copy the source's quantization tables. */ + for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { + if (srcinfo->quant_tbl_ptrs[tblno] != NULL) { + qtblptr = & dstinfo->quant_tbl_ptrs[tblno]; + if (*qtblptr == NULL) + *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo); + MEMCOPY((*qtblptr)->quantval, + srcinfo->quant_tbl_ptrs[tblno]->quantval, + SIZEOF((*qtblptr)->quantval)); + (*qtblptr)->sent_table = FALSE; + } + } + /* Copy the source's per-component info. + * Note we assume jpeg_set_defaults has allocated the dest comp_info array. + */ + dstinfo->num_components = srcinfo->num_components; + if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS) + ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components, + MAX_COMPONENTS); + for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info; + ci < dstinfo->num_components; ci++, incomp++, outcomp++) { + outcomp->component_id = incomp->component_id; + outcomp->h_samp_factor = incomp->h_samp_factor; + outcomp->v_samp_factor = incomp->v_samp_factor; + outcomp->quant_tbl_no = incomp->quant_tbl_no; + /* Make sure saved quantization table for component matches the qtable + * slot. If not, the input file re-used this qtable slot. + * IJG encoder currently cannot duplicate this. + */ + tblno = outcomp->quant_tbl_no; + if (tblno < 0 || tblno >= NUM_QUANT_TBLS || + srcinfo->quant_tbl_ptrs[tblno] == NULL) + ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno); + slot_quant = srcinfo->quant_tbl_ptrs[tblno]; + c_quant = incomp->quant_table; + if (c_quant != NULL) { + for (coefi = 0; coefi < DCTSIZE2; coefi++) { + if (c_quant->quantval[coefi] != slot_quant->quantval[coefi]) + ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); + } + } + /* Note: we do not copy the source's Huffman table assignments; + * instead we rely on jpeg_set_colorspace to have made a suitable choice. + */ + } + /* Also copy JFIF version and resolution information, if available. + * Strictly speaking this isn't "critical" info, but it's nearly + * always appropriate to copy it if available. In particular, + * if the application chooses to copy JFIF 1.02 extension markers from + * the source file, we need to copy the version to make sure we don't + * emit a file that has 1.02 extensions but a claimed version of 1.01. + * We will *not*, however, copy version info from mislabeled "2.01" files. + */ + if (srcinfo->saw_JFIF_marker) { + if (srcinfo->JFIF_major_version == 1) { + dstinfo->JFIF_major_version = srcinfo->JFIF_major_version; + dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version; + } + dstinfo->density_unit = srcinfo->density_unit; + dstinfo->X_density = srcinfo->X_density; + dstinfo->Y_density = srcinfo->Y_density; + } +} + + +/* + * Master selection of compression modules for transcoding. + * This substitutes for jcinit.c's initialization of the full compressor. + */ + +LOCAL(void) +transencode_master_selection (j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays) +{ + /* Although we don't actually use input_components for transcoding, + * jcmaster.c's initial_setup will complain if input_components is 0. + */ + cinfo->input_components = 1; + /* Initialize master control (includes parameter checking/processing) */ + jinit_c_master_control(cinfo, TRUE /* transcode only */); + + /* Entropy encoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { +#ifdef C_ARITH_CODING_SUPPORTED + jinit_arith_encoder(cinfo); +#else + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); +#endif + } else { + if (cinfo->progressive_mode) { +#ifdef C_PROGRESSIVE_SUPPORTED + jinit_phuff_encoder(cinfo); +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else + jinit_huff_encoder(cinfo); + } + + /* We need a special coefficient buffer controller. */ + transencode_coef_controller(cinfo, coef_arrays); + + jinit_marker_writer(cinfo); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Write the datastream header (SOI, JFIF) immediately. + * Frame and scan headers are postponed till later. + * This lets application insert special markers after the SOI. + */ + (*cinfo->marker->write_file_header) (cinfo); +} + + +/* + * The rest of this file is a special implementation of the coefficient + * buffer controller. This is similar to jccoefct.c, but it handles only + * output from presupplied virtual arrays. Furthermore, we generate any + * dummy padding blocks on-the-fly rather than expecting them to be present + * in the arrays. + */ + +/* Private buffer controller object */ + +typedef struct { + struct jpeg_c_coef_controller pub; /* public fields */ + + JDIMENSION iMCU_row_num; /* iMCU row # within image */ + JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ + int MCU_vert_offset; /* counts MCU rows within iMCU row */ + int MCU_rows_per_iMCU_row; /* number of such rows needed */ + + /* Virtual block array for each component. */ + jvirt_barray_ptr * whole_image; + + /* Workspace for constructing dummy blocks at right/bottom edges. */ + JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU]; +} my_coef_controller; + +typedef my_coef_controller * my_coef_ptr; + + +LOCAL(void) +start_iMCU_row (j_compress_ptr cinfo) +/* Reset within-iMCU-row counters for a new row */ +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* In an interleaved scan, an MCU row is the same as an iMCU row. + * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. + * But at the bottom of the image, process only what's left. + */ + if (cinfo->comps_in_scan > 1) { + coef->MCU_rows_per_iMCU_row = 1; + } else { + if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; + else + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; + } + + coef->mcu_ctr = 0; + coef->MCU_vert_offset = 0; +} + + +/* + * Initialize for a processing pass. + */ + +METHODDEF(void) +start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + if (pass_mode != JBUF_CRANK_DEST) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + coef->iMCU_row_num = 0; + start_iMCU_row(cinfo); +} + + +/* + * Process some data. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the scan. + * The data is obtained from the virtual arrays and fed to the entropy coder. + * Returns TRUE if the iMCU row is completed, FALSE if suspended. + * + * NB: input_buf is ignored; it is likely to be a NULL pointer. + */ + +METHODDEF(boolean) +compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + int blkn, ci, xindex, yindex, yoffset, blockcnt; + JDIMENSION start_col; + JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; + JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; + JBLOCKROW buffer_ptr; + jpeg_component_info *compptr; + + /* Align the virtual buffers for the components used in this scan. */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + buffer[ci] = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], + coef->iMCU_row_num * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } + + /* Loop to process one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; + MCU_col_num++) { + /* Construct list of pointers to DCT blocks belonging to this MCU */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + start_col = MCU_col_num * compptr->MCU_width; + blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width + : compptr->last_col_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + if (coef->iMCU_row_num < last_iMCU_row || + yindex+yoffset < compptr->last_row_height) { + /* Fill in pointers to real blocks in this row */ + buffer_ptr = buffer[ci][yindex+yoffset] + start_col; + for (xindex = 0; xindex < blockcnt; xindex++) + MCU_buffer[blkn++] = buffer_ptr++; + } else { + /* At bottom of image, need a whole row of dummy blocks */ + xindex = 0; + } + /* Fill in any dummy blocks needed in this row. + * Dummy blocks are filled in the same way as in jccoefct.c: + * all zeroes in the AC entries, DC entries equal to previous + * block's DC value. The init routine has already zeroed the + * AC entries, so we need only set the DC entries correctly. + */ + for (; xindex < compptr->MCU_width; xindex++) { + MCU_buffer[blkn] = coef->dummy_buffer[blkn]; + MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0]; + blkn++; + } + } + } + /* Try to write the MCU. */ + if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->mcu_ctr = MCU_col_num; + return FALSE; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->mcu_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + coef->iMCU_row_num++; + start_iMCU_row(cinfo); + return TRUE; +} + + +/* + * Initialize coefficient buffer controller. + * + * Each passed coefficient array must be the right size for that + * coefficient: width_in_blocks wide and height_in_blocks high, + * with unitheight at least v_samp_factor. + */ + +LOCAL(void) +transencode_coef_controller (j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays) +{ + my_coef_ptr coef; + JBLOCKROW buffer; + int i; + + coef = (my_coef_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_coef_controller)); + cinfo->coef = (struct jpeg_c_coef_controller *) coef; + coef->pub.start_pass = start_pass_coef; + coef->pub.compress_data = compress_output; + + /* Save pointer to virtual arrays */ + coef->whole_image = coef_arrays; + + /* Allocate and pre-zero space for dummy DCT blocks. */ + buffer = (JBLOCKROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { + coef->dummy_buffer[i] = buffer + i; + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdapimin.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdapimin.c new file mode 100755 index 0000000..cadb59f --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdapimin.c @@ -0,0 +1,395 @@ +/* + * jdapimin.c + * + * Copyright (C) 1994-1998, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the decompression half + * of the JPEG library. These are the "minimum" API routines that may be + * needed in either the normal full-decompression case or the + * transcoding-only case. + * + * Most of the routines intended to be called directly by an application + * are in this file or in jdapistd.c. But also see jcomapi.c for routines + * shared by compression and decompression, and jdtrans.c for the transcoding + * case. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* + * Initialization of a JPEG decompression object. + * The error manager must already be set up (in case memory manager fails). + */ + +GLOBAL(void) +jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) +{ + int i; + + /* Guard against version mismatches between library and caller. */ + cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ + if (version != JPEG_LIB_VERSION) + ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); + if (structsize != SIZEOF(struct jpeg_decompress_struct)) + ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, + (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize); + + /* For debugging purposes, we zero the whole master structure. + * But the application has already set the err pointer, and may have set + * client_data, so we have to save and restore those fields. + * Note: if application hasn't set client_data, tools like Purify may + * complain here. + */ + { + struct jpeg_error_mgr * err = cinfo->err; + void * client_data = cinfo->client_data; /* ignore Purify complaint here */ + MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct)); + cinfo->err = err; + cinfo->client_data = client_data; + } + cinfo->is_decompressor = TRUE; + + /* Initialize a memory manager instance for this object */ + jinit_memory_mgr((j_common_ptr) cinfo); + + /* Zero out pointers to permanent structures. */ + cinfo->progress = NULL; + cinfo->src = NULL; + + for (i = 0; i < NUM_QUANT_TBLS; i++) + cinfo->quant_tbl_ptrs[i] = NULL; + + for (i = 0; i < NUM_HUFF_TBLS; i++) { + cinfo->dc_huff_tbl_ptrs[i] = NULL; + cinfo->ac_huff_tbl_ptrs[i] = NULL; + } + + /* Initialize marker processor so application can override methods + * for COM, APPn markers before calling jpeg_read_header. + */ + cinfo->marker_list = NULL; + jinit_marker_reader(cinfo); + + /* And initialize the overall input controller. */ + jinit_input_controller(cinfo); + + /* OK, I'm ready */ + cinfo->global_state = DSTATE_START; +} + + +/* + * Destruction of a JPEG decompression object + */ + +GLOBAL(void) +jpeg_destroy_decompress (j_decompress_ptr cinfo) +{ + jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ +} + + +/* + * Abort processing of a JPEG decompression operation, + * but don't destroy the object itself. + */ + +GLOBAL(void) +jpeg_abort_decompress (j_decompress_ptr cinfo) +{ + jpeg_abort((j_common_ptr) cinfo); /* use common routine */ +} + + +/* + * Set default decompression parameters. + */ + +LOCAL(void) +default_decompress_parms (j_decompress_ptr cinfo) +{ + /* Guess the input colorspace, and set output colorspace accordingly. */ + /* (Wish JPEG committee had provided a real way to specify this...) */ + /* Note application may override our guesses. */ + switch (cinfo->num_components) { + case 1: + cinfo->jpeg_color_space = JCS_GRAYSCALE; + cinfo->out_color_space = JCS_GRAYSCALE; + break; + + case 3: + if (cinfo->saw_JFIF_marker) { + cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ + } else if (cinfo->saw_Adobe_marker) { + switch (cinfo->Adobe_transform) { + case 0: + cinfo->jpeg_color_space = JCS_RGB; + break; + case 1: + cinfo->jpeg_color_space = JCS_YCbCr; + break; + default: + WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); + cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ + break; + } + } else { + /* Saw no special markers, try to guess from the component IDs */ + int cid0 = cinfo->comp_info[0].component_id; + int cid1 = cinfo->comp_info[1].component_id; + int cid2 = cinfo->comp_info[2].component_id; + + if (cid0 == 1 && cid1 == 2 && cid2 == 3) + cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ + else if (cid0 == 82 && cid1 == 71 && cid2 == 66) + cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ + else { + TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); + cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ + } + } + /* Always guess RGB is proper output colorspace. */ + cinfo->out_color_space = JCS_RGB; + break; + + case 4: + if (cinfo->saw_Adobe_marker) { + switch (cinfo->Adobe_transform) { + case 0: + cinfo->jpeg_color_space = JCS_CMYK; + break; + case 2: + cinfo->jpeg_color_space = JCS_YCCK; + break; + default: + WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); + cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ + break; + } + } else { + /* No special markers, assume straight CMYK. */ + cinfo->jpeg_color_space = JCS_CMYK; + } + cinfo->out_color_space = JCS_CMYK; + break; + + default: + cinfo->jpeg_color_space = JCS_UNKNOWN; + cinfo->out_color_space = JCS_UNKNOWN; + break; + } + + /* Set defaults for other decompression parameters. */ + cinfo->scale_num = 1; /* 1:1 scaling */ + cinfo->scale_denom = 1; + cinfo->output_gamma = 1.0; + cinfo->buffered_image = FALSE; + cinfo->raw_data_out = FALSE; + cinfo->dct_method = JDCT_DEFAULT; + cinfo->do_fancy_upsampling = TRUE; + cinfo->do_block_smoothing = TRUE; + cinfo->quantize_colors = FALSE; + /* We set these in case application only sets quantize_colors. */ + cinfo->dither_mode = JDITHER_FS; +#ifdef QUANT_2PASS_SUPPORTED + cinfo->two_pass_quantize = TRUE; +#else + cinfo->two_pass_quantize = FALSE; +#endif + cinfo->desired_number_of_colors = 256; + cinfo->colormap = NULL; + /* Initialize for no mode change in buffered-image mode. */ + cinfo->enable_1pass_quant = FALSE; + cinfo->enable_external_quant = FALSE; + cinfo->enable_2pass_quant = FALSE; +} + + +/* + * Decompression startup: read start of JPEG datastream to see what's there. + * Need only initialize JPEG object and supply a data source before calling. + * + * This routine will read as far as the first SOS marker (ie, actual start of + * compressed data), and will save all tables and parameters in the JPEG + * object. It will also initialize the decompression parameters to default + * values, and finally return JPEG_HEADER_OK. On return, the application may + * adjust the decompression parameters and then call jpeg_start_decompress. + * (Or, if the application only wanted to determine the image parameters, + * the data need not be decompressed. In that case, call jpeg_abort or + * jpeg_destroy to release any temporary space.) + * If an abbreviated (tables only) datastream is presented, the routine will + * return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then + * re-use the JPEG object to read the abbreviated image datastream(s). + * It is unnecessary (but OK) to call jpeg_abort in this case. + * The JPEG_SUSPENDED return code only occurs if the data source module + * requests suspension of the decompressor. In this case the application + * should load more source data and then re-call jpeg_read_header to resume + * processing. + * If a non-suspending data source is used and require_image is TRUE, then the + * return code need not be inspected since only JPEG_HEADER_OK is possible. + * + * This routine is now just a front end to jpeg_consume_input, with some + * extra error checking. + */ + +GLOBAL(int) +jpeg_read_header (j_decompress_ptr cinfo, boolean require_image) +{ + int retcode; + + if (cinfo->global_state != DSTATE_START && + cinfo->global_state != DSTATE_INHEADER) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + retcode = jpeg_consume_input(cinfo); + + switch (retcode) { + case JPEG_REACHED_SOS: + retcode = JPEG_HEADER_OK; + break; + case JPEG_REACHED_EOI: + if (require_image) /* Complain if application wanted an image */ + ERREXIT(cinfo, JERR_NO_IMAGE); + /* Reset to start state; it would be safer to require the application to + * call jpeg_abort, but we can't change it now for compatibility reasons. + * A side effect is to free any temporary memory (there shouldn't be any). + */ + jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */ + retcode = JPEG_HEADER_TABLES_ONLY; + break; + case JPEG_SUSPENDED: + /* no work */ + break; + } + + return retcode; +} + + +/* + * Consume data in advance of what the decompressor requires. + * This can be called at any time once the decompressor object has + * been created and a data source has been set up. + * + * This routine is essentially a state machine that handles a couple + * of critical state-transition actions, namely initial setup and + * transition from header scanning to ready-for-start_decompress. + * All the actual input is done via the input controller's consume_input + * method. + */ + +GLOBAL(int) +jpeg_consume_input (j_decompress_ptr cinfo) +{ + int retcode = JPEG_SUSPENDED; + + /* NB: every possible DSTATE value should be listed in this switch */ + switch (cinfo->global_state) { + case DSTATE_START: + /* Start-of-datastream actions: reset appropriate modules */ + (*cinfo->inputctl->reset_input_controller) (cinfo); + /* Initialize application's data source module */ + (*cinfo->src->init_source) (cinfo); + cinfo->global_state = DSTATE_INHEADER; + /*FALLTHROUGH*/ + case DSTATE_INHEADER: + retcode = (*cinfo->inputctl->consume_input) (cinfo); + if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */ + /* Set up default parameters based on header data */ + default_decompress_parms(cinfo); + /* Set global state: ready for start_decompress */ + cinfo->global_state = DSTATE_READY; + } + break; + case DSTATE_READY: + /* Can't advance past first SOS until start_decompress is called */ + retcode = JPEG_REACHED_SOS; + break; + case DSTATE_PRELOAD: + case DSTATE_PRESCAN: + case DSTATE_SCANNING: + case DSTATE_RAW_OK: + case DSTATE_BUFIMAGE: + case DSTATE_BUFPOST: + case DSTATE_STOPPING: + retcode = (*cinfo->inputctl->consume_input) (cinfo); + break; + default: + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + } + return retcode; +} + + +/* + * Have we finished reading the input file? + */ + +GLOBAL(boolean) +jpeg_input_complete (j_decompress_ptr cinfo) +{ + /* Check for valid jpeg object */ + if (cinfo->global_state < DSTATE_START || + cinfo->global_state > DSTATE_STOPPING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + return cinfo->inputctl->eoi_reached; +} + + +/* + * Is there more than one scan? + */ + +GLOBAL(boolean) +jpeg_has_multiple_scans (j_decompress_ptr cinfo) +{ + /* Only valid after jpeg_read_header completes */ + if (cinfo->global_state < DSTATE_READY || + cinfo->global_state > DSTATE_STOPPING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + return cinfo->inputctl->has_multiple_scans; +} + + +/* + * Finish JPEG decompression. + * + * This will normally just verify the file trailer and release temp storage. + * + * Returns FALSE if suspended. The return value need be inspected only if + * a suspending data source is used. + */ + +GLOBAL(boolean) +jpeg_finish_decompress (j_decompress_ptr cinfo) +{ + if ((cinfo->global_state == DSTATE_SCANNING || + cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) { + /* Terminate final pass of non-buffered mode */ + if (cinfo->output_scanline < cinfo->output_height) + ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); + (*cinfo->master->finish_output_pass) (cinfo); + cinfo->global_state = DSTATE_STOPPING; + } else if (cinfo->global_state == DSTATE_BUFIMAGE) { + /* Finishing after a buffered-image operation */ + cinfo->global_state = DSTATE_STOPPING; + } else if (cinfo->global_state != DSTATE_STOPPING) { + /* STOPPING = repeat call after a suspension, anything else is error */ + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + } + /* Read until EOI */ + while (! cinfo->inputctl->eoi_reached) { + if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) + return FALSE; /* Suspend, come back later */ + } + /* Do final cleanup */ + (*cinfo->src->term_source) (cinfo); + /* We can use jpeg_abort to release memory and reset global_state */ + jpeg_abort((j_common_ptr) cinfo); + return TRUE; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdapistd.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdapistd.c new file mode 100755 index 0000000..2343da5 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdapistd.c @@ -0,0 +1,277 @@ +/* + * jdapistd.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the decompression half + * of the JPEG library. These are the "standard" API routines that are + * used in the normal full-decompression case. They are not used by a + * transcoding-only application. Note that if an application links in + * jpeg_start_decompress, it will end up linking in the entire decompressor. + * We thus must separate this file from jdapimin.c to avoid linking the + * whole decompression library into a transcoder. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jpegcomp.h" + + +/* Forward declarations */ +LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo)); + + +/* + * Decompression initialization. + * jpeg_read_header must be completed before calling this. + * + * If a multipass operating mode was selected, this will do all but the + * last pass, and thus may take a great deal of time. + * + * Returns FALSE if suspended. The return value need be inspected only if + * a suspending data source is used. + */ + +GLOBAL(boolean) +jpeg_start_decompress (j_decompress_ptr cinfo) +{ + if (cinfo->global_state == DSTATE_READY) { + /* First call: initialize master control, select active modules */ + jinit_master_decompress(cinfo); + if (cinfo->buffered_image) { + /* No more work here; expecting jpeg_start_output next */ + cinfo->global_state = DSTATE_BUFIMAGE; + return TRUE; + } + cinfo->global_state = DSTATE_PRELOAD; + } + if (cinfo->global_state == DSTATE_PRELOAD) { + /* If file has multiple scans, absorb them all into the coef buffer */ + if (cinfo->inputctl->has_multiple_scans) { +#ifdef D_MULTISCAN_FILES_SUPPORTED + for (;;) { + int retcode; + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + /* Absorb some more input */ + retcode = (*cinfo->inputctl->consume_input) (cinfo); + if (retcode == JPEG_SUSPENDED) + return FALSE; + if (retcode == JPEG_REACHED_EOI) + break; + /* Advance progress counter if appropriate */ + if (cinfo->progress != NULL && + (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { + if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { + /* jdmaster underestimated number of scans; ratchet up one scan */ + cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; + } + } + } +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif /* D_MULTISCAN_FILES_SUPPORTED */ + } + cinfo->output_scan_number = cinfo->input_scan_number; + } else if (cinfo->global_state != DSTATE_PRESCAN) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Perform any dummy output passes, and set up for the final pass */ + return output_pass_setup(cinfo); +} + + +/* + * Set up for an output pass, and perform any dummy pass(es) needed. + * Common subroutine for jpeg_start_decompress and jpeg_start_output. + * Entry: global_state = DSTATE_PRESCAN only if previously suspended. + * Exit: If done, returns TRUE and sets global_state for proper output mode. + * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN. + */ + +LOCAL(boolean) +output_pass_setup (j_decompress_ptr cinfo) +{ + if (cinfo->global_state != DSTATE_PRESCAN) { + /* First call: do pass setup */ + (*cinfo->master->prepare_for_output_pass) (cinfo); + cinfo->output_scanline = 0; + cinfo->global_state = DSTATE_PRESCAN; + } + /* Loop over any required dummy passes */ + while (cinfo->master->is_dummy_pass) { +#ifdef QUANT_2PASS_SUPPORTED + /* Crank through the dummy pass */ + while (cinfo->output_scanline < cinfo->output_height) { + JDIMENSION last_scanline; + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->output_scanline; + cinfo->progress->pass_limit = (long) cinfo->output_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + /* Process some data */ + last_scanline = cinfo->output_scanline; + (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL, + &cinfo->output_scanline, (JDIMENSION) 0); + if (cinfo->output_scanline == last_scanline) + return FALSE; /* No progress made, must suspend */ + } + /* Finish up dummy pass, and set up for another one */ + (*cinfo->master->finish_output_pass) (cinfo); + (*cinfo->master->prepare_for_output_pass) (cinfo); + cinfo->output_scanline = 0; +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif /* QUANT_2PASS_SUPPORTED */ + } + /* Ready for application to drive output pass through + * jpeg_read_scanlines or jpeg_read_raw_data. + */ + cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING; + return TRUE; +} + + +/* + * Read some scanlines of data from the JPEG decompressor. + * + * The return value will be the number of lines actually read. + * This may be less than the number requested in several cases, + * including bottom of image, data source suspension, and operating + * modes that emit multiple scanlines at a time. + * + * Note: we warn about excess calls to jpeg_read_scanlines() since + * this likely signals an application programmer error. However, + * an oversize buffer (max_lines > scanlines remaining) is not an error. + */ + +GLOBAL(JDIMENSION) +jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, + JDIMENSION max_lines) +{ + JDIMENSION row_ctr; + + if (cinfo->global_state != DSTATE_SCANNING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->output_scanline >= cinfo->output_height) { + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + return 0; + } + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->output_scanline; + cinfo->progress->pass_limit = (long) cinfo->output_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Process some data */ + row_ctr = 0; + (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines); + cinfo->output_scanline += row_ctr; + return row_ctr; +} + + +/* + * Alternate entry point to read raw data. + * Processes exactly one iMCU row per call, unless suspended. + */ + +GLOBAL(JDIMENSION) +jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, + JDIMENSION max_lines) +{ + JDIMENSION lines_per_iMCU_row; + + if (cinfo->global_state != DSTATE_RAW_OK) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->output_scanline >= cinfo->output_height) { + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + return 0; + } + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->output_scanline; + cinfo->progress->pass_limit = (long) cinfo->output_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Verify that at least one iMCU row can be returned. */ + lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size; + if (max_lines < lines_per_iMCU_row) + ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* Decompress directly into user's buffer. */ + if (! (*cinfo->coef->decompress_data) (cinfo, data)) + return 0; /* suspension forced, can do nothing more */ + + /* OK, we processed one iMCU row. */ + cinfo->output_scanline += lines_per_iMCU_row; + return lines_per_iMCU_row; +} + + +/* Additional entry points for buffered-image mode. */ + +#ifdef D_MULTISCAN_FILES_SUPPORTED + +/* + * Initialize for an output pass in buffered-image mode. + */ + +GLOBAL(boolean) +jpeg_start_output (j_decompress_ptr cinfo, int scan_number) +{ + if (cinfo->global_state != DSTATE_BUFIMAGE && + cinfo->global_state != DSTATE_PRESCAN) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Limit scan number to valid range */ + if (scan_number <= 0) + scan_number = 1; + if (cinfo->inputctl->eoi_reached && + scan_number > cinfo->input_scan_number) + scan_number = cinfo->input_scan_number; + cinfo->output_scan_number = scan_number; + /* Perform any dummy output passes, and set up for the real pass */ + return output_pass_setup(cinfo); +} + + +/* + * Finish up after an output pass in buffered-image mode. + * + * Returns FALSE if suspended. The return value need be inspected only if + * a suspending data source is used. + */ + +GLOBAL(boolean) +jpeg_finish_output (j_decompress_ptr cinfo) +{ + if ((cinfo->global_state == DSTATE_SCANNING || + cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) { + /* Terminate this pass. */ + /* We do not require the whole pass to have been completed. */ + (*cinfo->master->finish_output_pass) (cinfo); + cinfo->global_state = DSTATE_BUFPOST; + } else if (cinfo->global_state != DSTATE_BUFPOST) { + /* BUFPOST = repeat call after a suspension, anything else is error */ + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + } + /* Read markers looking for SOS or EOI */ + while (cinfo->input_scan_number <= cinfo->output_scan_number && + ! cinfo->inputctl->eoi_reached) { + if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) + return FALSE; /* Suspend, come back later */ + } + cinfo->global_state = DSTATE_BUFIMAGE; + return TRUE; +} + +#endif /* D_MULTISCAN_FILES_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdatadst.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdatadst.c new file mode 100755 index 0000000..2f48869 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdatadst.c @@ -0,0 +1,277 @@ +/* + * jdatadst.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Modified 2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains compression data destination routines for the case of + * emitting JPEG data to memory or to a file (or any stdio stream). + * While these routines are sufficient for most applications, + * some will want to use a different destination manager. + * IMPORTANT: we assume that fwrite() will correctly transcribe an array of + * JOCTETs into 8-bit-wide elements on external storage. If char is wider + * than 8 bits on your machine, you may need to do some tweaking. + */ + +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#include "jinclude.h" +#include "jpeglib.h" +#include "jerror.h" + +#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ +extern void * malloc JPP((size_t size)); +extern void free JPP((void *ptr)); +#endif + + +/* Expanded data destination object for stdio output */ + +typedef struct { + struct jpeg_destination_mgr pub; /* public fields */ + + FILE * outfile; /* target stream */ + JOCTET * buffer; /* start of buffer */ +} my_destination_mgr; + +typedef my_destination_mgr * my_dest_ptr; + +#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ + + +#if JPEG_LIB_VERSION >= 80 +/* Expanded data destination object for memory output */ + +typedef struct { + struct jpeg_destination_mgr pub; /* public fields */ + + unsigned char ** outbuffer; /* target buffer */ + unsigned long * outsize; + unsigned char * newbuffer; /* newly allocated buffer */ + JOCTET * buffer; /* start of buffer */ + size_t bufsize; +} my_mem_destination_mgr; + +typedef my_mem_destination_mgr * my_mem_dest_ptr; +#endif + + +/* + * Initialize destination --- called by jpeg_start_compress + * before any data is actually written. + */ + +METHODDEF(void) +init_destination (j_compress_ptr cinfo) +{ + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + + /* Allocate the output buffer --- it will be released when done with image */ + dest->buffer = (JOCTET *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; +} + +#if JPEG_LIB_VERSION >= 80 +METHODDEF(void) +init_mem_destination (j_compress_ptr cinfo) +{ + /* no work necessary here */ +} +#endif + + +/* + * Empty the output buffer --- called whenever buffer fills up. + * + * In typical applications, this should write the entire output buffer + * (ignoring the current state of next_output_byte & free_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been dumped. + * + * In applications that need to be able to suspend compression due to output + * overrun, a FALSE return indicates that the buffer cannot be emptied now. + * In this situation, the compressor will return to its caller (possibly with + * an indication that it has not accepted all the supplied scanlines). The + * application should resume compression after it has made more room in the + * output buffer. Note that there are substantial restrictions on the use of + * suspension --- see the documentation. + * + * When suspending, the compressor will back up to a convenient restart point + * (typically the start of the current MCU). next_output_byte & free_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point will be regenerated after resumption, so do not + * write it out when emptying the buffer externally. + */ + +METHODDEF(boolean) +empty_output_buffer (j_compress_ptr cinfo) +{ + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + + if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != + (size_t) OUTPUT_BUF_SIZE) + ERREXIT(cinfo, JERR_FILE_WRITE); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + + return TRUE; +} + +#if JPEG_LIB_VERSION >= 80 +METHODDEF(boolean) +empty_mem_output_buffer (j_compress_ptr cinfo) +{ + size_t nextsize; + JOCTET * nextbuffer; + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; + + /* Try to allocate new buffer with double size */ + nextsize = dest->bufsize * 2; + nextbuffer = malloc(nextsize); + + if (nextbuffer == NULL) + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); + + MEMCOPY(nextbuffer, dest->buffer, dest->bufsize); + + if (dest->newbuffer != NULL) + free(dest->newbuffer); + + dest->newbuffer = nextbuffer; + + dest->pub.next_output_byte = nextbuffer + dest->bufsize; + dest->pub.free_in_buffer = dest->bufsize; + + dest->buffer = nextbuffer; + dest->bufsize = nextsize; + + return TRUE; +} +#endif + + +/* + * Terminate destination --- called by jpeg_finish_compress + * after all data has been written. Usually needs to flush buffer. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ + +METHODDEF(void) +term_destination (j_compress_ptr cinfo) +{ + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; + + /* Write any data remaining in the buffer */ + if (datacount > 0) { + if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + fflush(dest->outfile); + /* Make sure we wrote the output file OK */ + if (ferror(dest->outfile)) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + +#if JPEG_LIB_VERSION >= 80 +METHODDEF(void) +term_mem_destination (j_compress_ptr cinfo) +{ + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; + + *dest->outbuffer = dest->buffer; + *dest->outsize = dest->bufsize - dest->pub.free_in_buffer; +} +#endif + + +/* + * Prepare for output to a stdio stream. + * The caller must have already opened the stream, and is responsible + * for closing it after finishing compression. + */ + +GLOBAL(void) +jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile) +{ + my_dest_ptr dest; + + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same file without re-executing jpeg_stdio_dest. + * This makes it dangerous to use this manager and a different destination + * manager serially with the same JPEG object, because their private object + * sizes may be different. Caveat programmer. + */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_destination_mgr)); + } + + dest = (my_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_destination; + dest->pub.empty_output_buffer = empty_output_buffer; + dest->pub.term_destination = term_destination; + dest->outfile = outfile; +} + + +#if JPEG_LIB_VERSION >= 80 +/* + * Prepare for output to a memory buffer. + * The caller may supply an own initial buffer with appropriate size. + * Otherwise, or when the actual data output exceeds the given size, + * the library adapts the buffer size as necessary. + * The standard library functions malloc/free are used for allocating + * larger memory, so the buffer is available to the application after + * finishing compression, and then the application is responsible for + * freeing the requested memory. + */ + +GLOBAL(void) +jpeg_mem_dest (j_compress_ptr cinfo, + unsigned char ** outbuffer, unsigned long * outsize) +{ + my_mem_dest_ptr dest; + + if (outbuffer == NULL || outsize == NULL) /* sanity check */ + ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same buffer without re-executing jpeg_mem_dest. + */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_mem_destination_mgr)); + } + + dest = (my_mem_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_mem_destination; + dest->pub.empty_output_buffer = empty_mem_output_buffer; + dest->pub.term_destination = term_mem_destination; + dest->outbuffer = outbuffer; + dest->outsize = outsize; + dest->newbuffer = NULL; + + if (*outbuffer == NULL || *outsize == 0) { + /* Allocate initial buffer */ + dest->newbuffer = *outbuffer = malloc(OUTPUT_BUF_SIZE); + if (dest->newbuffer == NULL) + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); + *outsize = OUTPUT_BUF_SIZE; + } + + dest->pub.next_output_byte = dest->buffer = *outbuffer; + dest->pub.free_in_buffer = dest->bufsize = *outsize; +} +#endif diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdatasrc.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdatasrc.c new file mode 100755 index 0000000..7609f76 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdatasrc.c @@ -0,0 +1,280 @@ +/* + * jdatasrc.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Modified 2009-2010 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains decompression data source routines for the case of + * reading JPEG data from memory or from a file (or any stdio stream). + * While these routines are sufficient for most applications, + * some will want to use a different source manager. + * IMPORTANT: we assume that fread() will correctly transcribe an array of + * JOCTETs from 8-bit-wide elements on external storage. If char is wider + * than 8 bits on your machine, you may need to do some tweaking. + */ + +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#include "jinclude.h" +#include "jpeglib.h" +#include "jerror.h" + + +/* Expanded data source object for stdio input */ + +typedef struct { + struct jpeg_source_mgr pub; /* public fields */ + + FILE * infile; /* source stream */ + JOCTET * buffer; /* start of buffer */ + boolean start_of_file; /* have we gotten any data yet? */ +} my_source_mgr; + +typedef my_source_mgr * my_src_ptr; + +#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */ + + +/* + * Initialize source --- called by jpeg_read_header + * before any data is actually read. + */ + +METHODDEF(void) +init_source (j_decompress_ptr cinfo) +{ + my_src_ptr src = (my_src_ptr) cinfo->src; + + /* We reset the empty-input-file flag for each image, + * but we don't clear the input buffer. + * This is correct behavior for reading a series of images from one source. + */ + src->start_of_file = TRUE; +} + +#if JPEG_LIB_VERSION >= 80 +METHODDEF(void) +init_mem_source (j_decompress_ptr cinfo) +{ + /* no work necessary here */ +} +#endif + + +/* + * Fill the input buffer --- called whenever buffer is emptied. + * + * In typical applications, this should read fresh data into the buffer + * (ignoring the current state of next_input_byte & bytes_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been reloaded. It is not necessary to + * fill the buffer entirely, only to obtain at least one more byte. + * + * There is no such thing as an EOF return. If the end of the file has been + * reached, the routine has a choice of ERREXIT() or inserting fake data into + * the buffer. In most cases, generating a warning message and inserting a + * fake EOI marker is the best course of action --- this will allow the + * decompressor to output however much of the image is there. However, + * the resulting error message is misleading if the real problem is an empty + * input file, so we handle that case specially. + * + * In applications that need to be able to suspend compression due to input + * not being available yet, a FALSE return indicates that no more data can be + * obtained right now, but more may be forthcoming later. In this situation, + * the decompressor will return to its caller (with an indication of the + * number of scanlines it has read, if any). The application should resume + * decompression after it has loaded more data into the input buffer. Note + * that there are substantial restrictions on the use of suspension --- see + * the documentation. + * + * When suspending, the decompressor will back up to a convenient restart point + * (typically the start of the current MCU). next_input_byte & bytes_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point must be rescanned after resumption, so move it to + * the front of the buffer rather than discarding it. + */ + +METHODDEF(boolean) +fill_input_buffer (j_decompress_ptr cinfo) +{ + my_src_ptr src = (my_src_ptr) cinfo->src; + size_t nbytes; + + nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); + + if (nbytes <= 0) { + if (src->start_of_file) /* Treat empty input file as fatal error */ + ERREXIT(cinfo, JERR_INPUT_EMPTY); + WARNMS(cinfo, JWRN_JPEG_EOF); + /* Insert a fake EOI marker */ + src->buffer[0] = (JOCTET) 0xFF; + src->buffer[1] = (JOCTET) JPEG_EOI; + nbytes = 2; + } + + src->pub.next_input_byte = src->buffer; + src->pub.bytes_in_buffer = nbytes; + src->start_of_file = FALSE; + + return TRUE; +} + +#if JPEG_LIB_VERSION >= 80 +METHODDEF(boolean) +fill_mem_input_buffer (j_decompress_ptr cinfo) +{ + static JOCTET mybuffer[4]; + + /* The whole JPEG data is expected to reside in the supplied memory + * buffer, so any request for more data beyond the given buffer size + * is treated as an error. + */ + WARNMS(cinfo, JWRN_JPEG_EOF); + /* Insert a fake EOI marker */ + mybuffer[0] = (JOCTET) 0xFF; + mybuffer[1] = (JOCTET) JPEG_EOI; + + cinfo->src->next_input_byte = mybuffer; + cinfo->src->bytes_in_buffer = 2; + + return TRUE; +} +#endif + + +/* + * Skip data --- used to skip over a potentially large amount of + * uninteresting data (such as an APPn marker). + * + * Writers of suspendable-input applications must note that skip_input_data + * is not granted the right to give a suspension return. If the skip extends + * beyond the data currently in the buffer, the buffer can be marked empty so + * that the next read will cause a fill_input_buffer call that can suspend. + * Arranging for additional bytes to be discarded before reloading the input + * buffer is the application writer's problem. + */ + +METHODDEF(void) +skip_input_data (j_decompress_ptr cinfo, long num_bytes) +{ + struct jpeg_source_mgr * src = cinfo->src; + + /* Just a dumb implementation for now. Could use fseek() except + * it doesn't work on pipes. Not clear that being smart is worth + * any trouble anyway --- large skips are infrequent. + */ + if (num_bytes > 0) { + while (num_bytes > (long) src->bytes_in_buffer) { + num_bytes -= (long) src->bytes_in_buffer; + (void) (*src->fill_input_buffer) (cinfo); + /* note we assume that fill_input_buffer will never return FALSE, + * so suspension need not be handled. + */ + } + src->next_input_byte += (size_t) num_bytes; + src->bytes_in_buffer -= (size_t) num_bytes; + } +} + + +/* + * An additional method that can be provided by data source modules is the + * resync_to_restart method for error recovery in the presence of RST markers. + * For the moment, this source module just uses the default resync method + * provided by the JPEG library. That method assumes that no backtracking + * is possible. + */ + + +/* + * Terminate source --- called by jpeg_finish_decompress + * after all data has been read. Often a no-op. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ + +METHODDEF(void) +term_source (j_decompress_ptr cinfo) +{ + /* no work necessary here */ +} + + +/* + * Prepare for input from a stdio stream. + * The caller must have already opened the stream, and is responsible + * for closing it after finishing decompression. + */ + +GLOBAL(void) +jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile) +{ + my_src_ptr src; + + /* The source object and input buffer are made permanent so that a series + * of JPEG images can be read from the same file by calling jpeg_stdio_src + * only before the first one. (If we discarded the buffer at the end of + * one image, we'd likely lose the start of the next one.) + * This makes it unsafe to use this manager and a different source + * manager serially with the same JPEG object. Caveat programmer. + */ + if (cinfo->src == NULL) { /* first time for this JPEG object? */ + cinfo->src = (struct jpeg_source_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_source_mgr)); + src = (my_src_ptr) cinfo->src; + src->buffer = (JOCTET *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + INPUT_BUF_SIZE * SIZEOF(JOCTET)); + } + + src = (my_src_ptr) cinfo->src; + src->pub.init_source = init_source; + src->pub.fill_input_buffer = fill_input_buffer; + src->pub.skip_input_data = skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ + src->pub.term_source = term_source; + src->infile = infile; + src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ + src->pub.next_input_byte = NULL; /* until buffer loaded */ +} + + +#if JPEG_LIB_VERSION >= 80 +/* + * Prepare for input from a supplied memory buffer. + * The buffer must contain the whole JPEG data. + */ + +GLOBAL(void) +jpeg_mem_src (j_decompress_ptr cinfo, + unsigned char * inbuffer, unsigned long insize) +{ + struct jpeg_source_mgr * src; + + if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */ + ERREXIT(cinfo, JERR_INPUT_EMPTY); + + /* The source object is made permanent so that a series of JPEG images + * can be read from the same buffer by calling jpeg_mem_src only before + * the first one. + */ + if (cinfo->src == NULL) { /* first time for this JPEG object? */ + cinfo->src = (struct jpeg_source_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(struct jpeg_source_mgr)); + } + + src = cinfo->src; + src->init_source = init_mem_source; + src->fill_input_buffer = fill_mem_input_buffer; + src->skip_input_data = skip_input_data; + src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ + src->term_source = term_source; + src->bytes_in_buffer = (size_t) insize; + src->next_input_byte = (JOCTET *) inbuffer; +} +#endif diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdcoefct.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdcoefct.c new file mode 100755 index 0000000..48a9fc6 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdcoefct.c @@ -0,0 +1,749 @@ +/* + * jdcoefct.c + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the coefficient buffer controller for decompression. + * This controller is the top level of the JPEG decompressor proper. + * The coefficient buffer lies between entropy decoding and inverse-DCT steps. + * + * In buffered-image mode, this controller is the interface between + * input-oriented processing and output-oriented processing. + * Also, the input side (only) is used when reading a file for transcoding. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jpegcomp.h" + +/* Block smoothing is only applicable for progressive JPEG, so: */ +#ifndef D_PROGRESSIVE_SUPPORTED +#undef BLOCK_SMOOTHING_SUPPORTED +#endif + +/* Private buffer controller object */ + +typedef struct { + struct jpeg_d_coef_controller pub; /* public fields */ + + /* These variables keep track of the current location of the input side. */ + /* cinfo->input_iMCU_row is also used for this. */ + JDIMENSION MCU_ctr; /* counts MCUs processed in current row */ + int MCU_vert_offset; /* counts MCU rows within iMCU row */ + int MCU_rows_per_iMCU_row; /* number of such rows needed */ + + /* The output side's location is represented by cinfo->output_iMCU_row. */ + + /* In single-pass modes, it's sufficient to buffer just one MCU. + * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks, + * and let the entropy decoder write into that workspace each time. + * (On 80x86, the workspace is FAR even though it's not really very big; + * this is to keep the module interfaces unchanged when a large coefficient + * buffer is necessary.) + * In multi-pass modes, this array points to the current MCU's blocks + * within the virtual arrays; it is used only by the input side. + */ + JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU]; + + /* Temporary workspace for one MCU */ + JCOEF * workspace; + +#ifdef D_MULTISCAN_FILES_SUPPORTED + /* In multi-pass modes, we need a virtual block array for each component. */ + jvirt_barray_ptr whole_image[MAX_COMPONENTS]; +#endif + +#ifdef BLOCK_SMOOTHING_SUPPORTED + /* When doing block smoothing, we latch coefficient Al values here */ + int * coef_bits_latch; +#define SAVED_COEFS 6 /* we save coef_bits[0..5] */ +#endif +} my_coef_controller; + +typedef my_coef_controller * my_coef_ptr; + +/* Forward declarations */ +METHODDEF(int) decompress_onepass + JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); +#ifdef D_MULTISCAN_FILES_SUPPORTED +METHODDEF(int) decompress_data + JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); +#endif +#ifdef BLOCK_SMOOTHING_SUPPORTED +LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo)); +METHODDEF(int) decompress_smooth_data + JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); +#endif + + +LOCAL(void) +start_iMCU_row (j_decompress_ptr cinfo) +/* Reset within-iMCU-row counters for a new row (input side) */ +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* In an interleaved scan, an MCU row is the same as an iMCU row. + * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. + * But at the bottom of the image, process only what's left. + */ + if (cinfo->comps_in_scan > 1) { + coef->MCU_rows_per_iMCU_row = 1; + } else { + if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; + else + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; + } + + coef->MCU_ctr = 0; + coef->MCU_vert_offset = 0; +} + + +/* + * Initialize for an input processing pass. + */ + +METHODDEF(void) +start_input_pass (j_decompress_ptr cinfo) +{ + cinfo->input_iMCU_row = 0; + start_iMCU_row(cinfo); +} + + +/* + * Initialize for an output processing pass. + */ + +METHODDEF(void) +start_output_pass (j_decompress_ptr cinfo) +{ +#ifdef BLOCK_SMOOTHING_SUPPORTED + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* If multipass, check to see whether to use block smoothing on this pass */ + if (coef->pub.coef_arrays != NULL) { + if (cinfo->do_block_smoothing && smoothing_ok(cinfo)) + coef->pub.decompress_data = decompress_smooth_data; + else + coef->pub.decompress_data = decompress_data; + } +#endif + cinfo->output_iMCU_row = 0; +} + + +/* + * Decompress and return some data in the single-pass case. + * Always attempts to emit one fully interleaved MCU row ("iMCU" row). + * Input and output must run in lockstep since we have only a one-MCU buffer. + * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. + * + * NB: output_buf contains a plane for each component in image, + * which we index according to the component's SOF position. + */ + +METHODDEF(int) +decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + int blkn, ci, xindex, yindex, yoffset, useful_width; + JSAMPARRAY output_ptr; + JDIMENSION start_col, output_col; + jpeg_component_info *compptr; + inverse_DCT_method_ptr inverse_DCT; + + /* Loop to process as much as one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; + MCU_col_num++) { + /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ + jzero_far((void FAR *) coef->MCU_buffer[0], + (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK))); + if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->MCU_ctr = MCU_col_num; + return JPEG_SUSPENDED; + } + /* Determine where data should go in output_buf and do the IDCT thing. + * We skip dummy blocks at the right and bottom edges (but blkn gets + * incremented past them!). Note the inner loop relies on having + * allocated the MCU_buffer[] blocks sequentially. + */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Don't bother to IDCT an uninteresting component. */ + if (! compptr->component_needed) { + blkn += compptr->MCU_blocks; + continue; + } + inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; + useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width + : compptr->last_col_width; + output_ptr = output_buf[compptr->component_index] + + yoffset * compptr->_DCT_scaled_size; + start_col = MCU_col_num * compptr->MCU_sample_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + if (cinfo->input_iMCU_row < last_iMCU_row || + yoffset+yindex < compptr->last_row_height) { + output_col = start_col; + for (xindex = 0; xindex < useful_width; xindex++) { + (*inverse_DCT) (cinfo, compptr, + (JCOEFPTR) coef->MCU_buffer[blkn+xindex], + output_ptr, output_col); + output_col += compptr->_DCT_scaled_size; + } + } + blkn += compptr->MCU_width; + output_ptr += compptr->_DCT_scaled_size; + } + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->MCU_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + cinfo->output_iMCU_row++; + if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { + start_iMCU_row(cinfo); + return JPEG_ROW_COMPLETED; + } + /* Completed the scan */ + (*cinfo->inputctl->finish_input_pass) (cinfo); + return JPEG_SCAN_COMPLETED; +} + + +/* + * Dummy consume-input routine for single-pass operation. + */ + +METHODDEF(int) +dummy_consume_data (j_decompress_ptr cinfo) +{ + return JPEG_SUSPENDED; /* Always indicate nothing was done */ +} + + +#ifdef D_MULTISCAN_FILES_SUPPORTED + +/* + * Consume input data and store it in the full-image coefficient buffer. + * We read as much as one fully interleaved MCU row ("iMCU" row) per call, + * ie, v_samp_factor block rows for each component in the scan. + * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. + */ + +METHODDEF(int) +consume_data (j_decompress_ptr cinfo) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + int blkn, ci, xindex, yindex, yoffset; + JDIMENSION start_col; + JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; + JBLOCKROW buffer_ptr; + jpeg_component_info *compptr; + + /* Align the virtual buffers for the components used in this scan. */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + buffer[ci] = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], + cinfo->input_iMCU_row * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, TRUE); + /* Note: entropy decoder expects buffer to be zeroed, + * but this is handled automatically by the memory manager + * because we requested a pre-zeroed array. + */ + } + + /* Loop to process one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; + MCU_col_num++) { + /* Construct list of pointers to DCT blocks belonging to this MCU */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + start_col = MCU_col_num * compptr->MCU_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + buffer_ptr = buffer[ci][yindex+yoffset] + start_col; + for (xindex = 0; xindex < compptr->MCU_width; xindex++) { + coef->MCU_buffer[blkn++] = buffer_ptr++; + } + } + } + /* Try to fetch the MCU. */ + if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->MCU_ctr = MCU_col_num; + return JPEG_SUSPENDED; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->MCU_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { + start_iMCU_row(cinfo); + return JPEG_ROW_COMPLETED; + } + /* Completed the scan */ + (*cinfo->inputctl->finish_input_pass) (cinfo); + return JPEG_SCAN_COMPLETED; +} + + +/* + * Decompress and return some data in the multi-pass case. + * Always attempts to emit one fully interleaved MCU row ("iMCU" row). + * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. + * + * NB: output_buf contains a plane for each component in image. + */ + +METHODDEF(int) +decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + JDIMENSION block_num; + int ci, block_row, block_rows; + JBLOCKARRAY buffer; + JBLOCKROW buffer_ptr; + JSAMPARRAY output_ptr; + JDIMENSION output_col; + jpeg_component_info *compptr; + inverse_DCT_method_ptr inverse_DCT; + + /* Force some input to be done if we are getting ahead of the input. */ + while (cinfo->input_scan_number < cinfo->output_scan_number || + (cinfo->input_scan_number == cinfo->output_scan_number && + cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { + if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) + return JPEG_SUSPENDED; + } + + /* OK, output from the virtual arrays. */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Don't bother to IDCT an uninteresting component. */ + if (! compptr->component_needed) + continue; + /* Align the virtual buffer for this component. */ + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + cinfo->output_iMCU_row * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + /* Count non-dummy DCT block rows in this iMCU row. */ + if (cinfo->output_iMCU_row < last_iMCU_row) + block_rows = compptr->v_samp_factor; + else { + /* NB: can't use last_row_height here; it is input-side-dependent! */ + block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (block_rows == 0) block_rows = compptr->v_samp_factor; + } + inverse_DCT = cinfo->idct->inverse_DCT[ci]; + output_ptr = output_buf[ci]; + /* Loop over all DCT blocks to be processed. */ + for (block_row = 0; block_row < block_rows; block_row++) { + buffer_ptr = buffer[block_row]; + output_col = 0; + for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) { + (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, + output_ptr, output_col); + buffer_ptr++; + output_col += compptr->_DCT_scaled_size; + } + output_ptr += compptr->_DCT_scaled_size; + } + } + + if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) + return JPEG_ROW_COMPLETED; + return JPEG_SCAN_COMPLETED; +} + +#endif /* D_MULTISCAN_FILES_SUPPORTED */ + + +#ifdef BLOCK_SMOOTHING_SUPPORTED + +/* + * This code applies interblock smoothing as described by section K.8 + * of the JPEG standard: the first 5 AC coefficients are estimated from + * the DC values of a DCT block and its 8 neighboring blocks. + * We apply smoothing only for progressive JPEG decoding, and only if + * the coefficients it can estimate are not yet known to full precision. + */ + +/* Natural-order array positions of the first 5 zigzag-order coefficients */ +#define Q01_POS 1 +#define Q10_POS 8 +#define Q20_POS 16 +#define Q11_POS 9 +#define Q02_POS 2 + +/* + * Determine whether block smoothing is applicable and safe. + * We also latch the current states of the coef_bits[] entries for the + * AC coefficients; otherwise, if the input side of the decompressor + * advances into a new scan, we might think the coefficients are known + * more accurately than they really are. + */ + +LOCAL(boolean) +smoothing_ok (j_decompress_ptr cinfo) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + boolean smoothing_useful = FALSE; + int ci, coefi; + jpeg_component_info *compptr; + JQUANT_TBL * qtable; + int * coef_bits; + int * coef_bits_latch; + + if (! cinfo->progressive_mode || cinfo->coef_bits == NULL) + return FALSE; + + /* Allocate latch area if not already done */ + if (coef->coef_bits_latch == NULL) + coef->coef_bits_latch = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components * + (SAVED_COEFS * SIZEOF(int))); + coef_bits_latch = coef->coef_bits_latch; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* All components' quantization values must already be latched. */ + if ((qtable = compptr->quant_table) == NULL) + return FALSE; + /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ + if (qtable->quantval[0] == 0 || + qtable->quantval[Q01_POS] == 0 || + qtable->quantval[Q10_POS] == 0 || + qtable->quantval[Q20_POS] == 0 || + qtable->quantval[Q11_POS] == 0 || + qtable->quantval[Q02_POS] == 0) + return FALSE; + /* DC values must be at least partly known for all components. */ + coef_bits = cinfo->coef_bits[ci]; + if (coef_bits[0] < 0) + return FALSE; + /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ + for (coefi = 1; coefi <= 5; coefi++) { + coef_bits_latch[coefi] = coef_bits[coefi]; + if (coef_bits[coefi] != 0) + smoothing_useful = TRUE; + } + coef_bits_latch += SAVED_COEFS; + } + + return smoothing_useful; +} + + +/* + * Variant of decompress_data for use when doing block smoothing. + */ + +METHODDEF(int) +decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) +{ + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + JDIMENSION block_num, last_block_column; + int ci, block_row, block_rows, access_rows; + JBLOCKARRAY buffer; + JBLOCKROW buffer_ptr, prev_block_row, next_block_row; + JSAMPARRAY output_ptr; + JDIMENSION output_col; + jpeg_component_info *compptr; + inverse_DCT_method_ptr inverse_DCT; + boolean first_row, last_row; + JCOEF * workspace; + int *coef_bits; + JQUANT_TBL *quanttbl; + INT32 Q00,Q01,Q02,Q10,Q11,Q20, num; + int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9; + int Al, pred; + + /* Keep a local variable to avoid looking it up more than once */ + workspace = coef->workspace; + + /* Force some input to be done if we are getting ahead of the input. */ + while (cinfo->input_scan_number <= cinfo->output_scan_number && + ! cinfo->inputctl->eoi_reached) { + if (cinfo->input_scan_number == cinfo->output_scan_number) { + /* If input is working on current scan, we ordinarily want it to + * have completed the current row. But if input scan is DC, + * we want it to keep one row ahead so that next block row's DC + * values are up to date. + */ + JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0; + if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta) + break; + } + if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) + return JPEG_SUSPENDED; + } + + /* OK, output from the virtual arrays. */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Don't bother to IDCT an uninteresting component. */ + if (! compptr->component_needed) + continue; + /* Count non-dummy DCT block rows in this iMCU row. */ + if (cinfo->output_iMCU_row < last_iMCU_row) { + block_rows = compptr->v_samp_factor; + access_rows = block_rows * 2; /* this and next iMCU row */ + last_row = FALSE; + } else { + /* NB: can't use last_row_height here; it is input-side-dependent! */ + block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (block_rows == 0) block_rows = compptr->v_samp_factor; + access_rows = block_rows; /* this iMCU row only */ + last_row = TRUE; + } + /* Align the virtual buffer for this component. */ + if (cinfo->output_iMCU_row > 0) { + access_rows += compptr->v_samp_factor; /* prior iMCU row too */ + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, + (JDIMENSION) access_rows, FALSE); + buffer += compptr->v_samp_factor; /* point to current iMCU row */ + first_row = FALSE; + } else { + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE); + first_row = TRUE; + } + /* Fetch component-dependent info */ + coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); + quanttbl = compptr->quant_table; + Q00 = quanttbl->quantval[0]; + Q01 = quanttbl->quantval[Q01_POS]; + Q10 = quanttbl->quantval[Q10_POS]; + Q20 = quanttbl->quantval[Q20_POS]; + Q11 = quanttbl->quantval[Q11_POS]; + Q02 = quanttbl->quantval[Q02_POS]; + inverse_DCT = cinfo->idct->inverse_DCT[ci]; + output_ptr = output_buf[ci]; + /* Loop over all DCT blocks to be processed. */ + for (block_row = 0; block_row < block_rows; block_row++) { + buffer_ptr = buffer[block_row]; + if (first_row && block_row == 0) + prev_block_row = buffer_ptr; + else + prev_block_row = buffer[block_row-1]; + if (last_row && block_row == block_rows-1) + next_block_row = buffer_ptr; + else + next_block_row = buffer[block_row+1]; + /* We fetch the surrounding DC values using a sliding-register approach. + * Initialize all nine here so as to do the right thing on narrow pics. + */ + DC1 = DC2 = DC3 = (int) prev_block_row[0][0]; + DC4 = DC5 = DC6 = (int) buffer_ptr[0][0]; + DC7 = DC8 = DC9 = (int) next_block_row[0][0]; + output_col = 0; + last_block_column = compptr->width_in_blocks - 1; + for (block_num = 0; block_num <= last_block_column; block_num++) { + /* Fetch current DCT block into workspace so we can modify it. */ + jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1); + /* Update DC values */ + if (block_num < last_block_column) { + DC3 = (int) prev_block_row[1][0]; + DC6 = (int) buffer_ptr[1][0]; + DC9 = (int) next_block_row[1][0]; + } + /* Compute coefficient estimates per K.8. + * An estimate is applied only if coefficient is still zero, + * and is not known to be fully accurate. + */ + /* AC01 */ + if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) { + num = 36 * Q00 * (DC4 - DC6); + if (num >= 0) { + pred = (int) (((Q01<<7) + num) / (Q01<<8)); + if (Al > 0 && pred >= (1< 0 && pred >= (1<= 0) { + pred = (int) (((Q10<<7) + num) / (Q10<<8)); + if (Al > 0 && pred >= (1< 0 && pred >= (1<= 0) { + pred = (int) (((Q20<<7) + num) / (Q20<<8)); + if (Al > 0 && pred >= (1< 0 && pred >= (1<= 0) { + pred = (int) (((Q11<<7) + num) / (Q11<<8)); + if (Al > 0 && pred >= (1< 0 && pred >= (1<= 0) { + pred = (int) (((Q02<<7) + num) / (Q02<<8)); + if (Al > 0 && pred >= (1< 0 && pred >= (1<_DCT_scaled_size; + } + output_ptr += compptr->_DCT_scaled_size; + } + } + + if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) + return JPEG_ROW_COMPLETED; + return JPEG_SCAN_COMPLETED; +} + +#endif /* BLOCK_SMOOTHING_SUPPORTED */ + + +/* + * Initialize coefficient buffer controller. + */ + +GLOBAL(void) +jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer) +{ + my_coef_ptr coef; + + coef = (my_coef_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_coef_controller)); + cinfo->coef = (struct jpeg_d_coef_controller *) coef; + coef->pub.start_input_pass = start_input_pass; + coef->pub.start_output_pass = start_output_pass; +#ifdef BLOCK_SMOOTHING_SUPPORTED + coef->coef_bits_latch = NULL; +#endif + + /* Create the coefficient buffer. */ + if (need_full_buffer) { +#ifdef D_MULTISCAN_FILES_SUPPORTED + /* Allocate a full-image virtual array for each component, */ + /* padded to a multiple of samp_factor DCT blocks in each direction. */ + /* Note we ask for a pre-zeroed array. */ + int ci, access_rows; + jpeg_component_info *compptr; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + access_rows = compptr->v_samp_factor; +#ifdef BLOCK_SMOOTHING_SUPPORTED + /* If block smoothing could be used, need a bigger window */ + if (cinfo->progressive_mode) + access_rows *= 3; +#endif + coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE, + (JDIMENSION) jround_up((long) compptr->width_in_blocks, + (long) compptr->h_samp_factor), + (JDIMENSION) jround_up((long) compptr->height_in_blocks, + (long) compptr->v_samp_factor), + (JDIMENSION) access_rows); + } + coef->pub.consume_data = consume_data; + coef->pub.decompress_data = decompress_data; + coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else { + /* We only need a single-MCU buffer. */ + JBLOCKROW buffer; + int i; + + buffer = (JBLOCKROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { + coef->MCU_buffer[i] = buffer + i; + } + coef->pub.consume_data = dummy_consume_data; + coef->pub.decompress_data = decompress_onepass; + coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ + } + + /* Allocate the workspace buffer */ + coef->workspace = (JCOEF *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(JCOEF) * DCTSIZE2); +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdcolext.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdcolext.c new file mode 100755 index 0000000..3b8aeff --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdcolext.c @@ -0,0 +1,141 @@ +/* + * jdcolext.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright (C) 2009, 2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains output colorspace conversion routines. + */ + + +/* This file is included by jdcolor.c */ + + +/* + * Convert some rows of samples to the output colorspace. + * + * Note that we change from noninterleaved, one-plane-per-component format + * to interleaved-pixel format. The output buffer is therefore three times + * as wide as the input buffer. + * A starting row offset is provided only for the input buffer. The caller + * can easily adjust the passed output_buf value to accommodate any row + * offset required on that side. + */ + +INLINE +LOCAL(void) +ycc_rgb_convert_internal (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int y, cb, cr; + register JSAMPROW outptr; + register JSAMPROW inptr0, inptr1, inptr2; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->output_width; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + register int * Crrtab = cconvert->Cr_r_tab; + register int * Cbbtab = cconvert->Cb_b_tab; + register INT32 * Crgtab = cconvert->Cr_g_tab; + register INT32 * Cbgtab = cconvert->Cb_g_tab; + SHIFT_TEMPS + + while (--num_rows >= 0) { + inptr0 = input_buf[0][input_row]; + inptr1 = input_buf[1][input_row]; + inptr2 = input_buf[2][input_row]; + input_row++; + outptr = *output_buf++; + for (col = 0; col < num_cols; col++) { + y = GETJSAMPLE(inptr0[col]); + cb = GETJSAMPLE(inptr1[col]); + cr = GETJSAMPLE(inptr2[col]); + /* Range-limiting is essential due to noise introduced by DCT losses. */ + outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; + outptr[RGB_GREEN] = range_limit[y + + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], + SCALEBITS))]; + outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; + /* Set unused byte to 0xFF so it can be interpreted as an opaque */ + /* alpha channel value */ +#ifdef RGB_ALPHA + outptr[RGB_ALPHA] = 0xFF; +#endif + outptr += RGB_PIXELSIZE; + } + } +} + + +/* + * Convert grayscale to RGB: just duplicate the graylevel three times. + * This is provided to support applications that don't want to cope + * with grayscale as a separate case. + */ + +INLINE +LOCAL(void) +gray_rgb_convert_internal (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + register JSAMPROW inptr, outptr; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->output_width; + + while (--num_rows >= 0) { + inptr = input_buf[0][input_row++]; + outptr = *output_buf++; + for (col = 0; col < num_cols; col++) { + /* We can dispense with GETJSAMPLE() here */ + outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col]; + /* Set unused byte to 0xFF so it can be interpreted as an opaque */ + /* alpha channel value */ +#ifdef RGB_ALPHA + outptr[RGB_ALPHA] = 0xFF; +#endif + outptr += RGB_PIXELSIZE; + } + } +} + + +/* + * Convert RGB to extended RGB: just swap the order of source pixels + */ + +INLINE +LOCAL(void) +rgb_rgb_convert_internal (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + register JSAMPROW inptr0, inptr1, inptr2; + register JSAMPROW outptr; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->output_width; + + while (--num_rows >= 0) { + inptr0 = input_buf[0][input_row]; + inptr1 = input_buf[1][input_row]; + inptr2 = input_buf[2][input_row]; + input_row++; + outptr = *output_buf++; + for (col = 0; col < num_cols; col++) { + /* We can dispense with GETJSAMPLE() here */ + outptr[RGB_RED] = inptr0[col]; + outptr[RGB_GREEN] = inptr1[col]; + outptr[RGB_BLUE] = inptr2[col]; + /* Set unused byte to 0xFF so it can be interpreted as an opaque */ + /* alpha channel value */ +#ifdef RGB_ALPHA + outptr[RGB_ALPHA] = 0xFF; +#endif + outptr += RGB_PIXELSIZE; + } + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdcolor.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdcolor.c new file mode 100755 index 0000000..694de9b --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdcolor.c @@ -0,0 +1,591 @@ +/* + * jdcolor.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2009, 2011-2012, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains output colorspace conversion routines. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jsimd.h" +#include "config.h" + + +/* Private subobject */ + +typedef struct { + struct jpeg_color_deconverter pub; /* public fields */ + + /* Private state for YCC->RGB conversion */ + int * Cr_r_tab; /* => table for Cr to R conversion */ + int * Cb_b_tab; /* => table for Cb to B conversion */ + INT32 * Cr_g_tab; /* => table for Cr to G conversion */ + INT32 * Cb_g_tab; /* => table for Cb to G conversion */ +} my_color_deconverter; + +typedef my_color_deconverter * my_cconvert_ptr; + + +/**************** YCbCr -> RGB conversion: most common case **************/ + +/* + * YCbCr is defined per CCIR 601-1, except that Cb and Cr are + * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. + * The conversion equations to be implemented are therefore + * R = Y + 1.40200 * Cr + * G = Y - 0.34414 * Cb - 0.71414 * Cr + * B = Y + 1.77200 * Cb + * where Cb and Cr represent the incoming values less CENTERJSAMPLE. + * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) + * + * To avoid floating-point arithmetic, we represent the fractional constants + * as integers scaled up by 2^16 (about 4 digits precision); we have to divide + * the products by 2^16, with appropriate rounding, to get the correct answer. + * Notice that Y, being an integral input, does not contribute any fraction + * so it need not participate in the rounding. + * + * For even more speed, we avoid doing any multiplications in the inner loop + * by precalculating the constants times Cb and Cr for all possible values. + * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); + * for 12-bit samples it is still acceptable. It's not very reasonable for + * 16-bit samples, but if you want lossless storage you shouldn't be changing + * colorspace anyway. + * The Cr=>R and Cb=>B values can be rounded to integers in advance; the + * values for the G calculation are left scaled up, since we must add them + * together before rounding. + */ + +#define SCALEBITS 16 /* speediest right-shift on some machines */ +#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) +#define FIX(x) ((INT32) ((x) * (1L<RGB colorspace conversion. + */ + +LOCAL(void) +build_ycc_rgb_table (j_decompress_ptr cinfo) +{ + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + int i; + INT32 x; + SHIFT_TEMPS + + cconvert->Cr_r_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + cconvert->Cb_b_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + cconvert->Cr_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + cconvert->Cb_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + + for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { + /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ + /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ + /* Cr=>R value is nearest int to 1.40200 * x */ + cconvert->Cr_r_tab[i] = (int) + RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); + /* Cb=>B value is nearest int to 1.77200 * x */ + cconvert->Cb_b_tab[i] = (int) + RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); + /* Cr=>G value is scaled-up -0.71414 * x */ + cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; + /* Cb=>G value is scaled-up -0.34414 * x */ + /* We also add in ONE_HALF so that need not do it in inner loop */ + cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; + } +} + + +/* + * Convert some rows of samples to the output colorspace. + */ + +METHODDEF(void) +ycc_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + switch (cinfo->out_color_space) { + case JCS_EXT_RGB: + ycc_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + ycc_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGR: + ycc_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + ycc_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + ycc_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + ycc_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + default: + ycc_rgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + } +} + + +/**************** Cases other than YCbCr -> RGB **************/ + + +/* + * Color conversion for no colorspace change: just copy the data, + * converting from separate-planes to interleaved representation. + */ + +METHODDEF(void) +null_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + register JSAMPROW inptr, outptr; + register JDIMENSION count; + register int num_components = cinfo->num_components; + JDIMENSION num_cols = cinfo->output_width; + int ci; + + while (--num_rows >= 0) { + for (ci = 0; ci < num_components; ci++) { + inptr = input_buf[ci][input_row]; + outptr = output_buf[0] + ci; + for (count = num_cols; count > 0; count--) { + *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ + outptr += num_components; + } + } + input_row++; + output_buf++; + } +} + + +/* + * Color conversion for grayscale: just copy the data. + * This also works for YCbCr -> grayscale conversion, in which + * we just copy the Y (luminance) component and ignore chrominance. + */ + +METHODDEF(void) +grayscale_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, + num_rows, cinfo->output_width); +} + + +/* + * Convert grayscale to RGB + */ + +METHODDEF(void) +gray_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + switch (cinfo->out_color_space) { + case JCS_EXT_RGB: + gray_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + gray_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGR: + gray_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + gray_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + gray_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + gray_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + default: + gray_rgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + } +} + + +/* + * Convert plain RGB to extended RGB + */ + +METHODDEF(void) +rgb_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + switch (cinfo->out_color_space) { + case JCS_EXT_RGB: + rgb_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + rgb_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGR: + rgb_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + rgb_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + rgb_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + rgb_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + default: + rgb_rgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + } +} + +/* + * Adobe-style YCCK->CMYK conversion. + * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same + * conversion as above, while passing K (black) unchanged. + * We assume build_ycc_rgb_table has been called. + */ + +METHODDEF(void) +ycck_cmyk_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int y, cb, cr; + register JSAMPROW outptr; + register JSAMPROW inptr0, inptr1, inptr2, inptr3; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->output_width; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + register int * Crrtab = cconvert->Cr_r_tab; + register int * Cbbtab = cconvert->Cb_b_tab; + register INT32 * Crgtab = cconvert->Cr_g_tab; + register INT32 * Cbgtab = cconvert->Cb_g_tab; + SHIFT_TEMPS + + while (--num_rows >= 0) { + inptr0 = input_buf[0][input_row]; + inptr1 = input_buf[1][input_row]; + inptr2 = input_buf[2][input_row]; + inptr3 = input_buf[3][input_row]; + input_row++; + outptr = *output_buf++; + for (col = 0; col < num_cols; col++) { + y = GETJSAMPLE(inptr0[col]); + cb = GETJSAMPLE(inptr1[col]); + cr = GETJSAMPLE(inptr2[col]); + /* Range-limiting is essential due to noise introduced by DCT losses. */ + outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ + outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], + SCALEBITS)))]; + outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ + /* K passes through unchanged */ + outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ + outptr += 4; + } + } +} + + +/* + * Empty method for start_pass. + */ + +METHODDEF(void) +start_pass_dcolor (j_decompress_ptr cinfo) +{ + /* no work needed */ +} + + +/* + * Module initialization routine for output colorspace conversion. + */ + +GLOBAL(void) +jinit_color_deconverter (j_decompress_ptr cinfo) +{ + my_cconvert_ptr cconvert; + int ci; + + cconvert = (my_cconvert_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_color_deconverter)); + cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; + cconvert->pub.start_pass = start_pass_dcolor; + + /* Make sure num_components agrees with jpeg_color_space */ + switch (cinfo->jpeg_color_space) { + case JCS_GRAYSCALE: + if (cinfo->num_components != 1) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + + case JCS_RGB: + case JCS_YCbCr: + if (cinfo->num_components != 3) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + + case JCS_CMYK: + case JCS_YCCK: + if (cinfo->num_components != 4) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + + default: /* JCS_UNKNOWN can be anything */ + if (cinfo->num_components < 1) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + } + + /* Set out_color_components and conversion method based on requested space. + * Also clear the component_needed flags for any unused components, + * so that earlier pipeline stages can avoid useless computation. + */ + + switch (cinfo->out_color_space) { + case JCS_GRAYSCALE: + cinfo->out_color_components = 1; + if (cinfo->jpeg_color_space == JCS_GRAYSCALE || + cinfo->jpeg_color_space == JCS_YCbCr) { + cconvert->pub.color_convert = grayscale_convert; + /* For color->grayscale conversion, only the Y (0) component is needed */ + for (ci = 1; ci < cinfo->num_components; ci++) + cinfo->comp_info[ci].component_needed = FALSE; + } else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_RGB: + case JCS_EXT_RGB: + case JCS_EXT_RGBX: + case JCS_EXT_BGR: + case JCS_EXT_BGRX: + case JCS_EXT_XBGR: + case JCS_EXT_XRGB: + case JCS_EXT_RGBA: + case JCS_EXT_BGRA: + case JCS_EXT_ABGR: + case JCS_EXT_ARGB: + cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space]; + if (cinfo->jpeg_color_space == JCS_YCbCr) { + if (jsimd_can_ycc_rgb()) + cconvert->pub.color_convert = jsimd_ycc_rgb_convert; + else { + cconvert->pub.color_convert = ycc_rgb_convert; + build_ycc_rgb_table(cinfo); + } + } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { + cconvert->pub.color_convert = gray_rgb_convert; + } else if (cinfo->jpeg_color_space == JCS_RGB) { + if (rgb_red[cinfo->out_color_space] == 0 && + rgb_green[cinfo->out_color_space] == 1 && + rgb_blue[cinfo->out_color_space] == 2 && + rgb_pixelsize[cinfo->out_color_space] == 3) + cconvert->pub.color_convert = null_convert; + else + cconvert->pub.color_convert = rgb_rgb_convert; + } else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_CMYK: + cinfo->out_color_components = 4; + if (cinfo->jpeg_color_space == JCS_YCCK) { + cconvert->pub.color_convert = ycck_cmyk_convert; + build_ycc_rgb_table(cinfo); + } else if (cinfo->jpeg_color_space == JCS_CMYK) { + cconvert->pub.color_convert = null_convert; + } else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + default: + /* Permit null conversion to same output space */ + if (cinfo->out_color_space == cinfo->jpeg_color_space) { + cinfo->out_color_components = cinfo->num_components; + cconvert->pub.color_convert = null_convert; + } else /* unsupported non-null conversion */ + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + } + + if (cinfo->quantize_colors) + cinfo->output_components = 1; /* single colormapped output component */ + else + cinfo->output_components = cinfo->out_color_components; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdct.h b/lib-third-party/libturbojpeg-ios/libjpeg/jdct.h new file mode 100755 index 0000000..3637448 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdct.h @@ -0,0 +1,232 @@ +/* + * jdct.h + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This include file contains common declarations for the forward and + * inverse DCT modules. These declarations are private to the DCT managers + * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms. + * The individual DCT algorithms are kept in separate files to ease + * machine-dependent tuning (e.g., assembly coding). + */ + + +/* + * A forward DCT routine is given a pointer to a work area of type DCTELEM[]; + * the DCT is to be performed in-place in that buffer. Type DCTELEM is int + * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT + * implementations use an array of type FAST_FLOAT, instead.) + * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE). + * The DCT outputs are returned scaled up by a factor of 8; they therefore + * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This + * convention improves accuracy in integer implementations and saves some + * work in floating-point ones. + * Quantization of the output coefficients is done by jcdctmgr.c. This + * step requires an unsigned type and also one with twice the bits. + */ + +#if BITS_IN_JSAMPLE == 8 +#ifndef WITH_SIMD +typedef int DCTELEM; /* 16 or 32 bits is fine */ +typedef unsigned int UDCTELEM; +typedef unsigned long long UDCTELEM2; +#else +typedef short DCTELEM; /* prefer 16 bit with SIMD for parellelism */ +typedef unsigned short UDCTELEM; +typedef unsigned int UDCTELEM2; +#endif +#else +typedef INT32 DCTELEM; /* must have 32 bits */ +typedef UINT32 UDCTELEM; +typedef unsigned long long UDCTELEM2; +#endif + + +/* + * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer + * to an output sample array. The routine must dequantize the input data as + * well as perform the IDCT; for dequantization, it uses the multiplier table + * pointed to by compptr->dct_table. The output data is to be placed into the + * sample array starting at a specified column. (Any row offset needed will + * be applied to the array pointer before it is passed to the IDCT code.) + * Note that the number of samples emitted by the IDCT routine is + * DCT_scaled_size * DCT_scaled_size. + */ + +/* typedef inverse_DCT_method_ptr is declared in jpegint.h */ + +/* + * Each IDCT routine has its own ideas about the best dct_table element type. + */ + +typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */ +#if BITS_IN_JSAMPLE == 8 +typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */ +#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */ +#else +typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */ +#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */ +#endif +typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */ + + +/* + * Each IDCT routine is responsible for range-limiting its results and + * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could + * be quite far out of range if the input data is corrupt, so a bulletproof + * range-limiting step is required. We use a mask-and-table-lookup method + * to do the combined operations quickly. See the comments with + * prepare_range_limit_table (in jdmaster.c) for more info. + */ + +#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE) + +#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ + + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_fdct_islow jFDislow +#define jpeg_fdct_ifast jFDifast +#define jpeg_fdct_float jFDfloat +#define jpeg_idct_islow jRDislow +#define jpeg_idct_ifast jRDifast +#define jpeg_idct_float jRDfloat +#define jpeg_idct_7x7 jRD7x7 +#define jpeg_idct_6x6 jRD6x6 +#define jpeg_idct_5x5 jRD5x5 +#define jpeg_idct_4x4 jRD4x4 +#define jpeg_idct_3x3 jRD3x3 +#define jpeg_idct_2x2 jRD2x2 +#define jpeg_idct_1x1 jRD1x1 +#define jpeg_idct_9x9 jRD9x9 +#define jpeg_idct_10x10 jRD10x10 +#define jpeg_idct_11x11 jRD11x11 +#define jpeg_idct_12x12 jRD12x12 +#define jpeg_idct_13x13 jRD13x13 +#define jpeg_idct_14x14 jRD14x14 +#define jpeg_idct_15x15 jRD15x15 +#define jpeg_idct_16x16 jRD16x16 +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +/* Extern declarations for the forward and inverse DCT routines. */ + +EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data)); +EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data)); +EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data)); + +EXTERN(void) jpeg_idct_islow + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_ifast + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_float + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_7x7 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_6x6 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_5x5 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_4x4 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_3x3 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_2x2 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_1x1 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_9x9 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_10x10 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_11x11 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_12x12 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_13x13 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_14x14 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_15x15 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_16x16 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + + +/* + * Macros for handling fixed-point arithmetic; these are used by many + * but not all of the DCT/IDCT modules. + * + * All values are expected to be of type INT32. + * Fractional constants are scaled left by CONST_BITS bits. + * CONST_BITS is defined within each module using these macros, + * and may differ from one module to the next. + */ + +#define ONE ((INT32) 1) +#define CONST_SCALE (ONE << CONST_BITS) + +/* Convert a positive real constant to an integer scaled by CONST_SCALE. + * Caution: some C compilers fail to reduce "FIX(constant)" at compile time, + * thus causing a lot of useless floating-point operations at run time. + */ + +#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) + +/* Descale and correctly round an INT32 value that's scaled by N bits. + * We assume RIGHT_SHIFT rounds towards minus infinity, so adding + * the fudge factor is correct for either sign of X. + */ + +#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) + +/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * This macro is used only when the two inputs will actually be no more than + * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a + * full 32x32 multiply. This provides a useful speedup on many machines. + * Unfortunately there is no way to specify a 16x16->32 multiply portably + * in C, but some C compilers will do the right thing if you provide the + * correct combination of casts. + */ + +#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ +#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const))) +#endif +#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ +#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const))) +#endif + +#ifndef MULTIPLY16C16 /* default definition */ +#define MULTIPLY16C16(var,const) ((var) * (const)) +#endif + +/* Same except both inputs are variables. */ + +#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ +#define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2))) +#endif + +#ifndef MULTIPLY16V16 /* default definition */ +#define MULTIPLY16V16(var1,var2) ((var1) * (var2)) +#endif diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jddctmgr.c b/lib-third-party/libturbojpeg-ios/libjpeg/jddctmgr.c new file mode 100755 index 0000000..1758bed --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jddctmgr.c @@ -0,0 +1,337 @@ +/* + * jddctmgr.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Modified 2002-2010 by Guido Vollbeding. + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the inverse-DCT management logic. + * This code selects a particular IDCT implementation to be used, + * and it performs related housekeeping chores. No code in this file + * is executed per IDCT step, only during output pass setup. + * + * Note that the IDCT routines are responsible for performing coefficient + * dequantization as well as the IDCT proper. This module sets up the + * dequantization multiplier table needed by the IDCT routine. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ +#include "jsimddct.h" +#include "jpegcomp.h" + + +/* + * The decompressor input side (jdinput.c) saves away the appropriate + * quantization table for each component at the start of the first scan + * involving that component. (This is necessary in order to correctly + * decode files that reuse Q-table slots.) + * When we are ready to make an output pass, the saved Q-table is converted + * to a multiplier table that will actually be used by the IDCT routine. + * The multiplier table contents are IDCT-method-dependent. To support + * application changes in IDCT method between scans, we can remake the + * multiplier tables if necessary. + * In buffered-image mode, the first output pass may occur before any data + * has been seen for some components, and thus before their Q-tables have + * been saved away. To handle this case, multiplier tables are preset + * to zeroes; the result of the IDCT will be a neutral gray level. + */ + + +/* Private subobject for this module */ + +typedef struct { + struct jpeg_inverse_dct pub; /* public fields */ + + /* This array contains the IDCT method code that each multiplier table + * is currently set up for, or -1 if it's not yet set up. + * The actual multiplier tables are pointed to by dct_table in the + * per-component comp_info structures. + */ + int cur_method[MAX_COMPONENTS]; +} my_idct_controller; + +typedef my_idct_controller * my_idct_ptr; + + +/* Allocated multiplier tables: big enough for any supported variant */ + +typedef union { + ISLOW_MULT_TYPE islow_array[DCTSIZE2]; +#ifdef DCT_IFAST_SUPPORTED + IFAST_MULT_TYPE ifast_array[DCTSIZE2]; +#endif +#ifdef DCT_FLOAT_SUPPORTED + FLOAT_MULT_TYPE float_array[DCTSIZE2]; +#endif +} multiplier_table; + + +/* The current scaled-IDCT routines require ISLOW-style multiplier tables, + * so be sure to compile that code if either ISLOW or SCALING is requested. + */ +#ifdef DCT_ISLOW_SUPPORTED +#define PROVIDE_ISLOW_TABLES +#else +#ifdef IDCT_SCALING_SUPPORTED +#define PROVIDE_ISLOW_TABLES +#endif +#endif + + +/* + * Prepare for an output pass. + * Here we select the proper IDCT routine for each component and build + * a matching multiplier table. + */ + +METHODDEF(void) +start_pass (j_decompress_ptr cinfo) +{ + my_idct_ptr idct = (my_idct_ptr) cinfo->idct; + int ci, i; + jpeg_component_info *compptr; + int method = 0; + inverse_DCT_method_ptr method_ptr = NULL; + JQUANT_TBL * qtbl; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Select the proper IDCT routine for this component's scaling */ + switch (compptr->_DCT_scaled_size) { +#ifdef IDCT_SCALING_SUPPORTED + case 1: + method_ptr = jpeg_idct_1x1; + method = JDCT_ISLOW; /* jidctred uses islow-style table */ + break; + case 2: + if (jsimd_can_idct_2x2()) + method_ptr = jsimd_idct_2x2; + else + method_ptr = jpeg_idct_2x2; + method = JDCT_ISLOW; /* jidctred uses islow-style table */ + break; + case 3: + method_ptr = jpeg_idct_3x3; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 4: + if (jsimd_can_idct_4x4()) + method_ptr = jsimd_idct_4x4; + else + method_ptr = jpeg_idct_4x4; + method = JDCT_ISLOW; /* jidctred uses islow-style table */ + break; + case 5: + method_ptr = jpeg_idct_5x5; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 6: + method_ptr = jpeg_idct_6x6; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 7: + method_ptr = jpeg_idct_7x7; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; +#endif + case DCTSIZE: + switch (cinfo->dct_method) { +#ifdef DCT_ISLOW_SUPPORTED + case JDCT_ISLOW: + if (jsimd_can_idct_islow()) + method_ptr = jsimd_idct_islow; + else + method_ptr = jpeg_idct_islow; + method = JDCT_ISLOW; + break; +#endif +#ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + if (jsimd_can_idct_ifast()) + method_ptr = jsimd_idct_ifast; + else + method_ptr = jpeg_idct_ifast; + method = JDCT_IFAST; + break; +#endif +#ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + if (jsimd_can_idct_float()) + method_ptr = jsimd_idct_float; + else + method_ptr = jpeg_idct_float; + method = JDCT_FLOAT; + break; +#endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + break; + case 9: + method_ptr = jpeg_idct_9x9; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 10: + method_ptr = jpeg_idct_10x10; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 11: + method_ptr = jpeg_idct_11x11; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 12: + method_ptr = jpeg_idct_12x12; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 13: + method_ptr = jpeg_idct_13x13; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 14: + method_ptr = jpeg_idct_14x14; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 15: + method_ptr = jpeg_idct_15x15; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + case 16: + method_ptr = jpeg_idct_16x16; + method = JDCT_ISLOW; /* jidctint uses islow-style table */ + break; + default: + ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); + break; + } + idct->pub.inverse_DCT[ci] = method_ptr; + /* Create multiplier table from quant table. + * However, we can skip this if the component is uninteresting + * or if we already built the table. Also, if no quant table + * has yet been saved for the component, we leave the + * multiplier table all-zero; we'll be reading zeroes from the + * coefficient controller's buffer anyway. + */ + if (! compptr->component_needed || idct->cur_method[ci] == method) + continue; + qtbl = compptr->quant_table; + if (qtbl == NULL) /* happens if no data yet for component */ + continue; + idct->cur_method[ci] = method; + switch (method) { +#ifdef PROVIDE_ISLOW_TABLES + case JDCT_ISLOW: + { + /* For LL&M IDCT method, multipliers are equal to raw quantization + * coefficients, but are stored as ints to ensure access efficiency. + */ + ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table; + for (i = 0; i < DCTSIZE2; i++) { + ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i]; + } + } + break; +#endif +#ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + { + /* For AA&N IDCT method, multipliers are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + * For integer operation, the multiplier table is to be scaled by + * IFAST_SCALE_BITS. + */ + IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table; +#define CONST_BITS 14 + static const INT16 aanscales[DCTSIZE2] = { + /* precomputed values scaled up by 14 bits */ + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, + 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, + 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, + 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, + 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 + }; + SHIFT_TEMPS + + for (i = 0; i < DCTSIZE2; i++) { + ifmtbl[i] = (IFAST_MULT_TYPE) + DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], + (INT32) aanscales[i]), + CONST_BITS-IFAST_SCALE_BITS); + } + } + break; +#endif +#ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + { + /* For float AA&N IDCT method, multipliers are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + */ + FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table; + int row, col; + static const double aanscalefactor[DCTSIZE] = { + 1.0, 1.387039845, 1.306562965, 1.175875602, + 1.0, 0.785694958, 0.541196100, 0.275899379 + }; + + i = 0; + for (row = 0; row < DCTSIZE; row++) { + for (col = 0; col < DCTSIZE; col++) { + fmtbl[i] = (FLOAT_MULT_TYPE) + ((double) qtbl->quantval[i] * + aanscalefactor[row] * aanscalefactor[col]); + i++; + } + } + } + break; +#endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + } +} + + +/* + * Initialize IDCT manager. + */ + +GLOBAL(void) +jinit_inverse_dct (j_decompress_ptr cinfo) +{ + my_idct_ptr idct; + int ci; + jpeg_component_info *compptr; + + idct = (my_idct_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_idct_controller)); + cinfo->idct = (struct jpeg_inverse_dct *) idct; + idct->pub.start_pass = start_pass; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Allocate and pre-zero a multiplier table for each component */ + compptr->dct_table = + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(multiplier_table)); + MEMZERO(compptr->dct_table, SIZEOF(multiplier_table)); + /* Mark multiplier table not yet set up for any method */ + idct->cur_method[ci] = -1; + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdhuff.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdhuff.c new file mode 100755 index 0000000..f822dba --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdhuff.c @@ -0,0 +1,808 @@ +/* + * jdhuff.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright (C) 2009-2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy decoding routines. + * + * Much of the complexity here has to do with supporting input suspension. + * If the data source module demands suspension, we want to be able to back + * up to the start of the current MCU. To do this, we copy state variables + * into local working storage, and update them back to the permanent + * storage only upon successful completion of an MCU. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdhuff.h" /* Declarations shared with jdphuff.c */ +#include "jpegcomp.h" + + +/* + * Expanded entropy decoder object for Huffman decoding. + * + * The savable_state subrecord contains fields that change within an MCU, + * but must not be updated permanently until we complete the MCU. + */ + +typedef struct { + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ +} savable_state; + +/* This macro is to work around compilers with missing or broken + * structure assignment. You'll need to fix this code if you have + * such a compiler and you change MAX_COMPS_IN_SCAN. + */ + +#ifndef NO_STRUCT_ASSIGN +#define ASSIGN_STATE(dest,src) ((dest) = (src)) +#else +#if MAX_COMPS_IN_SCAN == 4 +#define ASSIGN_STATE(dest,src) \ + ((dest).last_dc_val[0] = (src).last_dc_val[0], \ + (dest).last_dc_val[1] = (src).last_dc_val[1], \ + (dest).last_dc_val[2] = (src).last_dc_val[2], \ + (dest).last_dc_val[3] = (src).last_dc_val[3]) +#endif +#endif + + +typedef struct { + struct jpeg_entropy_decoder pub; /* public fields */ + + /* These fields are loaded into local variables at start of each MCU. + * In case of suspension, we exit WITHOUT updating them. + */ + bitread_perm_state bitstate; /* Bit buffer at start of MCU */ + savable_state saved; /* Other state at start of MCU */ + + /* These fields are NOT loaded into local working state. */ + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + + /* Pointers to derived tables (these workspaces have image lifespan) */ + d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; + d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]; + + /* Precalculated info set up by start_pass for use in decode_mcu: */ + + /* Pointers to derived tables to be used for each block within an MCU */ + d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU]; + d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU]; + /* Whether we care about the DC and AC coefficient values for each block */ + boolean dc_needed[D_MAX_BLOCKS_IN_MCU]; + boolean ac_needed[D_MAX_BLOCKS_IN_MCU]; +} huff_entropy_decoder; + +typedef huff_entropy_decoder * huff_entropy_ptr; + + +/* + * Initialize for a Huffman-compressed scan. + */ + +METHODDEF(void) +start_pass_huff_decoder (j_decompress_ptr cinfo) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci, blkn, dctbl, actbl; + jpeg_component_info * compptr; + + /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. + * This ought to be an error condition, but we make it a warning because + * there are some baseline files out there with all zeroes in these bytes. + */ + if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 || + cinfo->Ah != 0 || cinfo->Al != 0) + WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + dctbl = compptr->dc_tbl_no; + actbl = compptr->ac_tbl_no; + /* Compute derived values for Huffman tables */ + /* We may do this more than once for a table, but it's not expensive */ + jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl, + & entropy->dc_derived_tbls[dctbl]); + jpeg_make_d_derived_tbl(cinfo, FALSE, actbl, + & entropy->ac_derived_tbls[actbl]); + /* Initialize DC predictions to 0 */ + entropy->saved.last_dc_val[ci] = 0; + } + + /* Precalculate decoding info for each block in an MCU of this scan */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + /* Precalculate which table to use for each block */ + entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no]; + entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no]; + /* Decide whether we really care about the coefficient values */ + if (compptr->component_needed) { + entropy->dc_needed[blkn] = TRUE; + /* we don't need the ACs if producing a 1/8th-size image */ + entropy->ac_needed[blkn] = (compptr->_DCT_scaled_size > 1); + } else { + entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE; + } + } + + /* Initialize bitread state variables */ + entropy->bitstate.bits_left = 0; + entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ + entropy->pub.insufficient_data = FALSE; + + /* Initialize restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; +} + + +/* + * Compute the derived values for a Huffman table. + * This routine also performs some validation checks on the table. + * + * Note this is also used by jdphuff.c. + */ + +GLOBAL(void) +jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, + d_derived_tbl ** pdtbl) +{ + JHUFF_TBL *htbl; + d_derived_tbl *dtbl; + int p, i, l, si, numsymbols; + int lookbits, ctr; + char huffsize[257]; + unsigned int huffcode[257]; + unsigned int code; + + /* Note that huffsize[] and huffcode[] are filled in code-length order, + * paralleling the order of the symbols themselves in htbl->huffval[]. + */ + + /* Find the input Huffman table */ + if (tblno < 0 || tblno >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); + htbl = + isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno]; + if (htbl == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); + + /* Allocate a workspace if we haven't already done so. */ + if (*pdtbl == NULL) + *pdtbl = (d_derived_tbl *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(d_derived_tbl)); + dtbl = *pdtbl; + dtbl->pub = htbl; /* fill in back link */ + + /* Figure C.1: make table of Huffman code length for each symbol */ + + p = 0; + for (l = 1; l <= 16; l++) { + i = (int) htbl->bits[l]; + if (i < 0 || p + i > 256) /* protect against table overrun */ + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + while (i--) + huffsize[p++] = (char) l; + } + huffsize[p] = 0; + numsymbols = p; + + /* Figure C.2: generate the codes themselves */ + /* We also validate that the counts represent a legal Huffman code tree. */ + + code = 0; + si = huffsize[0]; + p = 0; + while (huffsize[p]) { + while (((int) huffsize[p]) == si) { + huffcode[p++] = code; + code++; + } + /* code is now 1 more than the last code used for codelength si; but + * it must still fit in si bits, since no code is allowed to be all ones. + */ + if (((INT32) code) >= (((INT32) 1) << si)) + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + code <<= 1; + si++; + } + + /* Figure F.15: generate decoding tables for bit-sequential decoding */ + + p = 0; + for (l = 1; l <= 16; l++) { + if (htbl->bits[l]) { + /* valoffset[l] = huffval[] index of 1st symbol of code length l, + * minus the minimum code of length l + */ + dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p]; + p += htbl->bits[l]; + dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */ + } else { + dtbl->maxcode[l] = -1; /* -1 if no codes of this length */ + } + } + dtbl->valoffset[17] = 0; + dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */ + + /* Compute lookahead tables to speed up decoding. + * First we set all the table entries to 0, indicating "too long"; + * then we iterate through the Huffman codes that are short enough and + * fill in all the entries that correspond to bit sequences starting + * with that code. + */ + + for (i = 0; i < (1 << HUFF_LOOKAHEAD); i++) + dtbl->lookup[i] = (HUFF_LOOKAHEAD + 1) << HUFF_LOOKAHEAD; + + p = 0; + for (l = 1; l <= HUFF_LOOKAHEAD; l++) { + for (i = 1; i <= (int) htbl->bits[l]; i++, p++) { + /* l = current code's length, p = its index in huffcode[] & huffval[]. */ + /* Generate left-justified code followed by all possible bit sequences */ + lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l); + for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) { + dtbl->lookup[lookbits] = (l << HUFF_LOOKAHEAD) | htbl->huffval[p]; + lookbits++; + } + } + } + + /* Validate symbols as being reasonable. + * For AC tables, we make no check, but accept all byte values 0..255. + * For DC tables, we require the symbols to be in range 0..15. + * (Tighter bounds could be applied depending on the data depth and mode, + * but this is sufficient to ensure safe decoding.) + */ + if (isDC) { + for (i = 0; i < numsymbols; i++) { + int sym = htbl->huffval[i]; + if (sym < 0 || sym > 15) + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + } + } +} + + +/* + * Out-of-line code for bit fetching (shared with jdphuff.c). + * See jdhuff.h for info about usage. + * Note: current values of get_buffer and bits_left are passed as parameters, + * but are returned in the corresponding fields of the state struct. + * + * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width + * of get_buffer to be used. (On machines with wider words, an even larger + * buffer could be used.) However, on some machines 32-bit shifts are + * quite slow and take time proportional to the number of places shifted. + * (This is true with most PC compilers, for instance.) In this case it may + * be a win to set MIN_GET_BITS to the minimum value of 15. This reduces the + * average shift distance at the cost of more calls to jpeg_fill_bit_buffer. + */ + +#ifdef SLOW_SHIFT_32 +#define MIN_GET_BITS 15 /* minimum allowable value */ +#else +#define MIN_GET_BITS (BIT_BUF_SIZE-7) +#endif + + +GLOBAL(boolean) +jpeg_fill_bit_buffer (bitread_working_state * state, + register bit_buf_type get_buffer, register int bits_left, + int nbits) +/* Load up the bit buffer to a depth of at least nbits */ +{ + /* Copy heavily used state fields into locals (hopefully registers) */ + register const JOCTET * next_input_byte = state->next_input_byte; + register size_t bytes_in_buffer = state->bytes_in_buffer; + j_decompress_ptr cinfo = state->cinfo; + + /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */ + /* (It is assumed that no request will be for more than that many bits.) */ + /* We fail to do so only if we hit a marker or are forced to suspend. */ + + if (cinfo->unread_marker == 0) { /* cannot advance past a marker */ + while (bits_left < MIN_GET_BITS) { + register int c; + + /* Attempt to read a byte */ + if (bytes_in_buffer == 0) { + if (! (*cinfo->src->fill_input_buffer) (cinfo)) + return FALSE; + next_input_byte = cinfo->src->next_input_byte; + bytes_in_buffer = cinfo->src->bytes_in_buffer; + } + bytes_in_buffer--; + c = GETJOCTET(*next_input_byte++); + + /* If it's 0xFF, check and discard stuffed zero byte */ + if (c == 0xFF) { + /* Loop here to discard any padding FF's on terminating marker, + * so that we can save a valid unread_marker value. NOTE: we will + * accept multiple FF's followed by a 0 as meaning a single FF data + * byte. This data pattern is not valid according to the standard. + */ + do { + if (bytes_in_buffer == 0) { + if (! (*cinfo->src->fill_input_buffer) (cinfo)) + return FALSE; + next_input_byte = cinfo->src->next_input_byte; + bytes_in_buffer = cinfo->src->bytes_in_buffer; + } + bytes_in_buffer--; + c = GETJOCTET(*next_input_byte++); + } while (c == 0xFF); + + if (c == 0) { + /* Found FF/00, which represents an FF data byte */ + c = 0xFF; + } else { + /* Oops, it's actually a marker indicating end of compressed data. + * Save the marker code for later use. + * Fine point: it might appear that we should save the marker into + * bitread working state, not straight into permanent state. But + * once we have hit a marker, we cannot need to suspend within the + * current MCU, because we will read no more bytes from the data + * source. So it is OK to update permanent state right away. + */ + cinfo->unread_marker = c; + /* See if we need to insert some fake zero bits. */ + goto no_more_bytes; + } + } + + /* OK, load c into get_buffer */ + get_buffer = (get_buffer << 8) | c; + bits_left += 8; + } /* end while */ + } else { + no_more_bytes: + /* We get here if we've read the marker that terminates the compressed + * data segment. There should be enough bits in the buffer register + * to satisfy the request; if so, no problem. + */ + if (nbits > bits_left) { + /* Uh-oh. Report corrupted data to user and stuff zeroes into + * the data stream, so that we can produce some kind of image. + * We use a nonvolatile flag to ensure that only one warning message + * appears per data segment. + */ + if (! cinfo->entropy->insufficient_data) { + WARNMS(cinfo, JWRN_HIT_MARKER); + cinfo->entropy->insufficient_data = TRUE; + } + /* Fill the buffer with zero bits */ + get_buffer <<= MIN_GET_BITS - bits_left; + bits_left = MIN_GET_BITS; + } + } + + /* Unload the local registers */ + state->next_input_byte = next_input_byte; + state->bytes_in_buffer = bytes_in_buffer; + state->get_buffer = get_buffer; + state->bits_left = bits_left; + + return TRUE; +} + + +/* Macro version of the above, which performs much better but does not + handle markers. We have to hand off any blocks with markers to the + slower routines. */ + +#define GET_BYTE \ +{ \ + register int c0, c1; \ + c0 = GETJOCTET(*buffer++); \ + c1 = GETJOCTET(*buffer); \ + /* Pre-execute most common case */ \ + get_buffer = (get_buffer << 8) | c0; \ + bits_left += 8; \ + if (c0 == 0xFF) { \ + /* Pre-execute case of FF/00, which represents an FF data byte */ \ + buffer++; \ + if (c1 != 0) { \ + /* Oops, it's actually a marker indicating end of compressed data. */ \ + cinfo->unread_marker = c1; \ + /* Back out pre-execution and fill the buffer with zero bits */ \ + buffer -= 2; \ + get_buffer &= ~0xFF; \ + } \ + } \ +} + +#if __WORDSIZE == 64 || defined(_WIN64) + +/* Pre-fetch 48 bytes, because the holding register is 64-bit */ +#define FILL_BIT_BUFFER_FAST \ + if (bits_left < 16) { \ + GET_BYTE GET_BYTE GET_BYTE GET_BYTE GET_BYTE GET_BYTE \ + } + +#else + +/* Pre-fetch 16 bytes, because the holding register is 32-bit */ +#define FILL_BIT_BUFFER_FAST \ + if (bits_left < 16) { \ + GET_BYTE GET_BYTE \ + } + +#endif + + +/* + * Out-of-line code for Huffman code decoding. + * See jdhuff.h for info about usage. + */ + +GLOBAL(int) +jpeg_huff_decode (bitread_working_state * state, + register bit_buf_type get_buffer, register int bits_left, + d_derived_tbl * htbl, int min_bits) +{ + register int l = min_bits; + register INT32 code; + + /* HUFF_DECODE has determined that the code is at least min_bits */ + /* bits long, so fetch that many bits in one swoop. */ + + CHECK_BIT_BUFFER(*state, l, return -1); + code = GET_BITS(l); + + /* Collect the rest of the Huffman code one bit at a time. */ + /* This is per Figure F.16 in the JPEG spec. */ + + while (code > htbl->maxcode[l]) { + code <<= 1; + CHECK_BIT_BUFFER(*state, 1, return -1); + code |= GET_BITS(1); + l++; + } + + /* Unload the local registers */ + state->get_buffer = get_buffer; + state->bits_left = bits_left; + + /* With garbage input we may reach the sentinel value l = 17. */ + + if (l > 16) { + WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE); + return 0; /* fake a zero as the safest result */ + } + + return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ]; +} + + +/* + * Figure F.12: extend sign bit. + * On some machines, a shift and add will be faster than a table lookup. + */ + +#define AVOID_TABLES +#ifdef AVOID_TABLES + +#define HUFF_EXTEND(x,s) ((x) + ((((x) - (1<<((s)-1))) >> 31) & (((-1)<<(s)) + 1))) + +#else + +#define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) + +static const int extend_test[16] = /* entry n is 2**(n-1) */ + { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; + +static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ + { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, + ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, + ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, + ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }; + +#endif /* AVOID_TABLES */ + + +/* + * Check for a restart marker & resynchronize decoder. + * Returns FALSE if must suspend. + */ + +LOCAL(boolean) +process_restart (j_decompress_ptr cinfo) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci; + + /* Throw away any unused bits remaining in bit buffer; */ + /* include any full bytes in next_marker's count of discarded bytes */ + cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; + entropy->bitstate.bits_left = 0; + + /* Advance past the RSTn marker */ + if (! (*cinfo->marker->read_restart_marker) (cinfo)) + return FALSE; + + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) + entropy->saved.last_dc_val[ci] = 0; + + /* Reset restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; + + /* Reset out-of-data flag, unless read_restart_marker left us smack up + * against a marker. In that case we will end up treating the next data + * segment as empty, and we can avoid producing bogus output pixels by + * leaving the flag set. + */ + if (cinfo->unread_marker == 0) + entropy->pub.insufficient_data = FALSE; + + return TRUE; +} + + +LOCAL(boolean) +decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + BITREAD_STATE_VARS; + int blkn; + savable_state state; + /* Outer loop handles each block in the MCU */ + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(state, entropy->saved); + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + JBLOCKROW block = MCU_data[blkn]; + d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn]; + d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn]; + register int s, k, r; + + /* Decode a single block's worth of coefficients */ + + /* Section F.2.2.1: decode the DC coefficient difference */ + HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); + if (s) { + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + } + + if (entropy->dc_needed[blkn]) { + /* Convert DC difference to actual value, update last_dc_val */ + int ci = cinfo->MCU_membership[blkn]; + s += state.last_dc_val[ci]; + state.last_dc_val[ci] = s; + /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ + (*block)[0] = (JCOEF) s; + } + + if (entropy->ac_needed[blkn]) { + + /* Section F.2.2.2: decode the AC coefficients */ + /* Since zeroes are skipped, output area must be cleared beforehand */ + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE(s, br_state, actbl, return FALSE, label2); + + r = s >> 4; + s &= 15; + + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + /* Output coefficient in natural (dezigzagged) order. + * Note: the extra entries in jpeg_natural_order[] will save us + * if k >= DCTSIZE2, which could happen if the data is corrupted. + */ + (*block)[jpeg_natural_order[k]] = (JCOEF) s; + } else { + if (r != 15) + break; + k += 15; + } + } + + } else { + + /* Section F.2.2.2: decode the AC coefficients */ + /* In this path we just discard the values */ + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE(s, br_state, actbl, return FALSE, label3); + + r = s >> 4; + s &= 15; + + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + DROP_BITS(s); + } else { + if (r != 15) + break; + k += 15; + } + } + } + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(entropy->saved, state); + return TRUE; +} + + +LOCAL(boolean) +decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + BITREAD_STATE_VARS; + JOCTET *buffer; + int blkn; + savable_state state; + /* Outer loop handles each block in the MCU */ + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + buffer = (JOCTET *) br_state.next_input_byte; + ASSIGN_STATE(state, entropy->saved); + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + JBLOCKROW block = MCU_data[blkn]; + d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn]; + d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn]; + register int s, k, r, l; + + HUFF_DECODE_FAST(s, l, dctbl); + if (s) { + FILL_BIT_BUFFER_FAST + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + } + + if (entropy->dc_needed[blkn]) { + int ci = cinfo->MCU_membership[blkn]; + s += state.last_dc_val[ci]; + state.last_dc_val[ci] = s; + (*block)[0] = (JCOEF) s; + } + + if (entropy->ac_needed[blkn]) { + + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE_FAST(s, l, actbl); + r = s >> 4; + s &= 15; + + if (s) { + k += r; + FILL_BIT_BUFFER_FAST + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + (*block)[jpeg_natural_order[k]] = (JCOEF) s; + } else { + if (r != 15) break; + k += 15; + } + } + + } else { + + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE_FAST(s, l, actbl); + r = s >> 4; + s &= 15; + + if (s) { + k += r; + FILL_BIT_BUFFER_FAST + DROP_BITS(s); + } else { + if (r != 15) break; + k += 15; + } + } + } + } + + if (cinfo->unread_marker != 0) { + cinfo->unread_marker = 0; + return FALSE; + } + + br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte); + br_state.next_input_byte = buffer; + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(entropy->saved, state); + return TRUE; +} + + +/* + * Decode and return one MCU's worth of Huffman-compressed coefficients. + * The coefficients are reordered from zigzag order into natural array order, + * but are not dequantized. + * + * The i'th block of the MCU is stored into the block pointed to by + * MCU_data[i]. WE ASSUME THIS AREA HAS BEEN ZEROED BY THE CALLER. + * (Wholesale zeroing is usually a little faster than retail...) + * + * Returns FALSE if data source requested suspension. In that case no + * changes have been made to permanent state. (Exception: some output + * coefficients may already have been assigned. This is harmless for + * this module, since we'll just re-assign them on the next call.) + */ + +#define BUFSIZE (DCTSIZE2 * 2) + +METHODDEF(boolean) +decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int usefast = 1; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + usefast = 0; + } + + if (cinfo->src->bytes_in_buffer < BUFSIZE * (size_t)cinfo->blocks_in_MCU + || cinfo->unread_marker != 0) + usefast = 0; + + /* If we've run out of data, just leave the MCU set to zeroes. + * This way, we return uniform gray for the remainder of the segment. + */ + if (! entropy->pub.insufficient_data) { + + if (usefast) { + if (!decode_mcu_fast(cinfo, MCU_data)) goto use_slow; + } + else { + use_slow: + if (!decode_mcu_slow(cinfo, MCU_data)) return FALSE; + } + + } + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; +} + + +/* + * Module initialization routine for Huffman entropy decoding. + */ + +GLOBAL(void) +jinit_huff_decoder (j_decompress_ptr cinfo) +{ + huff_entropy_ptr entropy; + int i; + + entropy = (huff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(huff_entropy_decoder)); + cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; + entropy->pub.start_pass = start_pass_huff_decoder; + entropy->pub.decode_mcu = decode_mcu; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdhuff.h b/lib-third-party/libturbojpeg-ios/libjpeg/jdhuff.h new file mode 100755 index 0000000..96f2dab --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdhuff.h @@ -0,0 +1,234 @@ +/* + * jdhuff.h + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright (C) 2010-2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains declarations for Huffman entropy decoding routines + * that are shared between the sequential decoder (jdhuff.c) and the + * progressive decoder (jdphuff.c). No other modules need to see these. + */ + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_make_d_derived_tbl jMkDDerived +#define jpeg_fill_bit_buffer jFilBitBuf +#define jpeg_huff_decode jHufDecode +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + + +/* Derived data constructed for each Huffman table */ + +#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */ + +typedef struct { + /* Basic tables: (element [0] of each array is unused) */ + INT32 maxcode[18]; /* largest code of length k (-1 if none) */ + /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ + INT32 valoffset[18]; /* huffval[] offset for codes of length k */ + /* valoffset[k] = huffval[] index of 1st symbol of code length k, less + * the smallest code of length k; so given a code of length k, the + * corresponding symbol is huffval[code + valoffset[k]] + */ + + /* Link to public Huffman table (needed only in jpeg_huff_decode) */ + JHUFF_TBL *pub; + + /* Lookahead table: indexed by the next HUFF_LOOKAHEAD bits of + * the input data stream. If the next Huffman code is no more + * than HUFF_LOOKAHEAD bits long, we can obtain its length and + * the corresponding symbol directly from this tables. + * + * The lower 8 bits of each table entry contain the number of + * bits in the corresponding Huffman code, or HUFF_LOOKAHEAD + 1 + * if too long. The next 8 bits of each entry contain the + * symbol. + */ + int lookup[1< 32 bits on your machine, and shifting/masking longs is + * reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE + * appropriately should be a win. Unfortunately we can't define the size + * with something like #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8) + * because not all machines measure sizeof in 8-bit bytes. + */ + +typedef struct { /* Bitreading state saved across MCUs */ + bit_buf_type get_buffer; /* current bit-extraction buffer */ + int bits_left; /* # of unused bits in it */ +} bitread_perm_state; + +typedef struct { /* Bitreading working state within an MCU */ + /* Current data source location */ + /* We need a copy, rather than munging the original, in case of suspension */ + const JOCTET * next_input_byte; /* => next byte to read from source */ + size_t bytes_in_buffer; /* # of bytes remaining in source buffer */ + /* Bit input buffer --- note these values are kept in register variables, + * not in this struct, inside the inner loops. + */ + bit_buf_type get_buffer; /* current bit-extraction buffer */ + int bits_left; /* # of unused bits in it */ + /* Pointer needed by jpeg_fill_bit_buffer. */ + j_decompress_ptr cinfo; /* back link to decompress master record */ +} bitread_working_state; + +/* Macros to declare and load/save bitread local variables. */ +#define BITREAD_STATE_VARS \ + register bit_buf_type get_buffer; \ + register int bits_left; \ + bitread_working_state br_state + +#define BITREAD_LOAD_STATE(cinfop,permstate) \ + br_state.cinfo = cinfop; \ + br_state.next_input_byte = cinfop->src->next_input_byte; \ + br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \ + get_buffer = permstate.get_buffer; \ + bits_left = permstate.bits_left; + +#define BITREAD_SAVE_STATE(cinfop,permstate) \ + cinfop->src->next_input_byte = br_state.next_input_byte; \ + cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \ + permstate.get_buffer = get_buffer; \ + permstate.bits_left = bits_left + +/* + * These macros provide the in-line portion of bit fetching. + * Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer + * before using GET_BITS, PEEK_BITS, or DROP_BITS. + * The variables get_buffer and bits_left are assumed to be locals, + * but the state struct might not be (jpeg_huff_decode needs this). + * CHECK_BIT_BUFFER(state,n,action); + * Ensure there are N bits in get_buffer; if suspend, take action. + * val = GET_BITS(n); + * Fetch next N bits. + * val = PEEK_BITS(n); + * Fetch next N bits without removing them from the buffer. + * DROP_BITS(n); + * Discard next N bits. + * The value N should be a simple variable, not an expression, because it + * is evaluated multiple times. + */ + +#define CHECK_BIT_BUFFER(state,nbits,action) \ + { if (bits_left < (nbits)) { \ + if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \ + { action; } \ + get_buffer = (state).get_buffer; bits_left = (state).bits_left; } } + +#define GET_BITS(nbits) \ + (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1)) + +#define PEEK_BITS(nbits) \ + (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1)) + +#define DROP_BITS(nbits) \ + (bits_left -= (nbits)) + +/* Load up the bit buffer to a depth of at least nbits */ +EXTERN(boolean) jpeg_fill_bit_buffer + JPP((bitread_working_state * state, register bit_buf_type get_buffer, + register int bits_left, int nbits)); + + +/* + * Code for extracting next Huffman-coded symbol from input bit stream. + * Again, this is time-critical and we make the main paths be macros. + * + * We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits + * without looping. Usually, more than 95% of the Huffman codes will be 8 + * or fewer bits long. The few overlength codes are handled with a loop, + * which need not be inline code. + * + * Notes about the HUFF_DECODE macro: + * 1. Near the end of the data segment, we may fail to get enough bits + * for a lookahead. In that case, we do it the hard way. + * 2. If the lookahead table contains no entry, the next code must be + * more than HUFF_LOOKAHEAD bits long. + * 3. jpeg_huff_decode returns -1 if forced to suspend. + */ + +#define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \ +{ register int nb, look; \ + if (bits_left < HUFF_LOOKAHEAD) { \ + if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \ + get_buffer = state.get_buffer; bits_left = state.bits_left; \ + if (bits_left < HUFF_LOOKAHEAD) { \ + nb = 1; goto slowlabel; \ + } \ + } \ + look = PEEK_BITS(HUFF_LOOKAHEAD); \ + if ((nb = (htbl->lookup[look] >> HUFF_LOOKAHEAD)) <= HUFF_LOOKAHEAD) { \ + DROP_BITS(nb); \ + result = htbl->lookup[look] & ((1 << HUFF_LOOKAHEAD) - 1); \ + } else { \ +slowlabel: \ + if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \ + { failaction; } \ + get_buffer = state.get_buffer; bits_left = state.bits_left; \ + } \ +} + +#define HUFF_DECODE_FAST(s,nb,htbl) \ + FILL_BIT_BUFFER_FAST; \ + s = PEEK_BITS(HUFF_LOOKAHEAD); \ + s = htbl->lookup[s]; \ + nb = s >> HUFF_LOOKAHEAD; \ + /* Pre-execute the common case of nb <= HUFF_LOOKAHEAD */ \ + DROP_BITS(nb); \ + s = s & ((1 << HUFF_LOOKAHEAD) - 1); \ + if (nb > HUFF_LOOKAHEAD) { \ + /* Equivalent of jpeg_huff_decode() */ \ + /* Don't use GET_BITS() here because we don't want to modify bits_left */ \ + s = (get_buffer >> bits_left) & ((1 << (nb)) - 1); \ + while (s > htbl->maxcode[nb]) { \ + s <<= 1; \ + s |= GET_BITS(1); \ + nb++; \ + } \ + s = htbl->pub->huffval[ (int) (s + htbl->valoffset[nb]) & 0xFF ]; \ + } + +/* Out-of-line case for Huffman code fetching */ +EXTERN(int) jpeg_huff_decode + JPP((bitread_working_state * state, register bit_buf_type get_buffer, + register int bits_left, d_derived_tbl * htbl, int min_bits)); diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdinput.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdinput.c new file mode 100755 index 0000000..eddace6 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdinput.c @@ -0,0 +1,397 @@ +/* + * jdinput.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains input control logic for the JPEG decompressor. + * These routines are concerned with controlling the decompressor's input + * processing (marker reading and coefficient decoding). The actual input + * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jpegcomp.h" + + +/* Private state */ + +typedef struct { + struct jpeg_input_controller pub; /* public fields */ + + boolean inheaders; /* TRUE until first SOS is reached */ +} my_input_controller; + +typedef my_input_controller * my_inputctl_ptr; + + +/* Forward declarations */ +METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo)); + + +/* + * Routines to calculate various quantities related to the size of the image. + */ + +LOCAL(void) +initial_setup (j_decompress_ptr cinfo) +/* Called once, when first SOS marker is reached */ +{ + int ci; + jpeg_component_info *compptr; + + /* Make sure image isn't bigger than I can handle */ + if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || + (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) + ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); + + /* For now, precision must match compiled-in value... */ + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + + /* Check that number of components won't exceed internal array sizes */ + if (cinfo->num_components > MAX_COMPONENTS) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPONENTS); + + /* Compute maximum sampling factors; check factor validity */ + cinfo->max_h_samp_factor = 1; + cinfo->max_v_samp_factor = 1; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || + compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) + ERREXIT(cinfo, JERR_BAD_SAMPLING); + cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, + compptr->h_samp_factor); + cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, + compptr->v_samp_factor); + } + +#if JPEG_LIB_VERSION >=80 + cinfo->block_size = DCTSIZE; + cinfo->natural_order = jpeg_natural_order; + cinfo->lim_Se = DCTSIZE2-1; +#endif + + /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. + * In the full decompressor, this will be overridden by jdmaster.c; + * but in the transcoder, jdmaster.c is not used, so we must do it here. + */ +#if JPEG_LIB_VERSION >= 70 + cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; +#else + cinfo->min_DCT_scaled_size = DCTSIZE; +#endif + + /* Compute dimensions of components */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { +#if JPEG_LIB_VERSION >= 70 + compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; +#else + compptr->DCT_scaled_size = DCTSIZE; +#endif + /* Size in DCT blocks */ + compptr->width_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, + (long) (cinfo->max_h_samp_factor * DCTSIZE)); + compptr->height_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, + (long) (cinfo->max_v_samp_factor * DCTSIZE)); + /* downsampled_width and downsampled_height will also be overridden by + * jdmaster.c if we are doing full decompression. The transcoder library + * doesn't use these values, but the calling application might. + */ + /* Size in samples */ + compptr->downsampled_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, + (long) cinfo->max_h_samp_factor); + compptr->downsampled_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, + (long) cinfo->max_v_samp_factor); + /* Mark component needed, until color conversion says otherwise */ + compptr->component_needed = TRUE; + /* Mark no quantization table yet saved for component */ + compptr->quant_table = NULL; + } + + /* Compute number of fully interleaved MCU rows. */ + cinfo->total_iMCU_rows = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); + + /* Decide whether file contains multiple scans */ + if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode) + cinfo->inputctl->has_multiple_scans = TRUE; + else + cinfo->inputctl->has_multiple_scans = FALSE; +} + + +LOCAL(void) +per_scan_setup (j_decompress_ptr cinfo) +/* Do computations that are needed before processing a JPEG scan */ +/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */ +{ + int ci, mcublks, tmp; + jpeg_component_info *compptr; + + if (cinfo->comps_in_scan == 1) { + + /* Noninterleaved (single-component) scan */ + compptr = cinfo->cur_comp_info[0]; + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = compptr->width_in_blocks; + cinfo->MCU_rows_in_scan = compptr->height_in_blocks; + + /* For noninterleaved scan, always one block per MCU */ + compptr->MCU_width = 1; + compptr->MCU_height = 1; + compptr->MCU_blocks = 1; + compptr->MCU_sample_width = compptr->_DCT_scaled_size; + compptr->last_col_width = 1; + /* For noninterleaved scans, it is convenient to define last_row_height + * as the number of block rows present in the last iMCU row. + */ + tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (tmp == 0) tmp = compptr->v_samp_factor; + compptr->last_row_height = tmp; + + /* Prepare array describing MCU composition */ + cinfo->blocks_in_MCU = 1; + cinfo->MCU_membership[0] = 0; + + } else { + + /* Interleaved (multi-component) scan */ + if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, + MAX_COMPS_IN_SCAN); + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width, + (long) (cinfo->max_h_samp_factor*DCTSIZE)); + cinfo->MCU_rows_in_scan = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); + + cinfo->blocks_in_MCU = 0; + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Sampling factors give # of blocks of component in each MCU */ + compptr->MCU_width = compptr->h_samp_factor; + compptr->MCU_height = compptr->v_samp_factor; + compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; + compptr->MCU_sample_width = compptr->MCU_width * compptr->_DCT_scaled_size; + /* Figure number of non-dummy blocks in last MCU column & row */ + tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); + if (tmp == 0) tmp = compptr->MCU_width; + compptr->last_col_width = tmp; + tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); + if (tmp == 0) tmp = compptr->MCU_height; + compptr->last_row_height = tmp; + /* Prepare array describing MCU composition */ + mcublks = compptr->MCU_blocks; + if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) + ERREXIT(cinfo, JERR_BAD_MCU_SIZE); + while (mcublks-- > 0) { + cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; + } + } + + } +} + + +/* + * Save away a copy of the Q-table referenced by each component present + * in the current scan, unless already saved during a prior scan. + * + * In a multiple-scan JPEG file, the encoder could assign different components + * the same Q-table slot number, but change table definitions between scans + * so that each component uses a different Q-table. (The IJG encoder is not + * currently capable of doing this, but other encoders might.) Since we want + * to be able to dequantize all the components at the end of the file, this + * means that we have to save away the table actually used for each component. + * We do this by copying the table at the start of the first scan containing + * the component. + * The JPEG spec prohibits the encoder from changing the contents of a Q-table + * slot between scans of a component using that slot. If the encoder does so + * anyway, this decoder will simply use the Q-table values that were current + * at the start of the first scan for the component. + * + * The decompressor output side looks only at the saved quant tables, + * not at the current Q-table slots. + */ + +LOCAL(void) +latch_quant_tables (j_decompress_ptr cinfo) +{ + int ci, qtblno; + jpeg_component_info *compptr; + JQUANT_TBL * qtbl; + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* No work if we already saved Q-table for this component */ + if (compptr->quant_table != NULL) + continue; + /* Make sure specified quantization table is present */ + qtblno = compptr->quant_tbl_no; + if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || + cinfo->quant_tbl_ptrs[qtblno] == NULL) + ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); + /* OK, save away the quantization table */ + qtbl = (JQUANT_TBL *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(JQUANT_TBL)); + MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL)); + compptr->quant_table = qtbl; + } +} + + +/* + * Initialize the input modules to read a scan of compressed data. + * The first call to this is done by jdmaster.c after initializing + * the entire decompressor (during jpeg_start_decompress). + * Subsequent calls come from consume_markers, below. + */ + +METHODDEF(void) +start_input_pass (j_decompress_ptr cinfo) +{ + per_scan_setup(cinfo); + latch_quant_tables(cinfo); + (*cinfo->entropy->start_pass) (cinfo); + (*cinfo->coef->start_input_pass) (cinfo); + cinfo->inputctl->consume_input = cinfo->coef->consume_data; +} + + +/* + * Finish up after inputting a compressed-data scan. + * This is called by the coefficient controller after it's read all + * the expected data of the scan. + */ + +METHODDEF(void) +finish_input_pass (j_decompress_ptr cinfo) +{ + cinfo->inputctl->consume_input = consume_markers; +} + + +/* + * Read JPEG markers before, between, or after compressed-data scans. + * Change state as necessary when a new scan is reached. + * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. + * + * The consume_input method pointer points either here or to the + * coefficient controller's consume_data routine, depending on whether + * we are reading a compressed data segment or inter-segment markers. + */ + +METHODDEF(int) +consume_markers (j_decompress_ptr cinfo) +{ + my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; + int val; + + if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */ + return JPEG_REACHED_EOI; + + val = (*cinfo->marker->read_markers) (cinfo); + + switch (val) { + case JPEG_REACHED_SOS: /* Found SOS */ + if (inputctl->inheaders) { /* 1st SOS */ + initial_setup(cinfo); + inputctl->inheaders = FALSE; + /* Note: start_input_pass must be called by jdmaster.c + * before any more input can be consumed. jdapimin.c is + * responsible for enforcing this sequencing. + */ + } else { /* 2nd or later SOS marker */ + if (! inputctl->pub.has_multiple_scans) + ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ + start_input_pass(cinfo); + } + break; + case JPEG_REACHED_EOI: /* Found EOI */ + inputctl->pub.eoi_reached = TRUE; + if (inputctl->inheaders) { /* Tables-only datastream, apparently */ + if (cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOF_NO_SOS); + } else { + /* Prevent infinite loop in coef ctlr's decompress_data routine + * if user set output_scan_number larger than number of scans. + */ + if (cinfo->output_scan_number > cinfo->input_scan_number) + cinfo->output_scan_number = cinfo->input_scan_number; + } + break; + case JPEG_SUSPENDED: + break; + } + + return val; +} + + +/* + * Reset state to begin a fresh datastream. + */ + +METHODDEF(void) +reset_input_controller (j_decompress_ptr cinfo) +{ + my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; + + inputctl->pub.consume_input = consume_markers; + inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ + inputctl->pub.eoi_reached = FALSE; + inputctl->inheaders = TRUE; + /* Reset other modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->marker->reset_marker_reader) (cinfo); + /* Reset progression state -- would be cleaner if entropy decoder did this */ + cinfo->coef_bits = NULL; +} + + +/* + * Initialize the input controller module. + * This is called only once, when the decompression object is created. + */ + +GLOBAL(void) +jinit_input_controller (j_decompress_ptr cinfo) +{ + my_inputctl_ptr inputctl; + + /* Create subobject in permanent pool */ + inputctl = (my_inputctl_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_input_controller)); + cinfo->inputctl = (struct jpeg_input_controller *) inputctl; + /* Initialize method pointers */ + inputctl->pub.consume_input = consume_markers; + inputctl->pub.reset_input_controller = reset_input_controller; + inputctl->pub.start_input_pass = start_input_pass; + inputctl->pub.finish_input_pass = finish_input_pass; + /* Initialize state: can't use reset_input_controller since we don't + * want to try to reset other modules yet. + */ + inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ + inputctl->pub.eoi_reached = FALSE; + inputctl->inheaders = TRUE; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdmainct.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdmainct.c new file mode 100755 index 0000000..eb32cae --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdmainct.c @@ -0,0 +1,514 @@ +/* + * jdmainct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the main buffer controller for decompression. + * The main buffer lies between the JPEG decompressor proper and the + * post-processor; it holds downsampled data in the JPEG colorspace. + * + * Note that this code is bypassed in raw-data mode, since the application + * supplies the equivalent of the main buffer in that case. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jpegcomp.h" + + +/* + * In the current system design, the main buffer need never be a full-image + * buffer; any full-height buffers will be found inside the coefficient or + * postprocessing controllers. Nonetheless, the main controller is not + * trivial. Its responsibility is to provide context rows for upsampling/ + * rescaling, and doing this in an efficient fashion is a bit tricky. + * + * Postprocessor input data is counted in "row groups". A row group + * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) + * sample rows of each component. (We require DCT_scaled_size values to be + * chosen such that these numbers are integers. In practice DCT_scaled_size + * values will likely be powers of two, so we actually have the stronger + * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.) + * Upsampling will typically produce max_v_samp_factor pixel rows from each + * row group (times any additional scale factor that the upsampler is + * applying). + * + * The coefficient controller will deliver data to us one iMCU row at a time; + * each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or + * exactly min_DCT_scaled_size row groups. (This amount of data corresponds + * to one row of MCUs when the image is fully interleaved.) Note that the + * number of sample rows varies across components, but the number of row + * groups does not. Some garbage sample rows may be included in the last iMCU + * row at the bottom of the image. + * + * Depending on the vertical scaling algorithm used, the upsampler may need + * access to the sample row(s) above and below its current input row group. + * The upsampler is required to set need_context_rows TRUE at global selection + * time if so. When need_context_rows is FALSE, this controller can simply + * obtain one iMCU row at a time from the coefficient controller and dole it + * out as row groups to the postprocessor. + * + * When need_context_rows is TRUE, this controller guarantees that the buffer + * passed to postprocessing contains at least one row group's worth of samples + * above and below the row group(s) being processed. Note that the context + * rows "above" the first passed row group appear at negative row offsets in + * the passed buffer. At the top and bottom of the image, the required + * context rows are manufactured by duplicating the first or last real sample + * row; this avoids having special cases in the upsampling inner loops. + * + * The amount of context is fixed at one row group just because that's a + * convenient number for this controller to work with. The existing + * upsamplers really only need one sample row of context. An upsampler + * supporting arbitrary output rescaling might wish for more than one row + * group of context when shrinking the image; tough, we don't handle that. + * (This is justified by the assumption that downsizing will be handled mostly + * by adjusting the DCT_scaled_size values, so that the actual scale factor at + * the upsample step needn't be much less than one.) + * + * To provide the desired context, we have to retain the last two row groups + * of one iMCU row while reading in the next iMCU row. (The last row group + * can't be processed until we have another row group for its below-context, + * and so we have to save the next-to-last group too for its above-context.) + * We could do this most simply by copying data around in our buffer, but + * that'd be very slow. We can avoid copying any data by creating a rather + * strange pointer structure. Here's how it works. We allocate a workspace + * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number + * of row groups per iMCU row). We create two sets of redundant pointers to + * the workspace. Labeling the physical row groups 0 to M+1, the synthesized + * pointer lists look like this: + * M+1 M-1 + * master pointer --> 0 master pointer --> 0 + * 1 1 + * ... ... + * M-3 M-3 + * M-2 M + * M-1 M+1 + * M M-2 + * M+1 M-1 + * 0 0 + * We read alternate iMCU rows using each master pointer; thus the last two + * row groups of the previous iMCU row remain un-overwritten in the workspace. + * The pointer lists are set up so that the required context rows appear to + * be adjacent to the proper places when we pass the pointer lists to the + * upsampler. + * + * The above pictures describe the normal state of the pointer lists. + * At top and bottom of the image, we diddle the pointer lists to duplicate + * the first or last sample row as necessary (this is cheaper than copying + * sample rows around). + * + * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that + * situation each iMCU row provides only one row group so the buffering logic + * must be different (eg, we must read two iMCU rows before we can emit the + * first row group). For now, we simply do not support providing context + * rows when min_DCT_scaled_size is 1. That combination seems unlikely to + * be worth providing --- if someone wants a 1/8th-size preview, they probably + * want it quick and dirty, so a context-free upsampler is sufficient. + */ + + +/* Private buffer controller object */ + +typedef struct { + struct jpeg_d_main_controller pub; /* public fields */ + + /* Pointer to allocated workspace (M or M+2 row groups). */ + JSAMPARRAY buffer[MAX_COMPONENTS]; + + boolean buffer_full; /* Have we gotten an iMCU row from decoder? */ + JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */ + + /* Remaining fields are only used in the context case. */ + + /* These are the master pointers to the funny-order pointer lists. */ + JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */ + + int whichptr; /* indicates which pointer set is now in use */ + int context_state; /* process_data state machine status */ + JDIMENSION rowgroups_avail; /* row groups available to postprocessor */ + JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ +} my_main_controller; + +typedef my_main_controller * my_main_ptr; + +/* context_state values: */ +#define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */ +#define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */ +#define CTX_POSTPONED_ROW 2 /* feeding postponed row group */ + + +/* Forward declarations */ +METHODDEF(void) process_data_simple_main + JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); +METHODDEF(void) process_data_context_main + JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); +#ifdef QUANT_2PASS_SUPPORTED +METHODDEF(void) process_data_crank_post + JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); +#endif + + +LOCAL(void) +alloc_funny_pointers (j_decompress_ptr cinfo) +/* Allocate space for the funny pointer lists. + * This is done only once, not once per pass. + */ +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + int ci, rgroup; + int M = cinfo->_min_DCT_scaled_size; + jpeg_component_info *compptr; + JSAMPARRAY xbuf; + + /* Get top-level space for component array pointers. + * We alloc both arrays with one call to save a few cycles. + */ + main_ptr->xbuffer[0] = (JSAMPIMAGE) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components * 2 * SIZEOF(JSAMPARRAY)); + main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / + cinfo->_min_DCT_scaled_size; /* height of a row group of component */ + /* Get space for pointer lists --- M+4 row groups in each list. + * We alloc both pointer lists with one call to save a few cycles. + */ + xbuf = (JSAMPARRAY) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW)); + xbuf += rgroup; /* want one row group at negative offsets */ + main_ptr->xbuffer[0][ci] = xbuf; + xbuf += rgroup * (M + 4); + main_ptr->xbuffer[1][ci] = xbuf; + } +} + + +LOCAL(void) +make_funny_pointers (j_decompress_ptr cinfo) +/* Create the funny pointer lists discussed in the comments above. + * The actual workspace is already allocated (in main_ptr->buffer), + * and the space for the pointer lists is allocated too. + * This routine just fills in the curiously ordered lists. + * This will be repeated at the beginning of each pass. + */ +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + int ci, i, rgroup; + int M = cinfo->_min_DCT_scaled_size; + jpeg_component_info *compptr; + JSAMPARRAY buf, xbuf0, xbuf1; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / + cinfo->_min_DCT_scaled_size; /* height of a row group of component */ + xbuf0 = main_ptr->xbuffer[0][ci]; + xbuf1 = main_ptr->xbuffer[1][ci]; + /* First copy the workspace pointers as-is */ + buf = main_ptr->buffer[ci]; + for (i = 0; i < rgroup * (M + 2); i++) { + xbuf0[i] = xbuf1[i] = buf[i]; + } + /* In the second list, put the last four row groups in swapped order */ + for (i = 0; i < rgroup * 2; i++) { + xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i]; + xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i]; + } + /* The wraparound pointers at top and bottom will be filled later + * (see set_wraparound_pointers, below). Initially we want the "above" + * pointers to duplicate the first actual data line. This only needs + * to happen in xbuffer[0]. + */ + for (i = 0; i < rgroup; i++) { + xbuf0[i - rgroup] = xbuf0[0]; + } + } +} + + +LOCAL(void) +set_wraparound_pointers (j_decompress_ptr cinfo) +/* Set up the "wraparound" pointers at top and bottom of the pointer lists. + * This changes the pointer list state from top-of-image to the normal state. + */ +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + int ci, i, rgroup; + int M = cinfo->_min_DCT_scaled_size; + jpeg_component_info *compptr; + JSAMPARRAY xbuf0, xbuf1; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / + cinfo->_min_DCT_scaled_size; /* height of a row group of component */ + xbuf0 = main_ptr->xbuffer[0][ci]; + xbuf1 = main_ptr->xbuffer[1][ci]; + for (i = 0; i < rgroup; i++) { + xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i]; + xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i]; + xbuf0[rgroup*(M+2) + i] = xbuf0[i]; + xbuf1[rgroup*(M+2) + i] = xbuf1[i]; + } + } +} + + +LOCAL(void) +set_bottom_pointers (j_decompress_ptr cinfo) +/* Change the pointer lists to duplicate the last sample row at the bottom + * of the image. whichptr indicates which xbuffer holds the final iMCU row. + * Also sets rowgroups_avail to indicate number of nondummy row groups in row. + */ +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + int ci, i, rgroup, iMCUheight, rows_left; + jpeg_component_info *compptr; + JSAMPARRAY xbuf; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Count sample rows in one iMCU row and in one row group */ + iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size; + rgroup = iMCUheight / cinfo->_min_DCT_scaled_size; + /* Count nondummy sample rows remaining for this component */ + rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight); + if (rows_left == 0) rows_left = iMCUheight; + /* Count nondummy row groups. Should get same answer for each component, + * so we need only do it once. + */ + if (ci == 0) { + main_ptr->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1); + } + /* Duplicate the last real sample row rgroup*2 times; this pads out the + * last partial rowgroup and ensures at least one full rowgroup of context. + */ + xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci]; + for (i = 0; i < rgroup * 2; i++) { + xbuf[rows_left + i] = xbuf[rows_left-1]; + } + } +} + + +/* + * Initialize for a processing pass. + */ + +METHODDEF(void) +start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + + switch (pass_mode) { + case JBUF_PASS_THRU: + if (cinfo->upsample->need_context_rows) { + main_ptr->pub.process_data = process_data_context_main; + make_funny_pointers(cinfo); /* Create the xbuffer[] lists */ + main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */ + main_ptr->context_state = CTX_PREPARE_FOR_IMCU; + main_ptr->iMCU_row_ctr = 0; + } else { + /* Simple case with no context needed */ + main_ptr->pub.process_data = process_data_simple_main; + } + main_ptr->buffer_full = FALSE; /* Mark buffer empty */ + main_ptr->rowgroup_ctr = 0; + break; +#ifdef QUANT_2PASS_SUPPORTED + case JBUF_CRANK_DEST: + /* For last pass of 2-pass quantization, just crank the postprocessor */ + main_ptr->pub.process_data = process_data_crank_post; + break; +#endif + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } +} + + +/* + * Process some data. + * This handles the simple case where no context is required. + */ + +METHODDEF(void) +process_data_simple_main (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + JDIMENSION rowgroups_avail; + + /* Read input data if we haven't filled the main buffer yet */ + if (! main_ptr->buffer_full) { + if (! (*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer)) + return; /* suspension forced, can do nothing more */ + main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ + } + + /* There are always min_DCT_scaled_size row groups in an iMCU row. */ + rowgroups_avail = (JDIMENSION) cinfo->_min_DCT_scaled_size; + /* Note: at the bottom of the image, we may pass extra garbage row groups + * to the postprocessor. The postprocessor has to check for bottom + * of image anyway (at row resolution), so no point in us doing it too. + */ + + /* Feed the postprocessor */ + (*cinfo->post->post_process_data) (cinfo, main_ptr->buffer, + &main_ptr->rowgroup_ctr, rowgroups_avail, + output_buf, out_row_ctr, out_rows_avail); + + /* Has postprocessor consumed all the data yet? If so, mark buffer empty */ + if (main_ptr->rowgroup_ctr >= rowgroups_avail) { + main_ptr->buffer_full = FALSE; + main_ptr->rowgroup_ctr = 0; + } +} + + +/* + * Process some data. + * This handles the case where context rows must be provided. + */ + +METHODDEF(void) +process_data_context_main (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +{ + my_main_ptr main_ptr = (my_main_ptr) cinfo->main; + + /* Read input data if we haven't filled the main buffer yet */ + if (! main_ptr->buffer_full) { + if (! (*cinfo->coef->decompress_data) (cinfo, + main_ptr->xbuffer[main_ptr->whichptr])) + return; /* suspension forced, can do nothing more */ + main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ + main_ptr->iMCU_row_ctr++; /* count rows received */ + } + + /* Postprocessor typically will not swallow all the input data it is handed + * in one call (due to filling the output buffer first). Must be prepared + * to exit and restart. This switch lets us keep track of how far we got. + * Note that each case falls through to the next on successful completion. + */ + switch (main_ptr->context_state) { + case CTX_POSTPONED_ROW: + /* Call postprocessor using previously set pointers for postponed row */ + (*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr], + &main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, + output_buf, out_row_ctr, out_rows_avail); + if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail) + return; /* Need to suspend */ + main_ptr->context_state = CTX_PREPARE_FOR_IMCU; + if (*out_row_ctr >= out_rows_avail) + return; /* Postprocessor exactly filled output buf */ + /*FALLTHROUGH*/ + case CTX_PREPARE_FOR_IMCU: + /* Prepare to process first M-1 row groups of this iMCU row */ + main_ptr->rowgroup_ctr = 0; + main_ptr->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size - 1); + /* Check for bottom of image: if so, tweak pointers to "duplicate" + * the last sample row, and adjust rowgroups_avail to ignore padding rows. + */ + if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows) + set_bottom_pointers(cinfo); + main_ptr->context_state = CTX_PROCESS_IMCU; + /*FALLTHROUGH*/ + case CTX_PROCESS_IMCU: + /* Call postprocessor using previously set pointers */ + (*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr], + &main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, + output_buf, out_row_ctr, out_rows_avail); + if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail) + return; /* Need to suspend */ + /* After the first iMCU, change wraparound pointers to normal state */ + if (main_ptr->iMCU_row_ctr == 1) + set_wraparound_pointers(cinfo); + /* Prepare to load new iMCU row using other xbuffer list */ + main_ptr->whichptr ^= 1; /* 0=>1 or 1=>0 */ + main_ptr->buffer_full = FALSE; + /* Still need to process last row group of this iMCU row, */ + /* which is saved at index M+1 of the other xbuffer */ + main_ptr->rowgroup_ctr = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 1); + main_ptr->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 2); + main_ptr->context_state = CTX_POSTPONED_ROW; + } +} + + +/* + * Process some data. + * Final pass of two-pass quantization: just call the postprocessor. + * Source data will be the postprocessor controller's internal buffer. + */ + +#ifdef QUANT_2PASS_SUPPORTED + +METHODDEF(void) +process_data_crank_post (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +{ + (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL, + (JDIMENSION *) NULL, (JDIMENSION) 0, + output_buf, out_row_ctr, out_rows_avail); +} + +#endif /* QUANT_2PASS_SUPPORTED */ + + +/* + * Initialize main buffer controller. + */ + +GLOBAL(void) +jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer) +{ + my_main_ptr main_ptr; + int ci, rgroup, ngroups; + jpeg_component_info *compptr; + + main_ptr = (my_main_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_main_controller)); + cinfo->main = (struct jpeg_d_main_controller *) main_ptr; + main_ptr->pub.start_pass = start_pass_main; + + if (need_full_buffer) /* shouldn't happen */ + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + /* Allocate the workspace. + * ngroups is the number of row groups we need. + */ + if (cinfo->upsample->need_context_rows) { + if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */ + ERREXIT(cinfo, JERR_NOTIMPL); + alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */ + ngroups = cinfo->_min_DCT_scaled_size + 2; + } else { + ngroups = cinfo->_min_DCT_scaled_size; + } + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / + cinfo->_min_DCT_scaled_size; /* height of a row group of component */ + main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + compptr->width_in_blocks * compptr->_DCT_scaled_size, + (JDIMENSION) (rgroup * ngroups)); + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdmarker.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdmarker.c new file mode 100755 index 0000000..6fc0f7d --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdmarker.c @@ -0,0 +1,1365 @@ +/* + * jdmarker.c + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Copyright (C) 2012, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to decode JPEG datastream markers. + * Most of the complexity arises from our desire to support input + * suspension: if not all of the data for a marker is available, + * we must exit back to the application. On resumption, we reprocess + * the marker. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +typedef enum { /* JPEG marker codes */ + M_SOF0 = 0xc0, + M_SOF1 = 0xc1, + M_SOF2 = 0xc2, + M_SOF3 = 0xc3, + + M_SOF5 = 0xc5, + M_SOF6 = 0xc6, + M_SOF7 = 0xc7, + + M_JPG = 0xc8, + M_SOF9 = 0xc9, + M_SOF10 = 0xca, + M_SOF11 = 0xcb, + + M_SOF13 = 0xcd, + M_SOF14 = 0xce, + M_SOF15 = 0xcf, + + M_DHT = 0xc4, + + M_DAC = 0xcc, + + M_RST0 = 0xd0, + M_RST1 = 0xd1, + M_RST2 = 0xd2, + M_RST3 = 0xd3, + M_RST4 = 0xd4, + M_RST5 = 0xd5, + M_RST6 = 0xd6, + M_RST7 = 0xd7, + + M_SOI = 0xd8, + M_EOI = 0xd9, + M_SOS = 0xda, + M_DQT = 0xdb, + M_DNL = 0xdc, + M_DRI = 0xdd, + M_DHP = 0xde, + M_EXP = 0xdf, + + M_APP0 = 0xe0, + M_APP1 = 0xe1, + M_APP2 = 0xe2, + M_APP3 = 0xe3, + M_APP4 = 0xe4, + M_APP5 = 0xe5, + M_APP6 = 0xe6, + M_APP7 = 0xe7, + M_APP8 = 0xe8, + M_APP9 = 0xe9, + M_APP10 = 0xea, + M_APP11 = 0xeb, + M_APP12 = 0xec, + M_APP13 = 0xed, + M_APP14 = 0xee, + M_APP15 = 0xef, + + M_JPG0 = 0xf0, + M_JPG13 = 0xfd, + M_COM = 0xfe, + + M_TEM = 0x01, + + M_ERROR = 0x100 +} JPEG_MARKER; + + +/* Private state */ + +typedef struct { + struct jpeg_marker_reader pub; /* public fields */ + + /* Application-overridable marker processing methods */ + jpeg_marker_parser_method process_COM; + jpeg_marker_parser_method process_APPn[16]; + + /* Limit on marker data length to save for each marker type */ + unsigned int length_limit_COM; + unsigned int length_limit_APPn[16]; + + /* Status of COM/APPn marker saving */ + jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */ + unsigned int bytes_read; /* data bytes read so far in marker */ + /* Note: cur_marker is not linked into marker_list until it's all read. */ +} my_marker_reader; + +typedef my_marker_reader * my_marker_ptr; + + +/* + * Macros for fetching data from the data source module. + * + * At all times, cinfo->src->next_input_byte and ->bytes_in_buffer reflect + * the current restart point; we update them only when we have reached a + * suitable place to restart if a suspension occurs. + */ + +/* Declare and initialize local copies of input pointer/count */ +#define INPUT_VARS(cinfo) \ + struct jpeg_source_mgr * datasrc = (cinfo)->src; \ + const JOCTET * next_input_byte = datasrc->next_input_byte; \ + size_t bytes_in_buffer = datasrc->bytes_in_buffer + +/* Unload the local copies --- do this only at a restart boundary */ +#define INPUT_SYNC(cinfo) \ + ( datasrc->next_input_byte = next_input_byte, \ + datasrc->bytes_in_buffer = bytes_in_buffer ) + +/* Reload the local copies --- used only in MAKE_BYTE_AVAIL */ +#define INPUT_RELOAD(cinfo) \ + ( next_input_byte = datasrc->next_input_byte, \ + bytes_in_buffer = datasrc->bytes_in_buffer ) + +/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available. + * Note we do *not* do INPUT_SYNC before calling fill_input_buffer, + * but we must reload the local copies after a successful fill. + */ +#define MAKE_BYTE_AVAIL(cinfo,action) \ + if (bytes_in_buffer == 0) { \ + if (! (*datasrc->fill_input_buffer) (cinfo)) \ + { action; } \ + INPUT_RELOAD(cinfo); \ + } + +/* Read a byte into variable V. + * If must suspend, take the specified action (typically "return FALSE"). + */ +#define INPUT_BYTE(cinfo,V,action) \ + MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ + bytes_in_buffer--; \ + V = GETJOCTET(*next_input_byte++); ) + +/* As above, but read two bytes interpreted as an unsigned 16-bit integer. + * V should be declared unsigned int or perhaps INT32. + */ +#define INPUT_2BYTES(cinfo,V,action) \ + MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ + bytes_in_buffer--; \ + V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \ + MAKE_BYTE_AVAIL(cinfo,action); \ + bytes_in_buffer--; \ + V += GETJOCTET(*next_input_byte++); ) + + +/* + * Routines to process JPEG markers. + * + * Entry condition: JPEG marker itself has been read and its code saved + * in cinfo->unread_marker; input restart point is just after the marker. + * + * Exit: if return TRUE, have read and processed any parameters, and have + * updated the restart point to point after the parameters. + * If return FALSE, was forced to suspend before reaching end of + * marker parameters; restart point has not been moved. Same routine + * will be called again after application supplies more input data. + * + * This approach to suspension assumes that all of a marker's parameters + * can fit into a single input bufferload. This should hold for "normal" + * markers. Some COM/APPn markers might have large parameter segments + * that might not fit. If we are simply dropping such a marker, we use + * skip_input_data to get past it, and thereby put the problem on the + * source manager's shoulders. If we are saving the marker's contents + * into memory, we use a slightly different convention: when forced to + * suspend, the marker processor updates the restart point to the end of + * what it's consumed (ie, the end of the buffer) before returning FALSE. + * On resumption, cinfo->unread_marker still contains the marker code, + * but the data source will point to the next chunk of marker data. + * The marker processor must retain internal state to deal with this. + * + * Note that we don't bother to avoid duplicate trace messages if a + * suspension occurs within marker parameters. Other side effects + * require more care. + */ + + +LOCAL(boolean) +get_soi (j_decompress_ptr cinfo) +/* Process an SOI marker */ +{ + int i; + + TRACEMS(cinfo, 1, JTRC_SOI); + + if (cinfo->marker->saw_SOI) + ERREXIT(cinfo, JERR_SOI_DUPLICATE); + + /* Reset all parameters that are defined to be reset by SOI */ + + for (i = 0; i < NUM_ARITH_TBLS; i++) { + cinfo->arith_dc_L[i] = 0; + cinfo->arith_dc_U[i] = 1; + cinfo->arith_ac_K[i] = 5; + } + cinfo->restart_interval = 0; + + /* Set initial assumptions for colorspace etc */ + + cinfo->jpeg_color_space = JCS_UNKNOWN; + cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */ + + cinfo->saw_JFIF_marker = FALSE; + cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */ + cinfo->JFIF_minor_version = 1; + cinfo->density_unit = 0; + cinfo->X_density = 1; + cinfo->Y_density = 1; + cinfo->saw_Adobe_marker = FALSE; + cinfo->Adobe_transform = 0; + + cinfo->marker->saw_SOI = TRUE; + + return TRUE; +} + + +LOCAL(boolean) +get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith) +/* Process a SOFn marker */ +{ + INT32 length; + int c, ci; + jpeg_component_info * compptr; + INPUT_VARS(cinfo); + + cinfo->progressive_mode = is_prog; + cinfo->arith_code = is_arith; + + INPUT_2BYTES(cinfo, length, return FALSE); + + INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE); + INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE); + INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE); + INPUT_BYTE(cinfo, cinfo->num_components, return FALSE); + + length -= 8; + + TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker, + (int) cinfo->image_width, (int) cinfo->image_height, + cinfo->num_components); + + if (cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOF_DUPLICATE); + + /* We don't support files in which the image height is initially specified */ + /* as 0 and is later redefined by DNL. As long as we have to check that, */ + /* might as well have a general sanity check. */ + if (cinfo->image_height <= 0 || cinfo->image_width <= 0 + || cinfo->num_components <= 0) + ERREXIT(cinfo, JERR_EMPTY_IMAGE); + + if (length != (cinfo->num_components * 3)) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + if (cinfo->comp_info == NULL) /* do only once, even if suspend */ + cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components * SIZEOF(jpeg_component_info)); + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + compptr->component_index = ci; + INPUT_BYTE(cinfo, compptr->component_id, return FALSE); + INPUT_BYTE(cinfo, c, return FALSE); + compptr->h_samp_factor = (c >> 4) & 15; + compptr->v_samp_factor = (c ) & 15; + INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE); + + TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT, + compptr->component_id, compptr->h_samp_factor, + compptr->v_samp_factor, compptr->quant_tbl_no); + } + + cinfo->marker->saw_SOF = TRUE; + + INPUT_SYNC(cinfo); + return TRUE; +} + + +LOCAL(boolean) +get_sos (j_decompress_ptr cinfo) +/* Process a SOS marker */ +{ + INT32 length; + int i, ci, n, c, cc; + jpeg_component_info * compptr; + INPUT_VARS(cinfo); + + if (! cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOS_NO_SOF); + + INPUT_2BYTES(cinfo, length, return FALSE); + + INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */ + + TRACEMS1(cinfo, 1, JTRC_SOS, n); + + if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + cinfo->comps_in_scan = n; + + /* Collect the component-spec parameters */ + + for (i = 0; i < MAX_COMPS_IN_SCAN; i++) + cinfo->cur_comp_info[i] = NULL; + + for (i = 0; i < n; i++) { + INPUT_BYTE(cinfo, cc, return FALSE); + INPUT_BYTE(cinfo, c, return FALSE); + + for (ci = 0, compptr = cinfo->comp_info; + ci < cinfo->num_components && ci < MAX_COMPS_IN_SCAN; + ci++, compptr++) { + if (cc == compptr->component_id && !cinfo->cur_comp_info[ci]) + goto id_found; + } + + ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); + + id_found: + + cinfo->cur_comp_info[i] = compptr; + compptr->dc_tbl_no = (c >> 4) & 15; + compptr->ac_tbl_no = (c ) & 15; + + TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, + compptr->dc_tbl_no, compptr->ac_tbl_no); + } + + /* Collect the additional scan parameters Ss, Se, Ah/Al. */ + INPUT_BYTE(cinfo, c, return FALSE); + cinfo->Ss = c; + INPUT_BYTE(cinfo, c, return FALSE); + cinfo->Se = c; + INPUT_BYTE(cinfo, c, return FALSE); + cinfo->Ah = (c >> 4) & 15; + cinfo->Al = (c ) & 15; + + TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se, + cinfo->Ah, cinfo->Al); + + /* Prepare to scan data & restart markers */ + cinfo->marker->next_restart_num = 0; + + /* Count another SOS marker */ + cinfo->input_scan_number++; + + INPUT_SYNC(cinfo); + return TRUE; +} + + +#ifdef D_ARITH_CODING_SUPPORTED + +LOCAL(boolean) +get_dac (j_decompress_ptr cinfo) +/* Process a DAC marker */ +{ + INT32 length; + int index, val; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + while (length > 0) { + INPUT_BYTE(cinfo, index, return FALSE); + INPUT_BYTE(cinfo, val, return FALSE); + + length -= 2; + + TRACEMS2(cinfo, 1, JTRC_DAC, index, val); + + if (index < 0 || index >= (2*NUM_ARITH_TBLS)) + ERREXIT1(cinfo, JERR_DAC_INDEX, index); + + if (index >= NUM_ARITH_TBLS) { /* define AC table */ + cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val; + } else { /* define DC table */ + cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F); + cinfo->arith_dc_U[index] = (UINT8) (val >> 4); + if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index]) + ERREXIT1(cinfo, JERR_DAC_VALUE, val); + } + } + + if (length != 0) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + INPUT_SYNC(cinfo); + return TRUE; +} + +#else /* ! D_ARITH_CODING_SUPPORTED */ + +#define get_dac(cinfo) skip_variable(cinfo) + +#endif /* D_ARITH_CODING_SUPPORTED */ + + +LOCAL(boolean) +get_dht (j_decompress_ptr cinfo) +/* Process a DHT marker */ +{ + INT32 length; + UINT8 bits[17]; + UINT8 huffval[256]; + int i, index, count; + JHUFF_TBL **htblptr; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + while (length > 16) { + INPUT_BYTE(cinfo, index, return FALSE); + + TRACEMS1(cinfo, 1, JTRC_DHT, index); + + bits[0] = 0; + count = 0; + for (i = 1; i <= 16; i++) { + INPUT_BYTE(cinfo, bits[i], return FALSE); + count += bits[i]; + } + + length -= 1 + 16; + + TRACEMS8(cinfo, 2, JTRC_HUFFBITS, + bits[1], bits[2], bits[3], bits[4], + bits[5], bits[6], bits[7], bits[8]); + TRACEMS8(cinfo, 2, JTRC_HUFFBITS, + bits[9], bits[10], bits[11], bits[12], + bits[13], bits[14], bits[15], bits[16]); + + /* Here we just do minimal validation of the counts to avoid walking + * off the end of our table space. jdhuff.c will check more carefully. + */ + if (count > 256 || ((INT32) count) > length) + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + + for (i = 0; i < count; i++) + INPUT_BYTE(cinfo, huffval[i], return FALSE); + + length -= count; + + if (index & 0x10) { /* AC table definition */ + index -= 0x10; + htblptr = &cinfo->ac_huff_tbl_ptrs[index]; + } else { /* DC table definition */ + htblptr = &cinfo->dc_huff_tbl_ptrs[index]; + } + + if (index < 0 || index >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_DHT_INDEX, index); + + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + + MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); + MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval)); + } + + if (length != 0) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + INPUT_SYNC(cinfo); + return TRUE; +} + + +LOCAL(boolean) +get_dqt (j_decompress_ptr cinfo) +/* Process a DQT marker */ +{ + INT32 length; + int n, i, prec; + unsigned int tmp; + JQUANT_TBL *quant_ptr; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + while (length > 0) { + INPUT_BYTE(cinfo, n, return FALSE); + prec = n >> 4; + n &= 0x0F; + + TRACEMS2(cinfo, 1, JTRC_DQT, n, prec); + + if (n >= NUM_QUANT_TBLS) + ERREXIT1(cinfo, JERR_DQT_INDEX, n); + + if (cinfo->quant_tbl_ptrs[n] == NULL) + cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo); + quant_ptr = cinfo->quant_tbl_ptrs[n]; + + for (i = 0; i < DCTSIZE2; i++) { + if (prec) + INPUT_2BYTES(cinfo, tmp, return FALSE); + else + INPUT_BYTE(cinfo, tmp, return FALSE); + /* We convert the zigzag-order table to natural array order. */ + quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp; + } + + if (cinfo->err->trace_level >= 2) { + for (i = 0; i < DCTSIZE2; i += 8) { + TRACEMS8(cinfo, 2, JTRC_QUANTVALS, + quant_ptr->quantval[i], quant_ptr->quantval[i+1], + quant_ptr->quantval[i+2], quant_ptr->quantval[i+3], + quant_ptr->quantval[i+4], quant_ptr->quantval[i+5], + quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]); + } + } + + length -= DCTSIZE2+1; + if (prec) length -= DCTSIZE2; + } + + if (length != 0) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + INPUT_SYNC(cinfo); + return TRUE; +} + + +LOCAL(boolean) +get_dri (j_decompress_ptr cinfo) +/* Process a DRI marker */ +{ + INT32 length; + unsigned int tmp; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + + if (length != 4) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + INPUT_2BYTES(cinfo, tmp, return FALSE); + + TRACEMS1(cinfo, 1, JTRC_DRI, tmp); + + cinfo->restart_interval = tmp; + + INPUT_SYNC(cinfo); + return TRUE; +} + + +/* + * Routines for processing APPn and COM markers. + * These are either saved in memory or discarded, per application request. + * APP0 and APP14 are specially checked to see if they are + * JFIF and Adobe markers, respectively. + */ + +#define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */ +#define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */ +#define APPN_DATA_LEN 14 /* Must be the largest of the above!! */ + + +LOCAL(void) +examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data, + unsigned int datalen, INT32 remaining) +/* Examine first few bytes from an APP0. + * Take appropriate action if it is a JFIF marker. + * datalen is # of bytes at data[], remaining is length of rest of marker data. + */ +{ + INT32 totallen = (INT32) datalen + remaining; + + if (datalen >= APP0_DATA_LEN && + GETJOCTET(data[0]) == 0x4A && + GETJOCTET(data[1]) == 0x46 && + GETJOCTET(data[2]) == 0x49 && + GETJOCTET(data[3]) == 0x46 && + GETJOCTET(data[4]) == 0) { + /* Found JFIF APP0 marker: save info */ + cinfo->saw_JFIF_marker = TRUE; + cinfo->JFIF_major_version = GETJOCTET(data[5]); + cinfo->JFIF_minor_version = GETJOCTET(data[6]); + cinfo->density_unit = GETJOCTET(data[7]); + cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]); + cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]); + /* Check version. + * Major version must be 1, anything else signals an incompatible change. + * (We used to treat this as an error, but now it's a nonfatal warning, + * because some bozo at Hijaak couldn't read the spec.) + * Minor version should be 0..2, but process anyway if newer. + */ + if (cinfo->JFIF_major_version != 1) + WARNMS2(cinfo, JWRN_JFIF_MAJOR, + cinfo->JFIF_major_version, cinfo->JFIF_minor_version); + /* Generate trace messages */ + TRACEMS5(cinfo, 1, JTRC_JFIF, + cinfo->JFIF_major_version, cinfo->JFIF_minor_version, + cinfo->X_density, cinfo->Y_density, cinfo->density_unit); + /* Validate thumbnail dimensions and issue appropriate messages */ + if (GETJOCTET(data[12]) | GETJOCTET(data[13])) + TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, + GETJOCTET(data[12]), GETJOCTET(data[13])); + totallen -= APP0_DATA_LEN; + if (totallen != + ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3)) + TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen); + } else if (datalen >= 6 && + GETJOCTET(data[0]) == 0x4A && + GETJOCTET(data[1]) == 0x46 && + GETJOCTET(data[2]) == 0x58 && + GETJOCTET(data[3]) == 0x58 && + GETJOCTET(data[4]) == 0) { + /* Found JFIF "JFXX" extension APP0 marker */ + /* The library doesn't actually do anything with these, + * but we try to produce a helpful trace message. + */ + switch (GETJOCTET(data[5])) { + case 0x10: + TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen); + break; + case 0x11: + TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen); + break; + case 0x13: + TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen); + break; + default: + TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, + GETJOCTET(data[5]), (int) totallen); + break; + } + } else { + /* Start of APP0 does not match "JFIF" or "JFXX", or too short */ + TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen); + } +} + + +LOCAL(void) +examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data, + unsigned int datalen, INT32 remaining) +/* Examine first few bytes from an APP14. + * Take appropriate action if it is an Adobe marker. + * datalen is # of bytes at data[], remaining is length of rest of marker data. + */ +{ + unsigned int version, flags0, flags1, transform; + + if (datalen >= APP14_DATA_LEN && + GETJOCTET(data[0]) == 0x41 && + GETJOCTET(data[1]) == 0x64 && + GETJOCTET(data[2]) == 0x6F && + GETJOCTET(data[3]) == 0x62 && + GETJOCTET(data[4]) == 0x65) { + /* Found Adobe APP14 marker */ + version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]); + flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]); + flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]); + transform = GETJOCTET(data[11]); + TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform); + cinfo->saw_Adobe_marker = TRUE; + cinfo->Adobe_transform = (UINT8) transform; + } else { + /* Start of APP14 does not match "Adobe", or too short */ + TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining)); + } +} + + +METHODDEF(boolean) +get_interesting_appn (j_decompress_ptr cinfo) +/* Process an APP0 or APP14 marker without saving it */ +{ + INT32 length; + JOCTET b[APPN_DATA_LEN]; + unsigned int i, numtoread; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + /* get the interesting part of the marker data */ + if (length >= APPN_DATA_LEN) + numtoread = APPN_DATA_LEN; + else if (length > 0) + numtoread = (unsigned int) length; + else + numtoread = 0; + for (i = 0; i < numtoread; i++) + INPUT_BYTE(cinfo, b[i], return FALSE); + length -= numtoread; + + /* process it */ + switch (cinfo->unread_marker) { + case M_APP0: + examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length); + break; + case M_APP14: + examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length); + break; + default: + /* can't get here unless jpeg_save_markers chooses wrong processor */ + ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker); + break; + } + + /* skip any remaining data -- could be lots */ + INPUT_SYNC(cinfo); + if (length > 0) + (*cinfo->src->skip_input_data) (cinfo, (long) length); + + return TRUE; +} + + +#ifdef SAVE_MARKERS_SUPPORTED + +METHODDEF(boolean) +save_marker (j_decompress_ptr cinfo) +/* Save an APPn or COM marker into the marker list */ +{ + my_marker_ptr marker = (my_marker_ptr) cinfo->marker; + jpeg_saved_marker_ptr cur_marker = marker->cur_marker; + unsigned int bytes_read, data_length; + JOCTET FAR * data; + INT32 length = 0; + INPUT_VARS(cinfo); + + if (cur_marker == NULL) { + /* begin reading a marker */ + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + if (length >= 0) { /* watch out for bogus length word */ + /* figure out how much we want to save */ + unsigned int limit; + if (cinfo->unread_marker == (int) M_COM) + limit = marker->length_limit_COM; + else + limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0]; + if ((unsigned int) length < limit) + limit = (unsigned int) length; + /* allocate and initialize the marker item */ + cur_marker = (jpeg_saved_marker_ptr) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(struct jpeg_marker_struct) + limit); + cur_marker->next = NULL; + cur_marker->marker = (UINT8) cinfo->unread_marker; + cur_marker->original_length = (unsigned int) length; + cur_marker->data_length = limit; + /* data area is just beyond the jpeg_marker_struct */ + data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1); + marker->cur_marker = cur_marker; + marker->bytes_read = 0; + bytes_read = 0; + data_length = limit; + } else { + /* deal with bogus length word */ + bytes_read = data_length = 0; + data = NULL; + } + } else { + /* resume reading a marker */ + bytes_read = marker->bytes_read; + data_length = cur_marker->data_length; + data = cur_marker->data + bytes_read; + } + + while (bytes_read < data_length) { + INPUT_SYNC(cinfo); /* move the restart point to here */ + marker->bytes_read = bytes_read; + /* If there's not at least one byte in buffer, suspend */ + MAKE_BYTE_AVAIL(cinfo, return FALSE); + /* Copy bytes with reasonable rapidity */ + while (bytes_read < data_length && bytes_in_buffer > 0) { + *data++ = *next_input_byte++; + bytes_in_buffer--; + bytes_read++; + } + } + + /* Done reading what we want to read */ + if (cur_marker != NULL) { /* will be NULL if bogus length word */ + /* Add new marker to end of list */ + if (cinfo->marker_list == NULL) { + cinfo->marker_list = cur_marker; + } else { + jpeg_saved_marker_ptr prev = cinfo->marker_list; + while (prev->next != NULL) + prev = prev->next; + prev->next = cur_marker; + } + /* Reset pointer & calc remaining data length */ + data = cur_marker->data; + length = cur_marker->original_length - data_length; + } + /* Reset to initial state for next marker */ + marker->cur_marker = NULL; + + /* Process the marker if interesting; else just make a generic trace msg */ + switch (cinfo->unread_marker) { + case M_APP0: + examine_app0(cinfo, data, data_length, length); + break; + case M_APP14: + examine_app14(cinfo, data, data_length, length); + break; + default: + TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, + (int) (data_length + length)); + break; + } + + /* skip any remaining data -- could be lots */ + INPUT_SYNC(cinfo); /* do before skip_input_data */ + if (length > 0) + (*cinfo->src->skip_input_data) (cinfo, (long) length); + + return TRUE; +} + +#endif /* SAVE_MARKERS_SUPPORTED */ + + +METHODDEF(boolean) +skip_variable (j_decompress_ptr cinfo) +/* Skip over an unknown or uninteresting variable-length marker */ +{ + INT32 length; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length); + + INPUT_SYNC(cinfo); /* do before skip_input_data */ + if (length > 0) + (*cinfo->src->skip_input_data) (cinfo, (long) length); + + return TRUE; +} + + +/* + * Find the next JPEG marker, save it in cinfo->unread_marker. + * Returns FALSE if had to suspend before reaching a marker; + * in that case cinfo->unread_marker is unchanged. + * + * Note that the result might not be a valid marker code, + * but it will never be 0 or FF. + */ + +LOCAL(boolean) +next_marker (j_decompress_ptr cinfo) +{ + int c; + INPUT_VARS(cinfo); + + for (;;) { + INPUT_BYTE(cinfo, c, return FALSE); + /* Skip any non-FF bytes. + * This may look a bit inefficient, but it will not occur in a valid file. + * We sync after each discarded byte so that a suspending data source + * can discard the byte from its buffer. + */ + while (c != 0xFF) { + cinfo->marker->discarded_bytes++; + INPUT_SYNC(cinfo); + INPUT_BYTE(cinfo, c, return FALSE); + } + /* This loop swallows any duplicate FF bytes. Extra FFs are legal as + * pad bytes, so don't count them in discarded_bytes. We assume there + * will not be so many consecutive FF bytes as to overflow a suspending + * data source's input buffer. + */ + do { + INPUT_BYTE(cinfo, c, return FALSE); + } while (c == 0xFF); + if (c != 0) + break; /* found a valid marker, exit loop */ + /* Reach here if we found a stuffed-zero data sequence (FF/00). + * Discard it and loop back to try again. + */ + cinfo->marker->discarded_bytes += 2; + INPUT_SYNC(cinfo); + } + + if (cinfo->marker->discarded_bytes != 0) { + WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c); + cinfo->marker->discarded_bytes = 0; + } + + cinfo->unread_marker = c; + + INPUT_SYNC(cinfo); + return TRUE; +} + + +LOCAL(boolean) +first_marker (j_decompress_ptr cinfo) +/* Like next_marker, but used to obtain the initial SOI marker. */ +/* For this marker, we do not allow preceding garbage or fill; otherwise, + * we might well scan an entire input file before realizing it ain't JPEG. + * If an application wants to process non-JFIF files, it must seek to the + * SOI before calling the JPEG library. + */ +{ + int c, c2; + INPUT_VARS(cinfo); + + INPUT_BYTE(cinfo, c, return FALSE); + INPUT_BYTE(cinfo, c2, return FALSE); + if (c != 0xFF || c2 != (int) M_SOI) + ERREXIT2(cinfo, JERR_NO_SOI, c, c2); + + cinfo->unread_marker = c2; + + INPUT_SYNC(cinfo); + return TRUE; +} + + +/* + * Read markers until SOS or EOI. + * + * Returns same codes as are defined for jpeg_consume_input: + * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. + */ + +METHODDEF(int) +read_markers (j_decompress_ptr cinfo) +{ + /* Outer loop repeats once for each marker. */ + for (;;) { + /* Collect the marker proper, unless we already did. */ + /* NB: first_marker() enforces the requirement that SOI appear first. */ + if (cinfo->unread_marker == 0) { + if (! cinfo->marker->saw_SOI) { + if (! first_marker(cinfo)) + return JPEG_SUSPENDED; + } else { + if (! next_marker(cinfo)) + return JPEG_SUSPENDED; + } + } + /* At this point cinfo->unread_marker contains the marker code and the + * input point is just past the marker proper, but before any parameters. + * A suspension will cause us to return with this state still true. + */ + switch (cinfo->unread_marker) { + case M_SOI: + if (! get_soi(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_SOF0: /* Baseline */ + case M_SOF1: /* Extended sequential, Huffman */ + if (! get_sof(cinfo, FALSE, FALSE)) + return JPEG_SUSPENDED; + break; + + case M_SOF2: /* Progressive, Huffman */ + if (! get_sof(cinfo, TRUE, FALSE)) + return JPEG_SUSPENDED; + break; + + case M_SOF9: /* Extended sequential, arithmetic */ + if (! get_sof(cinfo, FALSE, TRUE)) + return JPEG_SUSPENDED; + break; + + case M_SOF10: /* Progressive, arithmetic */ + if (! get_sof(cinfo, TRUE, TRUE)) + return JPEG_SUSPENDED; + break; + + /* Currently unsupported SOFn types */ + case M_SOF3: /* Lossless, Huffman */ + case M_SOF5: /* Differential sequential, Huffman */ + case M_SOF6: /* Differential progressive, Huffman */ + case M_SOF7: /* Differential lossless, Huffman */ + case M_JPG: /* Reserved for JPEG extensions */ + case M_SOF11: /* Lossless, arithmetic */ + case M_SOF13: /* Differential sequential, arithmetic */ + case M_SOF14: /* Differential progressive, arithmetic */ + case M_SOF15: /* Differential lossless, arithmetic */ + ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker); + break; + + case M_SOS: + if (! get_sos(cinfo)) + return JPEG_SUSPENDED; + cinfo->unread_marker = 0; /* processed the marker */ + return JPEG_REACHED_SOS; + + case M_EOI: + TRACEMS(cinfo, 1, JTRC_EOI); + cinfo->unread_marker = 0; /* processed the marker */ + return JPEG_REACHED_EOI; + + case M_DAC: + if (! get_dac(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_DHT: + if (! get_dht(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_DQT: + if (! get_dqt(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_DRI: + if (! get_dri(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_APP0: + case M_APP1: + case M_APP2: + case M_APP3: + case M_APP4: + case M_APP5: + case M_APP6: + case M_APP7: + case M_APP8: + case M_APP9: + case M_APP10: + case M_APP11: + case M_APP12: + case M_APP13: + case M_APP14: + case M_APP15: + if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[ + cinfo->unread_marker - (int) M_APP0]) (cinfo)) + return JPEG_SUSPENDED; + break; + + case M_COM: + if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo)) + return JPEG_SUSPENDED; + break; + + case M_RST0: /* these are all parameterless */ + case M_RST1: + case M_RST2: + case M_RST3: + case M_RST4: + case M_RST5: + case M_RST6: + case M_RST7: + case M_TEM: + TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker); + break; + + case M_DNL: /* Ignore DNL ... perhaps the wrong thing */ + if (! skip_variable(cinfo)) + return JPEG_SUSPENDED; + break; + + default: /* must be DHP, EXP, JPGn, or RESn */ + /* For now, we treat the reserved markers as fatal errors since they are + * likely to be used to signal incompatible JPEG Part 3 extensions. + * Once the JPEG 3 version-number marker is well defined, this code + * ought to change! + */ + ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker); + break; + } + /* Successfully processed marker, so reset state variable */ + cinfo->unread_marker = 0; + } /* end loop */ +} + + +/* + * Read a restart marker, which is expected to appear next in the datastream; + * if the marker is not there, take appropriate recovery action. + * Returns FALSE if suspension is required. + * + * This is called by the entropy decoder after it has read an appropriate + * number of MCUs. cinfo->unread_marker may be nonzero if the entropy decoder + * has already read a marker from the data source. Under normal conditions + * cinfo->unread_marker will be reset to 0 before returning; if not reset, + * it holds a marker which the decoder will be unable to read past. + */ + +METHODDEF(boolean) +read_restart_marker (j_decompress_ptr cinfo) +{ + /* Obtain a marker unless we already did. */ + /* Note that next_marker will complain if it skips any data. */ + if (cinfo->unread_marker == 0) { + if (! next_marker(cinfo)) + return FALSE; + } + + if (cinfo->unread_marker == + ((int) M_RST0 + cinfo->marker->next_restart_num)) { + /* Normal case --- swallow the marker and let entropy decoder continue */ + TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num); + cinfo->unread_marker = 0; + } else { + /* Uh-oh, the restart markers have been messed up. */ + /* Let the data source manager determine how to resync. */ + if (! (*cinfo->src->resync_to_restart) (cinfo, + cinfo->marker->next_restart_num)) + return FALSE; + } + + /* Update next-restart state */ + cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7; + + return TRUE; +} + + +/* + * This is the default resync_to_restart method for data source managers + * to use if they don't have any better approach. Some data source managers + * may be able to back up, or may have additional knowledge about the data + * which permits a more intelligent recovery strategy; such managers would + * presumably supply their own resync method. + * + * read_restart_marker calls resync_to_restart if it finds a marker other than + * the restart marker it was expecting. (This code is *not* used unless + * a nonzero restart interval has been declared.) cinfo->unread_marker is + * the marker code actually found (might be anything, except 0 or FF). + * The desired restart marker number (0..7) is passed as a parameter. + * This routine is supposed to apply whatever error recovery strategy seems + * appropriate in order to position the input stream to the next data segment. + * Note that cinfo->unread_marker is treated as a marker appearing before + * the current data-source input point; usually it should be reset to zero + * before returning. + * Returns FALSE if suspension is required. + * + * This implementation is substantially constrained by wanting to treat the + * input as a data stream; this means we can't back up. Therefore, we have + * only the following actions to work with: + * 1. Simply discard the marker and let the entropy decoder resume at next + * byte of file. + * 2. Read forward until we find another marker, discarding intervening + * data. (In theory we could look ahead within the current bufferload, + * without having to discard data if we don't find the desired marker. + * This idea is not implemented here, in part because it makes behavior + * dependent on buffer size and chance buffer-boundary positions.) + * 3. Leave the marker unread (by failing to zero cinfo->unread_marker). + * This will cause the entropy decoder to process an empty data segment, + * inserting dummy zeroes, and then we will reprocess the marker. + * + * #2 is appropriate if we think the desired marker lies ahead, while #3 is + * appropriate if the found marker is a future restart marker (indicating + * that we have missed the desired restart marker, probably because it got + * corrupted). + * We apply #2 or #3 if the found marker is a restart marker no more than + * two counts behind or ahead of the expected one. We also apply #2 if the + * found marker is not a legal JPEG marker code (it's certainly bogus data). + * If the found marker is a restart marker more than 2 counts away, we do #1 + * (too much risk that the marker is erroneous; with luck we will be able to + * resync at some future point). + * For any valid non-restart JPEG marker, we apply #3. This keeps us from + * overrunning the end of a scan. An implementation limited to single-scan + * files might find it better to apply #2 for markers other than EOI, since + * any other marker would have to be bogus data in that case. + */ + +GLOBAL(boolean) +jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired) +{ + int marker = cinfo->unread_marker; + int action = 1; + + /* Always put up a warning. */ + WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired); + + /* Outer loop handles repeated decision after scanning forward. */ + for (;;) { + if (marker < (int) M_SOF0) + action = 2; /* invalid marker */ + else if (marker < (int) M_RST0 || marker > (int) M_RST7) + action = 3; /* valid non-restart marker */ + else { + if (marker == ((int) M_RST0 + ((desired+1) & 7)) || + marker == ((int) M_RST0 + ((desired+2) & 7))) + action = 3; /* one of the next two expected restarts */ + else if (marker == ((int) M_RST0 + ((desired-1) & 7)) || + marker == ((int) M_RST0 + ((desired-2) & 7))) + action = 2; /* a prior restart, so advance */ + else + action = 1; /* desired restart or too far away */ + } + TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action); + switch (action) { + case 1: + /* Discard marker and let entropy decoder resume processing. */ + cinfo->unread_marker = 0; + return TRUE; + case 2: + /* Scan to the next marker, and repeat the decision loop. */ + if (! next_marker(cinfo)) + return FALSE; + marker = cinfo->unread_marker; + break; + case 3: + /* Return without advancing past this marker. */ + /* Entropy decoder will be forced to process an empty segment. */ + return TRUE; + } + } /* end loop */ +} + + +/* + * Reset marker processing state to begin a fresh datastream. + */ + +METHODDEF(void) +reset_marker_reader (j_decompress_ptr cinfo) +{ + my_marker_ptr marker = (my_marker_ptr) cinfo->marker; + + cinfo->comp_info = NULL; /* until allocated by get_sof */ + cinfo->input_scan_number = 0; /* no SOS seen yet */ + cinfo->unread_marker = 0; /* no pending marker */ + marker->pub.saw_SOI = FALSE; /* set internal state too */ + marker->pub.saw_SOF = FALSE; + marker->pub.discarded_bytes = 0; + marker->cur_marker = NULL; +} + + +/* + * Initialize the marker reader module. + * This is called only once, when the decompression object is created. + */ + +GLOBAL(void) +jinit_marker_reader (j_decompress_ptr cinfo) +{ + my_marker_ptr marker; + int i; + + /* Create subobject in permanent pool */ + marker = (my_marker_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_marker_reader)); + cinfo->marker = (struct jpeg_marker_reader *) marker; + /* Initialize public method pointers */ + marker->pub.reset_marker_reader = reset_marker_reader; + marker->pub.read_markers = read_markers; + marker->pub.read_restart_marker = read_restart_marker; + /* Initialize COM/APPn processing. + * By default, we examine and then discard APP0 and APP14, + * but simply discard COM and all other APPn. + */ + marker->process_COM = skip_variable; + marker->length_limit_COM = 0; + for (i = 0; i < 16; i++) { + marker->process_APPn[i] = skip_variable; + marker->length_limit_APPn[i] = 0; + } + marker->process_APPn[0] = get_interesting_appn; + marker->process_APPn[14] = get_interesting_appn; + /* Reset marker processing state */ + reset_marker_reader(cinfo); +} + + +/* + * Control saving of COM and APPn markers into marker_list. + */ + +#ifdef SAVE_MARKERS_SUPPORTED + +GLOBAL(void) +jpeg_save_markers (j_decompress_ptr cinfo, int marker_code, + unsigned int length_limit) +{ + my_marker_ptr marker = (my_marker_ptr) cinfo->marker; + long maxlength; + jpeg_marker_parser_method processor; + + /* Length limit mustn't be larger than what we can allocate + * (should only be a concern in a 16-bit environment). + */ + maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct); + if (((long) length_limit) > maxlength) + length_limit = (unsigned int) maxlength; + + /* Choose processor routine to use. + * APP0/APP14 have special requirements. + */ + if (length_limit) { + processor = save_marker; + /* If saving APP0/APP14, save at least enough for our internal use. */ + if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN) + length_limit = APP0_DATA_LEN; + else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN) + length_limit = APP14_DATA_LEN; + } else { + processor = skip_variable; + /* If discarding APP0/APP14, use our regular on-the-fly processor. */ + if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14) + processor = get_interesting_appn; + } + + if (marker_code == (int) M_COM) { + marker->process_COM = processor; + marker->length_limit_COM = length_limit; + } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) { + marker->process_APPn[marker_code - (int) M_APP0] = processor; + marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit; + } else + ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code); +} + +#endif /* SAVE_MARKERS_SUPPORTED */ + + +/* + * Install a special processing method for COM or APPn markers. + */ + +GLOBAL(void) +jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code, + jpeg_marker_parser_method routine) +{ + my_marker_ptr marker = (my_marker_ptr) cinfo->marker; + + if (marker_code == (int) M_COM) + marker->process_COM = routine; + else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) + marker->process_APPn[marker_code - (int) M_APP0] = routine; + else + ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code); +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdmaster.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdmaster.c new file mode 100755 index 0000000..225e825 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdmaster.c @@ -0,0 +1,732 @@ +/* + * jdmaster.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Modified 2002-2009 by Guido Vollbeding. + * Copyright (C) 2009-2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains master control logic for the JPEG decompressor. + * These routines are concerned with selecting the modules to be executed + * and with determining the number of passes and the work to be done in each + * pass. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jpegcomp.h" + + +/* Private state */ + +typedef struct { + struct jpeg_decomp_master pub; /* public fields */ + + int pass_number; /* # of passes completed */ + + boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */ + + /* Saved references to initialized quantizer modules, + * in case we need to switch modes. + */ + struct jpeg_color_quantizer * quantizer_1pass; + struct jpeg_color_quantizer * quantizer_2pass; +} my_decomp_master; + +typedef my_decomp_master * my_master_ptr; + + +/* + * Determine whether merged upsample/color conversion should be used. + * CRUCIAL: this must match the actual capabilities of jdmerge.c! + */ + +LOCAL(boolean) +use_merged_upsample (j_decompress_ptr cinfo) +{ +#ifdef UPSAMPLE_MERGING_SUPPORTED + /* Merging is the equivalent of plain box-filter upsampling */ + if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling) + return FALSE; + /* jdmerge.c only supports YCC=>RGB color conversion */ + if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 || + (cinfo->out_color_space != JCS_RGB && + cinfo->out_color_space != JCS_EXT_RGB && + cinfo->out_color_space != JCS_EXT_RGBX && + cinfo->out_color_space != JCS_EXT_BGR && + cinfo->out_color_space != JCS_EXT_BGRX && + cinfo->out_color_space != JCS_EXT_XBGR && + cinfo->out_color_space != JCS_EXT_XRGB && + cinfo->out_color_space != JCS_EXT_RGBA && + cinfo->out_color_space != JCS_EXT_BGRA && + cinfo->out_color_space != JCS_EXT_ABGR && + cinfo->out_color_space != JCS_EXT_ARGB) || + cinfo->out_color_components != rgb_pixelsize[cinfo->out_color_space]) + return FALSE; + /* and it only handles 2h1v or 2h2v sampling ratios */ + if (cinfo->comp_info[0].h_samp_factor != 2 || + cinfo->comp_info[1].h_samp_factor != 1 || + cinfo->comp_info[2].h_samp_factor != 1 || + cinfo->comp_info[0].v_samp_factor > 2 || + cinfo->comp_info[1].v_samp_factor != 1 || + cinfo->comp_info[2].v_samp_factor != 1) + return FALSE; + /* furthermore, it doesn't work if we've scaled the IDCTs differently */ + if (cinfo->comp_info[0]._DCT_scaled_size != cinfo->_min_DCT_scaled_size || + cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size || + cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size) + return FALSE; + /* ??? also need to test for upsample-time rescaling, when & if supported */ + return TRUE; /* by golly, it'll work... */ +#else + return FALSE; +#endif +} + + +/* + * Compute output image dimensions and related values. + * NOTE: this is exported for possible use by application. + * Hence it mustn't do anything that can't be done twice. + */ + +#if JPEG_LIB_VERSION >= 80 +GLOBAL(void) +#else +LOCAL(void) +#endif +jpeg_core_output_dimensions (j_decompress_ptr cinfo) +/* Do computations that are needed before master selection phase. + * This function is used for transcoding and full decompression. + */ +{ +#ifdef IDCT_SCALING_SUPPORTED + int ci; + jpeg_component_info *compptr; + + /* Compute actual output image dimensions and DCT scaling choices. */ + if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) { + /* Provide 1/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 1; + cinfo->_min_DCT_v_scaled_size = 1; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) { + /* Provide 2/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 2L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 2L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 2; + cinfo->_min_DCT_v_scaled_size = 2; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) { + /* Provide 3/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 3L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 3L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 3; + cinfo->_min_DCT_v_scaled_size = 3; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) { + /* Provide 4/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 4L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 4L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 4; + cinfo->_min_DCT_v_scaled_size = 4; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) { + /* Provide 5/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 5L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 5L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 5; + cinfo->_min_DCT_v_scaled_size = 5; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) { + /* Provide 6/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 6L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 6L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 6; + cinfo->_min_DCT_v_scaled_size = 6; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) { + /* Provide 7/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 7L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 7L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 7; + cinfo->_min_DCT_v_scaled_size = 7; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) { + /* Provide 8/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 8L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 8L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 8; + cinfo->_min_DCT_v_scaled_size = 8; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) { + /* Provide 9/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 9L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 9L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 9; + cinfo->_min_DCT_v_scaled_size = 9; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) { + /* Provide 10/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 10L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 10L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 10; + cinfo->_min_DCT_v_scaled_size = 10; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) { + /* Provide 11/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 11L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 11L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 11; + cinfo->_min_DCT_v_scaled_size = 11; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) { + /* Provide 12/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 12L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 12L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 12; + cinfo->_min_DCT_v_scaled_size = 12; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) { + /* Provide 13/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 13L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 13L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 13; + cinfo->_min_DCT_v_scaled_size = 13; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) { + /* Provide 14/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 14L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 14L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 14; + cinfo->_min_DCT_v_scaled_size = 14; + } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) { + /* Provide 15/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 15L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 15L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 15; + cinfo->_min_DCT_v_scaled_size = 15; + } else { + /* Provide 16/block_size scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * 16L, (long) DCTSIZE); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * 16L, (long) DCTSIZE); + cinfo->_min_DCT_h_scaled_size = 16; + cinfo->_min_DCT_v_scaled_size = 16; + } + + /* Recompute dimensions of components */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + compptr->_DCT_h_scaled_size = cinfo->_min_DCT_h_scaled_size; + compptr->_DCT_v_scaled_size = cinfo->_min_DCT_v_scaled_size; + } + +#else /* !IDCT_SCALING_SUPPORTED */ + + /* Hardwire it to "no scaling" */ + cinfo->output_width = cinfo->image_width; + cinfo->output_height = cinfo->image_height; + /* jdinput.c has already initialized DCT_scaled_size, + * and has computed unscaled downsampled_width and downsampled_height. + */ + +#endif /* IDCT_SCALING_SUPPORTED */ +} + + +/* + * Compute output image dimensions and related values. + * NOTE: this is exported for possible use by application. + * Hence it mustn't do anything that can't be done twice. + * Also note that it may be called before the master module is initialized! + */ + +GLOBAL(void) +jpeg_calc_output_dimensions (j_decompress_ptr cinfo) +/* Do computations that are needed before master selection phase */ +{ +#ifdef IDCT_SCALING_SUPPORTED + int ci; + jpeg_component_info *compptr; +#endif + + /* Prevent application from calling me at wrong times */ + if (cinfo->global_state != DSTATE_READY) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* Compute core output image dimensions and DCT scaling choices. */ + jpeg_core_output_dimensions(cinfo); + +#ifdef IDCT_SCALING_SUPPORTED + + /* In selecting the actual DCT scaling for each component, we try to + * scale up the chroma components via IDCT scaling rather than upsampling. + * This saves time if the upsampler gets to use 1:1 scaling. + * Note this code adapts subsampling ratios which are powers of 2. + */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + int ssize = cinfo->_min_DCT_scaled_size; + while (ssize < DCTSIZE && + ((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) % + (compptr->h_samp_factor * ssize * 2) == 0) && + ((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) % + (compptr->v_samp_factor * ssize * 2) == 0)) { + ssize = ssize * 2; + } +#if JPEG_LIB_VERSION >= 70 + compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize; +#else + compptr->DCT_scaled_size = ssize; +#endif + } + + /* Recompute downsampled dimensions of components; + * application needs to know these if using raw downsampled data. + */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Size in samples, after IDCT scaling */ + compptr->downsampled_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * + (long) (compptr->h_samp_factor * compptr->_DCT_scaled_size), + (long) (cinfo->max_h_samp_factor * DCTSIZE)); + compptr->downsampled_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * + (long) (compptr->v_samp_factor * compptr->_DCT_scaled_size), + (long) (cinfo->max_v_samp_factor * DCTSIZE)); + } + +#else /* !IDCT_SCALING_SUPPORTED */ + + /* Hardwire it to "no scaling" */ + cinfo->output_width = cinfo->image_width; + cinfo->output_height = cinfo->image_height; + /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE, + * and has computed unscaled downsampled_width and downsampled_height. + */ + +#endif /* IDCT_SCALING_SUPPORTED */ + + /* Report number of components in selected colorspace. */ + /* Probably this should be in the color conversion module... */ + switch (cinfo->out_color_space) { + case JCS_GRAYSCALE: + cinfo->out_color_components = 1; + break; + case JCS_RGB: + case JCS_EXT_RGB: + case JCS_EXT_RGBX: + case JCS_EXT_BGR: + case JCS_EXT_BGRX: + case JCS_EXT_XBGR: + case JCS_EXT_XRGB: + case JCS_EXT_RGBA: + case JCS_EXT_BGRA: + case JCS_EXT_ABGR: + case JCS_EXT_ARGB: + cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space]; + break; + case JCS_YCbCr: + cinfo->out_color_components = 3; + break; + case JCS_CMYK: + case JCS_YCCK: + cinfo->out_color_components = 4; + break; + default: /* else must be same colorspace as in file */ + cinfo->out_color_components = cinfo->num_components; + break; + } + cinfo->output_components = (cinfo->quantize_colors ? 1 : + cinfo->out_color_components); + + /* See if upsampler will want to emit more than one row at a time */ + if (use_merged_upsample(cinfo)) + cinfo->rec_outbuf_height = cinfo->max_v_samp_factor; + else + cinfo->rec_outbuf_height = 1; +} + + +/* + * Several decompression processes need to range-limit values to the range + * 0..MAXJSAMPLE; the input value may fall somewhat outside this range + * due to noise introduced by quantization, roundoff error, etc. These + * processes are inner loops and need to be as fast as possible. On most + * machines, particularly CPUs with pipelines or instruction prefetch, + * a (subscript-check-less) C table lookup + * x = sample_range_limit[x]; + * is faster than explicit tests + * if (x < 0) x = 0; + * else if (x > MAXJSAMPLE) x = MAXJSAMPLE; + * These processes all use a common table prepared by the routine below. + * + * For most steps we can mathematically guarantee that the initial value + * of x is within MAXJSAMPLE+1 of the legal range, so a table running from + * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial + * limiting step (just after the IDCT), a wildly out-of-range value is + * possible if the input data is corrupt. To avoid any chance of indexing + * off the end of memory and getting a bad-pointer trap, we perform the + * post-IDCT limiting thus: + * x = range_limit[x & MASK]; + * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit + * samples. Under normal circumstances this is more than enough range and + * a correct output will be generated; with bogus input data the mask will + * cause wraparound, and we will safely generate a bogus-but-in-range output. + * For the post-IDCT step, we want to convert the data from signed to unsigned + * representation by adding CENTERJSAMPLE at the same time that we limit it. + * So the post-IDCT limiting table ends up looking like this: + * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE, + * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), + * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), + * 0,1,...,CENTERJSAMPLE-1 + * Negative inputs select values from the upper half of the table after + * masking. + * + * We can save some space by overlapping the start of the post-IDCT table + * with the simpler range limiting table. The post-IDCT table begins at + * sample_range_limit + CENTERJSAMPLE. + * + * Note that the table is allocated in near data space on PCs; it's small + * enough and used often enough to justify this. + */ + +LOCAL(void) +prepare_range_limit_table (j_decompress_ptr cinfo) +/* Allocate and fill in the sample_range_limit table */ +{ + JSAMPLE * table; + int i; + + table = (JSAMPLE *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE)); + table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */ + cinfo->sample_range_limit = table; + /* First segment of "simple" table: limit[x] = 0 for x < 0 */ + MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE)); + /* Main part of "simple" table: limit[x] = x */ + for (i = 0; i <= MAXJSAMPLE; i++) + table[i] = (JSAMPLE) i; + table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ + /* End of simple table, rest of first half of post-IDCT table */ + for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) + table[i] = MAXJSAMPLE; + /* Second half of post-IDCT table */ + MEMZERO(table + (2 * (MAXJSAMPLE+1)), + (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE)); + MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), + cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE)); +} + + +/* + * Master selection of decompression modules. + * This is done once at jpeg_start_decompress time. We determine + * which modules will be used and give them appropriate initialization calls. + * We also initialize the decompressor input side to begin consuming data. + * + * Since jpeg_read_header has finished, we know what is in the SOF + * and (first) SOS markers. We also have all the application parameter + * settings. + */ + +LOCAL(void) +master_selection (j_decompress_ptr cinfo) +{ + my_master_ptr master = (my_master_ptr) cinfo->master; + boolean use_c_buffer; + long samplesperrow; + JDIMENSION jd_samplesperrow; + + /* Initialize dimensions and other stuff */ + jpeg_calc_output_dimensions(cinfo); + prepare_range_limit_table(cinfo); + + /* Width of an output scanline must be representable as JDIMENSION. */ + samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components; + jd_samplesperrow = (JDIMENSION) samplesperrow; + if ((long) jd_samplesperrow != samplesperrow) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + + /* Initialize my private state */ + master->pass_number = 0; + master->using_merged_upsample = use_merged_upsample(cinfo); + + /* Color quantizer selection */ + master->quantizer_1pass = NULL; + master->quantizer_2pass = NULL; + /* No mode changes if not using buffered-image mode. */ + if (! cinfo->quantize_colors || ! cinfo->buffered_image) { + cinfo->enable_1pass_quant = FALSE; + cinfo->enable_external_quant = FALSE; + cinfo->enable_2pass_quant = FALSE; + } + if (cinfo->quantize_colors) { + if (cinfo->raw_data_out) + ERREXIT(cinfo, JERR_NOTIMPL); + /* 2-pass quantizer only works in 3-component color space. */ + if (cinfo->out_color_components != 3) { + cinfo->enable_1pass_quant = TRUE; + cinfo->enable_external_quant = FALSE; + cinfo->enable_2pass_quant = FALSE; + cinfo->colormap = NULL; + } else if (cinfo->colormap != NULL) { + cinfo->enable_external_quant = TRUE; + } else if (cinfo->two_pass_quantize) { + cinfo->enable_2pass_quant = TRUE; + } else { + cinfo->enable_1pass_quant = TRUE; + } + + if (cinfo->enable_1pass_quant) { +#ifdef QUANT_1PASS_SUPPORTED + jinit_1pass_quantizer(cinfo); + master->quantizer_1pass = cinfo->cquantize; +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } + + /* We use the 2-pass code to map to external colormaps. */ + if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) { +#ifdef QUANT_2PASS_SUPPORTED + jinit_2pass_quantizer(cinfo); + master->quantizer_2pass = cinfo->cquantize; +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } + /* If both quantizers are initialized, the 2-pass one is left active; + * this is necessary for starting with quantization to an external map. + */ + } + + /* Post-processing: in particular, color conversion first */ + if (! cinfo->raw_data_out) { + if (master->using_merged_upsample) { +#ifdef UPSAMPLE_MERGING_SUPPORTED + jinit_merged_upsampler(cinfo); /* does color conversion too */ +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else { + jinit_color_deconverter(cinfo); + jinit_upsampler(cinfo); + } + jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); + } + /* Inverse DCT */ + jinit_inverse_dct(cinfo); + /* Entropy decoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { +#ifdef D_ARITH_CODING_SUPPORTED + jinit_arith_decoder(cinfo); +#else + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); +#endif + } else { + if (cinfo->progressive_mode) { +#ifdef D_PROGRESSIVE_SUPPORTED + jinit_phuff_decoder(cinfo); +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else + jinit_huff_decoder(cinfo); + } + + /* Initialize principal buffer controllers. */ + use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image; + jinit_d_coef_controller(cinfo, use_c_buffer); + + if (! cinfo->raw_data_out) + jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Initialize input side of decompressor to consume first scan. */ + (*cinfo->inputctl->start_input_pass) (cinfo); + +#ifdef D_MULTISCAN_FILES_SUPPORTED + /* If jpeg_start_decompress will read the whole file, initialize + * progress monitoring appropriately. The input step is counted + * as one pass. + */ + if (cinfo->progress != NULL && ! cinfo->buffered_image && + cinfo->inputctl->has_multiple_scans) { + int nscans; + /* Estimate number of scans to set pass_limit. */ + if (cinfo->progressive_mode) { + /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ + nscans = 2 + 3 * cinfo->num_components; + } else { + /* For a nonprogressive multiscan file, estimate 1 scan per component. */ + nscans = cinfo->num_components; + } + cinfo->progress->pass_counter = 0L; + cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; + cinfo->progress->completed_passes = 0; + cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2); + /* Count the input pass as done */ + master->pass_number++; + } +#endif /* D_MULTISCAN_FILES_SUPPORTED */ +} + + +/* + * Per-pass setup. + * This is called at the beginning of each output pass. We determine which + * modules will be active during this pass and give them appropriate + * start_pass calls. We also set is_dummy_pass to indicate whether this + * is a "real" output pass or a dummy pass for color quantization. + * (In the latter case, jdapistd.c will crank the pass to completion.) + */ + +METHODDEF(void) +prepare_for_output_pass (j_decompress_ptr cinfo) +{ + my_master_ptr master = (my_master_ptr) cinfo->master; + + if (master->pub.is_dummy_pass) { +#ifdef QUANT_2PASS_SUPPORTED + /* Final pass of 2-pass quantization */ + master->pub.is_dummy_pass = FALSE; + (*cinfo->cquantize->start_pass) (cinfo, FALSE); + (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST); + (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST); +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif /* QUANT_2PASS_SUPPORTED */ + } else { + if (cinfo->quantize_colors && cinfo->colormap == NULL) { + /* Select new quantization method */ + if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) { + cinfo->cquantize = master->quantizer_2pass; + master->pub.is_dummy_pass = TRUE; + } else if (cinfo->enable_1pass_quant) { + cinfo->cquantize = master->quantizer_1pass; + } else { + ERREXIT(cinfo, JERR_MODE_CHANGE); + } + } + (*cinfo->idct->start_pass) (cinfo); + (*cinfo->coef->start_output_pass) (cinfo); + if (! cinfo->raw_data_out) { + if (! master->using_merged_upsample) + (*cinfo->cconvert->start_pass) (cinfo); + (*cinfo->upsample->start_pass) (cinfo); + if (cinfo->quantize_colors) + (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass); + (*cinfo->post->start_pass) (cinfo, + (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); + (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); + } + } + + /* Set up progress monitor's pass info if present */ + if (cinfo->progress != NULL) { + cinfo->progress->completed_passes = master->pass_number; + cinfo->progress->total_passes = master->pass_number + + (master->pub.is_dummy_pass ? 2 : 1); + /* In buffered-image mode, we assume one more output pass if EOI not + * yet reached, but no more passes if EOI has been reached. + */ + if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) { + cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1); + } + } +} + + +/* + * Finish up at end of an output pass. + */ + +METHODDEF(void) +finish_output_pass (j_decompress_ptr cinfo) +{ + my_master_ptr master = (my_master_ptr) cinfo->master; + + if (cinfo->quantize_colors) + (*cinfo->cquantize->finish_pass) (cinfo); + master->pass_number++; +} + + +#ifdef D_MULTISCAN_FILES_SUPPORTED + +/* + * Switch to a new external colormap between output passes. + */ + +GLOBAL(void) +jpeg_new_colormap (j_decompress_ptr cinfo) +{ + my_master_ptr master = (my_master_ptr) cinfo->master; + + /* Prevent application from calling me at wrong times */ + if (cinfo->global_state != DSTATE_BUFIMAGE) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + if (cinfo->quantize_colors && cinfo->enable_external_quant && + cinfo->colormap != NULL) { + /* Select 2-pass quantizer for external colormap use */ + cinfo->cquantize = master->quantizer_2pass; + /* Notify quantizer of colormap change */ + (*cinfo->cquantize->new_color_map) (cinfo); + master->pub.is_dummy_pass = FALSE; /* just in case */ + } else + ERREXIT(cinfo, JERR_MODE_CHANGE); +} + +#endif /* D_MULTISCAN_FILES_SUPPORTED */ + + +/* + * Initialize master decompression control and select active modules. + * This is performed at the start of jpeg_start_decompress. + */ + +GLOBAL(void) +jinit_master_decompress (j_decompress_ptr cinfo) +{ + my_master_ptr master; + + master = (my_master_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_decomp_master)); + cinfo->master = (struct jpeg_decomp_master *) master; + master->pub.prepare_for_output_pass = prepare_for_output_pass; + master->pub.finish_output_pass = finish_output_pass; + + master->pub.is_dummy_pass = FALSE; + + master_selection(cinfo); +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdmerge.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdmerge.c new file mode 100755 index 0000000..5336125 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdmerge.c @@ -0,0 +1,463 @@ +/* + * jdmerge.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2009, 2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains code for merged upsampling/color conversion. + * + * This file combines functions from jdsample.c and jdcolor.c; + * read those files first to understand what's going on. + * + * When the chroma components are to be upsampled by simple replication + * (ie, box filtering), we can save some work in color conversion by + * calculating all the output pixels corresponding to a pair of chroma + * samples at one time. In the conversion equations + * R = Y + K1 * Cr + * G = Y + K2 * Cb + K3 * Cr + * B = Y + K4 * Cb + * only the Y term varies among the group of pixels corresponding to a pair + * of chroma samples, so the rest of the terms can be calculated just once. + * At typical sampling ratios, this eliminates half or three-quarters of the + * multiplications needed for color conversion. + * + * This file currently provides implementations for the following cases: + * YCbCr => RGB color conversion only. + * Sampling ratios of 2h1v or 2h2v. + * No scaling needed at upsample time. + * Corner-aligned (non-CCIR601) sampling alignment. + * Other special cases could be added, but in most applications these are + * the only common cases. (For uncommon cases we fall back on the more + * general code in jdsample.c and jdcolor.c.) + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jsimd.h" +#include "config.h" + +#ifdef UPSAMPLE_MERGING_SUPPORTED + + +/* Private subobject */ + +typedef struct { + struct jpeg_upsampler pub; /* public fields */ + + /* Pointer to routine to do actual upsampling/conversion of one row group */ + JMETHOD(void, upmethod, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf)); + + /* Private state for YCC->RGB conversion */ + int * Cr_r_tab; /* => table for Cr to R conversion */ + int * Cb_b_tab; /* => table for Cb to B conversion */ + INT32 * Cr_g_tab; /* => table for Cr to G conversion */ + INT32 * Cb_g_tab; /* => table for Cb to G conversion */ + + /* For 2:1 vertical sampling, we produce two output rows at a time. + * We need a "spare" row buffer to hold the second output row if the + * application provides just a one-row buffer; we also use the spare + * to discard the dummy last row if the image height is odd. + */ + JSAMPROW spare_row; + boolean spare_full; /* T if spare buffer is occupied */ + + JDIMENSION out_row_width; /* samples per output row */ + JDIMENSION rows_to_go; /* counts rows remaining in image */ +} my_upsampler; + +typedef my_upsampler * my_upsample_ptr; + +#define SCALEBITS 16 /* speediest right-shift on some machines */ +#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) +#define FIX(x) ((INT32) ((x) * (1L<RGB colorspace conversion. + * This is taken directly from jdcolor.c; see that file for more info. + */ + +LOCAL(void) +build_ycc_rgb_table (j_decompress_ptr cinfo) +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + int i; + INT32 x; + SHIFT_TEMPS + + upsample->Cr_r_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + upsample->Cb_b_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + upsample->Cr_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + upsample->Cb_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + + for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { + /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ + /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ + /* Cr=>R value is nearest int to 1.40200 * x */ + upsample->Cr_r_tab[i] = (int) + RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); + /* Cb=>B value is nearest int to 1.77200 * x */ + upsample->Cb_b_tab[i] = (int) + RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); + /* Cr=>G value is scaled-up -0.71414 * x */ + upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x; + /* Cb=>G value is scaled-up -0.34414 * x */ + /* We also add in ONE_HALF so that need not do it in inner loop */ + upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; + } +} + + +/* + * Initialize for an upsampling pass. + */ + +METHODDEF(void) +start_pass_merged_upsample (j_decompress_ptr cinfo) +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + + /* Mark the spare buffer empty */ + upsample->spare_full = FALSE; + /* Initialize total-height counter for detecting bottom of image */ + upsample->rows_to_go = cinfo->output_height; +} + + +/* + * Control routine to do upsampling (and color conversion). + * + * The control routine just handles the row buffering considerations. + */ + +METHODDEF(void) +merged_2v_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +/* 2:1 vertical sampling case: may need a spare row. */ +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + JSAMPROW work_ptrs[2]; + JDIMENSION num_rows; /* number of rows returned to caller */ + + if (upsample->spare_full) { + /* If we have a spare row saved from a previous cycle, just return it. */ + jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0, + 1, upsample->out_row_width); + num_rows = 1; + upsample->spare_full = FALSE; + } else { + /* Figure number of rows to return to caller. */ + num_rows = 2; + /* Not more than the distance to the end of the image. */ + if (num_rows > upsample->rows_to_go) + num_rows = upsample->rows_to_go; + /* And not more than what the client can accept: */ + out_rows_avail -= *out_row_ctr; + if (num_rows > out_rows_avail) + num_rows = out_rows_avail; + /* Create output pointer array for upsampler. */ + work_ptrs[0] = output_buf[*out_row_ctr]; + if (num_rows > 1) { + work_ptrs[1] = output_buf[*out_row_ctr + 1]; + } else { + work_ptrs[1] = upsample->spare_row; + upsample->spare_full = TRUE; + } + /* Now do the upsampling. */ + (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs); + } + + /* Adjust counts */ + *out_row_ctr += num_rows; + upsample->rows_to_go -= num_rows; + /* When the buffer is emptied, declare this input row group consumed */ + if (! upsample->spare_full) + (*in_row_group_ctr)++; +} + + +METHODDEF(void) +merged_1v_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +/* 1:1 vertical sampling case: much easier, never need a spare row. */ +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + + /* Just do the upsampling. */ + (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, + output_buf + *out_row_ctr); + /* Adjust counts */ + (*out_row_ctr)++; + (*in_row_group_ctr)++; +} + + +/* + * These are the routines invoked by the control routines to do + * the actual upsampling/conversion. One row group is processed per call. + * + * Note: since we may be writing directly into application-supplied buffers, + * we have to be honest about the output width; we can't assume the buffer + * has been rounded up to an even width. + */ + + +/* + * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. + */ + +METHODDEF(void) +h2v1_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + switch (cinfo->out_color_space) { + case JCS_EXT_RGB: + extrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + extrgbx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_BGR: + extbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + extbgrx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + extxbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + extxrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + default: + h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + } +} + + +/* + * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. + */ + +METHODDEF(void) +h2v2_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + switch (cinfo->out_color_space) { + case JCS_EXT_RGB: + extrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + extrgbx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_BGR: + extbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + extbgrx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + extxbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + extxrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + default: + h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, + output_buf); + break; + } +} + + +/* + * Module initialization routine for merged upsampling/color conversion. + * + * NB: this is called under the conditions determined by use_merged_upsample() + * in jdmaster.c. That routine MUST correspond to the actual capabilities + * of this module; no safety checks are made here. + */ + +GLOBAL(void) +jinit_merged_upsampler (j_decompress_ptr cinfo) +{ + my_upsample_ptr upsample; + + upsample = (my_upsample_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_upsampler)); + cinfo->upsample = (struct jpeg_upsampler *) upsample; + upsample->pub.start_pass = start_pass_merged_upsample; + upsample->pub.need_context_rows = FALSE; + + upsample->out_row_width = cinfo->output_width * cinfo->out_color_components; + + if (cinfo->max_v_samp_factor == 2) { + upsample->pub.upsample = merged_2v_upsample; + if (jsimd_can_h2v2_merged_upsample()) + upsample->upmethod = jsimd_h2v2_merged_upsample; + else + upsample->upmethod = h2v2_merged_upsample; + /* Allocate a spare row buffer */ + upsample->spare_row = (JSAMPROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE))); + } else { + upsample->pub.upsample = merged_1v_upsample; + if (jsimd_can_h2v1_merged_upsample()) + upsample->upmethod = jsimd_h2v1_merged_upsample; + else + upsample->upmethod = h2v1_merged_upsample; + /* No spare row needed */ + upsample->spare_row = NULL; + } + + build_ycc_rgb_table(cinfo); +} + +#endif /* UPSAMPLE_MERGING_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdmrgext.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdmrgext.c new file mode 100755 index 0000000..2b93265 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdmrgext.c @@ -0,0 +1,184 @@ +/* + * jdmrgext.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Copyright (C) 2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains code for merged upsampling/color conversion. + */ + + +/* This file is included by jdmerge.c */ + + +/* + * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. + */ + +INLINE +LOCAL(void) +h2v1_merged_upsample_internal (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + register int y, cred, cgreen, cblue; + int cb, cr; + register JSAMPROW outptr; + JSAMPROW inptr0, inptr1, inptr2; + JDIMENSION col; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + int * Crrtab = upsample->Cr_r_tab; + int * Cbbtab = upsample->Cb_b_tab; + INT32 * Crgtab = upsample->Cr_g_tab; + INT32 * Cbgtab = upsample->Cb_g_tab; + SHIFT_TEMPS + + inptr0 = input_buf[0][in_row_group_ctr]; + inptr1 = input_buf[1][in_row_group_ctr]; + inptr2 = input_buf[2][in_row_group_ctr]; + outptr = output_buf[0]; + /* Loop for each pair of output pixels */ + for (col = cinfo->output_width >> 1; col > 0; col--) { + /* Do the chroma part of the calculation */ + cb = GETJSAMPLE(*inptr1++); + cr = GETJSAMPLE(*inptr2++); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + /* Fetch 2 Y values and emit 2 pixels */ + y = GETJSAMPLE(*inptr0++); + outptr[RGB_RED] = range_limit[y + cred]; + outptr[RGB_GREEN] = range_limit[y + cgreen]; + outptr[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr[RGB_ALPHA] = 0xFF; +#endif + outptr += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr0++); + outptr[RGB_RED] = range_limit[y + cred]; + outptr[RGB_GREEN] = range_limit[y + cgreen]; + outptr[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr[RGB_ALPHA] = 0xFF; +#endif + outptr += RGB_PIXELSIZE; + } + /* If image width is odd, do the last output column separately */ + if (cinfo->output_width & 1) { + cb = GETJSAMPLE(*inptr1); + cr = GETJSAMPLE(*inptr2); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + y = GETJSAMPLE(*inptr0); + outptr[RGB_RED] = range_limit[y + cred]; + outptr[RGB_GREEN] = range_limit[y + cgreen]; + outptr[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr[RGB_ALPHA] = 0xFF; +#endif + } +} + + +/* + * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. + */ + +INLINE +LOCAL(void) +h2v2_merged_upsample_internal (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + register int y, cred, cgreen, cblue; + int cb, cr; + register JSAMPROW outptr0, outptr1; + JSAMPROW inptr00, inptr01, inptr1, inptr2; + JDIMENSION col; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + int * Crrtab = upsample->Cr_r_tab; + int * Cbbtab = upsample->Cb_b_tab; + INT32 * Crgtab = upsample->Cr_g_tab; + INT32 * Cbgtab = upsample->Cb_g_tab; + SHIFT_TEMPS + + inptr00 = input_buf[0][in_row_group_ctr*2]; + inptr01 = input_buf[0][in_row_group_ctr*2 + 1]; + inptr1 = input_buf[1][in_row_group_ctr]; + inptr2 = input_buf[2][in_row_group_ctr]; + outptr0 = output_buf[0]; + outptr1 = output_buf[1]; + /* Loop for each group of output pixels */ + for (col = cinfo->output_width >> 1; col > 0; col--) { + /* Do the chroma part of the calculation */ + cb = GETJSAMPLE(*inptr1++); + cr = GETJSAMPLE(*inptr2++); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + /* Fetch 4 Y values and emit 4 pixels */ + y = GETJSAMPLE(*inptr00++); + outptr0[RGB_RED] = range_limit[y + cred]; + outptr0[RGB_GREEN] = range_limit[y + cgreen]; + outptr0[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr0[RGB_ALPHA] = 0xFF; +#endif + outptr0 += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr00++); + outptr0[RGB_RED] = range_limit[y + cred]; + outptr0[RGB_GREEN] = range_limit[y + cgreen]; + outptr0[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr0[RGB_ALPHA] = 0xFF; +#endif + outptr0 += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr01++); + outptr1[RGB_RED] = range_limit[y + cred]; + outptr1[RGB_GREEN] = range_limit[y + cgreen]; + outptr1[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr1[RGB_ALPHA] = 0xFF; +#endif + outptr1 += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr01++); + outptr1[RGB_RED] = range_limit[y + cred]; + outptr1[RGB_GREEN] = range_limit[y + cgreen]; + outptr1[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr1[RGB_ALPHA] = 0xFF; +#endif + outptr1 += RGB_PIXELSIZE; + } + /* If image width is odd, do the last output column separately */ + if (cinfo->output_width & 1) { + cb = GETJSAMPLE(*inptr1); + cr = GETJSAMPLE(*inptr2); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + y = GETJSAMPLE(*inptr00); + outptr0[RGB_RED] = range_limit[y + cred]; + outptr0[RGB_GREEN] = range_limit[y + cgreen]; + outptr0[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr0[RGB_ALPHA] = 0xFF; +#endif + y = GETJSAMPLE(*inptr01); + outptr1[RGB_RED] = range_limit[y + cred]; + outptr1[RGB_GREEN] = range_limit[y + cgreen]; + outptr1[RGB_BLUE] = range_limit[y + cblue]; +#ifdef RGB_ALPHA + outptr1[RGB_ALPHA] = 0xFF; +#endif + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdphuff.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdphuff.c new file mode 100755 index 0000000..2267809 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdphuff.c @@ -0,0 +1,668 @@ +/* + * jdphuff.c + * + * Copyright (C) 1995-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy decoding routines for progressive JPEG. + * + * Much of the complexity here has to do with supporting input suspension. + * If the data source module demands suspension, we want to be able to back + * up to the start of the current MCU. To do this, we copy state variables + * into local working storage, and update them back to the permanent + * storage only upon successful completion of an MCU. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdhuff.h" /* Declarations shared with jdhuff.c */ + + +#ifdef D_PROGRESSIVE_SUPPORTED + +/* + * Expanded entropy decoder object for progressive Huffman decoding. + * + * The savable_state subrecord contains fields that change within an MCU, + * but must not be updated permanently until we complete the MCU. + */ + +typedef struct { + unsigned int EOBRUN; /* remaining EOBs in EOBRUN */ + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ +} savable_state; + +/* This macro is to work around compilers with missing or broken + * structure assignment. You'll need to fix this code if you have + * such a compiler and you change MAX_COMPS_IN_SCAN. + */ + +#ifndef NO_STRUCT_ASSIGN +#define ASSIGN_STATE(dest,src) ((dest) = (src)) +#else +#if MAX_COMPS_IN_SCAN == 4 +#define ASSIGN_STATE(dest,src) \ + ((dest).EOBRUN = (src).EOBRUN, \ + (dest).last_dc_val[0] = (src).last_dc_val[0], \ + (dest).last_dc_val[1] = (src).last_dc_val[1], \ + (dest).last_dc_val[2] = (src).last_dc_val[2], \ + (dest).last_dc_val[3] = (src).last_dc_val[3]) +#endif +#endif + + +typedef struct { + struct jpeg_entropy_decoder pub; /* public fields */ + + /* These fields are loaded into local variables at start of each MCU. + * In case of suspension, we exit WITHOUT updating them. + */ + bitread_perm_state bitstate; /* Bit buffer at start of MCU */ + savable_state saved; /* Other state at start of MCU */ + + /* These fields are NOT loaded into local working state. */ + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + + /* Pointers to derived tables (these workspaces have image lifespan) */ + d_derived_tbl * derived_tbls[NUM_HUFF_TBLS]; + + d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */ +} phuff_entropy_decoder; + +typedef phuff_entropy_decoder * phuff_entropy_ptr; + +/* Forward declarations */ +METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); +METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); + + +/* + * Initialize for a Huffman-compressed scan. + */ + +METHODDEF(void) +start_pass_phuff_decoder (j_decompress_ptr cinfo) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + boolean is_DC_band, bad; + int ci, coefi, tbl; + int *coef_bit_ptr; + jpeg_component_info * compptr; + + is_DC_band = (cinfo->Ss == 0); + + /* Validate scan parameters */ + bad = FALSE; + if (is_DC_band) { + if (cinfo->Se != 0) + bad = TRUE; + } else { + /* need not check Ss/Se < 0 since they came from unsigned bytes */ + if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2) + bad = TRUE; + /* AC scans may have only one component */ + if (cinfo->comps_in_scan != 1) + bad = TRUE; + } + if (cinfo->Ah != 0) { + /* Successive approximation refinement scan: must have Al = Ah-1. */ + if (cinfo->Al != cinfo->Ah-1) + bad = TRUE; + } + if (cinfo->Al > 13) /* need not check for < 0 */ + bad = TRUE; + /* Arguably the maximum Al value should be less than 13 for 8-bit precision, + * but the spec doesn't say so, and we try to be liberal about what we + * accept. Note: large Al values could result in out-of-range DC + * coefficients during early scans, leading to bizarre displays due to + * overflows in the IDCT math. But we won't crash. + */ + if (bad) + ERREXIT4(cinfo, JERR_BAD_PROGRESSION, + cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); + /* Update progression status, and verify that scan order is legal. + * Note that inter-scan inconsistencies are treated as warnings + * not fatal errors ... not clear if this is right way to behave. + */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + int cindex = cinfo->cur_comp_info[ci]->component_index; + coef_bit_ptr = & cinfo->coef_bits[cindex][0]; + if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ + WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); + for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { + int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; + if (cinfo->Ah != expected) + WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); + coef_bit_ptr[coefi] = cinfo->Al; + } + } + + /* Select MCU decoding routine */ + if (cinfo->Ah == 0) { + if (is_DC_band) + entropy->pub.decode_mcu = decode_mcu_DC_first; + else + entropy->pub.decode_mcu = decode_mcu_AC_first; + } else { + if (is_DC_band) + entropy->pub.decode_mcu = decode_mcu_DC_refine; + else + entropy->pub.decode_mcu = decode_mcu_AC_refine; + } + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Make sure requested tables are present, and compute derived tables. + * We may build same derived table more than once, but it's not expensive. + */ + if (is_DC_band) { + if (cinfo->Ah == 0) { /* DC refinement needs no table */ + tbl = compptr->dc_tbl_no; + jpeg_make_d_derived_tbl(cinfo, TRUE, tbl, + & entropy->derived_tbls[tbl]); + } + } else { + tbl = compptr->ac_tbl_no; + jpeg_make_d_derived_tbl(cinfo, FALSE, tbl, + & entropy->derived_tbls[tbl]); + /* remember the single active table */ + entropy->ac_derived_tbl = entropy->derived_tbls[tbl]; + } + /* Initialize DC predictions to 0 */ + entropy->saved.last_dc_val[ci] = 0; + } + + /* Initialize bitread state variables */ + entropy->bitstate.bits_left = 0; + entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ + entropy->pub.insufficient_data = FALSE; + + /* Initialize private state variables */ + entropy->saved.EOBRUN = 0; + + /* Initialize restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; +} + + +/* + * Figure F.12: extend sign bit. + * On some machines, a shift and add will be faster than a table lookup. + */ + +#ifdef AVOID_TABLES + +#define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) + +#else + +#define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) + +static const int extend_test[16] = /* entry n is 2**(n-1) */ + { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; + +static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ + { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, + ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, + ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, + ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }; + +#endif /* AVOID_TABLES */ + + +/* + * Check for a restart marker & resynchronize decoder. + * Returns FALSE if must suspend. + */ + +LOCAL(boolean) +process_restart (j_decompress_ptr cinfo) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int ci; + + /* Throw away any unused bits remaining in bit buffer; */ + /* include any full bytes in next_marker's count of discarded bytes */ + cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; + entropy->bitstate.bits_left = 0; + + /* Advance past the RSTn marker */ + if (! (*cinfo->marker->read_restart_marker) (cinfo)) + return FALSE; + + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) + entropy->saved.last_dc_val[ci] = 0; + /* Re-init EOB run count, too */ + entropy->saved.EOBRUN = 0; + + /* Reset restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; + + /* Reset out-of-data flag, unless read_restart_marker left us smack up + * against a marker. In that case we will end up treating the next data + * segment as empty, and we can avoid producing bogus output pixels by + * leaving the flag set. + */ + if (cinfo->unread_marker == 0) + entropy->pub.insufficient_data = FALSE; + + return TRUE; +} + + +/* + * Huffman MCU decoding. + * Each of these routines decodes and returns one MCU's worth of + * Huffman-compressed coefficients. + * The coefficients are reordered from zigzag order into natural array order, + * but are not dequantized. + * + * The i'th block of the MCU is stored into the block pointed to by + * MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER. + * + * We return FALSE if data source requested suspension. In that case no + * changes have been made to permanent state. (Exception: some output + * coefficients may already have been assigned. This is harmless for + * spectral selection, since we'll just re-assign them on the next call. + * Successive approximation AC refinement has to be more careful, however.) + */ + +/* + * MCU decoding for DC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int Al = cinfo->Al; + register int s, r; + int blkn, ci; + JBLOCKROW block; + BITREAD_STATE_VARS; + savable_state state; + d_derived_tbl * tbl; + jpeg_component_info * compptr; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* If we've run out of data, just leave the MCU set to zeroes. + * This way, we return uniform gray for the remainder of the segment. + */ + if (! entropy->pub.insufficient_data) { + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(state, entropy->saved); + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + tbl = entropy->derived_tbls[compptr->dc_tbl_no]; + + /* Decode a single block's worth of coefficients */ + + /* Section F.2.2.1: decode the DC coefficient difference */ + HUFF_DECODE(s, br_state, tbl, return FALSE, label1); + if (s) { + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + } + + /* Convert DC difference to actual value, update last_dc_val */ + s += state.last_dc_val[ci]; + state.last_dc_val[ci] = s; + /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */ + (*block)[0] = (JCOEF) (s << Al); + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(entropy->saved, state); + } + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; +} + + +/* + * MCU decoding for AC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + +METHODDEF(boolean) +decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int Se = cinfo->Se; + int Al = cinfo->Al; + register int s, k, r; + unsigned int EOBRUN; + JBLOCKROW block; + BITREAD_STATE_VARS; + d_derived_tbl * tbl; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* If we've run out of data, just leave the MCU set to zeroes. + * This way, we return uniform gray for the remainder of the segment. + */ + if (! entropy->pub.insufficient_data) { + + /* Load up working state. + * We can avoid loading/saving bitread state if in an EOB run. + */ + EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */ + + /* There is always only one block per MCU */ + + if (EOBRUN > 0) /* if it's a band of zeroes... */ + EOBRUN--; /* ...process it now (we do nothing) */ + else { + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + block = MCU_data[0]; + tbl = entropy->ac_derived_tbl; + + for (k = cinfo->Ss; k <= Se; k++) { + HUFF_DECODE(s, br_state, tbl, return FALSE, label2); + r = s >> 4; + s &= 15; + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + /* Scale and output coefficient in natural (dezigzagged) order */ + (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al); + } else { + if (r == 15) { /* ZRL */ + k += 15; /* skip 15 zeroes in band */ + } else { /* EOBr, run length is 2^r + appended bits */ + EOBRUN = 1 << r; + if (r) { /* EOBr, r > 0 */ + CHECK_BIT_BUFFER(br_state, r, return FALSE); + r = GET_BITS(r); + EOBRUN += r; + } + EOBRUN--; /* this band is processed at this moment */ + break; /* force end-of-band */ + } + } + } + + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + } + + /* Completed MCU, so update state */ + entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */ + } + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; +} + + +/* + * MCU decoding for DC successive approximation refinement scan. + * Note: we assume such scans can be multi-component, although the spec + * is not very clear on the point. + */ + +METHODDEF(boolean) +decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ + int blkn; + JBLOCKROW block; + BITREAD_STATE_VARS; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* Not worth the cycles to check insufficient_data here, + * since we will not change the data anyway if we read zeroes. + */ + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + + /* Encoded data is simply the next bit of the two's-complement DC value */ + CHECK_BIT_BUFFER(br_state, 1, return FALSE); + if (GET_BITS(1)) + (*block)[0] |= p1; + /* Note: since we use |=, repeating the assignment later is safe */ + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; +} + + +/* + * MCU decoding for AC successive approximation refinement scan. + */ + +METHODDEF(boolean) +decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) +{ + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int Se = cinfo->Se; + int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ + int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ + register int s, k, r; + unsigned int EOBRUN; + JBLOCKROW block; + JCOEFPTR thiscoef; + BITREAD_STATE_VARS; + d_derived_tbl * tbl; + int num_newnz; + int newnz_pos[DCTSIZE2]; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* If we've run out of data, don't modify the MCU. + */ + if (! entropy->pub.insufficient_data) { + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */ + + /* There is always only one block per MCU */ + block = MCU_data[0]; + tbl = entropy->ac_derived_tbl; + + /* If we are forced to suspend, we must undo the assignments to any newly + * nonzero coefficients in the block, because otherwise we'd get confused + * next time about which coefficients were already nonzero. + * But we need not undo addition of bits to already-nonzero coefficients; + * instead, we can test the current bit to see if we already did it. + */ + num_newnz = 0; + + /* initialize coefficient loop counter to start of band */ + k = cinfo->Ss; + + if (EOBRUN == 0) { + for (; k <= Se; k++) { + HUFF_DECODE(s, br_state, tbl, goto undoit, label3); + r = s >> 4; + s &= 15; + if (s) { + if (s != 1) /* size of new coef should always be 1 */ + WARNMS(cinfo, JWRN_HUFF_BAD_CODE); + CHECK_BIT_BUFFER(br_state, 1, goto undoit); + if (GET_BITS(1)) + s = p1; /* newly nonzero coef is positive */ + else + s = m1; /* newly nonzero coef is negative */ + } else { + if (r != 15) { + EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */ + if (r) { + CHECK_BIT_BUFFER(br_state, r, goto undoit); + r = GET_BITS(r); + EOBRUN += r; + } + break; /* rest of block is handled by EOB logic */ + } + /* note s = 0 for processing ZRL */ + } + /* Advance over already-nonzero coefs and r still-zero coefs, + * appending correction bits to the nonzeroes. A correction bit is 1 + * if the absolute value of the coefficient must be increased. + */ + do { + thiscoef = *block + jpeg_natural_order[k]; + if (*thiscoef != 0) { + CHECK_BIT_BUFFER(br_state, 1, goto undoit); + if (GET_BITS(1)) { + if ((*thiscoef & p1) == 0) { /* do nothing if already set it */ + if (*thiscoef >= 0) + *thiscoef += p1; + else + *thiscoef += m1; + } + } + } else { + if (--r < 0) + break; /* reached target zero coefficient */ + } + k++; + } while (k <= Se); + if (s) { + int pos = jpeg_natural_order[k]; + /* Output newly nonzero coefficient */ + (*block)[pos] = (JCOEF) s; + /* Remember its position in case we have to suspend */ + newnz_pos[num_newnz++] = pos; + } + } + } + + if (EOBRUN > 0) { + /* Scan any remaining coefficient positions after the end-of-band + * (the last newly nonzero coefficient, if any). Append a correction + * bit to each already-nonzero coefficient. A correction bit is 1 + * if the absolute value of the coefficient must be increased. + */ + for (; k <= Se; k++) { + thiscoef = *block + jpeg_natural_order[k]; + if (*thiscoef != 0) { + CHECK_BIT_BUFFER(br_state, 1, goto undoit); + if (GET_BITS(1)) { + if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */ + if (*thiscoef >= 0) + *thiscoef += p1; + else + *thiscoef += m1; + } + } + } + } + /* Count one block completed in EOB run */ + EOBRUN--; + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */ + } + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; + +undoit: + /* Re-zero any output coefficients that we made newly nonzero */ + while (num_newnz > 0) + (*block)[newnz_pos[--num_newnz]] = 0; + + return FALSE; +} + + +/* + * Module initialization routine for progressive Huffman entropy decoding. + */ + +GLOBAL(void) +jinit_phuff_decoder (j_decompress_ptr cinfo) +{ + phuff_entropy_ptr entropy; + int *coef_bit_ptr; + int ci, i; + + entropy = (phuff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(phuff_entropy_decoder)); + cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; + entropy->pub.start_pass = start_pass_phuff_decoder; + + /* Mark derived tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->derived_tbls[i] = NULL; + } + + /* Create progression status table */ + cinfo->coef_bits = (int (*)[DCTSIZE2]) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components*DCTSIZE2*SIZEOF(int)); + coef_bit_ptr = & cinfo->coef_bits[0][0]; + for (ci = 0; ci < cinfo->num_components; ci++) + for (i = 0; i < DCTSIZE2; i++) + *coef_bit_ptr++ = -1; +} + +#endif /* D_PROGRESSIVE_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdpostct.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdpostct.c new file mode 100755 index 0000000..571563d --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdpostct.c @@ -0,0 +1,290 @@ +/* + * jdpostct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the decompression postprocessing controller. + * This controller manages the upsampling, color conversion, and color + * quantization/reduction steps; specifically, it controls the buffering + * between upsample/color conversion and color quantization/reduction. + * + * If no color quantization/reduction is required, then this module has no + * work to do, and it just hands off to the upsample/color conversion code. + * An integrated upsample/convert/quantize process would replace this module + * entirely. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* Private buffer controller object */ + +typedef struct { + struct jpeg_d_post_controller pub; /* public fields */ + + /* Color quantization source buffer: this holds output data from + * the upsample/color conversion step to be passed to the quantizer. + * For two-pass color quantization, we need a full-image buffer; + * for one-pass operation, a strip buffer is sufficient. + */ + jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */ + JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */ + JDIMENSION strip_height; /* buffer size in rows */ + /* for two-pass mode only: */ + JDIMENSION starting_row; /* row # of first row in current strip */ + JDIMENSION next_row; /* index of next row to fill/empty in strip */ +} my_post_controller; + +typedef my_post_controller * my_post_ptr; + + +/* Forward declarations */ +METHODDEF(void) post_process_1pass + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); +#ifdef QUANT_2PASS_SUPPORTED +METHODDEF(void) post_process_prepass + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); +METHODDEF(void) post_process_2pass + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); +#endif + + +/* + * Initialize for a processing pass. + */ + +METHODDEF(void) +start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) +{ + my_post_ptr post = (my_post_ptr) cinfo->post; + + switch (pass_mode) { + case JBUF_PASS_THRU: + if (cinfo->quantize_colors) { + /* Single-pass processing with color quantization. */ + post->pub.post_process_data = post_process_1pass; + /* We could be doing buffered-image output before starting a 2-pass + * color quantization; in that case, jinit_d_post_controller did not + * allocate a strip buffer. Use the virtual-array buffer as workspace. + */ + if (post->buffer == NULL) { + post->buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, post->whole_image, + (JDIMENSION) 0, post->strip_height, TRUE); + } + } else { + /* For single-pass processing without color quantization, + * I have no work to do; just call the upsampler directly. + */ + post->pub.post_process_data = cinfo->upsample->upsample; + } + break; +#ifdef QUANT_2PASS_SUPPORTED + case JBUF_SAVE_AND_PASS: + /* First pass of 2-pass quantization */ + if (post->whole_image == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + post->pub.post_process_data = post_process_prepass; + break; + case JBUF_CRANK_DEST: + /* Second pass of 2-pass quantization */ + if (post->whole_image == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + post->pub.post_process_data = post_process_2pass; + break; +#endif /* QUANT_2PASS_SUPPORTED */ + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } + post->starting_row = post->next_row = 0; +} + + +/* + * Process some data in the one-pass (strip buffer) case. + * This is used for color precision reduction as well as one-pass quantization. + */ + +METHODDEF(void) +post_process_1pass (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +{ + my_post_ptr post = (my_post_ptr) cinfo->post; + JDIMENSION num_rows, max_rows; + + /* Fill the buffer, but not more than what we can dump out in one go. */ + /* Note we rely on the upsampler to detect bottom of image. */ + max_rows = out_rows_avail - *out_row_ctr; + if (max_rows > post->strip_height) + max_rows = post->strip_height; + num_rows = 0; + (*cinfo->upsample->upsample) (cinfo, + input_buf, in_row_group_ctr, in_row_groups_avail, + post->buffer, &num_rows, max_rows); + /* Quantize and emit data. */ + (*cinfo->cquantize->color_quantize) (cinfo, + post->buffer, output_buf + *out_row_ctr, (int) num_rows); + *out_row_ctr += num_rows; +} + + +#ifdef QUANT_2PASS_SUPPORTED + +/* + * Process some data in the first pass of 2-pass quantization. + */ + +METHODDEF(void) +post_process_prepass (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +{ + my_post_ptr post = (my_post_ptr) cinfo->post; + JDIMENSION old_next_row, num_rows; + + /* Reposition virtual buffer if at start of strip. */ + if (post->next_row == 0) { + post->buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, post->whole_image, + post->starting_row, post->strip_height, TRUE); + } + + /* Upsample some data (up to a strip height's worth). */ + old_next_row = post->next_row; + (*cinfo->upsample->upsample) (cinfo, + input_buf, in_row_group_ctr, in_row_groups_avail, + post->buffer, &post->next_row, post->strip_height); + + /* Allow quantizer to scan new data. No data is emitted, */ + /* but we advance out_row_ctr so outer loop can tell when we're done. */ + if (post->next_row > old_next_row) { + num_rows = post->next_row - old_next_row; + (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row, + (JSAMPARRAY) NULL, (int) num_rows); + *out_row_ctr += num_rows; + } + + /* Advance if we filled the strip. */ + if (post->next_row >= post->strip_height) { + post->starting_row += post->strip_height; + post->next_row = 0; + } +} + + +/* + * Process some data in the second pass of 2-pass quantization. + */ + +METHODDEF(void) +post_process_2pass (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +{ + my_post_ptr post = (my_post_ptr) cinfo->post; + JDIMENSION num_rows, max_rows; + + /* Reposition virtual buffer if at start of strip. */ + if (post->next_row == 0) { + post->buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, post->whole_image, + post->starting_row, post->strip_height, FALSE); + } + + /* Determine number of rows to emit. */ + num_rows = post->strip_height - post->next_row; /* available in strip */ + max_rows = out_rows_avail - *out_row_ctr; /* available in output area */ + if (num_rows > max_rows) + num_rows = max_rows; + /* We have to check bottom of image here, can't depend on upsampler. */ + max_rows = cinfo->output_height - post->starting_row; + if (num_rows > max_rows) + num_rows = max_rows; + + /* Quantize and emit data. */ + (*cinfo->cquantize->color_quantize) (cinfo, + post->buffer + post->next_row, output_buf + *out_row_ctr, + (int) num_rows); + *out_row_ctr += num_rows; + + /* Advance if we filled the strip. */ + post->next_row += num_rows; + if (post->next_row >= post->strip_height) { + post->starting_row += post->strip_height; + post->next_row = 0; + } +} + +#endif /* QUANT_2PASS_SUPPORTED */ + + +/* + * Initialize postprocessing controller. + */ + +GLOBAL(void) +jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer) +{ + my_post_ptr post; + + post = (my_post_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_post_controller)); + cinfo->post = (struct jpeg_d_post_controller *) post; + post->pub.start_pass = start_pass_dpost; + post->whole_image = NULL; /* flag for no virtual arrays */ + post->buffer = NULL; /* flag for no strip buffer */ + + /* Create the quantization buffer, if needed */ + if (cinfo->quantize_colors) { + /* The buffer strip height is max_v_samp_factor, which is typically + * an efficient number of rows for upsampling to return. + * (In the presence of output rescaling, we might want to be smarter?) + */ + post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor; + if (need_full_buffer) { + /* Two-pass color quantization: need full-image storage. */ + /* We round up the number of rows to a multiple of the strip height. */ +#ifdef QUANT_2PASS_SUPPORTED + post->whole_image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + cinfo->output_width * cinfo->out_color_components, + (JDIMENSION) jround_up((long) cinfo->output_height, + (long) post->strip_height), + post->strip_height); +#else + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); +#endif /* QUANT_2PASS_SUPPORTED */ + } else { + /* One-pass color quantization: just make a strip buffer. */ + post->buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->output_width * cinfo->out_color_components, + post->strip_height); + } + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdsample.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdsample.c new file mode 100755 index 0000000..1864dd6 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdsample.c @@ -0,0 +1,496 @@ +/* + * jdsample.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains upsampling routines. + * + * Upsampling input data is counted in "row groups". A row group + * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) + * sample rows of each component. Upsampling will normally produce + * max_v_samp_factor pixel rows from each row group (but this could vary + * if the upsampler is applying a scale factor of its own). + * + * An excellent reference for image resampling is + * Digital Image Warping, George Wolberg, 1990. + * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jsimd.h" +#include "jpegcomp.h" + + +/* Pointer to routine to upsample a single component */ +typedef JMETHOD(void, upsample1_ptr, + (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +/* Private subobject */ + +typedef struct { + struct jpeg_upsampler pub; /* public fields */ + + /* Color conversion buffer. When using separate upsampling and color + * conversion steps, this buffer holds one upsampled row group until it + * has been color converted and output. + * Note: we do not allocate any storage for component(s) which are full-size, + * ie do not need rescaling. The corresponding entry of color_buf[] is + * simply set to point to the input data array, thereby avoiding copying. + */ + JSAMPARRAY color_buf[MAX_COMPONENTS]; + + /* Per-component upsampling method pointers */ + upsample1_ptr methods[MAX_COMPONENTS]; + + int next_row_out; /* counts rows emitted from color_buf */ + JDIMENSION rows_to_go; /* counts rows remaining in image */ + + /* Height of an input row group for each component. */ + int rowgroup_height[MAX_COMPONENTS]; + + /* These arrays save pixel expansion factors so that int_expand need not + * recompute them each time. They are unused for other upsampling methods. + */ + UINT8 h_expand[MAX_COMPONENTS]; + UINT8 v_expand[MAX_COMPONENTS]; +} my_upsampler; + +typedef my_upsampler * my_upsample_ptr; + + +/* + * Initialize for an upsampling pass. + */ + +METHODDEF(void) +start_pass_upsample (j_decompress_ptr cinfo) +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + + /* Mark the conversion buffer empty */ + upsample->next_row_out = cinfo->max_v_samp_factor; + /* Initialize total-height counter for detecting bottom of image */ + upsample->rows_to_go = cinfo->output_height; +} + + +/* + * Control routine to do upsampling (and color conversion). + * + * In this version we upsample each component independently. + * We upsample one row group into the conversion buffer, then apply + * color conversion a row at a time. + */ + +METHODDEF(void) +sep_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + int ci; + jpeg_component_info * compptr; + JDIMENSION num_rows; + + /* Fill the conversion buffer, if it's empty */ + if (upsample->next_row_out >= cinfo->max_v_samp_factor) { + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Invoke per-component upsample method. Notice we pass a POINTER + * to color_buf[ci], so that fullsize_upsample can change it. + */ + (*upsample->methods[ci]) (cinfo, compptr, + input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), + upsample->color_buf + ci); + } + upsample->next_row_out = 0; + } + + /* Color-convert and emit rows */ + + /* How many we have in the buffer: */ + num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out); + /* Not more than the distance to the end of the image. Need this test + * in case the image height is not a multiple of max_v_samp_factor: + */ + if (num_rows > upsample->rows_to_go) + num_rows = upsample->rows_to_go; + /* And not more than what the client can accept: */ + out_rows_avail -= *out_row_ctr; + if (num_rows > out_rows_avail) + num_rows = out_rows_avail; + + (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf, + (JDIMENSION) upsample->next_row_out, + output_buf + *out_row_ctr, + (int) num_rows); + + /* Adjust counts */ + *out_row_ctr += num_rows; + upsample->rows_to_go -= num_rows; + upsample->next_row_out += num_rows; + /* When the buffer is emptied, declare this input row group consumed */ + if (upsample->next_row_out >= cinfo->max_v_samp_factor) + (*in_row_group_ctr)++; +} + + +/* + * These are the routines invoked by sep_upsample to upsample pixel values + * of a single component. One row group is processed per call. + */ + + +/* + * For full-size components, we just make color_buf[ci] point at the + * input buffer, and thus avoid copying any data. Note that this is + * safe only because sep_upsample doesn't declare the input row group + * "consumed" until we are done color converting and emitting it. + */ + +METHODDEF(void) +fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) +{ + *output_data_ptr = input_data; +} + + +/* + * This is a no-op version used for "uninteresting" components. + * These components will not be referenced by color conversion. + */ + +METHODDEF(void) +noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) +{ + *output_data_ptr = NULL; /* safety check */ +} + + +/* + * This version handles any integral sampling ratios. + * This is not used for typical JPEG files, so it need not be fast. + * Nor, for that matter, is it particularly accurate: the algorithm is + * simple replication of the input pixel onto the corresponding output + * pixels. The hi-falutin sampling literature refers to this as a + * "box filter". A box filter tends to introduce visible artifacts, + * so if you are actually going to use 3:1 or 4:1 sampling ratios + * you would be well advised to improve this code. + */ + +METHODDEF(void) +int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) +{ + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register JSAMPLE invalue; + register int h; + JSAMPROW outend; + int h_expand, v_expand; + int inrow, outrow; + + h_expand = upsample->h_expand[compptr->component_index]; + v_expand = upsample->v_expand[compptr->component_index]; + + inrow = outrow = 0; + while (outrow < cinfo->max_v_samp_factor) { + /* Generate one output row with proper horizontal expansion */ + inptr = input_data[inrow]; + outptr = output_data[outrow]; + outend = outptr + cinfo->output_width; + while (outptr < outend) { + invalue = *inptr++; /* don't need GETJSAMPLE() here */ + for (h = h_expand; h > 0; h--) { + *outptr++ = invalue; + } + } + /* Generate any additional output rows by duplicating the first one */ + if (v_expand > 1) { + jcopy_sample_rows(output_data, outrow, output_data, outrow+1, + v_expand-1, cinfo->output_width); + } + inrow++; + outrow += v_expand; + } +} + + +/* + * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. + * It's still a box filter. + */ + +METHODDEF(void) +h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) +{ + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register JSAMPLE invalue; + JSAMPROW outend; + int inrow; + + for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { + inptr = input_data[inrow]; + outptr = output_data[inrow]; + outend = outptr + cinfo->output_width; + while (outptr < outend) { + invalue = *inptr++; /* don't need GETJSAMPLE() here */ + *outptr++ = invalue; + *outptr++ = invalue; + } + } +} + + +/* + * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. + * It's still a box filter. + */ + +METHODDEF(void) +h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) +{ + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register JSAMPLE invalue; + JSAMPROW outend; + int inrow, outrow; + + inrow = outrow = 0; + while (outrow < cinfo->max_v_samp_factor) { + inptr = input_data[inrow]; + outptr = output_data[outrow]; + outend = outptr + cinfo->output_width; + while (outptr < outend) { + invalue = *inptr++; /* don't need GETJSAMPLE() here */ + *outptr++ = invalue; + *outptr++ = invalue; + } + jcopy_sample_rows(output_data, outrow, output_data, outrow+1, + 1, cinfo->output_width); + inrow++; + outrow += 2; + } +} + + +/* + * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. + * + * The upsampling algorithm is linear interpolation between pixel centers, + * also known as a "triangle filter". This is a good compromise between + * speed and visual quality. The centers of the output pixels are 1/4 and 3/4 + * of the way between input pixel centers. + * + * A note about the "bias" calculations: when rounding fractional values to + * integer, we do not want to always round 0.5 up to the next integer. + * If we did that, we'd introduce a noticeable bias towards larger values. + * Instead, this code is arranged so that 0.5 will be rounded up or down at + * alternate pixel locations (a simple ordered dither pattern). + */ + +METHODDEF(void) +h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) +{ + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register int invalue; + register JDIMENSION colctr; + int inrow; + + for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { + inptr = input_data[inrow]; + outptr = output_data[inrow]; + /* Special case for first column */ + invalue = GETJSAMPLE(*inptr++); + *outptr++ = (JSAMPLE) invalue; + *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2); + + for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { + /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ + invalue = GETJSAMPLE(*inptr++) * 3; + *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2); + *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2); + } + + /* Special case for last column */ + invalue = GETJSAMPLE(*inptr); + *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2); + *outptr++ = (JSAMPLE) invalue; + } +} + + +/* + * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. + * Again a triangle filter; see comments for h2v1 case, above. + * + * It is OK for us to reference the adjacent input rows because we demanded + * context from the main buffer controller (see initialization code). + */ + +METHODDEF(void) +h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) +{ + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr0, inptr1, outptr; +#if BITS_IN_JSAMPLE == 8 + register int thiscolsum, lastcolsum, nextcolsum; +#else + register INT32 thiscolsum, lastcolsum, nextcolsum; +#endif + register JDIMENSION colctr; + int inrow, outrow, v; + + inrow = outrow = 0; + while (outrow < cinfo->max_v_samp_factor) { + for (v = 0; v < 2; v++) { + /* inptr0 points to nearest input row, inptr1 points to next nearest */ + inptr0 = input_data[inrow]; + if (v == 0) /* next nearest is row above */ + inptr1 = input_data[inrow-1]; + else /* next nearest is row below */ + inptr1 = input_data[inrow+1]; + outptr = output_data[outrow++]; + + /* Special case for first column */ + thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); + nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); + *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4); + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4); + lastcolsum = thiscolsum; thiscolsum = nextcolsum; + + for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { + /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ + /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ + nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4); + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4); + lastcolsum = thiscolsum; thiscolsum = nextcolsum; + } + + /* Special case for last column */ + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4); + *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4); + } + inrow++; + } +} + + +/* + * Module initialization routine for upsampling. + */ + +GLOBAL(void) +jinit_upsampler (j_decompress_ptr cinfo) +{ + my_upsample_ptr upsample; + int ci; + jpeg_component_info * compptr; + boolean need_buffer, do_fancy; + int h_in_group, v_in_group, h_out_group, v_out_group; + + upsample = (my_upsample_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_upsampler)); + cinfo->upsample = (struct jpeg_upsampler *) upsample; + upsample->pub.start_pass = start_pass_upsample; + upsample->pub.upsample = sep_upsample; + upsample->pub.need_context_rows = FALSE; /* until we find out differently */ + + if (cinfo->CCIR601_sampling) /* this isn't supported */ + ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); + + /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, + * so don't ask for it. + */ + do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; + + /* Verify we can handle the sampling factors, select per-component methods, + * and create storage as needed. + */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Compute size of an "input group" after IDCT scaling. This many samples + * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. + */ + h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / + cinfo->_min_DCT_scaled_size; + v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / + cinfo->_min_DCT_scaled_size; + h_out_group = cinfo->max_h_samp_factor; + v_out_group = cinfo->max_v_samp_factor; + upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ + need_buffer = TRUE; + if (! compptr->component_needed) { + /* Don't bother to upsample an uninteresting component. */ + upsample->methods[ci] = noop_upsample; + need_buffer = FALSE; + } else if (h_in_group == h_out_group && v_in_group == v_out_group) { + /* Fullsize components can be processed without any work. */ + upsample->methods[ci] = fullsize_upsample; + need_buffer = FALSE; + } else if (h_in_group * 2 == h_out_group && + v_in_group == v_out_group) { + /* Special cases for 2h1v upsampling */ + if (do_fancy && compptr->downsampled_width > 2) { + if (jsimd_can_h2v1_fancy_upsample()) + upsample->methods[ci] = jsimd_h2v1_fancy_upsample; + else + upsample->methods[ci] = h2v1_fancy_upsample; + } else { + if (jsimd_can_h2v1_upsample()) + upsample->methods[ci] = jsimd_h2v1_upsample; + else + upsample->methods[ci] = h2v1_upsample; + } + } else if (h_in_group * 2 == h_out_group && + v_in_group * 2 == v_out_group) { + /* Special cases for 2h2v upsampling */ + if (do_fancy && compptr->downsampled_width > 2) { + if (jsimd_can_h2v2_fancy_upsample()) + upsample->methods[ci] = jsimd_h2v2_fancy_upsample; + else + upsample->methods[ci] = h2v2_fancy_upsample; + upsample->pub.need_context_rows = TRUE; + } else { + if (jsimd_can_h2v2_upsample()) + upsample->methods[ci] = jsimd_h2v2_upsample; + else + upsample->methods[ci] = h2v2_upsample; + } + } else if ((h_out_group % h_in_group) == 0 && + (v_out_group % v_in_group) == 0) { + /* Generic integral-factors upsampling method */ + upsample->methods[ci] = int_upsample; + upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); + upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group); + } else + ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); + if (need_buffer) { + upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) jround_up((long) cinfo->output_width, + (long) cinfo->max_h_samp_factor), + (JDIMENSION) cinfo->max_v_samp_factor); + } + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jdtrans.c b/lib-third-party/libturbojpeg-ios/libjpeg/jdtrans.c new file mode 100755 index 0000000..f0cd0ae --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jdtrans.c @@ -0,0 +1,152 @@ +/* + * jdtrans.c + * + * Copyright (C) 1995-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains library routines for transcoding decompression, + * that is, reading raw DCT coefficient arrays from an input JPEG file. + * The routines in jdapimin.c will also be needed by a transcoder. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* Forward declarations */ +LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo)); + + +/* + * Read the coefficient arrays from a JPEG file. + * jpeg_read_header must be completed before calling this. + * + * The entire image is read into a set of virtual coefficient-block arrays, + * one per component. The return value is a pointer to the array of + * virtual-array descriptors. These can be manipulated directly via the + * JPEG memory manager, or handed off to jpeg_write_coefficients(). + * To release the memory occupied by the virtual arrays, call + * jpeg_finish_decompress() when done with the data. + * + * An alternative usage is to simply obtain access to the coefficient arrays + * during a buffered-image-mode decompression operation. This is allowed + * after any jpeg_finish_output() call. The arrays can be accessed until + * jpeg_finish_decompress() is called. (Note that any call to the library + * may reposition the arrays, so don't rely on access_virt_barray() results + * to stay valid across library calls.) + * + * Returns NULL if suspended. This case need be checked only if + * a suspending data source is used. + */ + +GLOBAL(jvirt_barray_ptr *) +jpeg_read_coefficients (j_decompress_ptr cinfo) +{ + if (cinfo->global_state == DSTATE_READY) { + /* First call: initialize active modules */ + transdecode_master_selection(cinfo); + cinfo->global_state = DSTATE_RDCOEFS; + } + if (cinfo->global_state == DSTATE_RDCOEFS) { + /* Absorb whole file into the coef buffer */ + for (;;) { + int retcode; + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + /* Absorb some more input */ + retcode = (*cinfo->inputctl->consume_input) (cinfo); + if (retcode == JPEG_SUSPENDED) + return NULL; + if (retcode == JPEG_REACHED_EOI) + break; + /* Advance progress counter if appropriate */ + if (cinfo->progress != NULL && + (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { + if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { + /* startup underestimated number of scans; ratchet up one scan */ + cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; + } + } + } + /* Set state so that jpeg_finish_decompress does the right thing */ + cinfo->global_state = DSTATE_STOPPING; + } + /* At this point we should be in state DSTATE_STOPPING if being used + * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access + * to the coefficients during a full buffered-image-mode decompression. + */ + if ((cinfo->global_state == DSTATE_STOPPING || + cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) { + return cinfo->coef->coef_arrays; + } + /* Oops, improper usage */ + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + return NULL; /* keep compiler happy */ +} + + +/* + * Master selection of decompression modules for transcoding. + * This substitutes for jdmaster.c's initialization of the full decompressor. + */ + +LOCAL(void) +transdecode_master_selection (j_decompress_ptr cinfo) +{ + /* This is effectively a buffered-image operation. */ + cinfo->buffered_image = TRUE; + +#if JPEG_LIB_VERSION >= 80 + /* Compute output image dimensions and related values. */ + jpeg_core_output_dimensions(cinfo); +#endif + + /* Entropy decoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { +#ifdef D_ARITH_CODING_SUPPORTED + jinit_arith_decoder(cinfo); +#else + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); +#endif + } else { + if (cinfo->progressive_mode) { +#ifdef D_PROGRESSIVE_SUPPORTED + jinit_phuff_decoder(cinfo); +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } else + jinit_huff_decoder(cinfo); + } + + /* Always get a full-image coefficient buffer. */ + jinit_d_coef_controller(cinfo, TRUE); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Initialize input side of decompressor to consume first scan. */ + (*cinfo->inputctl->start_input_pass) (cinfo); + + /* Initialize progress monitoring. */ + if (cinfo->progress != NULL) { + int nscans; + /* Estimate number of scans to set pass_limit. */ + if (cinfo->progressive_mode) { + /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ + nscans = 2 + 3 * cinfo->num_components; + } else if (cinfo->inputctl->has_multiple_scans) { + /* For a nonprogressive multiscan file, estimate 1 scan per component. */ + nscans = cinfo->num_components; + } else { + nscans = 1; + } + cinfo->progress->pass_counter = 0L; + cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; + cinfo->progress->completed_passes = 0; + cinfo->progress->total_passes = 1; + } +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jerror.c b/lib-third-party/libturbojpeg-ios/libjpeg/jerror.c new file mode 100755 index 0000000..3da7be8 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jerror.c @@ -0,0 +1,252 @@ +/* + * jerror.c + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains simple error-reporting and trace-message routines. + * These are suitable for Unix-like systems and others where writing to + * stderr is the right thing to do. Many applications will want to replace + * some or all of these routines. + * + * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile, + * you get a Windows-specific hack to display error messages in a dialog box. + * It ain't much, but it beats dropping error messages into the bit bucket, + * which is what happens to output to stderr under most Windows C compilers. + * + * These routines are used by both the compression and decompression code. + */ + +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#include "jinclude.h" +#include "jpeglib.h" +#include "jversion.h" +#include "jerror.h" + +#ifdef USE_WINDOWS_MESSAGEBOX +#include +#endif + +#ifndef EXIT_FAILURE /* define exit() codes if not provided */ +#define EXIT_FAILURE 1 +#endif + + +/* + * Create the message string table. + * We do this from the master message list in jerror.h by re-reading + * jerror.h with a suitable definition for macro JMESSAGE. + * The message table is made an external symbol just in case any applications + * want to refer to it directly. + */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_std_message_table jMsgTable +#endif + +#define JMESSAGE(code,string) string , + +const char * const jpeg_std_message_table[] = { +#include "jerror.h" + NULL +}; + + +/* + * Error exit handler: must not return to caller. + * + * Applications may override this if they want to get control back after + * an error. Typically one would longjmp somewhere instead of exiting. + * The setjmp buffer can be made a private field within an expanded error + * handler object. Note that the info needed to generate an error message + * is stored in the error object, so you can generate the message now or + * later, at your convenience. + * You should make sure that the JPEG object is cleaned up (with jpeg_abort + * or jpeg_destroy) at some point. + */ + +METHODDEF(void) +error_exit (j_common_ptr cinfo) +{ + /* Always display the message */ + (*cinfo->err->output_message) (cinfo); + + /* Let the memory manager delete any temp files before we die */ + jpeg_destroy(cinfo); + + exit(EXIT_FAILURE); +} + + +/* + * Actual output of an error or trace message. + * Applications may override this method to send JPEG messages somewhere + * other than stderr. + * + * On Windows, printing to stderr is generally completely useless, + * so we provide optional code to produce an error-dialog popup. + * Most Windows applications will still prefer to override this routine, + * but if they don't, it'll do something at least marginally useful. + * + * NOTE: to use the library in an environment that doesn't support the + * C stdio library, you may have to delete the call to fprintf() entirely, + * not just not use this routine. + */ + +METHODDEF(void) +output_message (j_common_ptr cinfo) +{ + char buffer[JMSG_LENGTH_MAX]; + + /* Create the message */ + (*cinfo->err->format_message) (cinfo, buffer); + +#ifdef USE_WINDOWS_MESSAGEBOX + /* Display it in a message dialog box */ + MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", + MB_OK | MB_ICONERROR); +#else + /* Send it to stderr, adding a newline */ + fprintf(stderr, "%s\n", buffer); +#endif +} + + +/* + * Decide whether to emit a trace or warning message. + * msg_level is one of: + * -1: recoverable corrupt-data warning, may want to abort. + * 0: important advisory messages (always display to user). + * 1: first level of tracing detail. + * 2,3,...: successively more detailed tracing messages. + * An application might override this method if it wanted to abort on warnings + * or change the policy about which messages to display. + */ + +METHODDEF(void) +emit_message (j_common_ptr cinfo, int msg_level) +{ + struct jpeg_error_mgr * err = cinfo->err; + + if (msg_level < 0) { + /* It's a warning message. Since corrupt files may generate many warnings, + * the policy implemented here is to show only the first warning, + * unless trace_level >= 3. + */ + if (err->num_warnings == 0 || err->trace_level >= 3) + (*err->output_message) (cinfo); + /* Always count warnings in num_warnings. */ + err->num_warnings++; + } else { + /* It's a trace message. Show it if trace_level >= msg_level. */ + if (err->trace_level >= msg_level) + (*err->output_message) (cinfo); + } +} + + +/* + * Format a message string for the most recent JPEG error or message. + * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX + * characters. Note that no '\n' character is added to the string. + * Few applications should need to override this method. + */ + +METHODDEF(void) +format_message (j_common_ptr cinfo, char * buffer) +{ + struct jpeg_error_mgr * err = cinfo->err; + int msg_code = err->msg_code; + const char * msgtext = NULL; + const char * msgptr; + char ch; + boolean isstring; + + /* Look up message string in proper table */ + if (msg_code > 0 && msg_code <= err->last_jpeg_message) { + msgtext = err->jpeg_message_table[msg_code]; + } else if (err->addon_message_table != NULL && + msg_code >= err->first_addon_message && + msg_code <= err->last_addon_message) { + msgtext = err->addon_message_table[msg_code - err->first_addon_message]; + } + + /* Defend against bogus message number */ + if (msgtext == NULL) { + err->msg_parm.i[0] = msg_code; + msgtext = err->jpeg_message_table[0]; + } + + /* Check for string parameter, as indicated by %s in the message text */ + isstring = FALSE; + msgptr = msgtext; + while ((ch = *msgptr++) != '\0') { + if (ch == '%') { + if (*msgptr == 's') isstring = TRUE; + break; + } + } + + /* Format the message into the passed buffer */ + if (isstring) + sprintf(buffer, msgtext, err->msg_parm.s); + else + sprintf(buffer, msgtext, + err->msg_parm.i[0], err->msg_parm.i[1], + err->msg_parm.i[2], err->msg_parm.i[3], + err->msg_parm.i[4], err->msg_parm.i[5], + err->msg_parm.i[6], err->msg_parm.i[7]); +} + + +/* + * Reset error state variables at start of a new image. + * This is called during compression startup to reset trace/error + * processing to default state, without losing any application-specific + * method pointers. An application might possibly want to override + * this method if it has additional error processing state. + */ + +METHODDEF(void) +reset_error_mgr (j_common_ptr cinfo) +{ + cinfo->err->num_warnings = 0; + /* trace_level is not reset since it is an application-supplied parameter */ + cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ +} + + +/* + * Fill in the standard error-handling methods in a jpeg_error_mgr object. + * Typical call is: + * struct jpeg_compress_struct cinfo; + * struct jpeg_error_mgr err; + * + * cinfo.err = jpeg_std_error(&err); + * after which the application may override some of the methods. + */ + +GLOBAL(struct jpeg_error_mgr *) +jpeg_std_error (struct jpeg_error_mgr * err) +{ + err->error_exit = error_exit; + err->emit_message = emit_message; + err->output_message = output_message; + err->format_message = format_message; + err->reset_error_mgr = reset_error_mgr; + + err->trace_level = 0; /* default = no tracing */ + err->num_warnings = 0; /* no warnings emitted yet */ + err->msg_code = 0; /* may be useful as a flag for "no error" */ + + /* Initialize message table pointers */ + err->jpeg_message_table = jpeg_std_message_table; + err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; + + err->addon_message_table = NULL; + err->first_addon_message = 0; /* for safety */ + err->last_addon_message = 0; + + return err; +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jerror.h b/lib-third-party/libturbojpeg-ios/libjpeg/jerror.h new file mode 100755 index 0000000..275086e --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jerror.h @@ -0,0 +1,314 @@ +/* + * jerror.h + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * Modified 1997-2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the error and message codes for the JPEG library. + * Edit this file to add new codes, or to translate the message strings to + * some other language. + * A set of error-reporting macros are defined too. Some applications using + * the JPEG library may wish to include this file to get the error codes + * and/or the macros. + */ + +/* + * To define the enum list of message codes, include this file without + * defining macro JMESSAGE. To create a message string table, include it + * again with a suitable JMESSAGE definition (see jerror.c for an example). + */ +#ifndef JMESSAGE +#ifndef JERROR_H +/* First time through, define the enum list */ +#define JMAKE_ENUM_LIST +#else +/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ +#define JMESSAGE(code,string) +#endif /* JERROR_H */ +#endif /* JMESSAGE */ + +#ifdef JMAKE_ENUM_LIST + +typedef enum { + +#define JMESSAGE(code,string) code , + +#endif /* JMAKE_ENUM_LIST */ + +JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */ + +/* For maintenance convenience, list is alphabetical by message code name */ +#if JPEG_LIB_VERSION < 70 +JMESSAGE(JERR_ARITH_NOTIMPL, + "Sorry, arithmetic coding is not implemented") +#endif +JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") +JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") +JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode") +JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") +#if JPEG_LIB_VERSION >= 70 +JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request") +#endif +JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range") +JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") +#if JPEG_LIB_VERSION >= 70 +JMESSAGE(JERR_BAD_DROP_SAMPLING, + "Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c") +#endif +JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") +JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") +JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") +JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") +JMESSAGE(JERR_BAD_LIB_VERSION, + "Wrong JPEG library version: library is %d, caller expects %d") +JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") +JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") +JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") +JMESSAGE(JERR_BAD_PROGRESSION, + "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") +JMESSAGE(JERR_BAD_PROG_SCRIPT, + "Invalid progressive parameters at scan script entry %d") +JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") +JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") +JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") +JMESSAGE(JERR_BAD_STRUCT_SIZE, + "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") +JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") +JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") +JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") +JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet") +JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d") +JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request") +JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d") +JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x") +JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d") +JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d") +JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)") +JMESSAGE(JERR_EMS_READ, "Read from EMS failed") +JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed") +JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan") +JMESSAGE(JERR_FILE_READ, "Input file read error") +JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") +JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") +JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow") +JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") +JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") +JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") +JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") +JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, + "Cannot transcode due to multiple use of quantization table %d") +JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") +JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") +JMESSAGE(JERR_NOTIMPL, "Not implemented yet") +JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") +#if JPEG_LIB_VERSION >= 70 +JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined") +#endif +JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") +JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined") +JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image") +JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined") +JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") +JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") +JMESSAGE(JERR_QUANT_COMPONENTS, + "Cannot quantize more than %d color components") +JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") +JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") +JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") +JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") +JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") +JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") +JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF") +JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") +JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") +JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") +JMESSAGE(JERR_TFILE_WRITE, + "Write failed on temporary file --- out of disk space?") +JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") +JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") +JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") +JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") +JMESSAGE(JERR_XMS_READ, "Read from XMS failed") +JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") +JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) +JMESSAGE(JMSG_VERSION, JVERSION) +JMESSAGE(JTRC_16BIT_TABLES, + "Caution: quantization tables are too coarse for baseline JPEG") +JMESSAGE(JTRC_ADOBE, + "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") +JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") +JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") +JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") +JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x") +JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d") +JMESSAGE(JTRC_DRI, "Define Restart Interval %u") +JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u") +JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u") +JMESSAGE(JTRC_EOI, "End Of Image") +JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") +JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") +JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, + "Warning: thumbnail image size does not match data length %u") +JMESSAGE(JTRC_JFIF_EXTENSION, + "JFIF extension marker: type 0x%02x, length %u") +JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") +JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") +JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") +JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u") +JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors") +JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors") +JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization") +JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") +JMESSAGE(JTRC_RST, "RST%d") +JMESSAGE(JTRC_SMOOTH_NOTIMPL, + "Smoothing not supported with nonstandard sampling ratios") +JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") +JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") +JMESSAGE(JTRC_SOI, "Start of Image") +JMESSAGE(JTRC_SOS, "Start Of Scan: %d components") +JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d") +JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d") +JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") +JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") +JMESSAGE(JTRC_THUMB_JPEG, + "JFIF extension marker: JPEG-compressed thumbnail image, length %u") +JMESSAGE(JTRC_THUMB_PALETTE, + "JFIF extension marker: palette thumbnail image, length %u") +JMESSAGE(JTRC_THUMB_RGB, + "JFIF extension marker: RGB thumbnail image, length %u") +JMESSAGE(JTRC_UNKNOWN_IDS, + "Unrecognized component IDs %d %d %d, assuming YCbCr") +JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") +JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") +JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") +#if JPEG_LIB_VERSION >= 70 +JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") +#endif +JMESSAGE(JWRN_BOGUS_PROGRESSION, + "Inconsistent progression sequence for component %d coefficient %d") +JMESSAGE(JWRN_EXTRANEOUS_DATA, + "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") +JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") +JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") +JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") +JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") +JMESSAGE(JWRN_MUST_RESYNC, + "Corrupt JPEG data: found marker 0x%02x instead of RST%d") +JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") +JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") +#if JPEG_LIB_VERSION < 70 +JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request") +#if defined(C_ARITH_CODING_SUPPORTED) || defined(D_ARITH_CODING_SUPPORTED) +JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined") +JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") +#endif +#endif + +#ifdef JMAKE_ENUM_LIST + + JMSG_LASTMSGCODE +} J_MESSAGE_CODE; + +#undef JMAKE_ENUM_LIST +#endif /* JMAKE_ENUM_LIST */ + +/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ +#undef JMESSAGE + + +#ifndef JERROR_H +#define JERROR_H + +/* Macros to simplify using the error and trace message stuff */ +/* The first parameter is either type of cinfo pointer */ + +/* Fatal errors (print message and exit) */ +#define ERREXIT(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT3(cinfo,code,p1,p2,p3) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (cinfo)->err->msg_parm.i[3] = (p4), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXITS(cinfo,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + +#define MAKESTMT(stuff) do { stuff } while (0) + +/* Nonfatal errors (we can keep going, but the data is probably corrupt) */ +#define WARNMS(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) +#define WARNMS1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) +#define WARNMS2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) + +/* Informational/debugging messages */ +#define TRACEMS(cinfo,lvl,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS1(cinfo,lvl,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS2(cinfo,lvl,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + _mp[4] = (p5); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMSS(cinfo,lvl,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) + +#endif /* JERROR_H */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jfdctflt.c b/lib-third-party/libturbojpeg-ios/libjpeg/jfdctflt.c new file mode 100755 index 0000000..79d7a00 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jfdctflt.c @@ -0,0 +1,168 @@ +/* + * jfdctflt.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a floating-point implementation of the + * forward DCT (Discrete Cosine Transform). + * + * This implementation should be more accurate than either of the integer + * DCT implementations. However, it may not give the same results on all + * machines because of differences in roundoff behavior. Speed will depend + * on the hardware's floating point capacity. + * + * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT + * on each column. Direct algorithms are also available, but they are + * much more complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with a fixed-point + * implementation, accuracy is lost due to imprecise representation of the + * scaled quantization values. However, that problem does not arise if + * we use floating point arithmetic. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ + +#ifdef DCT_FLOAT_SUPPORTED + + +/* + * This module is specialized to the case DCTSIZE = 8. + */ + +#if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +#endif + + +/* + * Perform the forward DCT on one block of samples. + */ + +GLOBAL(void) +jpeg_fdct_float (FAST_FLOAT * data) +{ + FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + FAST_FLOAT tmp10, tmp11, tmp12, tmp13; + FAST_FLOAT z1, z2, z3, z4, z5, z11, z13; + FAST_FLOAT *dataptr; + int ctr; + + /* Pass 1: process rows. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[0] + dataptr[7]; + tmp7 = dataptr[0] - dataptr[7]; + tmp1 = dataptr[1] + dataptr[6]; + tmp6 = dataptr[1] - dataptr[6]; + tmp2 = dataptr[2] + dataptr[5]; + tmp5 = dataptr[2] - dataptr[5]; + tmp3 = dataptr[3] + dataptr[4]; + tmp4 = dataptr[3] - dataptr[4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[0] = tmp10 + tmp11; /* phase 3 */ + dataptr[4] = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ + dataptr[2] = tmp13 + z1; /* phase 5 */ + dataptr[6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ + z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ + z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ + z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[5] = z13 + z2; /* phase 6 */ + dataptr[3] = z13 - z2; + dataptr[1] = z11 + z4; + dataptr[7] = z11 - z4; + + dataptr += DCTSIZE; /* advance pointer to next row */ + } + + /* Pass 2: process columns. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; + tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; + tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; + tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; + tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; + tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; + tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; + tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ + dataptr[DCTSIZE*4] = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ + dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ + dataptr[DCTSIZE*6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ + z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ + z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ + z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ + dataptr[DCTSIZE*3] = z13 - z2; + dataptr[DCTSIZE*1] = z11 + z4; + dataptr[DCTSIZE*7] = z11 - z4; + + dataptr++; /* advance pointer to next column */ + } +} + +#endif /* DCT_FLOAT_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jfdctfst.c b/lib-third-party/libturbojpeg-ios/libjpeg/jfdctfst.c new file mode 100755 index 0000000..ccb378a --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jfdctfst.c @@ -0,0 +1,224 @@ +/* + * jfdctfst.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a fast, not so accurate integer implementation of the + * forward DCT (Discrete Cosine Transform). + * + * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT + * on each column. Direct algorithms are also available, but they are + * much more complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with fixed-point math, + * accuracy is lost due to imprecise representation of the scaled + * quantization values. The smaller the quantization table entry, the less + * precise the scaled value, so this implementation does worse with high- + * quality-setting files than with low-quality ones. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ + +#ifdef DCT_IFAST_SUPPORTED + + +/* + * This module is specialized to the case DCTSIZE = 8. + */ + +#if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +#endif + + +/* Scaling decisions are generally the same as in the LL&M algorithm; + * see jfdctint.c for more details. However, we choose to descale + * (right shift) multiplication products as soon as they are formed, + * rather than carrying additional fractional bits into subsequent additions. + * This compromises accuracy slightly, but it lets us save a few shifts. + * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) + * everywhere except in the multiplications proper; this saves a good deal + * of work on 16-bit-int machines. + * + * Again to save a few shifts, the intermediate results between pass 1 and + * pass 2 are not upscaled, but are represented only to integral precision. + * + * A final compromise is to represent the multiplicative constants to only + * 8 fractional bits, rather than 13. This saves some shifting work on some + * machines, and may also reduce the cost of multiplication (since there + * are fewer one-bits in the constants). + */ + +#define CONST_BITS 8 + + +/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + +#if CONST_BITS == 8 +#define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */ +#define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */ +#define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */ +#define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */ +#else +#define FIX_0_382683433 FIX(0.382683433) +#define FIX_0_541196100 FIX(0.541196100) +#define FIX_0_707106781 FIX(0.707106781) +#define FIX_1_306562965 FIX(1.306562965) +#endif + + +/* We can gain a little more speed, with a further compromise in accuracy, + * by omitting the addition in a descaling shift. This yields an incorrectly + * rounded result half the time... + */ + +#ifndef USE_ACCURATE_ROUNDING +#undef DESCALE +#define DESCALE(x,n) RIGHT_SHIFT(x, n) +#endif + + +/* Multiply a DCTELEM variable by an INT32 constant, and immediately + * descale to yield a DCTELEM result. + */ + +#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) + + +/* + * Perform the forward DCT on one block of samples. + */ + +GLOBAL(void) +jpeg_fdct_ifast (DCTELEM * data) +{ + DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + DCTELEM tmp10, tmp11, tmp12, tmp13; + DCTELEM z1, z2, z3, z4, z5, z11, z13; + DCTELEM *dataptr; + int ctr; + SHIFT_TEMPS + + /* Pass 1: process rows. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[0] + dataptr[7]; + tmp7 = dataptr[0] - dataptr[7]; + tmp1 = dataptr[1] + dataptr[6]; + tmp6 = dataptr[1] - dataptr[6]; + tmp2 = dataptr[2] + dataptr[5]; + tmp5 = dataptr[2] - dataptr[5]; + tmp3 = dataptr[3] + dataptr[4]; + tmp4 = dataptr[3] - dataptr[4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[0] = tmp10 + tmp11; /* phase 3 */ + dataptr[4] = tmp10 - tmp11; + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ + dataptr[2] = tmp13 + z1; /* phase 5 */ + dataptr[6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */ + z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ + z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ + z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[5] = z13 + z2; /* phase 6 */ + dataptr[3] = z13 - z2; + dataptr[1] = z11 + z4; + dataptr[7] = z11 - z4; + + dataptr += DCTSIZE; /* advance pointer to next row */ + } + + /* Pass 2: process columns. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; + tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; + tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; + tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; + tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; + tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; + tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; + tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ + dataptr[DCTSIZE*4] = tmp10 - tmp11; + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ + dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ + dataptr[DCTSIZE*6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */ + z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ + z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ + z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ + dataptr[DCTSIZE*3] = z13 - z2; + dataptr[DCTSIZE*1] = z11 + z4; + dataptr[DCTSIZE*7] = z11 - z4; + + dataptr++; /* advance pointer to next column */ + } +} + +#endif /* DCT_IFAST_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jfdctint.c b/lib-third-party/libturbojpeg-ios/libjpeg/jfdctint.c new file mode 100755 index 0000000..0a78b64 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jfdctint.c @@ -0,0 +1,283 @@ +/* + * jfdctint.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a slow-but-accurate integer implementation of the + * forward DCT (Discrete Cosine Transform). + * + * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT + * on each column. Direct algorithms are also available, but they are + * much more complex and seem not to be any faster when reduced to code. + * + * This implementation is based on an algorithm described in + * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT + * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, + * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. + * The primary algorithm described there uses 11 multiplies and 29 adds. + * We use their alternate method with 12 multiplies and 32 adds. + * The advantage of this method is that no data path contains more than one + * multiplication; this allows a very simple and accurate implementation in + * scaled fixed-point arithmetic, with a minimal number of shifts. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ + +#ifdef DCT_ISLOW_SUPPORTED + + +/* + * This module is specialized to the case DCTSIZE = 8. + */ + +#if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +#endif + + +/* + * The poop on this scaling stuff is as follows: + * + * Each 1-D DCT step produces outputs which are a factor of sqrt(N) + * larger than the true DCT outputs. The final outputs are therefore + * a factor of N larger than desired; since N=8 this can be cured by + * a simple right shift at the end of the algorithm. The advantage of + * this arrangement is that we save two multiplications per 1-D DCT, + * because the y0 and y4 outputs need not be divided by sqrt(N). + * In the IJG code, this factor of 8 is removed by the quantization step + * (in jcdctmgr.c), NOT in this module. + * + * We have to do addition and subtraction of the integer inputs, which + * is no problem, and multiplication by fractional constants, which is + * a problem to do in integer arithmetic. We multiply all the constants + * by CONST_SCALE and convert them to integer constants (thus retaining + * CONST_BITS bits of precision in the constants). After doing a + * multiplication we have to divide the product by CONST_SCALE, with proper + * rounding, to produce the correct output. This division can be done + * cheaply as a right shift of CONST_BITS bits. We postpone shifting + * as long as possible so that partial sums can be added together with + * full fractional precision. + * + * The outputs of the first pass are scaled up by PASS1_BITS bits so that + * they are represented to better-than-integral precision. These outputs + * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word + * with the recommended scaling. (For 12-bit sample data, the intermediate + * array is INT32 anyway.) + * + * To avoid overflow of the 32-bit intermediate results in pass 2, we must + * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis + * shows that the values given below are the most effective. + */ + +#if BITS_IN_JSAMPLE == 8 +#define CONST_BITS 13 +#define PASS1_BITS 2 +#else +#define CONST_BITS 13 +#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ +#endif + +/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + +#if CONST_BITS == 13 +#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ +#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ +#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */ +#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ +#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ +#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */ +#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */ +#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ +#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */ +#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */ +#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ +#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */ +#else +#define FIX_0_298631336 FIX(0.298631336) +#define FIX_0_390180644 FIX(0.390180644) +#define FIX_0_541196100 FIX(0.541196100) +#define FIX_0_765366865 FIX(0.765366865) +#define FIX_0_899976223 FIX(0.899976223) +#define FIX_1_175875602 FIX(1.175875602) +#define FIX_1_501321110 FIX(1.501321110) +#define FIX_1_847759065 FIX(1.847759065) +#define FIX_1_961570560 FIX(1.961570560) +#define FIX_2_053119869 FIX(2.053119869) +#define FIX_2_562915447 FIX(2.562915447) +#define FIX_3_072711026 FIX(3.072711026) +#endif + + +/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * For 8-bit samples with the recommended scaling, all the variable + * and constant values involved are no more than 16 bits wide, so a + * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. + * For 12-bit samples, a full 32-bit multiplication will be needed. + */ + +#if BITS_IN_JSAMPLE == 8 +#define MULTIPLY(var,const) MULTIPLY16C16(var,const) +#else +#define MULTIPLY(var,const) ((var) * (const)) +#endif + + +/* + * Perform the forward DCT on one block of samples. + */ + +GLOBAL(void) +jpeg_fdct_islow (DCTELEM * data) +{ + INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + INT32 tmp10, tmp11, tmp12, tmp13; + INT32 z1, z2, z3, z4, z5; + DCTELEM *dataptr; + int ctr; + SHIFT_TEMPS + + /* Pass 1: process rows. */ + /* Note results are scaled up by sqrt(8) compared to a true DCT; */ + /* furthermore, we scale the results by 2**PASS1_BITS. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[0] + dataptr[7]; + tmp7 = dataptr[0] - dataptr[7]; + tmp1 = dataptr[1] + dataptr[6]; + tmp6 = dataptr[1] - dataptr[6]; + tmp2 = dataptr[2] + dataptr[5]; + tmp5 = dataptr[2] - dataptr[5]; + tmp3 = dataptr[3] + dataptr[4]; + tmp4 = dataptr[3] - dataptr[4]; + + /* Even part per LL&M figure 1 --- note that published figure is faulty; + * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". + */ + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); + dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); + dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), + CONST_BITS-PASS1_BITS); + dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), + CONST_BITS-PASS1_BITS); + + /* Odd part per figure 8 --- note paper omits factor of sqrt(2). + * cK represents cos(K*pi/16). + * i0..i3 in the paper are tmp4..tmp7 here. + */ + + z1 = tmp4 + tmp7; + z2 = tmp5 + tmp6; + z3 = tmp4 + tmp6; + z4 = tmp5 + tmp7; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); + dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); + dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); + dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); + + dataptr += DCTSIZE; /* advance pointer to next row */ + } + + /* Pass 2: process columns. + * We remove the PASS1_BITS scaling, but leave the results scaled up + * by an overall factor of 8. + */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; + tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; + tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; + tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; + tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; + tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; + tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; + tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; + + /* Even part per LL&M figure 1 --- note that published figure is faulty; + * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". + */ + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); + dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); + dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), + CONST_BITS+PASS1_BITS); + + /* Odd part per figure 8 --- note paper omits factor of sqrt(2). + * cK represents cos(K*pi/16). + * i0..i3 in the paper are tmp4..tmp7 here. + */ + + z1 = tmp4 + tmp7; + z2 = tmp5 + tmp6; + z3 = tmp4 + tmp6; + z4 = tmp5 + tmp7; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, + CONST_BITS+PASS1_BITS); + + dataptr++; /* advance pointer to next column */ + } +} + +#endif /* DCT_ISLOW_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jidctflt.c b/lib-third-party/libturbojpeg-ios/libjpeg/jidctflt.c new file mode 100755 index 0000000..0188ce3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jidctflt.c @@ -0,0 +1,242 @@ +/* + * jidctflt.c + * + * Copyright (C) 1994-1998, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a floating-point implementation of the + * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine + * must also perform dequantization of the input coefficients. + * + * This implementation should be more accurate than either of the integer + * IDCT implementations. However, it may not give the same results on all + * machines because of differences in roundoff behavior. Speed will depend + * on the hardware's floating point capacity. + * + * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT + * on each row (or vice versa, but it's more convenient to emit a row at + * a time). Direct algorithms are also available, but they are much more + * complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with a fixed-point + * implementation, accuracy is lost due to imprecise representation of the + * scaled quantization values. However, that problem does not arise if + * we use floating point arithmetic. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ + +#ifdef DCT_FLOAT_SUPPORTED + + +/* + * This module is specialized to the case DCTSIZE = 8. + */ + +#if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +#endif + + +/* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce a float result. + */ + +#define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval)) + + +/* + * Perform dequantization and inverse DCT on one block of coefficients. + */ + +GLOBAL(void) +jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + FAST_FLOAT tmp10, tmp11, tmp12, tmp13; + FAST_FLOAT z5, z10, z11, z12, z13; + JCOEFPTR inptr; + FLOAT_MULT_TYPE * quantptr; + FAST_FLOAT * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; ctr--) { + /* Due to quantization, we will usually find that many of the input + * coefficients are zero, especially the AC terms. We can exploit this + * by short-circuiting the IDCT calculation for any column in which all + * the AC terms are zero. In that case each output is equal to the + * DC coefficient (with scale factor as needed). + * With typical images and quantization tables, half or more of the + * column DCT calculations can be simplified this way. + */ + + if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && + inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && + inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && + inptr[DCTSIZE*7] == 0) { + /* AC terms all zero */ + FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + wsptr[DCTSIZE*4] = dcval; + wsptr[DCTSIZE*5] = dcval; + wsptr[DCTSIZE*6] = dcval; + wsptr[DCTSIZE*7] = dcval; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + continue; + } + + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp10 = tmp0 + tmp2; /* phase 3 */ + tmp11 = tmp0 - tmp2; + + tmp13 = tmp1 + tmp3; /* phases 5-3 */ + tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ + + tmp0 = tmp10 + tmp13; /* phase 2 */ + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + z13 = tmp6 + tmp5; /* phase 6 */ + z10 = tmp6 - tmp5; + z11 = tmp4 + tmp7; + z12 = tmp4 - tmp7; + + tmp7 = z11 + z13; /* phase 5 */ + tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ + + z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ + tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ + tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; /* phase 2 */ + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + wsptr[DCTSIZE*0] = tmp0 + tmp7; + wsptr[DCTSIZE*7] = tmp0 - tmp7; + wsptr[DCTSIZE*1] = tmp1 + tmp6; + wsptr[DCTSIZE*6] = tmp1 - tmp6; + wsptr[DCTSIZE*2] = tmp2 + tmp5; + wsptr[DCTSIZE*5] = tmp2 - tmp5; + wsptr[DCTSIZE*4] = tmp3 + tmp4; + wsptr[DCTSIZE*3] = tmp3 - tmp4; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + } + + /* Pass 2: process rows from work array, store into output array. */ + /* Note that we must descale the results by a factor of 8 == 2**3. */ + + wsptr = workspace; + for (ctr = 0; ctr < DCTSIZE; ctr++) { + outptr = output_buf[ctr] + output_col; + /* Rows of zeroes can be exploited in the same way as we did with columns. + * However, the column calculation has created many nonzero AC terms, so + * the simplification applies less often (typically 5% to 10% of the time). + * And testing floats for zero is relatively expensive, so we don't bother. + */ + + /* Even part */ + + tmp10 = wsptr[0] + wsptr[4]; + tmp11 = wsptr[0] - wsptr[4]; + + tmp13 = wsptr[2] + wsptr[6]; + tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13; + + tmp0 = tmp10 + tmp13; + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + z13 = wsptr[5] + wsptr[3]; + z10 = wsptr[5] - wsptr[3]; + z11 = wsptr[1] + wsptr[7]; + z12 = wsptr[1] - wsptr[7]; + + tmp7 = z11 + z13; + tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); + + z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ + tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ + tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + /* Final output stage: scale down by a factor of 8 and range-limit */ + + outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } +} + +#endif /* DCT_FLOAT_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jidctfst.c b/lib-third-party/libturbojpeg-ios/libjpeg/jidctfst.c new file mode 100755 index 0000000..dba4216 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jidctfst.c @@ -0,0 +1,368 @@ +/* + * jidctfst.c + * + * Copyright (C) 1994-1998, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a fast, not so accurate integer implementation of the + * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine + * must also perform dequantization of the input coefficients. + * + * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT + * on each row (or vice versa, but it's more convenient to emit a row at + * a time). Direct algorithms are also available, but they are much more + * complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with fixed-point math, + * accuracy is lost due to imprecise representation of the scaled + * quantization values. The smaller the quantization table entry, the less + * precise the scaled value, so this implementation does worse with high- + * quality-setting files than with low-quality ones. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ + +#ifdef DCT_IFAST_SUPPORTED + + +/* + * This module is specialized to the case DCTSIZE = 8. + */ + +#if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +#endif + + +/* Scaling decisions are generally the same as in the LL&M algorithm; + * see jidctint.c for more details. However, we choose to descale + * (right shift) multiplication products as soon as they are formed, + * rather than carrying additional fractional bits into subsequent additions. + * This compromises accuracy slightly, but it lets us save a few shifts. + * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) + * everywhere except in the multiplications proper; this saves a good deal + * of work on 16-bit-int machines. + * + * The dequantized coefficients are not integers because the AA&N scaling + * factors have been incorporated. We represent them scaled up by PASS1_BITS, + * so that the first and second IDCT rounds have the same input scaling. + * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to + * avoid a descaling shift; this compromises accuracy rather drastically + * for small quantization table entries, but it saves a lot of shifts. + * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway, + * so we use a much larger scaling factor to preserve accuracy. + * + * A final compromise is to represent the multiplicative constants to only + * 8 fractional bits, rather than 13. This saves some shifting work on some + * machines, and may also reduce the cost of multiplication (since there + * are fewer one-bits in the constants). + */ + +#if BITS_IN_JSAMPLE == 8 +#define CONST_BITS 8 +#define PASS1_BITS 2 +#else +#define CONST_BITS 8 +#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ +#endif + +/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + +#if CONST_BITS == 8 +#define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ +#define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ +#define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ +#define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ +#else +#define FIX_1_082392200 FIX(1.082392200) +#define FIX_1_414213562 FIX(1.414213562) +#define FIX_1_847759065 FIX(1.847759065) +#define FIX_2_613125930 FIX(2.613125930) +#endif + + +/* We can gain a little more speed, with a further compromise in accuracy, + * by omitting the addition in a descaling shift. This yields an incorrectly + * rounded result half the time... + */ + +#ifndef USE_ACCURATE_ROUNDING +#undef DESCALE +#define DESCALE(x,n) RIGHT_SHIFT(x, n) +#endif + + +/* Multiply a DCTELEM variable by an INT32 constant, and immediately + * descale to yield a DCTELEM result. + */ + +#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) + + +/* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce a DCTELEM result. For 8-bit data a 16x16->16 + * multiplication will do. For 12-bit data, the multiplier table is + * declared INT32, so a 32-bit multiply will be used. + */ + +#if BITS_IN_JSAMPLE == 8 +#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) +#else +#define DEQUANTIZE(coef,quantval) \ + DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) +#endif + + +/* Like DESCALE, but applies to a DCTELEM and produces an int. + * We assume that int right shift is unsigned if INT32 right shift is. + */ + +#ifdef RIGHT_SHIFT_IS_UNSIGNED +#define ISHIFT_TEMPS DCTELEM ishift_temp; +#if BITS_IN_JSAMPLE == 8 +#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */ +#else +#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */ +#endif +#define IRIGHT_SHIFT(x,shft) \ + ((ishift_temp = (x)) < 0 ? \ + (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \ + (ishift_temp >> (shft))) +#else +#define ISHIFT_TEMPS +#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) +#endif + +#ifdef USE_ACCURATE_ROUNDING +#define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n)) +#else +#define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n)) +#endif + + +/* + * Perform dequantization and inverse DCT on one block of coefficients. + */ + +GLOBAL(void) +jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + DCTELEM tmp10, tmp11, tmp12, tmp13; + DCTELEM z5, z10, z11, z12, z13; + JCOEFPTR inptr; + IFAST_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE2]; /* buffers data between passes */ + SHIFT_TEMPS /* for DESCALE */ + ISHIFT_TEMPS /* for IDESCALE */ + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (IFAST_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; ctr--) { + /* Due to quantization, we will usually find that many of the input + * coefficients are zero, especially the AC terms. We can exploit this + * by short-circuiting the IDCT calculation for any column in which all + * the AC terms are zero. In that case each output is equal to the + * DC coefficient (with scale factor as needed). + * With typical images and quantization tables, half or more of the + * column DCT calculations can be simplified this way. + */ + + if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && + inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && + inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && + inptr[DCTSIZE*7] == 0) { + /* AC terms all zero */ + int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + wsptr[DCTSIZE*4] = dcval; + wsptr[DCTSIZE*5] = dcval; + wsptr[DCTSIZE*6] = dcval; + wsptr[DCTSIZE*7] = dcval; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + continue; + } + + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp10 = tmp0 + tmp2; /* phase 3 */ + tmp11 = tmp0 - tmp2; + + tmp13 = tmp1 + tmp3; /* phases 5-3 */ + tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ + + tmp0 = tmp10 + tmp13; /* phase 2 */ + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + z13 = tmp6 + tmp5; /* phase 6 */ + z10 = tmp6 - tmp5; + z11 = tmp4 + tmp7; + z12 = tmp4 - tmp7; + + tmp7 = z11 + z13; /* phase 5 */ + tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ + + z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ + tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ + tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; /* phase 2 */ + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7); + wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7); + wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6); + wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6); + wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5); + wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5); + wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4); + wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4); + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + } + + /* Pass 2: process rows from work array, store into output array. */ + /* Note that we must descale the results by a factor of 8 == 2**3, */ + /* and also undo the PASS1_BITS scaling. */ + + wsptr = workspace; + for (ctr = 0; ctr < DCTSIZE; ctr++) { + outptr = output_buf[ctr] + output_col; + /* Rows of zeroes can be exploited in the same way as we did with columns. + * However, the column calculation has created many nonzero AC terms, so + * the simplification applies less often (typically 5% to 10% of the time). + * On machines with very fast multiplication, it's possible that the + * test takes more time than it's worth. In that case this section + * may be commented out. + */ + +#ifndef NO_ZERO_ROW_TEST + if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && + wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + outptr[2] = dcval; + outptr[3] = dcval; + outptr[4] = dcval; + outptr[5] = dcval; + outptr[6] = dcval; + outptr[7] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } +#endif + + /* Even part */ + + tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]); + tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]); + + tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]); + tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) + - tmp13; + + tmp0 = tmp10 + tmp13; + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3]; + z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3]; + z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; + z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; + + tmp7 = z11 + z13; /* phase 5 */ + tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ + + z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ + tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ + tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; /* phase 2 */ + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + /* Final output stage: scale down by a factor of 8 and range-limit */ + + outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } +} + +#endif /* DCT_IFAST_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jidctint.c b/lib-third-party/libturbojpeg-ios/libjpeg/jidctint.c new file mode 100755 index 0000000..77d8121 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jidctint.c @@ -0,0 +1,2623 @@ +/* + * jidctint.c + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Modification developed 2002-2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a slow-but-accurate integer implementation of the + * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine + * must also perform dequantization of the input coefficients. + * + * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT + * on each row (or vice versa, but it's more convenient to emit a row at + * a time). Direct algorithms are also available, but they are much more + * complex and seem not to be any faster when reduced to code. + * + * This implementation is based on an algorithm described in + * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT + * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, + * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. + * The primary algorithm described there uses 11 multiplies and 29 adds. + * We use their alternate method with 12 multiplies and 32 adds. + * The advantage of this method is that no data path contains more than one + * multiplication; this allows a very simple and accurate implementation in + * scaled fixed-point arithmetic, with a minimal number of shifts. + * + * We also provide IDCT routines with various output sample block sizes for + * direct resolution reduction or enlargement without additional resampling: + * NxN (N=1...16) pixels for one 8x8 input DCT block. + * + * For N<8 we simply take the corresponding low-frequency coefficients of + * the 8x8 input DCT block and apply an NxN point IDCT on the sub-block + * to yield the downscaled outputs. + * This can be seen as direct low-pass downsampling from the DCT domain + * point of view rather than the usual spatial domain point of view, + * yielding significant computational savings and results at least + * as good as common bilinear (averaging) spatial downsampling. + * + * For N>8 we apply a partial NxN IDCT on the 8 input coefficients as + * lower frequencies and higher frequencies assumed to be zero. + * It turns out that the computational effort is similar to the 8x8 IDCT + * regarding the output size. + * Furthermore, the scaling and descaling is the same for all IDCT sizes. + * + * CAUTION: We rely on the FIX() macro except for the N=1,2,4,8 cases + * since there would be too many additional constants to pre-calculate. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ + +#ifdef DCT_ISLOW_SUPPORTED + + +/* + * This module is specialized to the case DCTSIZE = 8. + */ + +#if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */ +#endif + + +/* + * The poop on this scaling stuff is as follows: + * + * Each 1-D IDCT step produces outputs which are a factor of sqrt(N) + * larger than the true IDCT outputs. The final outputs are therefore + * a factor of N larger than desired; since N=8 this can be cured by + * a simple right shift at the end of the algorithm. The advantage of + * this arrangement is that we save two multiplications per 1-D IDCT, + * because the y0 and y4 inputs need not be divided by sqrt(N). + * + * We have to do addition and subtraction of the integer inputs, which + * is no problem, and multiplication by fractional constants, which is + * a problem to do in integer arithmetic. We multiply all the constants + * by CONST_SCALE and convert them to integer constants (thus retaining + * CONST_BITS bits of precision in the constants). After doing a + * multiplication we have to divide the product by CONST_SCALE, with proper + * rounding, to produce the correct output. This division can be done + * cheaply as a right shift of CONST_BITS bits. We postpone shifting + * as long as possible so that partial sums can be added together with + * full fractional precision. + * + * The outputs of the first pass are scaled up by PASS1_BITS bits so that + * they are represented to better-than-integral precision. These outputs + * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word + * with the recommended scaling. (To scale up 12-bit sample data further, an + * intermediate INT32 array would be needed.) + * + * To avoid overflow of the 32-bit intermediate results in pass 2, we must + * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis + * shows that the values given below are the most effective. + */ + +#if BITS_IN_JSAMPLE == 8 +#define CONST_BITS 13 +#define PASS1_BITS 2 +#else +#define CONST_BITS 13 +#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ +#endif + +/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + +#if CONST_BITS == 13 +#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ +#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ +#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */ +#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ +#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ +#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */ +#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */ +#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ +#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */ +#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */ +#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ +#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */ +#else +#define FIX_0_298631336 FIX(0.298631336) +#define FIX_0_390180644 FIX(0.390180644) +#define FIX_0_541196100 FIX(0.541196100) +#define FIX_0_765366865 FIX(0.765366865) +#define FIX_0_899976223 FIX(0.899976223) +#define FIX_1_175875602 FIX(1.175875602) +#define FIX_1_501321110 FIX(1.501321110) +#define FIX_1_847759065 FIX(1.847759065) +#define FIX_1_961570560 FIX(1.961570560) +#define FIX_2_053119869 FIX(2.053119869) +#define FIX_2_562915447 FIX(2.562915447) +#define FIX_3_072711026 FIX(3.072711026) +#endif + + +/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * For 8-bit samples with the recommended scaling, all the variable + * and constant values involved are no more than 16 bits wide, so a + * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. + * For 12-bit samples, a full 32-bit multiplication will be needed. + */ + +#if BITS_IN_JSAMPLE == 8 +#define MULTIPLY(var,const) MULTIPLY16C16(var,const) +#else +#define MULTIPLY(var,const) ((var) * (const)) +#endif + + +/* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce an int result. In this module, both inputs and result + * are 16 bits or less, so either int or short multiply will work. + */ + +#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval)) + + +/* + * Perform dequantization and inverse DCT on one block of coefficients. + */ + +GLOBAL(void) +jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp1, tmp2, tmp3; + INT32 tmp10, tmp11, tmp12, tmp13; + INT32 z1, z2, z3, z4, z5; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE2]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ + /* furthermore, we scale the results by 2**PASS1_BITS. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; ctr--) { + /* Due to quantization, we will usually find that many of the input + * coefficients are zero, especially the AC terms. We can exploit this + * by short-circuiting the IDCT calculation for any column in which all + * the AC terms are zero. In that case each output is equal to the + * DC coefficient (with scale factor as needed). + * With typical images and quantization tables, half or more of the + * column DCT calculations can be simplified this way. + */ + + if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && + inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && + inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && + inptr[DCTSIZE*7] == 0) { + /* AC terms all zero */ + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + wsptr[DCTSIZE*4] = dcval; + wsptr[DCTSIZE*5] = dcval; + wsptr[DCTSIZE*6] = dcval; + wsptr[DCTSIZE*7] = dcval; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + continue; + } + + /* Even part: reverse the even part of the forward DCT. */ + /* The rotator is sqrt(2)*c(-6). */ + + z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + z1 = MULTIPLY(z2 + z3, FIX_0_541196100); + tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); + tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + + z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + + tmp0 = (z2 + z3) << CONST_BITS; + tmp1 = (z2 - z3) << CONST_BITS; + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + /* Odd part per figure 8; the matrix is unitary and hence its + * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. + */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + + z1 = tmp0 + tmp3; + z2 = tmp1 + tmp2; + z3 = tmp0 + tmp2; + z4 = tmp1 + tmp3; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + tmp0 += z1 + z3; + tmp1 += z2 + z4; + tmp2 += z2 + z3; + tmp3 += z1 + z4; + + /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ + + wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + } + + /* Pass 2: process rows from work array, store into output array. */ + /* Note that we must descale the results by a factor of 8 == 2**3, */ + /* and also undo the PASS1_BITS scaling. */ + + wsptr = workspace; + for (ctr = 0; ctr < DCTSIZE; ctr++) { + outptr = output_buf[ctr] + output_col; + /* Rows of zeroes can be exploited in the same way as we did with columns. + * However, the column calculation has created many nonzero AC terms, so + * the simplification applies less often (typically 5% to 10% of the time). + * On machines with very fast multiplication, it's possible that the + * test takes more time than it's worth. In that case this section + * may be commented out. + */ + +#ifndef NO_ZERO_ROW_TEST + if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && + wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + outptr[2] = dcval; + outptr[3] = dcval; + outptr[4] = dcval; + outptr[5] = dcval; + outptr[6] = dcval; + outptr[7] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } +#endif + + /* Even part: reverse the even part of the forward DCT. */ + /* The rotator is sqrt(2)*c(-6). */ + + z2 = (INT32) wsptr[2]; + z3 = (INT32) wsptr[6]; + + z1 = MULTIPLY(z2 + z3, FIX_0_541196100); + tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); + tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + + tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS; + tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS; + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + /* Odd part per figure 8; the matrix is unitary and hence its + * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. + */ + + tmp0 = (INT32) wsptr[7]; + tmp1 = (INT32) wsptr[5]; + tmp2 = (INT32) wsptr[3]; + tmp3 = (INT32) wsptr[1]; + + z1 = tmp0 + tmp3; + z2 = tmp1 + tmp2; + z3 = tmp0 + tmp2; + z4 = tmp1 + tmp3; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + tmp0 += z1 + z3; + tmp1 += z2 + z4; + tmp2 += z2 + z3; + tmp3 += z1 + z4; + + /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ + + outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } +} + +#ifdef IDCT_SCALING_SUPPORTED + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 7x7 output block. + * + * Optimized algorithm with 12 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/14). + */ + +GLOBAL(void) +jpeg_idct_7x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12, tmp13; + INT32 z1, z2, z3; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[7*7]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 7; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + tmp13 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp13 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + tmp13 += ONE << (CONST_BITS-PASS1_BITS-1); + + z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */ + tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */ + tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */ + tmp0 = z1 + z3; + z2 -= tmp0; + tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */ + tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */ + tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */ + tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */ + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + + tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */ + tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */ + tmp0 = tmp1 - tmp2; + tmp1 += tmp2; + tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276)); /* -c1 */ + tmp1 += tmp2; + z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */ + tmp0 += z2; + tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */ + + /* Final output stage */ + + wsptr[7*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[7*6] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS); + wsptr[7*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS); + wsptr[7*5] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS); + wsptr[7*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS); + wsptr[7*4] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS); + wsptr[7*3] = (int) RIGHT_SHIFT(tmp13, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 7 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 7; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + tmp13 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + tmp13 <<= CONST_BITS; + + z1 = (INT32) wsptr[2]; + z2 = (INT32) wsptr[4]; + z3 = (INT32) wsptr[6]; + + tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */ + tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */ + tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */ + tmp0 = z1 + z3; + z2 -= tmp0; + tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */ + tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */ + tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */ + tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */ + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + + tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */ + tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */ + tmp0 = tmp1 - tmp2; + tmp1 += tmp2; + tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276)); /* -c1 */ + tmp1 += tmp2; + z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */ + tmp0 += z2; + tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 7; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 6x6 output block. + * + * Optimized algorithm with 3 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/12). + */ + +GLOBAL(void) +jpeg_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12; + INT32 z1, z2, z3; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[6*6]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 6; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp0 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */ + tmp1 = tmp0 + tmp10; + tmp11 = RIGHT_SHIFT(tmp0 - tmp10 - tmp10, CONST_BITS-PASS1_BITS); + tmp10 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */ + tmp10 = tmp1 + tmp0; + tmp12 = tmp1 - tmp0; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */ + tmp0 = tmp1 + ((z1 + z2) << CONST_BITS); + tmp2 = tmp1 + ((z3 - z2) << CONST_BITS); + tmp1 = (z1 - z2 - z3) << PASS1_BITS; + + /* Final output stage */ + + wsptr[6*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[6*5] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS); + wsptr[6*1] = (int) (tmp11 + tmp1); + wsptr[6*4] = (int) (tmp11 - tmp1); + wsptr[6*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS); + wsptr[6*3] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 6 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 6; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + tmp0 <<= CONST_BITS; + tmp2 = (INT32) wsptr[4]; + tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */ + tmp1 = tmp0 + tmp10; + tmp11 = tmp0 - tmp10 - tmp10; + tmp10 = (INT32) wsptr[2]; + tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */ + tmp10 = tmp1 + tmp0; + tmp12 = tmp1 - tmp0; + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */ + tmp0 = tmp1 + ((z1 + z2) << CONST_BITS); + tmp2 = tmp1 + ((z3 - z2) << CONST_BITS); + tmp1 = (z1 - z2 - z3) << CONST_BITS; + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 6; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 5x5 output block. + * + * Optimized algorithm with 5 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/10). + */ + +GLOBAL(void) +jpeg_idct_5x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp1, tmp10, tmp11, tmp12; + INT32 z1, z2, z3; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[5*5]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 5; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp12 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + tmp12 += ONE << (CONST_BITS-PASS1_BITS-1); + tmp0 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + tmp1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */ + z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */ + z3 = tmp12 + z2; + tmp10 = z3 + z1; + tmp11 = z3 - z1; + tmp12 -= z2 << 2; + + /* Odd part */ + + z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + + z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */ + tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */ + tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */ + + /* Final output stage */ + + wsptr[5*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[5*4] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS); + wsptr[5*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS); + wsptr[5*3] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS); + wsptr[5*2] = (int) RIGHT_SHIFT(tmp12, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 5 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 5; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + tmp12 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + tmp12 <<= CONST_BITS; + tmp0 = (INT32) wsptr[2]; + tmp1 = (INT32) wsptr[4]; + z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */ + z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */ + z3 = tmp12 + z2; + tmp10 = z3 + z1; + tmp11 = z3 - z1; + tmp12 -= z2 << 2; + + /* Odd part */ + + z2 = (INT32) wsptr[1]; + z3 = (INT32) wsptr[3]; + + z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */ + tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */ + tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 5; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 3x3 output block. + * + * Optimized algorithm with 2 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/6). + */ + +GLOBAL(void) +jpeg_idct_3x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp2, tmp10, tmp12; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[3*3]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 3; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp0 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */ + tmp10 = tmp0 + tmp12; + tmp2 = tmp0 - tmp12 - tmp12; + + /* Odd part */ + + tmp12 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */ + + /* Final output stage */ + + wsptr[3*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[3*2] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS); + wsptr[3*1] = (int) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 3 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 3; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + tmp0 <<= CONST_BITS; + tmp2 = (INT32) wsptr[2]; + tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */ + tmp10 = tmp0 + tmp12; + tmp2 = tmp0 - tmp12 - tmp12; + + /* Odd part */ + + tmp12 = (INT32) wsptr[1]; + tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 3; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 9x9 output block. + * + * Optimized algorithm with 10 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/18). + */ + +GLOBAL(void) +jpeg_idct_9x9 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13, tmp14; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*9]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp0 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + tmp0 += ONE << (CONST_BITS-PASS1_BITS-1); + + z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */ + tmp1 = tmp0 + tmp3; + tmp2 = tmp0 - tmp3 - tmp3; + + tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */ + tmp11 = tmp2 + tmp0; + tmp14 = tmp2 - tmp0 - tmp0; + + tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */ + tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */ + tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */ + + tmp10 = tmp1 + tmp0 - tmp3; + tmp12 = tmp1 - tmp0 + tmp2; + tmp13 = tmp1 - tmp2 + tmp3; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + z2 = MULTIPLY(z2, - FIX(1.224744871)); /* -c3 */ + + tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */ + tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */ + tmp0 = tmp2 + tmp3 - z2; + tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */ + tmp2 += z2 - tmp1; + tmp3 += z2 + tmp1; + tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */ + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS); + wsptr[8*7] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS); + wsptr[8*3] = (int) RIGHT_SHIFT(tmp13 + tmp3, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp13 - tmp3, CONST_BITS-PASS1_BITS); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp14, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 9 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 9; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + tmp0 <<= CONST_BITS; + + z1 = (INT32) wsptr[2]; + z2 = (INT32) wsptr[4]; + z3 = (INT32) wsptr[6]; + + tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */ + tmp1 = tmp0 + tmp3; + tmp2 = tmp0 - tmp3 - tmp3; + + tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */ + tmp11 = tmp2 + tmp0; + tmp14 = tmp2 - tmp0 - tmp0; + + tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */ + tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */ + tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */ + + tmp10 = tmp1 + tmp0 - tmp3; + tmp12 = tmp1 - tmp0 + tmp2; + tmp13 = tmp1 - tmp2 + tmp3; + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + z4 = (INT32) wsptr[7]; + + z2 = MULTIPLY(z2, - FIX(1.224744871)); /* -c3 */ + + tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */ + tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */ + tmp0 = tmp2 + tmp3 - z2; + tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */ + tmp2 += z2 - tmp1; + tmp3 += z2 + tmp1; + tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 10x10 output block. + * + * Optimized algorithm with 12 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/20). + */ + +GLOBAL(void) +jpeg_idct_10x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp10, tmp11, tmp12, tmp13, tmp14; + INT32 tmp20, tmp21, tmp22, tmp23, tmp24; + INT32 z1, z2, z3, z4, z5; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*10]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + z3 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + z3 += ONE << (CONST_BITS-PASS1_BITS-1); + z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */ + z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */ + tmp10 = z3 + z1; + tmp11 = z3 - z2; + + tmp22 = RIGHT_SHIFT(z3 - ((z1 - z2) << 1), /* c0 = (c4-c8)*2 */ + CONST_BITS-PASS1_BITS); + + z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */ + tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */ + tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */ + + tmp20 = tmp10 + tmp12; + tmp24 = tmp10 - tmp12; + tmp21 = tmp11 + tmp13; + tmp23 = tmp11 - tmp13; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + tmp11 = z2 + z4; + tmp13 = z2 - z4; + + tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */ + z5 = z3 << CONST_BITS; + + z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */ + z4 = z5 + tmp12; + + tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */ + tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */ + + z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */ + z4 = z5 - tmp12 - (tmp13 << (CONST_BITS - 1)); + + tmp12 = (z1 - tmp13 - z3) << PASS1_BITS; + + tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */ + tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */ + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*9] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) (tmp22 + tmp12); + wsptr[8*7] = (int) (tmp22 - tmp12); + wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 10 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 10; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + z3 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + z3 <<= CONST_BITS; + z4 = (INT32) wsptr[4]; + z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */ + z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */ + tmp10 = z3 + z1; + tmp11 = z3 - z2; + + tmp22 = z3 - ((z1 - z2) << 1); /* c0 = (c4-c8)*2 */ + + z2 = (INT32) wsptr[2]; + z3 = (INT32) wsptr[6]; + + z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */ + tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */ + tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */ + + tmp20 = tmp10 + tmp12; + tmp24 = tmp10 - tmp12; + tmp21 = tmp11 + tmp13; + tmp23 = tmp11 - tmp13; + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + z3 <<= CONST_BITS; + z4 = (INT32) wsptr[7]; + + tmp11 = z2 + z4; + tmp13 = z2 - z4; + + tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */ + + z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */ + z4 = z3 + tmp12; + + tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */ + tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */ + + z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */ + z4 = z3 - tmp12 - (tmp13 << (CONST_BITS - 1)); + + tmp12 = ((z1 - tmp13) << CONST_BITS) - z3; + + tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */ + tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 11x11 output block. + * + * Optimized algorithm with 24 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/22). + */ + +GLOBAL(void) +jpeg_idct_11x11 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp10, tmp11, tmp12, tmp13, tmp14; + INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*11]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp10 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + tmp10 += ONE << (CONST_BITS-PASS1_BITS-1); + + z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132)); /* c2+c4 */ + tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045)); /* c2-c6 */ + z4 = z1 + z3; + tmp24 = MULTIPLY(z4, - FIX(1.155664402)); /* -(c2-c10) */ + z4 -= z2; + tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976)); /* c2 */ + tmp21 = tmp20 + tmp23 + tmp25 - + MULTIPLY(z2, FIX(1.821790775)); /* c2+c4+c10-c6 */ + tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */ + tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */ + tmp24 += tmp25; + tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120)); /* c8+c10 */ + tmp24 += MULTIPLY(z2, FIX(1.944413522)) - /* c2+c8 */ + MULTIPLY(z1, FIX(1.390975730)); /* c4+c10 */ + tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562)); /* c0 */ + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + tmp11 = z1 + z2; + tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */ + tmp11 = MULTIPLY(tmp11, FIX(0.887983902)); /* c3-c9 */ + tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295)); /* c5-c9 */ + tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */ + tmp10 = tmp11 + tmp12 + tmp13 - + MULTIPLY(z1, FIX(0.923107866)); /* c7+c5+c3-c1-2*c9 */ + z1 = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */ + tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588)); /* c1+c7+3*c9-c3 */ + tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623)); /* c3+c5-c7-c9 */ + z1 = MULTIPLY(z2 + z4, - FIX(1.798248910)); /* -(c1+c9) */ + tmp11 += z1; + tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632)); /* c1+c5+c9-c7 */ + tmp14 += MULTIPLY(z2, - FIX(1.467221301)) + /* -(c5+c9) */ + MULTIPLY(z3, FIX(1.001388905)) - /* c1-c9 */ + MULTIPLY(z4, FIX(1.684843907)); /* c3+c9 */ + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*10] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*9] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*7] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp25, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 11 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 11; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + tmp10 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + tmp10 <<= CONST_BITS; + + z1 = (INT32) wsptr[2]; + z2 = (INT32) wsptr[4]; + z3 = (INT32) wsptr[6]; + + tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132)); /* c2+c4 */ + tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045)); /* c2-c6 */ + z4 = z1 + z3; + tmp24 = MULTIPLY(z4, - FIX(1.155664402)); /* -(c2-c10) */ + z4 -= z2; + tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976)); /* c2 */ + tmp21 = tmp20 + tmp23 + tmp25 - + MULTIPLY(z2, FIX(1.821790775)); /* c2+c4+c10-c6 */ + tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */ + tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */ + tmp24 += tmp25; + tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120)); /* c8+c10 */ + tmp24 += MULTIPLY(z2, FIX(1.944413522)) - /* c2+c8 */ + MULTIPLY(z1, FIX(1.390975730)); /* c4+c10 */ + tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562)); /* c0 */ + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + z4 = (INT32) wsptr[7]; + + tmp11 = z1 + z2; + tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */ + tmp11 = MULTIPLY(tmp11, FIX(0.887983902)); /* c3-c9 */ + tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295)); /* c5-c9 */ + tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */ + tmp10 = tmp11 + tmp12 + tmp13 - + MULTIPLY(z1, FIX(0.923107866)); /* c7+c5+c3-c1-2*c9 */ + z1 = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */ + tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588)); /* c1+c7+3*c9-c3 */ + tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623)); /* c3+c5-c7-c9 */ + z1 = MULTIPLY(z2 + z4, - FIX(1.798248910)); /* -(c1+c9) */ + tmp11 += z1; + tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632)); /* c1+c5+c9-c7 */ + tmp14 += MULTIPLY(z2, - FIX(1.467221301)) + /* -(c5+c9) */ + MULTIPLY(z3, FIX(1.001388905)) - /* c1-c9 */ + MULTIPLY(z4, FIX(1.684843907)); /* c3+c9 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 12x12 output block. + * + * Optimized algorithm with 15 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/24). + */ + +GLOBAL(void) +jpeg_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15; + INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*12]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + z3 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + z3 += ONE << (CONST_BITS-PASS1_BITS-1); + + z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */ + + tmp10 = z3 + z4; + tmp11 = z3 - z4; + + z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */ + z1 <<= CONST_BITS; + z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + z2 <<= CONST_BITS; + + tmp12 = z1 - z2; + + tmp21 = z3 + tmp12; + tmp24 = z3 - tmp12; + + tmp12 = z4 + z2; + + tmp20 = tmp10 + tmp12; + tmp25 = tmp10 - tmp12; + + tmp12 = z4 - z1 - z2; + + tmp22 = tmp11 + tmp12; + tmp23 = tmp11 - tmp12; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + tmp11 = MULTIPLY(z2, FIX(1.306562965)); /* c3 */ + tmp14 = MULTIPLY(z2, - FIX_0_541196100); /* -c9 */ + + tmp10 = z1 + z3; + tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669)); /* c7 */ + tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384)); /* c5-c7 */ + tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716)); /* c1-c5 */ + tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580)); /* -(c7+c11) */ + tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */ + tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */ + tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) - /* c7-c11 */ + MULTIPLY(z4, FIX(1.982889723)); /* c5+c7 */ + + z1 -= z4; + z2 -= z3; + z3 = MULTIPLY(z1 + z2, FIX_0_541196100); /* c9 */ + tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865); /* c3-c9 */ + tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065); /* c3+c9 */ + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*11] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*10] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*9] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*7] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 12 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 12; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + z3 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + z3 <<= CONST_BITS; + + z4 = (INT32) wsptr[4]; + z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */ + + tmp10 = z3 + z4; + tmp11 = z3 - z4; + + z1 = (INT32) wsptr[2]; + z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */ + z1 <<= CONST_BITS; + z2 = (INT32) wsptr[6]; + z2 <<= CONST_BITS; + + tmp12 = z1 - z2; + + tmp21 = z3 + tmp12; + tmp24 = z3 - tmp12; + + tmp12 = z4 + z2; + + tmp20 = tmp10 + tmp12; + tmp25 = tmp10 - tmp12; + + tmp12 = z4 - z1 - z2; + + tmp22 = tmp11 + tmp12; + tmp23 = tmp11 - tmp12; + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + z4 = (INT32) wsptr[7]; + + tmp11 = MULTIPLY(z2, FIX(1.306562965)); /* c3 */ + tmp14 = MULTIPLY(z2, - FIX_0_541196100); /* -c9 */ + + tmp10 = z1 + z3; + tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669)); /* c7 */ + tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384)); /* c5-c7 */ + tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716)); /* c1-c5 */ + tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580)); /* -(c7+c11) */ + tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */ + tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */ + tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) - /* c7-c11 */ + MULTIPLY(z4, FIX(1.982889723)); /* c5+c7 */ + + z1 -= z4; + z2 -= z3; + z3 = MULTIPLY(z1 + z2, FIX_0_541196100); /* c9 */ + tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865); /* c3-c9 */ + tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065); /* c3+c9 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 13x13 output block. + * + * Optimized algorithm with 29 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/26). + */ + +GLOBAL(void) +jpeg_idct_13x13 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15; + INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*13]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + z1 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + z1 += ONE << (CONST_BITS-PASS1_BITS-1); + + z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z4 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp10 = z3 + z4; + tmp11 = z3 - z4; + + tmp12 = MULTIPLY(tmp10, FIX(1.155388986)); /* (c4+c6)/2 */ + tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1; /* (c4-c6)/2 */ + + tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13; /* c2 */ + tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13; /* c10 */ + + tmp12 = MULTIPLY(tmp10, FIX(0.316450131)); /* (c8-c12)/2 */ + tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1; /* (c8+c12)/2 */ + + tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13; /* c6 */ + tmp25 = MULTIPLY(z2, - FIX(1.252223920)) + tmp12 + tmp13; /* c4 */ + + tmp12 = MULTIPLY(tmp10, FIX(0.435816023)); /* (c2-c10)/2 */ + tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1; /* (c2+c10)/2 */ + + tmp23 = MULTIPLY(z2, - FIX(0.170464608)) - tmp12 - tmp13; /* c12 */ + tmp24 = MULTIPLY(z2, - FIX(0.803364869)) + tmp12 - tmp13; /* c8 */ + + tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1; /* c0 */ + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651)); /* c3 */ + tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945)); /* c5 */ + tmp15 = z1 + z4; + tmp13 = MULTIPLY(tmp15, FIX(0.937797057)); /* c7 */ + tmp10 = tmp11 + tmp12 + tmp13 - + MULTIPLY(z1, FIX(2.020082300)); /* c7+c5+c3-c1 */ + tmp14 = MULTIPLY(z2 + z3, - FIX(0.338443458)); /* -c11 */ + tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */ + tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */ + tmp14 = MULTIPLY(z2 + z4, - FIX(1.163874945)); /* -c5 */ + tmp11 += tmp14; + tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */ + tmp14 = MULTIPLY(z3 + z4, - FIX(0.657217813)); /* -c9 */ + tmp12 += tmp14; + tmp13 += tmp14; + tmp15 = MULTIPLY(tmp15, FIX(0.338443458)); /* c11 */ + tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */ + MULTIPLY(z2, FIX(0.466105296)); /* c1-c7 */ + z1 = MULTIPLY(z3 - z2, FIX(0.937797057)); /* c7 */ + tmp14 += z1; + tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) - /* c3-c7 */ + MULTIPLY(z4, FIX(1.742345811)); /* c1+c11 */ + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*12] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*11] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*10] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*9] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS); + wsptr[8*7] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp26, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 13 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 13; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + z1 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + z1 <<= CONST_BITS; + + z2 = (INT32) wsptr[2]; + z3 = (INT32) wsptr[4]; + z4 = (INT32) wsptr[6]; + + tmp10 = z3 + z4; + tmp11 = z3 - z4; + + tmp12 = MULTIPLY(tmp10, FIX(1.155388986)); /* (c4+c6)/2 */ + tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1; /* (c4-c6)/2 */ + + tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13; /* c2 */ + tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13; /* c10 */ + + tmp12 = MULTIPLY(tmp10, FIX(0.316450131)); /* (c8-c12)/2 */ + tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1; /* (c8+c12)/2 */ + + tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13; /* c6 */ + tmp25 = MULTIPLY(z2, - FIX(1.252223920)) + tmp12 + tmp13; /* c4 */ + + tmp12 = MULTIPLY(tmp10, FIX(0.435816023)); /* (c2-c10)/2 */ + tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1; /* (c2+c10)/2 */ + + tmp23 = MULTIPLY(z2, - FIX(0.170464608)) - tmp12 - tmp13; /* c12 */ + tmp24 = MULTIPLY(z2, - FIX(0.803364869)) + tmp12 - tmp13; /* c8 */ + + tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1; /* c0 */ + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + z4 = (INT32) wsptr[7]; + + tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651)); /* c3 */ + tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945)); /* c5 */ + tmp15 = z1 + z4; + tmp13 = MULTIPLY(tmp15, FIX(0.937797057)); /* c7 */ + tmp10 = tmp11 + tmp12 + tmp13 - + MULTIPLY(z1, FIX(2.020082300)); /* c7+c5+c3-c1 */ + tmp14 = MULTIPLY(z2 + z3, - FIX(0.338443458)); /* -c11 */ + tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */ + tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */ + tmp14 = MULTIPLY(z2 + z4, - FIX(1.163874945)); /* -c5 */ + tmp11 += tmp14; + tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */ + tmp14 = MULTIPLY(z3 + z4, - FIX(0.657217813)); /* -c9 */ + tmp12 += tmp14; + tmp13 += tmp14; + tmp15 = MULTIPLY(tmp15, FIX(0.338443458)); /* c11 */ + tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */ + MULTIPLY(z2, FIX(0.466105296)); /* c1-c7 */ + z1 = MULTIPLY(z3 - z2, FIX(0.937797057)); /* c7 */ + tmp14 += z1; + tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) - /* c3-c7 */ + MULTIPLY(z4, FIX(1.742345811)); /* c1+c11 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 14x14 output block. + * + * Optimized algorithm with 20 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/28). + */ + +GLOBAL(void) +jpeg_idct_14x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16; + INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*14]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + z1 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + z1 += ONE << (CONST_BITS-PASS1_BITS-1); + z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z2 = MULTIPLY(z4, FIX(1.274162392)); /* c4 */ + z3 = MULTIPLY(z4, FIX(0.314692123)); /* c12 */ + z4 = MULTIPLY(z4, FIX(0.881747734)); /* c8 */ + + tmp10 = z1 + z2; + tmp11 = z1 + z3; + tmp12 = z1 - z4; + + tmp23 = RIGHT_SHIFT(z1 - ((z2 + z3 - z4) << 1), /* c0 = (c4+c12-c8)*2 */ + CONST_BITS-PASS1_BITS); + + z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + z3 = MULTIPLY(z1 + z2, FIX(1.105676686)); /* c6 */ + + tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */ + tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */ + tmp15 = MULTIPLY(z1, FIX(0.613604268)) - /* c10 */ + MULTIPLY(z2, FIX(1.378756276)); /* c2 */ + + tmp20 = tmp10 + tmp13; + tmp26 = tmp10 - tmp13; + tmp21 = tmp11 + tmp14; + tmp25 = tmp11 - tmp14; + tmp22 = tmp12 + tmp15; + tmp24 = tmp12 - tmp15; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + tmp13 = z4 << CONST_BITS; + + tmp14 = z1 + z3; + tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607)); /* c3 */ + tmp12 = MULTIPLY(tmp14, FIX(1.197448846)); /* c5 */ + tmp10 = tmp11 + tmp12 + tmp13 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */ + tmp14 = MULTIPLY(tmp14, FIX(0.752406978)); /* c9 */ + tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426)); /* c9+c11-c13 */ + z1 -= z2; + tmp15 = MULTIPLY(z1, FIX(0.467085129)) - tmp13; /* c11 */ + tmp16 += tmp15; + z1 += z4; + z4 = MULTIPLY(z2 + z3, - FIX(0.158341681)) - tmp13; /* -c13 */ + tmp11 += z4 - MULTIPLY(z2, FIX(0.424103948)); /* c3-c9-c13 */ + tmp12 += z4 - MULTIPLY(z3, FIX(2.373959773)); /* c3+c5-c13 */ + z4 = MULTIPLY(z3 - z2, FIX(1.405321284)); /* c1 */ + tmp14 += z4 + tmp13 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */ + tmp15 += z4 + MULTIPLY(z2, FIX(0.674957567)); /* c1+c11-c5 */ + + tmp13 = (z1 - z3) << PASS1_BITS; + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*13] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*12] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*11] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*3] = (int) (tmp23 + tmp13); + wsptr[8*10] = (int) (tmp23 - tmp13); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*9] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS-PASS1_BITS); + wsptr[8*7] = (int) RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 14 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 14; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + z1 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + z1 <<= CONST_BITS; + z4 = (INT32) wsptr[4]; + z2 = MULTIPLY(z4, FIX(1.274162392)); /* c4 */ + z3 = MULTIPLY(z4, FIX(0.314692123)); /* c12 */ + z4 = MULTIPLY(z4, FIX(0.881747734)); /* c8 */ + + tmp10 = z1 + z2; + tmp11 = z1 + z3; + tmp12 = z1 - z4; + + tmp23 = z1 - ((z2 + z3 - z4) << 1); /* c0 = (c4+c12-c8)*2 */ + + z1 = (INT32) wsptr[2]; + z2 = (INT32) wsptr[6]; + + z3 = MULTIPLY(z1 + z2, FIX(1.105676686)); /* c6 */ + + tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */ + tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */ + tmp15 = MULTIPLY(z1, FIX(0.613604268)) - /* c10 */ + MULTIPLY(z2, FIX(1.378756276)); /* c2 */ + + tmp20 = tmp10 + tmp13; + tmp26 = tmp10 - tmp13; + tmp21 = tmp11 + tmp14; + tmp25 = tmp11 - tmp14; + tmp22 = tmp12 + tmp15; + tmp24 = tmp12 - tmp15; + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + z4 = (INT32) wsptr[7]; + z4 <<= CONST_BITS; + + tmp14 = z1 + z3; + tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607)); /* c3 */ + tmp12 = MULTIPLY(tmp14, FIX(1.197448846)); /* c5 */ + tmp10 = tmp11 + tmp12 + z4 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */ + tmp14 = MULTIPLY(tmp14, FIX(0.752406978)); /* c9 */ + tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426)); /* c9+c11-c13 */ + z1 -= z2; + tmp15 = MULTIPLY(z1, FIX(0.467085129)) - z4; /* c11 */ + tmp16 += tmp15; + tmp13 = MULTIPLY(z2 + z3, - FIX(0.158341681)) - z4; /* -c13 */ + tmp11 += tmp13 - MULTIPLY(z2, FIX(0.424103948)); /* c3-c9-c13 */ + tmp12 += tmp13 - MULTIPLY(z3, FIX(2.373959773)); /* c3+c5-c13 */ + tmp13 = MULTIPLY(z3 - z2, FIX(1.405321284)); /* c1 */ + tmp14 += tmp13 + z4 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */ + tmp15 += tmp13 + MULTIPLY(z2, FIX(0.674957567)); /* c1+c11-c5 */ + + tmp13 = ((z1 - z3) << CONST_BITS) + z4; + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp16, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp16, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 15x15 output block. + * + * Optimized algorithm with 22 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/30). + */ + +GLOBAL(void) +jpeg_idct_15x15 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16; + INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*15]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + z1 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + z1 += ONE << (CONST_BITS-PASS1_BITS-1); + + z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + z4 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */ + tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */ + + tmp12 = z1 - tmp10; + tmp13 = z1 + tmp11; + z1 -= (tmp11 - tmp10) << 1; /* c0 = (c6-c12)*2 */ + + z4 = z2 - z3; + z3 += z2; + tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */ + tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */ + z2 = MULTIPLY(z2, FIX(1.439773946)); /* c4+c14 */ + + tmp20 = tmp13 + tmp10 + tmp11; + tmp23 = tmp12 - tmp10 + tmp11 + z2; + + tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */ + tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */ + + tmp25 = tmp13 - tmp10 - tmp11; + tmp26 = tmp12 + tmp10 - tmp11 - z2; + + tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */ + tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */ + + tmp21 = tmp12 + tmp10 + tmp11; + tmp24 = tmp13 - tmp10 + tmp11; + tmp11 += tmp11; + tmp22 = z1 + tmp11; /* c10 = c6-c12 */ + tmp27 = z1 - tmp11 - tmp11; /* c0 = (c6-c12)*2 */ + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z4 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z3 = MULTIPLY(z4, FIX(1.224744871)); /* c5 */ + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + tmp13 = z2 - z4; + tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876)); /* c9 */ + tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148)); /* c3-c9 */ + tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899)); /* c3+c9 */ + + tmp13 = MULTIPLY(z2, - FIX(0.831253876)); /* -c9 */ + tmp15 = MULTIPLY(z2, - FIX(1.344997024)); /* -c3 */ + z2 = z1 - z4; + tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353)); /* c1 */ + + tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */ + tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */ + tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3; /* c5 */ + z2 = MULTIPLY(z1 + z4, FIX(0.575212477)); /* c11 */ + tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3; /* c7-c11 */ + tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3; /* c11+c13 */ + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*14] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*13] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*12] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*11] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*10] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS); + wsptr[8*9] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS-PASS1_BITS); + wsptr[8*7] = (int) RIGHT_SHIFT(tmp27, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 15 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 15; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + z1 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + z1 <<= CONST_BITS; + + z2 = (INT32) wsptr[2]; + z3 = (INT32) wsptr[4]; + z4 = (INT32) wsptr[6]; + + tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */ + tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */ + + tmp12 = z1 - tmp10; + tmp13 = z1 + tmp11; + z1 -= (tmp11 - tmp10) << 1; /* c0 = (c6-c12)*2 */ + + z4 = z2 - z3; + z3 += z2; + tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */ + tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */ + z2 = MULTIPLY(z2, FIX(1.439773946)); /* c4+c14 */ + + tmp20 = tmp13 + tmp10 + tmp11; + tmp23 = tmp12 - tmp10 + tmp11 + z2; + + tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */ + tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */ + + tmp25 = tmp13 - tmp10 - tmp11; + tmp26 = tmp12 + tmp10 - tmp11 - z2; + + tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */ + tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */ + + tmp21 = tmp12 + tmp10 + tmp11; + tmp24 = tmp13 - tmp10 + tmp11; + tmp11 += tmp11; + tmp22 = z1 + tmp11; /* c10 = c6-c12 */ + tmp27 = z1 - tmp11 - tmp11; /* c0 = (c6-c12)*2 */ + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z4 = (INT32) wsptr[5]; + z3 = MULTIPLY(z4, FIX(1.224744871)); /* c5 */ + z4 = (INT32) wsptr[7]; + + tmp13 = z2 - z4; + tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876)); /* c9 */ + tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148)); /* c3-c9 */ + tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899)); /* c3+c9 */ + + tmp13 = MULTIPLY(z2, - FIX(0.831253876)); /* -c9 */ + tmp15 = MULTIPLY(z2, - FIX(1.344997024)); /* -c3 */ + z2 = z1 - z4; + tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353)); /* c1 */ + + tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */ + tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */ + tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3; /* c5 */ + z2 = MULTIPLY(z1 + z4, FIX(0.575212477)); /* c11 */ + tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3; /* c7-c11 */ + tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3; /* c11+c13 */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp16, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp16, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp27, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a 16x16 output block. + * + * Optimized algorithm with 28 multiplications in the 1-D kernel. + * cK represents sqrt(2) * cos(K*pi/32). + */ + +GLOBAL(void) +jpeg_idct_16x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13; + INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[8*16]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) { + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp0 <<= CONST_BITS; + /* Add fudge factor here for final descale. */ + tmp0 += 1 << (CONST_BITS-PASS1_BITS-1); + + z1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */ + tmp2 = MULTIPLY(z1, FIX_0_541196100); /* c12[16] = c6[8] */ + + tmp10 = tmp0 + tmp1; + tmp11 = tmp0 - tmp1; + tmp12 = tmp0 + tmp2; + tmp13 = tmp0 - tmp2; + + z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + z3 = z1 - z2; + z4 = MULTIPLY(z3, FIX(0.275899379)); /* c14[16] = c7[8] */ + z3 = MULTIPLY(z3, FIX(1.387039845)); /* c2[16] = c1[8] */ + + tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447); /* (c6+c2)[16] = (c3+c1)[8] */ + tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223); /* (c6-c14)[16] = (c3-c7)[8] */ + tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */ + tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */ + + tmp20 = tmp10 + tmp0; + tmp27 = tmp10 - tmp0; + tmp21 = tmp12 + tmp1; + tmp26 = tmp12 - tmp1; + tmp22 = tmp13 + tmp2; + tmp25 = tmp13 - tmp2; + tmp23 = tmp11 + tmp3; + tmp24 = tmp11 - tmp3; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + tmp11 = z1 + z3; + + tmp1 = MULTIPLY(z1 + z2, FIX(1.353318001)); /* c3 */ + tmp2 = MULTIPLY(tmp11, FIX(1.247225013)); /* c5 */ + tmp3 = MULTIPLY(z1 + z4, FIX(1.093201867)); /* c7 */ + tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586)); /* c9 */ + tmp11 = MULTIPLY(tmp11, FIX(0.666655658)); /* c11 */ + tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528)); /* c13 */ + tmp0 = tmp1 + tmp2 + tmp3 - + MULTIPLY(z1, FIX(2.286341144)); /* c7+c5+c3-c1 */ + tmp13 = tmp10 + tmp11 + tmp12 - + MULTIPLY(z1, FIX(1.835730603)); /* c9+c11+c13-c15 */ + z1 = MULTIPLY(z2 + z3, FIX(0.138617169)); /* c15 */ + tmp1 += z1 + MULTIPLY(z2, FIX(0.071888074)); /* c9+c11-c3-c15 */ + tmp2 += z1 - MULTIPLY(z3, FIX(1.125726048)); /* c5+c7+c15-c3 */ + z1 = MULTIPLY(z3 - z2, FIX(1.407403738)); /* c1 */ + tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282)); /* c1+c11-c9-c13 */ + tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411)); /* c1+c5+c13-c7 */ + z2 += z4; + z1 = MULTIPLY(z2, - FIX(0.666655658)); /* -c11 */ + tmp1 += z1; + tmp3 += z1 + MULTIPLY(z4, FIX(1.065388962)); /* c3+c11+c15-c7 */ + z2 = MULTIPLY(z2, - FIX(1.247225013)); /* -c5 */ + tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809)); /* c1+c5+c9-c13 */ + tmp12 += z2; + z2 = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */ + tmp2 += z2; + tmp3 += z2; + z2 = MULTIPLY(z4 - z3, FIX(0.410524528)); /* c13 */ + tmp10 += z2; + tmp11 += z2; + + /* Final output stage */ + + wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[8*15] = (int) RIGHT_SHIFT(tmp20 - tmp0, CONST_BITS-PASS1_BITS); + wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp1, CONST_BITS-PASS1_BITS); + wsptr[8*14] = (int) RIGHT_SHIFT(tmp21 - tmp1, CONST_BITS-PASS1_BITS); + wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp2, CONST_BITS-PASS1_BITS); + wsptr[8*13] = (int) RIGHT_SHIFT(tmp22 - tmp2, CONST_BITS-PASS1_BITS); + wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp3, CONST_BITS-PASS1_BITS); + wsptr[8*12] = (int) RIGHT_SHIFT(tmp23 - tmp3, CONST_BITS-PASS1_BITS); + wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*11] = (int) RIGHT_SHIFT(tmp24 - tmp10, CONST_BITS-PASS1_BITS); + wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*10] = (int) RIGHT_SHIFT(tmp25 - tmp11, CONST_BITS-PASS1_BITS); + wsptr[8*6] = (int) RIGHT_SHIFT(tmp26 + tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*9] = (int) RIGHT_SHIFT(tmp26 - tmp12, CONST_BITS-PASS1_BITS); + wsptr[8*7] = (int) RIGHT_SHIFT(tmp27 + tmp13, CONST_BITS-PASS1_BITS); + wsptr[8*8] = (int) RIGHT_SHIFT(tmp27 - tmp13, CONST_BITS-PASS1_BITS); + } + + /* Pass 2: process 16 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 16; ctr++) { + outptr = output_buf[ctr] + output_col; + + /* Even part */ + + /* Add fudge factor here for final descale. */ + tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); + tmp0 <<= CONST_BITS; + + z1 = (INT32) wsptr[4]; + tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */ + tmp2 = MULTIPLY(z1, FIX_0_541196100); /* c12[16] = c6[8] */ + + tmp10 = tmp0 + tmp1; + tmp11 = tmp0 - tmp1; + tmp12 = tmp0 + tmp2; + tmp13 = tmp0 - tmp2; + + z1 = (INT32) wsptr[2]; + z2 = (INT32) wsptr[6]; + z3 = z1 - z2; + z4 = MULTIPLY(z3, FIX(0.275899379)); /* c14[16] = c7[8] */ + z3 = MULTIPLY(z3, FIX(1.387039845)); /* c2[16] = c1[8] */ + + tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447); /* (c6+c2)[16] = (c3+c1)[8] */ + tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223); /* (c6-c14)[16] = (c3-c7)[8] */ + tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */ + tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */ + + tmp20 = tmp10 + tmp0; + tmp27 = tmp10 - tmp0; + tmp21 = tmp12 + tmp1; + tmp26 = tmp12 - tmp1; + tmp22 = tmp13 + tmp2; + tmp25 = tmp13 - tmp2; + tmp23 = tmp11 + tmp3; + tmp24 = tmp11 - tmp3; + + /* Odd part */ + + z1 = (INT32) wsptr[1]; + z2 = (INT32) wsptr[3]; + z3 = (INT32) wsptr[5]; + z4 = (INT32) wsptr[7]; + + tmp11 = z1 + z3; + + tmp1 = MULTIPLY(z1 + z2, FIX(1.353318001)); /* c3 */ + tmp2 = MULTIPLY(tmp11, FIX(1.247225013)); /* c5 */ + tmp3 = MULTIPLY(z1 + z4, FIX(1.093201867)); /* c7 */ + tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586)); /* c9 */ + tmp11 = MULTIPLY(tmp11, FIX(0.666655658)); /* c11 */ + tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528)); /* c13 */ + tmp0 = tmp1 + tmp2 + tmp3 - + MULTIPLY(z1, FIX(2.286341144)); /* c7+c5+c3-c1 */ + tmp13 = tmp10 + tmp11 + tmp12 - + MULTIPLY(z1, FIX(1.835730603)); /* c9+c11+c13-c15 */ + z1 = MULTIPLY(z2 + z3, FIX(0.138617169)); /* c15 */ + tmp1 += z1 + MULTIPLY(z2, FIX(0.071888074)); /* c9+c11-c3-c15 */ + tmp2 += z1 - MULTIPLY(z3, FIX(1.125726048)); /* c5+c7+c15-c3 */ + z1 = MULTIPLY(z3 - z2, FIX(1.407403738)); /* c1 */ + tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282)); /* c1+c11-c9-c13 */ + tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411)); /* c1+c5+c13-c7 */ + z2 += z4; + z1 = MULTIPLY(z2, - FIX(0.666655658)); /* -c11 */ + tmp1 += z1; + tmp3 += z1 + MULTIPLY(z4, FIX(1.065388962)); /* c3+c11+c15-c7 */ + z2 = MULTIPLY(z2, - FIX(1.247225013)); /* -c5 */ + tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809)); /* c1+c5+c9-c13 */ + tmp12 += z2; + z2 = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */ + tmp2 += z2; + tmp3 += z2; + z2 = MULTIPLY(z4 - z3, FIX(0.410524528)); /* c13 */ + tmp10 += z2; + tmp11 += z2; + + /* Final output stage */ + + outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[15] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp10, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp11, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp12, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp27 + tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp27 - tmp13, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += 8; /* advance pointer to next row */ + } +} + +#endif /* IDCT_SCALING_SUPPORTED */ +#endif /* DCT_ISLOW_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jidctred.c b/lib-third-party/libturbojpeg-ios/libjpeg/jidctred.c new file mode 100755 index 0000000..421f3c7 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jidctred.c @@ -0,0 +1,398 @@ +/* + * jidctred.c + * + * Copyright (C) 1994-1998, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains inverse-DCT routines that produce reduced-size output: + * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block. + * + * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M) + * algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step + * with an 8-to-4 step that produces the four averages of two adjacent outputs + * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output). + * These steps were derived by computing the corresponding values at the end + * of the normal LL&M code, then simplifying as much as possible. + * + * 1x1 is trivial: just take the DC coefficient divided by 8. + * + * See jidctint.c for additional comments. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jdct.h" /* Private declarations for DCT subsystem */ + +#ifdef IDCT_SCALING_SUPPORTED + + +/* + * This module is specialized to the case DCTSIZE = 8. + */ + +#if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +#endif + + +/* Scaling is the same as in jidctint.c. */ + +#if BITS_IN_JSAMPLE == 8 +#define CONST_BITS 13 +#define PASS1_BITS 2 +#else +#define CONST_BITS 13 +#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ +#endif + +/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + +#if CONST_BITS == 13 +#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */ +#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */ +#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */ +#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */ +#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ +#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */ +#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ +#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */ +#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */ +#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */ +#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ +#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */ +#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ +#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */ +#else +#define FIX_0_211164243 FIX(0.211164243) +#define FIX_0_509795579 FIX(0.509795579) +#define FIX_0_601344887 FIX(0.601344887) +#define FIX_0_720959822 FIX(0.720959822) +#define FIX_0_765366865 FIX(0.765366865) +#define FIX_0_850430095 FIX(0.850430095) +#define FIX_0_899976223 FIX(0.899976223) +#define FIX_1_061594337 FIX(1.061594337) +#define FIX_1_272758580 FIX(1.272758580) +#define FIX_1_451774981 FIX(1.451774981) +#define FIX_1_847759065 FIX(1.847759065) +#define FIX_2_172734803 FIX(2.172734803) +#define FIX_2_562915447 FIX(2.562915447) +#define FIX_3_624509785 FIX(3.624509785) +#endif + + +/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * For 8-bit samples with the recommended scaling, all the variable + * and constant values involved are no more than 16 bits wide, so a + * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. + * For 12-bit samples, a full 32-bit multiplication will be needed. + */ + +#if BITS_IN_JSAMPLE == 8 +#define MULTIPLY(var,const) MULTIPLY16C16(var,const) +#else +#define MULTIPLY(var,const) ((var) * (const)) +#endif + + +/* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce an int result. In this module, both inputs and result + * are 16 bits or less, so either int or short multiply will work. + */ + +#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval)) + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 4x4 output block. + */ + +GLOBAL(void) +jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp2, tmp10, tmp12; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE*4]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { + /* Don't bother to process column 4, because second pass won't use it */ + if (ctr == DCTSIZE-4) + continue; + if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && + inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 && + inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { + /* AC terms all zero; we need not examine term 4 for 4x4 output */ + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + + continue; + } + + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp0 <<= (CONST_BITS+1); + + z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865); + + tmp10 = tmp0 + tmp2; + tmp12 = tmp0 - tmp2; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + + tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ + + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ + + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ + + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ + + tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ + + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ + + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ + + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ + + /* Final output stage */ + + wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1); + wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1); + wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1); + wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1); + } + + /* Pass 2: process 4 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 4; ctr++) { + outptr = output_buf[ctr] + output_col; + /* It's not clear whether a zero row test is worthwhile here ... */ + +#ifndef NO_ZERO_ROW_TEST + if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && + wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + outptr[2] = dcval; + outptr[3] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } +#endif + + /* Even part */ + + tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1); + + tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065) + + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865); + + tmp10 = tmp0 + tmp2; + tmp12 = tmp0 - tmp2; + + /* Odd part */ + + z1 = (INT32) wsptr[7]; + z2 = (INT32) wsptr[5]; + z3 = (INT32) wsptr[3]; + z4 = (INT32) wsptr[1]; + + tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ + + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ + + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ + + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ + + tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ + + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ + + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ + + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 2x2 output block. + */ + +GLOBAL(void) +jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + INT32 tmp0, tmp10, z1; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE*2]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { + /* Don't bother to process columns 2,4,6 */ + if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6) + continue; + if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 && + inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) { + /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */ + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + + continue; + } + + /* Even part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp10 = z1 << (CONST_BITS+2); + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */ + z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */ + z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */ + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ + + /* Final output stage */ + + wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2); + wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2); + } + + /* Pass 2: process 2 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 2; ctr++) { + outptr = output_buf[ctr] + output_col; + /* It's not clear whether a zero row test is worthwhile here ... */ + +#ifndef NO_ZERO_ROW_TEST + if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } +#endif + + /* Even part */ + + tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2); + + /* Odd part */ + + tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */ + + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */ + + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */ + + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3+2) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3+2) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } +} + + +/* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 1x1 output block. + */ + +GLOBAL(void) +jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) +{ + int dcval; + ISLOW_MULT_TYPE * quantptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + SHIFT_TEMPS + + /* We hardly need an inverse DCT routine for this: just take the + * average pixel value, which is one-eighth of the DC coefficient. + */ + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + dcval = DEQUANTIZE(coef_block[0], quantptr[0]); + dcval = (int) DESCALE((INT32) dcval, 3); + + output_buf[0][output_col] = range_limit[dcval & RANGE_MASK]; +} + +#endif /* IDCT_SCALING_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jinclude.h b/lib-third-party/libturbojpeg-ios/libjpeg/jinclude.h new file mode 100755 index 0000000..0a4f151 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jinclude.h @@ -0,0 +1,91 @@ +/* + * jinclude.h + * + * Copyright (C) 1991-1994, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file exists to provide a single place to fix any problems with + * including the wrong system include files. (Common problems are taken + * care of by the standard jconfig symbols, but on really weird systems + * you may have to edit this file.) + * + * NOTE: this file is NOT intended to be included by applications using the + * JPEG library. Most applications need only include jpeglib.h. + */ + + +/* Include auto-config file to find out which system include files we need. */ + +#include "jconfig.h" /* auto configuration options */ +#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ + +/* + * We need the NULL macro and size_t typedef. + * On an ANSI-conforming system it is sufficient to include . + * Otherwise, we get them from or ; we may have to + * pull in as well. + * Note that the core JPEG library does not require ; + * only the default error handler and data source/destination modules do. + * But we must pull it in because of the references to FILE in jpeglib.h. + * You can remove those references if you want to compile without . + */ + +#ifdef HAVE_STDDEF_H +#include +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef NEED_SYS_TYPES_H +#include +#endif + +#include + +/* + * We need memory copying and zeroing functions, plus strncpy(). + * ANSI and System V implementations declare these in . + * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). + * Some systems may declare memset and memcpy in . + * + * NOTE: we assume the size parameters to these functions are of type size_t. + * Change the casts in these macros if not! + */ + +#ifdef NEED_BSD_STRINGS + +#include +#define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) +#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) + +#else /* not BSD, assume ANSI/SysV string lib */ + +#include +#define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) +#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) + +#endif + +/* + * In ANSI C, and indeed any rational implementation, size_t is also the + * type returned by sizeof(). However, it seems there are some irrational + * implementations out there, in which sizeof() returns an int even though + * size_t is defined as long or unsigned long. To ensure consistent results + * we always use this SIZEOF() macro in place of using sizeof() directly. + */ + +#define SIZEOF(object) ((size_t) sizeof(object)) + +/* + * The modules that use fread() and fwrite() always invoke them through + * these macros. On some systems you may need to twiddle the argument casts. + * CAUTION: argument order is different from underlying functions! + */ + +#define JFREAD(file,buf,sizeofbuf) \ + ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) +#define JFWRITE(file,buf,sizeofbuf) \ + ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jmemmgr.c b/lib-third-party/libturbojpeg-ios/libjpeg/jmemmgr.c new file mode 100755 index 0000000..cf32524 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jmemmgr.c @@ -0,0 +1,1151 @@ +/* + * jmemmgr.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the JPEG system-independent memory management + * routines. This code is usable across a wide variety of machines; most + * of the system dependencies have been isolated in a separate file. + * The major functions provided here are: + * * pool-based allocation and freeing of memory; + * * policy decisions about how to divide available memory among the + * virtual arrays; + * * control logic for swapping virtual arrays between main memory and + * backing storage. + * The separate system-dependent file provides the actual backing-storage + * access code, and it contains the policy decision about how much total + * main memory to use. + * This file is system-dependent in the sense that some of its functions + * are unnecessary in some systems. For example, if there is enough virtual + * memory so that backing storage will never be used, much of the virtual + * array control logic could be removed. (Of course, if you have that much + * memory then you shouldn't care about a little bit of unused code...) + */ + +#define JPEG_INTERNALS +#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */ +#include "jinclude.h" +#include "jpeglib.h" +#include "jmemsys.h" /* import the system-dependent declarations */ + +#ifndef NO_GETENV +#ifndef HAVE_STDLIB_H /* should declare getenv() */ +extern char * getenv JPP((const char * name)); +#endif +#endif + + +LOCAL(size_t) +round_up_pow2 (size_t a, size_t b) +/* a rounded up to the next multiple of b, i.e. ceil(a/b)*b */ +/* Assumes a >= 0, b > 0, and b is a power of 2 */ +{ + return ((a + b - 1) & (~(b - 1))); +} + + +/* + * Some important notes: + * The allocation routines provided here must never return NULL. + * They should exit to error_exit if unsuccessful. + * + * It's not a good idea to try to merge the sarray and barray routines, + * even though they are textually almost the same, because samples are + * usually stored as bytes while coefficients are shorts or ints. Thus, + * in machines where byte pointers have a different representation from + * word pointers, the resulting machine code could not be the same. + */ + + +/* + * Many machines require storage alignment: longs must start on 4-byte + * boundaries, doubles on 8-byte boundaries, etc. On such machines, malloc() + * always returns pointers that are multiples of the worst-case alignment + * requirement, and we had better do so too. + * There isn't any really portable way to determine the worst-case alignment + * requirement. This module assumes that the alignment requirement is + * multiples of ALIGN_SIZE. + * By default, we define ALIGN_SIZE as sizeof(double). This is necessary on some + * workstations (where doubles really do need 8-byte alignment) and will work + * fine on nearly everything. If your machine has lesser alignment needs, + * you can save a few bytes by making ALIGN_SIZE smaller. + * The only place I know of where this will NOT work is certain Macintosh + * 680x0 compilers that define double as a 10-byte IEEE extended float. + * Doing 10-byte alignment is counterproductive because longwords won't be + * aligned well. Put "#define ALIGN_SIZE 4" in jconfig.h if you have + * such a compiler. + */ + +#ifndef ALIGN_SIZE /* so can override from jconfig.h */ +#ifndef WITH_SIMD +#define ALIGN_SIZE SIZEOF(double) +#else +#define ALIGN_SIZE 16 /* Most SIMD implementations require this */ +#endif +#endif + +/* + * We allocate objects from "pools", where each pool is gotten with a single + * request to jpeg_get_small() or jpeg_get_large(). There is no per-object + * overhead within a pool, except for alignment padding. Each pool has a + * header with a link to the next pool of the same class. + * Small and large pool headers are identical except that the latter's + * link pointer must be FAR on 80x86 machines. + */ + +typedef struct small_pool_struct * small_pool_ptr; + +typedef struct small_pool_struct { + small_pool_ptr next; /* next in list of pools */ + size_t bytes_used; /* how many bytes already used within pool */ + size_t bytes_left; /* bytes still available in this pool */ +} small_pool_hdr; + +typedef struct large_pool_struct FAR * large_pool_ptr; + +typedef struct large_pool_struct { + large_pool_ptr next; /* next in list of pools */ + size_t bytes_used; /* how many bytes already used within pool */ + size_t bytes_left; /* bytes still available in this pool */ +} large_pool_hdr; + +/* + * Here is the full definition of a memory manager object. + */ + +typedef struct { + struct jpeg_memory_mgr pub; /* public fields */ + + /* Each pool identifier (lifetime class) names a linked list of pools. */ + small_pool_ptr small_list[JPOOL_NUMPOOLS]; + large_pool_ptr large_list[JPOOL_NUMPOOLS]; + + /* Since we only have one lifetime class of virtual arrays, only one + * linked list is necessary (for each datatype). Note that the virtual + * array control blocks being linked together are actually stored somewhere + * in the small-pool list. + */ + jvirt_sarray_ptr virt_sarray_list; + jvirt_barray_ptr virt_barray_list; + + /* This counts total space obtained from jpeg_get_small/large */ + size_t total_space_allocated; + + /* alloc_sarray and alloc_barray set this value for use by virtual + * array routines. + */ + JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */ +} my_memory_mgr; + +typedef my_memory_mgr * my_mem_ptr; + + +/* + * The control blocks for virtual arrays. + * Note that these blocks are allocated in the "small" pool area. + * System-dependent info for the associated backing store (if any) is hidden + * inside the backing_store_info struct. + */ + +struct jvirt_sarray_control { + JSAMPARRAY mem_buffer; /* => the in-memory buffer */ + JDIMENSION rows_in_array; /* total virtual array height */ + JDIMENSION samplesperrow; /* width of array (and of memory buffer) */ + JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */ + JDIMENSION rows_in_mem; /* height of memory buffer */ + JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ + JDIMENSION cur_start_row; /* first logical row # in the buffer */ + JDIMENSION first_undef_row; /* row # of first uninitialized row */ + boolean pre_zero; /* pre-zero mode requested? */ + boolean dirty; /* do current buffer contents need written? */ + boolean b_s_open; /* is backing-store data valid? */ + jvirt_sarray_ptr next; /* link to next virtual sarray control block */ + backing_store_info b_s_info; /* System-dependent control info */ +}; + +struct jvirt_barray_control { + JBLOCKARRAY mem_buffer; /* => the in-memory buffer */ + JDIMENSION rows_in_array; /* total virtual array height */ + JDIMENSION blocksperrow; /* width of array (and of memory buffer) */ + JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */ + JDIMENSION rows_in_mem; /* height of memory buffer */ + JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ + JDIMENSION cur_start_row; /* first logical row # in the buffer */ + JDIMENSION first_undef_row; /* row # of first uninitialized row */ + boolean pre_zero; /* pre-zero mode requested? */ + boolean dirty; /* do current buffer contents need written? */ + boolean b_s_open; /* is backing-store data valid? */ + jvirt_barray_ptr next; /* link to next virtual barray control block */ + backing_store_info b_s_info; /* System-dependent control info */ +}; + + +#ifdef MEM_STATS /* optional extra stuff for statistics */ + +LOCAL(void) +print_mem_stats (j_common_ptr cinfo, int pool_id) +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + small_pool_ptr shdr_ptr; + large_pool_ptr lhdr_ptr; + + /* Since this is only a debugging stub, we can cheat a little by using + * fprintf directly rather than going through the trace message code. + * This is helpful because message parm array can't handle longs. + */ + fprintf(stderr, "Freeing pool %d, total space = %ld\n", + pool_id, mem->total_space_allocated); + + for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL; + lhdr_ptr = lhdr_ptr->next) { + fprintf(stderr, " Large chunk used %ld\n", + (long) lhdr_ptr->bytes_used); + } + + for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL; + shdr_ptr = shdr_ptr->next) { + fprintf(stderr, " Small chunk used %ld free %ld\n", + (long) shdr_ptr->bytes_used, + (long) shdr_ptr->bytes_left); + } +} + +#endif /* MEM_STATS */ + + +LOCAL(void) +out_of_memory (j_common_ptr cinfo, int which) +/* Report an out-of-memory error and stop execution */ +/* If we compiled MEM_STATS support, report alloc requests before dying */ +{ +#ifdef MEM_STATS + cinfo->err->trace_level = 2; /* force self_destruct to report stats */ +#endif + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which); +} + + +/* + * Allocation of "small" objects. + * + * For these, we use pooled storage. When a new pool must be created, + * we try to get enough space for the current request plus a "slop" factor, + * where the slop will be the amount of leftover space in the new pool. + * The speed vs. space tradeoff is largely determined by the slop values. + * A different slop value is provided for each pool class (lifetime), + * and we also distinguish the first pool of a class from later ones. + * NOTE: the values given work fairly well on both 16- and 32-bit-int + * machines, but may be too small if longs are 64 bits or more. + * + * Since we do not know what alignment malloc() gives us, we have to + * allocate ALIGN_SIZE-1 extra space per pool to have room for alignment + * adjustment. + */ + +static const size_t first_pool_slop[JPOOL_NUMPOOLS] = +{ + 1600, /* first PERMANENT pool */ + 16000 /* first IMAGE pool */ +}; + +static const size_t extra_pool_slop[JPOOL_NUMPOOLS] = +{ + 0, /* additional PERMANENT pools */ + 5000 /* additional IMAGE pools */ +}; + +#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */ + + +METHODDEF(void *) +alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject) +/* Allocate a "small" object */ +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + small_pool_ptr hdr_ptr, prev_hdr_ptr; + char * data_ptr; + size_t min_request, slop; + + /* + * Round up the requested size to a multiple of ALIGN_SIZE in order + * to assure alignment for the next object allocated in the same pool + * and so that algorithms can straddle outside the proper area up + * to the next alignment. + */ + sizeofobject = round_up_pow2(sizeofobject, ALIGN_SIZE); + + /* Check for unsatisfiable request (do now to ensure no overflow below) */ + if ((SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK) + out_of_memory(cinfo, 1); /* request exceeds malloc's ability */ + + /* See if space is available in any existing pool */ + if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + prev_hdr_ptr = NULL; + hdr_ptr = mem->small_list[pool_id]; + while (hdr_ptr != NULL) { + if (hdr_ptr->bytes_left >= sizeofobject) + break; /* found pool with enough space */ + prev_hdr_ptr = hdr_ptr; + hdr_ptr = hdr_ptr->next; + } + + /* Time to make a new pool? */ + if (hdr_ptr == NULL) { + /* min_request is what we need now, slop is what will be leftover */ + min_request = SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1; + if (prev_hdr_ptr == NULL) /* first pool in class? */ + slop = first_pool_slop[pool_id]; + else + slop = extra_pool_slop[pool_id]; + /* Don't ask for more than MAX_ALLOC_CHUNK */ + if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request)) + slop = (size_t) (MAX_ALLOC_CHUNK-min_request); + /* Try to get space, if fail reduce slop and try again */ + for (;;) { + hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop); + if (hdr_ptr != NULL) + break; + slop /= 2; + if (slop < MIN_SLOP) /* give up when it gets real small */ + out_of_memory(cinfo, 2); /* jpeg_get_small failed */ + } + mem->total_space_allocated += min_request + slop; + /* Success, initialize the new pool header and add to end of list */ + hdr_ptr->next = NULL; + hdr_ptr->bytes_used = 0; + hdr_ptr->bytes_left = sizeofobject + slop; + if (prev_hdr_ptr == NULL) /* first pool in class? */ + mem->small_list[pool_id] = hdr_ptr; + else + prev_hdr_ptr->next = hdr_ptr; + } + + /* OK, allocate the object from the current pool */ + data_ptr = (char *) hdr_ptr; /* point to first data byte in pool... */ + data_ptr += SIZEOF(small_pool_hdr); /* ...by skipping the header... */ + if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */ + data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE; + data_ptr += hdr_ptr->bytes_used; /* point to place for object */ + hdr_ptr->bytes_used += sizeofobject; + hdr_ptr->bytes_left -= sizeofobject; + + return (void *) data_ptr; +} + + +/* + * Allocation of "large" objects. + * + * The external semantics of these are the same as "small" objects, + * except that FAR pointers are used on 80x86. However the pool + * management heuristics are quite different. We assume that each + * request is large enough that it may as well be passed directly to + * jpeg_get_large; the pool management just links everything together + * so that we can free it all on demand. + * Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY + * structures. The routines that create these structures (see below) + * deliberately bunch rows together to ensure a large request size. + */ + +METHODDEF(void FAR *) +alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject) +/* Allocate a "large" object */ +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + large_pool_ptr hdr_ptr; + char FAR * data_ptr; + + /* + * Round up the requested size to a multiple of ALIGN_SIZE so that + * algorithms can straddle outside the proper area up to the next + * alignment. + */ + sizeofobject = round_up_pow2(sizeofobject, ALIGN_SIZE); + + /* Check for unsatisfiable request (do now to ensure no overflow below) */ + if ((SIZEOF(large_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK) + out_of_memory(cinfo, 3); /* request exceeds malloc's ability */ + + /* Always make a new pool */ + if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + + hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject + + SIZEOF(large_pool_hdr) + + ALIGN_SIZE - 1); + if (hdr_ptr == NULL) + out_of_memory(cinfo, 4); /* jpeg_get_large failed */ + mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr) + ALIGN_SIZE - 1; + + /* Success, initialize the new pool header and add to list */ + hdr_ptr->next = mem->large_list[pool_id]; + /* We maintain space counts in each pool header for statistical purposes, + * even though they are not needed for allocation. + */ + hdr_ptr->bytes_used = sizeofobject; + hdr_ptr->bytes_left = 0; + mem->large_list[pool_id] = hdr_ptr; + + data_ptr = (char *) hdr_ptr; /* point to first data byte in pool... */ + data_ptr += SIZEOF(small_pool_hdr); /* ...by skipping the header... */ + if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */ + data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE; + + return (void FAR *) data_ptr; +} + + +/* + * Creation of 2-D sample arrays. + * The pointers are in near heap, the samples themselves in FAR heap. + * + * To minimize allocation overhead and to allow I/O of large contiguous + * blocks, we allocate the sample rows in groups of as many rows as possible + * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request. + * NB: the virtual array control routines, later in this file, know about + * this chunking of rows. The rowsperchunk value is left in the mem manager + * object so that it can be saved away if this sarray is the workspace for + * a virtual array. + * + * Since we are often upsampling with a factor 2, we align the size (not + * the start) to 2 * ALIGN_SIZE so that the upsampling routines don't have + * to be as careful about size. + */ + +METHODDEF(JSAMPARRAY) +alloc_sarray (j_common_ptr cinfo, int pool_id, + JDIMENSION samplesperrow, JDIMENSION numrows) +/* Allocate a 2-D sample array */ +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + JSAMPARRAY result; + JSAMPROW workspace; + JDIMENSION rowsperchunk, currow, i; + long ltemp; + + /* Make sure each row is properly aligned */ + if ((ALIGN_SIZE % SIZEOF(JSAMPLE)) != 0) + out_of_memory(cinfo, 5); /* safety check */ + samplesperrow = (JDIMENSION)round_up_pow2(samplesperrow, (2 * ALIGN_SIZE) / SIZEOF(JSAMPLE)); + + /* Calculate max # of rows allowed in one allocation chunk */ + ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / + ((long) samplesperrow * SIZEOF(JSAMPLE)); + if (ltemp <= 0) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + if (ltemp < (long) numrows) + rowsperchunk = (JDIMENSION) ltemp; + else + rowsperchunk = numrows; + mem->last_rowsperchunk = rowsperchunk; + + /* Get space for row pointers (small object) */ + result = (JSAMPARRAY) alloc_small(cinfo, pool_id, + (size_t) (numrows * SIZEOF(JSAMPROW))); + + /* Get the rows themselves (large objects) */ + currow = 0; + while (currow < numrows) { + rowsperchunk = MIN(rowsperchunk, numrows - currow); + workspace = (JSAMPROW) alloc_large(cinfo, pool_id, + (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow + * SIZEOF(JSAMPLE))); + for (i = rowsperchunk; i > 0; i--) { + result[currow++] = workspace; + workspace += samplesperrow; + } + } + + return result; +} + + +/* + * Creation of 2-D coefficient-block arrays. + * This is essentially the same as the code for sample arrays, above. + */ + +METHODDEF(JBLOCKARRAY) +alloc_barray (j_common_ptr cinfo, int pool_id, + JDIMENSION blocksperrow, JDIMENSION numrows) +/* Allocate a 2-D coefficient-block array */ +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + JBLOCKARRAY result; + JBLOCKROW workspace; + JDIMENSION rowsperchunk, currow, i; + long ltemp; + + /* Make sure each row is properly aligned */ + if ((SIZEOF(JBLOCK) % ALIGN_SIZE) != 0) + out_of_memory(cinfo, 6); /* safety check */ + + /* Calculate max # of rows allowed in one allocation chunk */ + ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / + ((long) blocksperrow * SIZEOF(JBLOCK)); + if (ltemp <= 0) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + if (ltemp < (long) numrows) + rowsperchunk = (JDIMENSION) ltemp; + else + rowsperchunk = numrows; + mem->last_rowsperchunk = rowsperchunk; + + /* Get space for row pointers (small object) */ + result = (JBLOCKARRAY) alloc_small(cinfo, pool_id, + (size_t) (numrows * SIZEOF(JBLOCKROW))); + + /* Get the rows themselves (large objects) */ + currow = 0; + while (currow < numrows) { + rowsperchunk = MIN(rowsperchunk, numrows - currow); + workspace = (JBLOCKROW) alloc_large(cinfo, pool_id, + (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow + * SIZEOF(JBLOCK))); + for (i = rowsperchunk; i > 0; i--) { + result[currow++] = workspace; + workspace += blocksperrow; + } + } + + return result; +} + + +/* + * About virtual array management: + * + * The above "normal" array routines are only used to allocate strip buffers + * (as wide as the image, but just a few rows high). Full-image-sized buffers + * are handled as "virtual" arrays. The array is still accessed a strip at a + * time, but the memory manager must save the whole array for repeated + * accesses. The intended implementation is that there is a strip buffer in + * memory (as high as is possible given the desired memory limit), plus a + * backing file that holds the rest of the array. + * + * The request_virt_array routines are told the total size of the image and + * the maximum number of rows that will be accessed at once. The in-memory + * buffer must be at least as large as the maxaccess value. + * + * The request routines create control blocks but not the in-memory buffers. + * That is postponed until realize_virt_arrays is called. At that time the + * total amount of space needed is known (approximately, anyway), so free + * memory can be divided up fairly. + * + * The access_virt_array routines are responsible for making a specific strip + * area accessible (after reading or writing the backing file, if necessary). + * Note that the access routines are told whether the caller intends to modify + * the accessed strip; during a read-only pass this saves having to rewrite + * data to disk. The access routines are also responsible for pre-zeroing + * any newly accessed rows, if pre-zeroing was requested. + * + * In current usage, the access requests are usually for nonoverlapping + * strips; that is, successive access start_row numbers differ by exactly + * num_rows = maxaccess. This means we can get good performance with simple + * buffer dump/reload logic, by making the in-memory buffer be a multiple + * of the access height; then there will never be accesses across bufferload + * boundaries. The code will still work with overlapping access requests, + * but it doesn't handle bufferload overlaps very efficiently. + */ + + +METHODDEF(jvirt_sarray_ptr) +request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero, + JDIMENSION samplesperrow, JDIMENSION numrows, + JDIMENSION maxaccess) +/* Request a virtual 2-D sample array */ +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + jvirt_sarray_ptr result; + + /* Only IMAGE-lifetime virtual arrays are currently supported */ + if (pool_id != JPOOL_IMAGE) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + + /* get control block */ + result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id, + SIZEOF(struct jvirt_sarray_control)); + + result->mem_buffer = NULL; /* marks array not yet realized */ + result->rows_in_array = numrows; + result->samplesperrow = samplesperrow; + result->maxaccess = maxaccess; + result->pre_zero = pre_zero; + result->b_s_open = FALSE; /* no associated backing-store object */ + result->next = mem->virt_sarray_list; /* add to list of virtual arrays */ + mem->virt_sarray_list = result; + + return result; +} + + +METHODDEF(jvirt_barray_ptr) +request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero, + JDIMENSION blocksperrow, JDIMENSION numrows, + JDIMENSION maxaccess) +/* Request a virtual 2-D coefficient-block array */ +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + jvirt_barray_ptr result; + + /* Only IMAGE-lifetime virtual arrays are currently supported */ + if (pool_id != JPOOL_IMAGE) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + + /* get control block */ + result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id, + SIZEOF(struct jvirt_barray_control)); + + result->mem_buffer = NULL; /* marks array not yet realized */ + result->rows_in_array = numrows; + result->blocksperrow = blocksperrow; + result->maxaccess = maxaccess; + result->pre_zero = pre_zero; + result->b_s_open = FALSE; /* no associated backing-store object */ + result->next = mem->virt_barray_list; /* add to list of virtual arrays */ + mem->virt_barray_list = result; + + return result; +} + + +METHODDEF(void) +realize_virt_arrays (j_common_ptr cinfo) +/* Allocate the in-memory buffers for any unrealized virtual arrays */ +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + size_t space_per_minheight, maximum_space, avail_mem; + size_t minheights, max_minheights; + jvirt_sarray_ptr sptr; + jvirt_barray_ptr bptr; + + /* Compute the minimum space needed (maxaccess rows in each buffer) + * and the maximum space needed (full image height in each buffer). + * These may be of use to the system-dependent jpeg_mem_available routine. + */ + space_per_minheight = 0; + maximum_space = 0; + for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { + if (sptr->mem_buffer == NULL) { /* if not realized yet */ + space_per_minheight += (long) sptr->maxaccess * + (long) sptr->samplesperrow * SIZEOF(JSAMPLE); + maximum_space += (long) sptr->rows_in_array * + (long) sptr->samplesperrow * SIZEOF(JSAMPLE); + } + } + for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { + if (bptr->mem_buffer == NULL) { /* if not realized yet */ + space_per_minheight += (long) bptr->maxaccess * + (long) bptr->blocksperrow * SIZEOF(JBLOCK); + maximum_space += (long) bptr->rows_in_array * + (long) bptr->blocksperrow * SIZEOF(JBLOCK); + } + } + + if (space_per_minheight <= 0) + return; /* no unrealized arrays, no work */ + + /* Determine amount of memory to actually use; this is system-dependent. */ + avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space, + mem->total_space_allocated); + + /* If the maximum space needed is available, make all the buffers full + * height; otherwise parcel it out with the same number of minheights + * in each buffer. + */ + if (avail_mem >= maximum_space) + max_minheights = 1000000000L; + else { + max_minheights = avail_mem / space_per_minheight; + /* If there doesn't seem to be enough space, try to get the minimum + * anyway. This allows a "stub" implementation of jpeg_mem_available(). + */ + if (max_minheights <= 0) + max_minheights = 1; + } + + /* Allocate the in-memory buffers and initialize backing store as needed. */ + + for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { + if (sptr->mem_buffer == NULL) { /* if not realized yet */ + minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L; + if (minheights <= max_minheights) { + /* This buffer fits in memory */ + sptr->rows_in_mem = sptr->rows_in_array; + } else { + /* It doesn't fit in memory, create backing store. */ + sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess); + jpeg_open_backing_store(cinfo, & sptr->b_s_info, + (long) sptr->rows_in_array * + (long) sptr->samplesperrow * + (long) SIZEOF(JSAMPLE)); + sptr->b_s_open = TRUE; + } + sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE, + sptr->samplesperrow, sptr->rows_in_mem); + sptr->rowsperchunk = mem->last_rowsperchunk; + sptr->cur_start_row = 0; + sptr->first_undef_row = 0; + sptr->dirty = FALSE; + } + } + + for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { + if (bptr->mem_buffer == NULL) { /* if not realized yet */ + minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L; + if (minheights <= max_minheights) { + /* This buffer fits in memory */ + bptr->rows_in_mem = bptr->rows_in_array; + } else { + /* It doesn't fit in memory, create backing store. */ + bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess); + jpeg_open_backing_store(cinfo, & bptr->b_s_info, + (long) bptr->rows_in_array * + (long) bptr->blocksperrow * + (long) SIZEOF(JBLOCK)); + bptr->b_s_open = TRUE; + } + bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE, + bptr->blocksperrow, bptr->rows_in_mem); + bptr->rowsperchunk = mem->last_rowsperchunk; + bptr->cur_start_row = 0; + bptr->first_undef_row = 0; + bptr->dirty = FALSE; + } + } +} + + +LOCAL(void) +do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing) +/* Do backing store read or write of a virtual sample array */ +{ + long bytesperrow, file_offset, byte_count, rows, thisrow, i; + + bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE); + file_offset = ptr->cur_start_row * bytesperrow; + /* Loop to read or write each allocation chunk in mem_buffer */ + for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { + /* One chunk, but check for short chunk at end of buffer */ + rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i); + /* Transfer no more than is currently defined */ + thisrow = (long) ptr->cur_start_row + i; + rows = MIN(rows, (long) ptr->first_undef_row - thisrow); + /* Transfer no more than fits in file */ + rows = MIN(rows, (long) ptr->rows_in_array - thisrow); + if (rows <= 0) /* this chunk might be past end of file! */ + break; + byte_count = rows * bytesperrow; + if (writing) + (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + else + (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + file_offset += byte_count; + } +} + + +LOCAL(void) +do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing) +/* Do backing store read or write of a virtual coefficient-block array */ +{ + long bytesperrow, file_offset, byte_count, rows, thisrow, i; + + bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK); + file_offset = ptr->cur_start_row * bytesperrow; + /* Loop to read or write each allocation chunk in mem_buffer */ + for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { + /* One chunk, but check for short chunk at end of buffer */ + rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i); + /* Transfer no more than is currently defined */ + thisrow = (long) ptr->cur_start_row + i; + rows = MIN(rows, (long) ptr->first_undef_row - thisrow); + /* Transfer no more than fits in file */ + rows = MIN(rows, (long) ptr->rows_in_array - thisrow); + if (rows <= 0) /* this chunk might be past end of file! */ + break; + byte_count = rows * bytesperrow; + if (writing) + (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + else + (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + file_offset += byte_count; + } +} + + +METHODDEF(JSAMPARRAY) +access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr, + JDIMENSION start_row, JDIMENSION num_rows, + boolean writable) +/* Access the part of a virtual sample array starting at start_row */ +/* and extending for num_rows rows. writable is true if */ +/* caller intends to modify the accessed area. */ +{ + JDIMENSION end_row = start_row + num_rows; + JDIMENSION undef_row; + + /* debugging check */ + if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess || + ptr->mem_buffer == NULL) + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + + /* Make the desired part of the virtual array accessible */ + if (start_row < ptr->cur_start_row || + end_row > ptr->cur_start_row+ptr->rows_in_mem) { + if (! ptr->b_s_open) + ERREXIT(cinfo, JERR_VIRTUAL_BUG); + /* Flush old buffer contents if necessary */ + if (ptr->dirty) { + do_sarray_io(cinfo, ptr, TRUE); + ptr->dirty = FALSE; + } + /* Decide what part of virtual array to access. + * Algorithm: if target address > current window, assume forward scan, + * load starting at target address. If target address < current window, + * assume backward scan, load so that target area is top of window. + * Note that when switching from forward write to forward read, will have + * start_row = 0, so the limiting case applies and we load from 0 anyway. + */ + if (start_row > ptr->cur_start_row) { + ptr->cur_start_row = start_row; + } else { + /* use long arithmetic here to avoid overflow & unsigned problems */ + long ltemp; + + ltemp = (long) end_row - (long) ptr->rows_in_mem; + if (ltemp < 0) + ltemp = 0; /* don't fall off front end of file */ + ptr->cur_start_row = (JDIMENSION) ltemp; + } + /* Read in the selected part of the array. + * During the initial write pass, we will do no actual read + * because the selected part is all undefined. + */ + do_sarray_io(cinfo, ptr, FALSE); + } + /* Ensure the accessed part of the array is defined; prezero if needed. + * To improve locality of access, we only prezero the part of the array + * that the caller is about to access, not the entire in-memory array. + */ + if (ptr->first_undef_row < end_row) { + if (ptr->first_undef_row < start_row) { + if (writable) /* writer skipped over a section of array */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + undef_row = start_row; /* but reader is allowed to read ahead */ + } else { + undef_row = ptr->first_undef_row; + } + if (writable) + ptr->first_undef_row = end_row; + if (ptr->pre_zero) { + size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE); + undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ + end_row -= ptr->cur_start_row; + while (undef_row < end_row) { + jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); + undef_row++; + } + } else { + if (! writable) /* reader looking at undefined data */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + } + } + /* Flag the buffer dirty if caller will write in it */ + if (writable) + ptr->dirty = TRUE; + /* Return address of proper part of the buffer */ + return ptr->mem_buffer + (start_row - ptr->cur_start_row); +} + + +METHODDEF(JBLOCKARRAY) +access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr, + JDIMENSION start_row, JDIMENSION num_rows, + boolean writable) +/* Access the part of a virtual block array starting at start_row */ +/* and extending for num_rows rows. writable is true if */ +/* caller intends to modify the accessed area. */ +{ + JDIMENSION end_row = start_row + num_rows; + JDIMENSION undef_row; + + /* debugging check */ + if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess || + ptr->mem_buffer == NULL) + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + + /* Make the desired part of the virtual array accessible */ + if (start_row < ptr->cur_start_row || + end_row > ptr->cur_start_row+ptr->rows_in_mem) { + if (! ptr->b_s_open) + ERREXIT(cinfo, JERR_VIRTUAL_BUG); + /* Flush old buffer contents if necessary */ + if (ptr->dirty) { + do_barray_io(cinfo, ptr, TRUE); + ptr->dirty = FALSE; + } + /* Decide what part of virtual array to access. + * Algorithm: if target address > current window, assume forward scan, + * load starting at target address. If target address < current window, + * assume backward scan, load so that target area is top of window. + * Note that when switching from forward write to forward read, will have + * start_row = 0, so the limiting case applies and we load from 0 anyway. + */ + if (start_row > ptr->cur_start_row) { + ptr->cur_start_row = start_row; + } else { + /* use long arithmetic here to avoid overflow & unsigned problems */ + long ltemp; + + ltemp = (long) end_row - (long) ptr->rows_in_mem; + if (ltemp < 0) + ltemp = 0; /* don't fall off front end of file */ + ptr->cur_start_row = (JDIMENSION) ltemp; + } + /* Read in the selected part of the array. + * During the initial write pass, we will do no actual read + * because the selected part is all undefined. + */ + do_barray_io(cinfo, ptr, FALSE); + } + /* Ensure the accessed part of the array is defined; prezero if needed. + * To improve locality of access, we only prezero the part of the array + * that the caller is about to access, not the entire in-memory array. + */ + if (ptr->first_undef_row < end_row) { + if (ptr->first_undef_row < start_row) { + if (writable) /* writer skipped over a section of array */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + undef_row = start_row; /* but reader is allowed to read ahead */ + } else { + undef_row = ptr->first_undef_row; + } + if (writable) + ptr->first_undef_row = end_row; + if (ptr->pre_zero) { + size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK); + undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ + end_row -= ptr->cur_start_row; + while (undef_row < end_row) { + jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); + undef_row++; + } + } else { + if (! writable) /* reader looking at undefined data */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + } + } + /* Flag the buffer dirty if caller will write in it */ + if (writable) + ptr->dirty = TRUE; + /* Return address of proper part of the buffer */ + return ptr->mem_buffer + (start_row - ptr->cur_start_row); +} + + +/* + * Release all objects belonging to a specified pool. + */ + +METHODDEF(void) +free_pool (j_common_ptr cinfo, int pool_id) +{ + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + small_pool_ptr shdr_ptr; + large_pool_ptr lhdr_ptr; + size_t space_freed; + + if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + +#ifdef MEM_STATS + if (cinfo->err->trace_level > 1) + print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */ +#endif + + /* If freeing IMAGE pool, close any virtual arrays first */ + if (pool_id == JPOOL_IMAGE) { + jvirt_sarray_ptr sptr; + jvirt_barray_ptr bptr; + + for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { + if (sptr->b_s_open) { /* there may be no backing store */ + sptr->b_s_open = FALSE; /* prevent recursive close if error */ + (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info); + } + } + mem->virt_sarray_list = NULL; + for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { + if (bptr->b_s_open) { /* there may be no backing store */ + bptr->b_s_open = FALSE; /* prevent recursive close if error */ + (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info); + } + } + mem->virt_barray_list = NULL; + } + + /* Release large objects */ + lhdr_ptr = mem->large_list[pool_id]; + mem->large_list[pool_id] = NULL; + + while (lhdr_ptr != NULL) { + large_pool_ptr next_lhdr_ptr = lhdr_ptr->next; + space_freed = lhdr_ptr->bytes_used + + lhdr_ptr->bytes_left + + SIZEOF(large_pool_hdr); + jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed); + mem->total_space_allocated -= space_freed; + lhdr_ptr = next_lhdr_ptr; + } + + /* Release small objects */ + shdr_ptr = mem->small_list[pool_id]; + mem->small_list[pool_id] = NULL; + + while (shdr_ptr != NULL) { + small_pool_ptr next_shdr_ptr = shdr_ptr->next; + space_freed = shdr_ptr->bytes_used + + shdr_ptr->bytes_left + + SIZEOF(small_pool_hdr); + jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed); + mem->total_space_allocated -= space_freed; + shdr_ptr = next_shdr_ptr; + } +} + + +/* + * Close up shop entirely. + * Note that this cannot be called unless cinfo->mem is non-NULL. + */ + +METHODDEF(void) +self_destruct (j_common_ptr cinfo) +{ + int pool; + + /* Close all backing store, release all memory. + * Releasing pools in reverse order might help avoid fragmentation + * with some (brain-damaged) malloc libraries. + */ + for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) { + free_pool(cinfo, pool); + } + + /* Release the memory manager control block too. */ + jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr)); + cinfo->mem = NULL; /* ensures I will be called only once */ + + jpeg_mem_term(cinfo); /* system-dependent cleanup */ +} + + +/* + * Memory manager initialization. + * When this is called, only the error manager pointer is valid in cinfo! + */ + +GLOBAL(void) +jinit_memory_mgr (j_common_ptr cinfo) +{ + my_mem_ptr mem; + long max_to_use; + int pool; + size_t test_mac; + + cinfo->mem = NULL; /* for safety if init fails */ + + /* Check for configuration errors. + * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably + * doesn't reflect any real hardware alignment requirement. + * The test is a little tricky: for X>0, X and X-1 have no one-bits + * in common if and only if X is a power of 2, ie has only one one-bit. + * Some compilers may give an "unreachable code" warning here; ignore it. + */ + if ((ALIGN_SIZE & (ALIGN_SIZE-1)) != 0) + ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE); + /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be + * a multiple of ALIGN_SIZE. + * Again, an "unreachable code" warning may be ignored here. + * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK. + */ + test_mac = (size_t) MAX_ALLOC_CHUNK; + if ((long) test_mac != MAX_ALLOC_CHUNK || + (MAX_ALLOC_CHUNK % ALIGN_SIZE) != 0) + ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); + + max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */ + + /* Attempt to allocate memory manager's control block */ + mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr)); + + if (mem == NULL) { + jpeg_mem_term(cinfo); /* system-dependent cleanup */ + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0); + } + + /* OK, fill in the method pointers */ + mem->pub.alloc_small = alloc_small; + mem->pub.alloc_large = alloc_large; + mem->pub.alloc_sarray = alloc_sarray; + mem->pub.alloc_barray = alloc_barray; + mem->pub.request_virt_sarray = request_virt_sarray; + mem->pub.request_virt_barray = request_virt_barray; + mem->pub.realize_virt_arrays = realize_virt_arrays; + mem->pub.access_virt_sarray = access_virt_sarray; + mem->pub.access_virt_barray = access_virt_barray; + mem->pub.free_pool = free_pool; + mem->pub.self_destruct = self_destruct; + + /* Make MAX_ALLOC_CHUNK accessible to other modules */ + mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK; + + /* Initialize working state */ + mem->pub.max_memory_to_use = max_to_use; + + for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) { + mem->small_list[pool] = NULL; + mem->large_list[pool] = NULL; + } + mem->virt_sarray_list = NULL; + mem->virt_barray_list = NULL; + + mem->total_space_allocated = SIZEOF(my_memory_mgr); + + /* Declare ourselves open for business */ + cinfo->mem = & mem->pub; + + /* Check for an environment variable JPEGMEM; if found, override the + * default max_memory setting from jpeg_mem_init. Note that the + * surrounding application may again override this value. + * If your system doesn't support getenv(), define NO_GETENV to disable + * this feature. + */ +#ifndef NO_GETENV + { char * memenv; + + if ((memenv = getenv("JPEGMEM")) != NULL) { + char ch = 'x'; + + if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) { + if (ch == 'm' || ch == 'M') + max_to_use *= 1000L; + mem->pub.max_memory_to_use = max_to_use * 1000L; + } + } + } +#endif + +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jmemnobs.c b/lib-third-party/libturbojpeg-ios/libjpeg/jmemnobs.c new file mode 100755 index 0000000..34b1895 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jmemnobs.c @@ -0,0 +1,109 @@ +/* + * jmemnobs.c + * + * Copyright (C) 1992-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file provides a really simple implementation of the system- + * dependent portion of the JPEG memory manager. This implementation + * assumes that no backing-store files are needed: all required space + * can be obtained from malloc(). + * This is very portable in the sense that it'll compile on almost anything, + * but you'd better have lots of main memory (or virtual memory) if you want + * to process big images. + * Note that the max_memory_to_use option is ignored by this implementation. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jmemsys.h" /* import the system-dependent declarations */ + +#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ +extern void * malloc JPP((size_t size)); +extern void free JPP((void *ptr)); +#endif + + +/* + * Memory allocation and freeing are controlled by the regular library + * routines malloc() and free(). + */ + +GLOBAL(void *) +jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void *) malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) +{ + free(object); +} + + +/* + * "Large" objects are treated the same as "small" ones. + * NB: although we include FAR keywords in the routine declarations, + * this file won't actually work in 80x86 small/medium model; at least, + * you probably won't be able to process useful-size images in only 64KB. + */ + +GLOBAL(void FAR *) +jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void FAR *) malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) +{ + free(object); +} + + +/* + * This routine computes the total memory space available for allocation. + * Here we always say, "we got all you want bud!" + */ + +GLOBAL(size_t) +jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, + size_t max_bytes_needed, size_t already_allocated) +{ + return max_bytes_needed; +} + + +/* + * Backing store (temporary file) management. + * Since jpeg_mem_available always promised the moon, + * this should never be called and we can just error out. + */ + +GLOBAL(void) +jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + ERREXIT(cinfo, JERR_NO_BACKING_STORE); +} + + +/* + * These routines take care of any system-dependent initialization and + * cleanup required. Here, there isn't any. + */ + +GLOBAL(long) +jpeg_mem_init (j_common_ptr cinfo) +{ + return 0; /* just set max_memory_to_use to 0 */ +} + +GLOBAL(void) +jpeg_mem_term (j_common_ptr cinfo) +{ + /* no work */ +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jmemsys.h b/lib-third-party/libturbojpeg-ios/libjpeg/jmemsys.h new file mode 100755 index 0000000..b190945 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jmemsys.h @@ -0,0 +1,198 @@ +/* + * jmemsys.h + * + * Copyright (C) 1992-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This include file defines the interface between the system-independent + * and system-dependent portions of the JPEG memory manager. No other + * modules need include it. (The system-independent portion is jmemmgr.c; + * there are several different versions of the system-dependent portion.) + * + * This file works as-is for the system-dependent memory managers supplied + * in the IJG distribution. You may need to modify it if you write a + * custom memory manager. If system-dependent changes are needed in + * this file, the best method is to #ifdef them based on a configuration + * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR + * and USE_MAC_MEMMGR. + */ + + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_get_small jGetSmall +#define jpeg_free_small jFreeSmall +#define jpeg_get_large jGetLarge +#define jpeg_free_large jFreeLarge +#define jpeg_mem_available jMemAvail +#define jpeg_open_backing_store jOpenBackStore +#define jpeg_mem_init jMemInit +#define jpeg_mem_term jMemTerm +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + + +/* + * These two functions are used to allocate and release small chunks of + * memory. (Typically the total amount requested through jpeg_get_small is + * no more than 20K or so; this will be requested in chunks of a few K each.) + * Behavior should be the same as for the standard library functions malloc + * and free; in particular, jpeg_get_small must return NULL on failure. + * On most systems, these ARE malloc and free. jpeg_free_small is passed the + * size of the object being freed, just in case it's needed. + * On an 80x86 machine using small-data memory model, these manage near heap. + */ + +EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject)); +EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object, + size_t sizeofobject)); + +/* + * These two functions are used to allocate and release large chunks of + * memory (up to the total free space designated by jpeg_mem_available). + * The interface is the same as above, except that on an 80x86 machine, + * far pointers are used. On most other machines these are identical to + * the jpeg_get/free_small routines; but we keep them separate anyway, + * in case a different allocation strategy is desirable for large chunks. + */ + +EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo, + size_t sizeofobject)); +EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object, + size_t sizeofobject)); + +/* + * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may + * be requested in a single call to jpeg_get_large (and jpeg_get_small for that + * matter, but that case should never come into play). This macro is needed + * to model the 64Kb-segment-size limit of far addressing on 80x86 machines. + * On those machines, we expect that jconfig.h will provide a proper value. + * On machines with 32-bit flat address spaces, any large constant may be used. + * + * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type + * size_t and will be a multiple of sizeof(align_type). + */ + +#ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */ +#define MAX_ALLOC_CHUNK 1000000000L +#endif + +/* + * This routine computes the total space still available for allocation by + * jpeg_get_large. If more space than this is needed, backing store will be + * used. NOTE: any memory already allocated must not be counted. + * + * There is a minimum space requirement, corresponding to the minimum + * feasible buffer sizes; jmemmgr.c will request that much space even if + * jpeg_mem_available returns zero. The maximum space needed, enough to hold + * all working storage in memory, is also passed in case it is useful. + * Finally, the total space already allocated is passed. If no better + * method is available, cinfo->mem->max_memory_to_use - already_allocated + * is often a suitable calculation. + * + * It is OK for jpeg_mem_available to underestimate the space available + * (that'll just lead to more backing-store access than is really necessary). + * However, an overestimate will lead to failure. Hence it's wise to subtract + * a slop factor from the true available space. 5% should be enough. + * + * On machines with lots of virtual memory, any large constant may be returned. + * Conversely, zero may be returned to always use the minimum amount of memory. + */ + +EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo, + size_t min_bytes_needed, + size_t max_bytes_needed, + size_t already_allocated)); + + +/* + * This structure holds whatever state is needed to access a single + * backing-store object. The read/write/close method pointers are called + * by jmemmgr.c to manipulate the backing-store object; all other fields + * are private to the system-dependent backing store routines. + */ + +#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */ + + +#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */ + +typedef unsigned short XMSH; /* type of extended-memory handles */ +typedef unsigned short EMSH; /* type of expanded-memory handles */ + +typedef union { + short file_handle; /* DOS file handle if it's a temp file */ + XMSH xms_handle; /* handle if it's a chunk of XMS */ + EMSH ems_handle; /* handle if it's a chunk of EMS */ +} handle_union; + +#endif /* USE_MSDOS_MEMMGR */ + +#ifdef USE_MAC_MEMMGR /* Mac-specific junk */ +#include +#endif /* USE_MAC_MEMMGR */ + + +typedef struct backing_store_struct * backing_store_ptr; + +typedef struct backing_store_struct { + /* Methods for reading/writing/closing this backing-store object */ + JMETHOD(void, read_backing_store, (j_common_ptr cinfo, + backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count)); + JMETHOD(void, write_backing_store, (j_common_ptr cinfo, + backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count)); + JMETHOD(void, close_backing_store, (j_common_ptr cinfo, + backing_store_ptr info)); + + /* Private fields for system-dependent backing-store management */ +#ifdef USE_MSDOS_MEMMGR + /* For the MS-DOS manager (jmemdos.c), we need: */ + handle_union handle; /* reference to backing-store storage object */ + char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ +#else +#ifdef USE_MAC_MEMMGR + /* For the Mac manager (jmemmac.c), we need: */ + short temp_file; /* file reference number to temp file */ + FSSpec tempSpec; /* the FSSpec for the temp file */ + char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ +#else + /* For a typical implementation with temp files, we need: */ + FILE * temp_file; /* stdio reference to temp file */ + char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */ +#endif +#endif +} backing_store_info; + + +/* + * Initial opening of a backing-store object. This must fill in the + * read/write/close pointers in the object. The read/write routines + * may take an error exit if the specified maximum file size is exceeded. + * (If jpeg_mem_available always returns a large value, this routine can + * just take an error exit.) + */ + +EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo, + backing_store_ptr info, + long total_bytes_needed)); + + +/* + * These routines take care of any system-dependent initialization and + * cleanup required. jpeg_mem_init will be called before anything is + * allocated (and, therefore, nothing in cinfo is of use except the error + * manager pointer). It should return a suitable default value for + * max_memory_to_use; this may subsequently be overridden by the surrounding + * application. (Note that max_memory_to_use is only important if + * jpeg_mem_available chooses to consult it ... no one else will.) + * jpeg_mem_term may assume that all requested memory has been freed and that + * all opened backing-store objects have been closed. + */ + +EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo)); +EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo)); diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jmorecfg.h b/lib-third-party/libturbojpeg-ios/libjpeg/jmorecfg.h new file mode 100755 index 0000000..f22c4f3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jmorecfg.h @@ -0,0 +1,404 @@ +/* + * jmorecfg.h + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright (C) 2009, 2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains additional configuration options that customize the + * JPEG software for special applications or support machine-dependent + * optimizations. Most users will not need to touch this file. + */ + + +/* + * Define BITS_IN_JSAMPLE as either + * 8 for 8-bit sample values (the usual setting) + * 12 for 12-bit sample values + * Only 8 and 12 are legal data precisions for lossy JPEG according to the + * JPEG standard, and the IJG code does not support anything else! + * We do not support run-time selection of data precision, sorry. + */ + +#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ + + +/* + * Maximum number of components (color channels) allowed in JPEG image. + * To meet the letter of the JPEG spec, set this to 255. However, darn + * few applications need more than 4 channels (maybe 5 for CMYK + alpha + * mask). We recommend 10 as a reasonable compromise; use 4 if you are + * really short on memory. (Each allowed component costs a hundred or so + * bytes of storage, whether actually used in an image or not.) + */ + +#define MAX_COMPONENTS 10 /* maximum number of image components */ + + +/* + * Basic data types. + * You may need to change these if you have a machine with unusual data + * type sizes; for example, "char" not 8 bits, "short" not 16 bits, + * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits, + * but it had better be at least 16. + */ + +/* Representation of a single sample (pixel element value). + * We frequently allocate large arrays of these, so it's important to keep + * them small. But if you have memory to burn and access to char or short + * arrays is very slow on your hardware, you might want to change these. + */ + +#if BITS_IN_JSAMPLE == 8 +/* JSAMPLE should be the smallest type that will hold the values 0..255. + * You can use a signed char by having GETJSAMPLE mask it with 0xFF. + */ + +#ifdef HAVE_UNSIGNED_CHAR + +typedef unsigned char JSAMPLE; +#define GETJSAMPLE(value) ((int) (value)) + +#else /* not HAVE_UNSIGNED_CHAR */ + +typedef char JSAMPLE; +#ifdef __CHAR_UNSIGNED__ +#define GETJSAMPLE(value) ((int) (value)) +#else +#define GETJSAMPLE(value) ((int) (value) & 0xFF) +#endif /* __CHAR_UNSIGNED__ */ + +#endif /* HAVE_UNSIGNED_CHAR */ + +#define MAXJSAMPLE 255 +#define CENTERJSAMPLE 128 + +#endif /* BITS_IN_JSAMPLE == 8 */ + + +#if BITS_IN_JSAMPLE == 12 +/* JSAMPLE should be the smallest type that will hold the values 0..4095. + * On nearly all machines "short" will do nicely. + */ + +typedef short JSAMPLE; +#define GETJSAMPLE(value) ((int) (value)) + +#define MAXJSAMPLE 4095 +#define CENTERJSAMPLE 2048 + +#endif /* BITS_IN_JSAMPLE == 12 */ + + +/* Representation of a DCT frequency coefficient. + * This should be a signed value of at least 16 bits; "short" is usually OK. + * Again, we allocate large arrays of these, but you can change to int + * if you have memory to burn and "short" is really slow. + */ + +typedef short JCOEF; + + +/* Compressed datastreams are represented as arrays of JOCTET. + * These must be EXACTLY 8 bits wide, at least once they are written to + * external storage. Note that when using the stdio data source/destination + * managers, this is also the data type passed to fread/fwrite. + */ + +#ifdef HAVE_UNSIGNED_CHAR + +typedef unsigned char JOCTET; +#define GETJOCTET(value) (value) + +#else /* not HAVE_UNSIGNED_CHAR */ + +typedef char JOCTET; +#ifdef __CHAR_UNSIGNED__ +#define GETJOCTET(value) (value) +#else +#define GETJOCTET(value) ((value) & 0xFF) +#endif /* __CHAR_UNSIGNED__ */ + +#endif /* HAVE_UNSIGNED_CHAR */ + + +/* These typedefs are used for various table entries and so forth. + * They must be at least as wide as specified; but making them too big + * won't cost a huge amount of memory, so we don't provide special + * extraction code like we did for JSAMPLE. (In other words, these + * typedefs live at a different point on the speed/space tradeoff curve.) + */ + +/* UINT8 must hold at least the values 0..255. */ + +#ifdef HAVE_UNSIGNED_CHAR +typedef unsigned char UINT8; +#else /* not HAVE_UNSIGNED_CHAR */ +#ifdef __CHAR_UNSIGNED__ +typedef char UINT8; +#else /* not __CHAR_UNSIGNED__ */ +typedef short UINT8; +#endif /* __CHAR_UNSIGNED__ */ +#endif /* HAVE_UNSIGNED_CHAR */ + +/* UINT16 must hold at least the values 0..65535. */ + +#ifdef HAVE_UNSIGNED_SHORT +typedef unsigned short UINT16; +#else /* not HAVE_UNSIGNED_SHORT */ +typedef unsigned int UINT16; +#endif /* HAVE_UNSIGNED_SHORT */ + +/* INT16 must hold at least the values -32768..32767. */ + +#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ +typedef short INT16; +#endif + +/* INT32 must hold at least signed 32-bit values. */ + +#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ +typedef long INT32; +#endif + +/* Datatype used for image dimensions. The JPEG standard only supports + * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore + * "unsigned int" is sufficient on all machines. However, if you need to + * handle larger images and you don't mind deviating from the spec, you + * can change this datatype. + */ + +typedef unsigned int JDIMENSION; + +#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */ + + +/* These macros are used in all function definitions and extern declarations. + * You could modify them if you need to change function linkage conventions; + * in particular, you'll need to do that to make the library a Windows DLL. + * Another application is to make all functions global for use with debuggers + * or code profilers that require it. + */ + +/* a function called through method pointers: */ +#define METHODDEF(type) static type +/* a function used only in its module: */ +#define LOCAL(type) static type +/* a function referenced thru EXTERNs: */ +#define GLOBAL(type) type +/* a reference to a GLOBAL function: */ +#define EXTERN(type) extern type + + +/* This macro is used to declare a "method", that is, a function pointer. + * We want to supply prototype parameters if the compiler can cope. + * Note that the arglist parameter must be parenthesized! + * Again, you can customize this if you need special linkage keywords. + */ + +#ifdef HAVE_PROTOTYPES +#define JMETHOD(type,methodname,arglist) type (*methodname) arglist +#else +#define JMETHOD(type,methodname,arglist) type (*methodname) () +#endif + + +/* Here is the pseudo-keyword for declaring pointers that must be "far" + * on 80x86 machines. Most of the specialized coding for 80x86 is handled + * by just saying "FAR *" where such a pointer is needed. In a few places + * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol. + */ + +#ifdef NEED_FAR_POINTERS +#define FAR far +#else +#define FAR +#endif + + +/* + * On a few systems, type boolean and/or its values FALSE, TRUE may appear + * in standard header files. Or you may have conflicts with application- + * specific header files that you want to include together with these files. + * Defining HAVE_BOOLEAN before including jpeglib.h should make it work. + */ + +#ifndef HAVE_BOOLEAN +typedef int boolean; +#endif +#ifndef FALSE /* in case these macros already exist */ +#define FALSE 0 /* values of boolean */ +#endif +#ifndef TRUE +#define TRUE 1 +#endif + + +/* + * The remaining options affect code selection within the JPEG library, + * but they don't need to be visible to most applications using the library. + * To minimize application namespace pollution, the symbols won't be + * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined. + */ + +#ifdef JPEG_INTERNALS +#define JPEG_INTERNAL_OPTIONS +#endif + +#ifdef JPEG_INTERNAL_OPTIONS + + +/* + * These defines indicate whether to include various optional functions. + * Undefining some of these symbols will produce a smaller but less capable + * library. Note that you can leave certain source files out of the + * compilation/linking process if you've #undef'd the corresponding symbols. + * (You may HAVE to do that if your compiler doesn't like null source files.) + */ + +/* Capability options common to encoder and decoder: */ + +#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ +#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ +#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ + +/* Encoder capability options: */ + +#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ +#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ +#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ +/* Note: if you selected 12-bit data precision, it is dangerous to turn off + * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit + * precision, so jchuff.c normally uses entropy optimization to compute + * usable tables for higher precision. If you don't want to do optimization, + * you'll have to supply different default Huffman tables. + * The exact same statements apply for progressive JPEG: the default tables + * don't work for progressive mode. (This may get fixed, however.) + */ +#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */ + +/* Decoder capability options: */ + +#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ +#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ +#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ +#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ +#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ +#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ +#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ +#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ +#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ + +/* more capability options later, no doubt */ + + +/* + * Ordering of RGB data in scanlines passed to or from the application. + * If your application wants to deal with data in the order B,G,R, just + * change these macros. You can also deal with formats such as R,G,B,X + * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing + * the offsets will also change the order in which colormap data is organized. + * RESTRICTIONS: + * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. + * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not + * useful if you are using JPEG color spaces other than YCbCr or grayscale. + * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE + * is not 3 (they don't understand about dummy color components!). So you + * can't use color quantization if you change that value. + */ + +#define RGB_RED 0 /* Offset of Red in an RGB scanline element */ +#define RGB_GREEN 1 /* Offset of Green */ +#define RGB_BLUE 2 /* Offset of Blue */ +#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ + +#define JPEG_NUMCS 16 + +#define EXT_RGB_RED 0 +#define EXT_RGB_GREEN 1 +#define EXT_RGB_BLUE 2 +#define EXT_RGB_PIXELSIZE 3 + +#define EXT_RGBX_RED 0 +#define EXT_RGBX_GREEN 1 +#define EXT_RGBX_BLUE 2 +#define EXT_RGBX_PIXELSIZE 4 + +#define EXT_BGR_RED 2 +#define EXT_BGR_GREEN 1 +#define EXT_BGR_BLUE 0 +#define EXT_BGR_PIXELSIZE 3 + +#define EXT_BGRX_RED 2 +#define EXT_BGRX_GREEN 1 +#define EXT_BGRX_BLUE 0 +#define EXT_BGRX_PIXELSIZE 4 + +#define EXT_XBGR_RED 3 +#define EXT_XBGR_GREEN 2 +#define EXT_XBGR_BLUE 1 +#define EXT_XBGR_PIXELSIZE 4 + +#define EXT_XRGB_RED 1 +#define EXT_XRGB_GREEN 2 +#define EXT_XRGB_BLUE 3 +#define EXT_XRGB_PIXELSIZE 4 + +static const int rgb_red[JPEG_NUMCS] = { + -1, -1, RGB_RED, -1, -1, -1, EXT_RGB_RED, EXT_RGBX_RED, + EXT_BGR_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED, + EXT_RGBX_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED +}; + +static const int rgb_green[JPEG_NUMCS] = { + -1, -1, RGB_GREEN, -1, -1, -1, EXT_RGB_GREEN, EXT_RGBX_GREEN, + EXT_BGR_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN, + EXT_RGBX_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN +}; + +static const int rgb_blue[JPEG_NUMCS] = { + -1, -1, RGB_BLUE, -1, -1, -1, EXT_RGB_BLUE, EXT_RGBX_BLUE, + EXT_BGR_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE, + EXT_RGBX_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE +}; + +static const int rgb_pixelsize[JPEG_NUMCS] = { + -1, -1, RGB_PIXELSIZE, -1, -1, -1, EXT_RGB_PIXELSIZE, EXT_RGBX_PIXELSIZE, + EXT_BGR_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE, + EXT_RGBX_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE +}; + +/* Definitions for speed-related optimizations. */ + +/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying + * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER + * as short on such a machine. MULTIPLIER must be at least 16 bits wide. + */ + +#ifndef MULTIPLIER +#ifndef WITH_SIMD +#define MULTIPLIER int /* type for fastest integer multiply */ +#else +#define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */ +#endif +#endif + + +/* FAST_FLOAT should be either float or double, whichever is done faster + * by your compiler. (Note that this type is only used in the floating point + * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) + * Typically, float is faster in ANSI C compilers, while double is faster in + * pre-ANSI compilers (because they insist on converting to double anyway). + * The code below therefore chooses float if we have ANSI-style prototypes. + */ + +#ifndef FAST_FLOAT +#ifdef HAVE_PROTOTYPES +#define FAST_FLOAT float +#else +#define FAST_FLOAT double +#endif +#endif + +#endif /* JPEG_INTERNAL_OPTIONS */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jpegcomp.h b/lib-third-party/libturbojpeg-ios/libjpeg/jpegcomp.h new file mode 100755 index 0000000..ed9eeab --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jpegcomp.h @@ -0,0 +1,30 @@ +/* + * jpegcomp.h + * + * Copyright (C) 2010, D. R. Commander + * For conditions of distribution and use, see the accompanying README file. + * + * JPEG compatibility macros + * These declarations are considered internal to the JPEG library; most + * applications using the library shouldn't need to include this file. + */ + +#if JPEG_LIB_VERSION >= 70 +#define _DCT_scaled_size DCT_h_scaled_size +#define _DCT_h_scaled_size DCT_h_scaled_size +#define _DCT_v_scaled_size DCT_v_scaled_size +#define _min_DCT_scaled_size min_DCT_h_scaled_size +#define _min_DCT_h_scaled_size min_DCT_h_scaled_size +#define _min_DCT_v_scaled_size min_DCT_v_scaled_size +#define _jpeg_width jpeg_width +#define _jpeg_height jpeg_height +#else +#define _DCT_scaled_size DCT_scaled_size +#define _DCT_h_scaled_size DCT_scaled_size +#define _DCT_v_scaled_size DCT_scaled_size +#define _min_DCT_scaled_size min_DCT_scaled_size +#define _min_DCT_h_scaled_size min_DCT_scaled_size +#define _min_DCT_v_scaled_size min_DCT_scaled_size +#define _jpeg_width image_width +#define _jpeg_height image_height +#endif diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jpegint.h b/lib-third-party/libturbojpeg-ios/libjpeg/jpegint.h new file mode 100755 index 0000000..7871748 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jpegint.h @@ -0,0 +1,401 @@ +/* + * jpegint.h + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Modified 1997-2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file provides common declarations for the various JPEG modules. + * These declarations are considered internal to the JPEG library; most + * applications using the library shouldn't need to include this file. + */ + + +/* Declarations for both compression & decompression */ + +typedef enum { /* Operating modes for buffer controllers */ + JBUF_PASS_THRU, /* Plain stripwise operation */ + /* Remaining modes require a full-image buffer to have been created */ + JBUF_SAVE_SOURCE, /* Run source subobject only, save output */ + JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */ + JBUF_SAVE_AND_PASS /* Run both subobjects, save output */ +} J_BUF_MODE; + +/* Values of global_state field (jdapi.c has some dependencies on ordering!) */ +#define CSTATE_START 100 /* after create_compress */ +#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */ +#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */ +#define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */ +#define DSTATE_START 200 /* after create_decompress */ +#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */ +#define DSTATE_READY 202 /* found SOS, ready for start_decompress */ +#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/ +#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */ +#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */ +#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */ +#define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */ +#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */ +#define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */ +#define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */ + + +/* Declarations for compression modules */ + +/* Master control module */ +struct jpeg_comp_master { + JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo)); + JMETHOD(void, pass_startup, (j_compress_ptr cinfo)); + JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); + + /* State variables made visible to other modules */ + boolean call_pass_startup; /* True if pass_startup must be called */ + boolean is_last_pass; /* True during last pass */ +}; + +/* Main buffer control (downsampled-data buffer) */ +struct jpeg_c_main_controller { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, process_data, (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail)); +}; + +/* Compression preprocessing (downsampling input buffer control) */ +struct jpeg_c_prep_controller { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, pre_process_data, (j_compress_ptr cinfo, + JSAMPARRAY input_buf, + JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail, + JSAMPIMAGE output_buf, + JDIMENSION *out_row_group_ctr, + JDIMENSION out_row_groups_avail)); +}; + +/* Coefficient buffer control */ +struct jpeg_c_coef_controller { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(boolean, compress_data, (j_compress_ptr cinfo, + JSAMPIMAGE input_buf)); +}; + +/* Colorspace conversion */ +struct jpeg_color_converter { + JMETHOD(void, start_pass, (j_compress_ptr cinfo)); + JMETHOD(void, color_convert, (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +}; + +/* Downsampling */ +struct jpeg_downsampler { + JMETHOD(void, start_pass, (j_compress_ptr cinfo)); + JMETHOD(void, downsample, (j_compress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_index, + JSAMPIMAGE output_buf, + JDIMENSION out_row_group_index)); + + boolean need_context_rows; /* TRUE if need rows above & below */ +}; + +/* Forward DCT (also controls coefficient quantization) */ +struct jpeg_forward_dct { + JMETHOD(void, start_pass, (j_compress_ptr cinfo)); + /* perhaps this should be an array??? */ + JMETHOD(void, forward_DCT, (j_compress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY sample_data, JBLOCKROW coef_blocks, + JDIMENSION start_row, JDIMENSION start_col, + JDIMENSION num_blocks)); +}; + +/* Entropy encoding */ +struct jpeg_entropy_encoder { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics)); + JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data)); + JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); +}; + +/* Marker writing */ +struct jpeg_marker_writer { + JMETHOD(void, write_file_header, (j_compress_ptr cinfo)); + JMETHOD(void, write_frame_header, (j_compress_ptr cinfo)); + JMETHOD(void, write_scan_header, (j_compress_ptr cinfo)); + JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo)); + JMETHOD(void, write_tables_only, (j_compress_ptr cinfo)); + /* These routines are exported to allow insertion of extra markers */ + /* Probably only COM and APPn markers should be written this way */ + JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker, + unsigned int datalen)); + JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val)); +}; + + +/* Declarations for decompression modules */ + +/* Master control module */ +struct jpeg_decomp_master { + JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); + + /* State variables made visible to other modules */ + boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ +}; + +/* Input control module */ +struct jpeg_input_controller { + JMETHOD(int, consume_input, (j_decompress_ptr cinfo)); + JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo)); + JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo)); + + /* State variables made visible to other modules */ + boolean has_multiple_scans; /* True if file has multiple scans */ + boolean eoi_reached; /* True when EOI has been consumed */ +}; + +/* Main buffer control (downsampled-data buffer) */ +struct jpeg_d_main_controller { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, process_data, (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); +}; + +/* Coefficient buffer control */ +struct jpeg_d_coef_controller { + JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); + JMETHOD(int, consume_data, (j_decompress_ptr cinfo)); + JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo)); + JMETHOD(int, decompress_data, (j_decompress_ptr cinfo, + JSAMPIMAGE output_buf)); + /* Pointer to array of coefficient virtual arrays, or NULL if none */ + jvirt_barray_ptr *coef_arrays; +}; + +/* Decompression postprocessing (color quantization buffer control) */ +struct jpeg_d_post_controller { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, post_process_data, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); +}; + +/* Marker reading & parsing */ +struct jpeg_marker_reader { + JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo)); + /* Read markers until SOS or EOI. + * Returns same codes as are defined for jpeg_consume_input: + * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. + */ + JMETHOD(int, read_markers, (j_decompress_ptr cinfo)); + /* Read a restart marker --- exported for use by entropy decoder only */ + jpeg_marker_parser_method read_restart_marker; + + /* State of marker reader --- nominally internal, but applications + * supplying COM or APPn handlers might like to know the state. + */ + boolean saw_SOI; /* found SOI? */ + boolean saw_SOF; /* found SOF? */ + int next_restart_num; /* next restart number expected (0-7) */ + unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ +}; + +/* Entropy decoding */ +struct jpeg_entropy_decoder { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); + + /* This is here to share code between baseline and progressive decoders; */ + /* other modules probably should not use it */ + boolean insufficient_data; /* set TRUE after emitting warning */ +}; + +/* Inverse DCT (also performs dequantization) */ +typedef JMETHOD(void, inverse_DCT_method_ptr, + (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col)); + +struct jpeg_inverse_dct { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + /* It is useful to allow each component to have a separate IDCT method. */ + inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; +}; + +/* Upsampling (note that upsampler must also call color converter) */ +struct jpeg_upsampler { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, upsample, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); + + boolean need_context_rows; /* TRUE if need rows above & below */ +}; + +/* Colorspace conversion */ +struct jpeg_color_deconverter { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, color_convert, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +}; + +/* Color quantization or color precision reduction */ +struct jpeg_color_quantizer { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); + JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPARRAY output_buf, + int num_rows)); + JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); +}; + + +/* Miscellaneous useful macros */ + +#undef MAX +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#undef MIN +#define MIN(a,b) ((a) < (b) ? (a) : (b)) + + +/* We assume that right shift corresponds to signed division by 2 with + * rounding towards minus infinity. This is correct for typical "arithmetic + * shift" instructions that shift in copies of the sign bit. But some + * C compilers implement >> with an unsigned shift. For these machines you + * must define RIGHT_SHIFT_IS_UNSIGNED. + * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity. + * It is only applied with constant shift counts. SHIFT_TEMPS must be + * included in the variables of any routine using RIGHT_SHIFT. + */ + +#ifdef RIGHT_SHIFT_IS_UNSIGNED +#define SHIFT_TEMPS INT32 shift_temp; +#define RIGHT_SHIFT(x,shft) \ + ((shift_temp = (x)) < 0 ? \ + (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \ + (shift_temp >> (shft))) +#else +#define SHIFT_TEMPS +#define RIGHT_SHIFT(x,shft) ((x) >> (shft)) +#endif + + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jinit_compress_master jICompress +#define jinit_c_master_control jICMaster +#define jinit_c_main_controller jICMainC +#define jinit_c_prep_controller jICPrepC +#define jinit_c_coef_controller jICCoefC +#define jinit_color_converter jICColor +#define jinit_downsampler jIDownsampler +#define jinit_forward_dct jIFDCT +#define jinit_huff_encoder jIHEncoder +#define jinit_phuff_encoder jIPHEncoder +#define jinit_arith_encoder jIAEncoder +#define jinit_marker_writer jIMWriter +#define jinit_master_decompress jIDMaster +#define jinit_d_main_controller jIDMainC +#define jinit_d_coef_controller jIDCoefC +#define jinit_d_post_controller jIDPostC +#define jinit_input_controller jIInCtlr +#define jinit_marker_reader jIMReader +#define jinit_huff_decoder jIHDecoder +#define jinit_phuff_decoder jIPHDecoder +#define jinit_arith_decoder jIADecoder +#define jinit_inverse_dct jIIDCT +#define jinit_upsampler jIUpsampler +#define jinit_color_deconverter jIDColor +#define jinit_1pass_quantizer jI1Quant +#define jinit_2pass_quantizer jI2Quant +#define jinit_merged_upsampler jIMUpsampler +#define jinit_memory_mgr jIMemMgr +#define jdiv_round_up jDivRound +#define jround_up jRound +#define jcopy_sample_rows jCopySamples +#define jcopy_block_row jCopyBlocks +#define jzero_far jZeroFar +#define jpeg_zigzag_order jZIGTable +#define jpeg_natural_order jZAGTable +#define jpeg_aritab jAriTab +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + + +/* Compression module initialization routines */ +EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); +EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, + boolean transcode_only)); +EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo, + boolean need_full_buffer)); +EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo, + boolean need_full_buffer)); +EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo, + boolean need_full_buffer)); +EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo)); +EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); +EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); +EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo)); +EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo)); +EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo)); +EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo)); +/* Decompression module initialization routines */ +EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo, + boolean need_full_buffer)); +EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo, + boolean need_full_buffer)); +EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo, + boolean need_full_buffer)); +EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo)); +EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo)); +/* Memory manager initialization */ +EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo)); + +/* Utility routines in jutils.c */ +EXTERN(long) jdiv_round_up JPP((long a, long b)); +EXTERN(long) jround_up JPP((long a, long b)); +EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row, + JSAMPARRAY output_array, int dest_row, + int num_rows, JDIMENSION num_cols)); +EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, + JDIMENSION num_blocks)); +EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero)); +/* Constant tables in jutils.c */ +#if 0 /* This table is not actually needed in v6a */ +extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ +#endif +extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ + +/* Arithmetic coding probability estimation tables in jaricom.c */ +extern const INT32 jpeg_aritab[]; + +/* Suppress undefined-structure complaints if necessary. */ + +#ifdef INCOMPLETE_TYPES_BROKEN +#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ +struct jvirt_sarray_control { long dummy; }; +struct jvirt_barray_control { long dummy; }; +#endif +#endif /* INCOMPLETE_TYPES_BROKEN */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jpeglib.h b/lib-third-party/libturbojpeg-ios/libjpeg/jpeglib.h new file mode 100755 index 0000000..d19a3ef --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jpeglib.h @@ -0,0 +1,1213 @@ +/* + * jpeglib.h + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Modified 2002-2009 by Guido Vollbeding. + * Copyright (C) 2009-2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the application interface for the JPEG library. + * Most applications using the library need only include this file, + * and perhaps jerror.h if they want to know the exact error codes. + */ + +#ifndef JPEGLIB_H +#define JPEGLIB_H + +/* + * First we include the configuration files that record how this + * installation of the JPEG library is set up. jconfig.h can be + * generated automatically for many systems. jmorecfg.h contains + * manual configuration options that most people need not worry about. + */ + +#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ +#include "jconfig.h" /* widely used configuration options */ +#endif +#include "jmorecfg.h" /* seldom changed options */ + + +#ifdef __cplusplus +#ifndef DONT_USE_EXTERN_C +extern "C" { +#endif +#endif + + +/* Various constants determining the sizes of things. + * All of these are specified by the JPEG standard, so don't change them + * if you want to be compatible. + */ + +#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ +#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ +#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */ +#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */ +#define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */ +#define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */ +#define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */ +/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard; + * the PostScript DCT filter can emit files with many more than 10 blocks/MCU. + * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU + * to handle it. We even let you do this from the jconfig.h file. However, + * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe + * sometimes emits noncompliant files doesn't mean you should too. + */ +#define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */ +#ifndef D_MAX_BLOCKS_IN_MCU +#define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */ +#endif + + +/* Data structures for images (arrays of samples and of DCT coefficients). + * On 80x86 machines, the image arrays are too big for near pointers, + * but the pointer arrays can fit in near memory. + */ + +typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */ +typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ +typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ + +typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ +typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */ +typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */ +typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */ + +typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */ + + +/* Types for JPEG compression parameters and working tables. */ + + +/* DCT coefficient quantization tables. */ + +typedef struct { + /* This array gives the coefficient quantizers in natural array order + * (not the zigzag order in which they are stored in a JPEG DQT marker). + * CAUTION: IJG versions prior to v6a kept this array in zigzag order. + */ + UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ +} JQUANT_TBL; + + +/* Huffman coding tables. */ + +typedef struct { + /* These two fields directly represent the contents of a JPEG DHT marker */ + UINT8 bits[17]; /* bits[k] = # of symbols with codes of */ + /* length k bits; bits[0] is unused */ + UINT8 huffval[256]; /* The symbols, in order of incr code length */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ +} JHUFF_TBL; + + +/* Basic info about one component (color channel). */ + +typedef struct { + /* These values are fixed over the whole image. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOF marker. */ + int component_id; /* identifier for this component (0..255) */ + int component_index; /* its index in SOF or cinfo->comp_info[] */ + int h_samp_factor; /* horizontal sampling factor (1..4) */ + int v_samp_factor; /* vertical sampling factor (1..4) */ + int quant_tbl_no; /* quantization table selector (0..3) */ + /* These values may vary between scans. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOS marker. */ + /* The decompressor output side may not use these variables. */ + int dc_tbl_no; /* DC entropy table selector (0..3) */ + int ac_tbl_no; /* AC entropy table selector (0..3) */ + + /* Remaining fields should be treated as private by applications. */ + + /* These values are computed during compression or decompression startup: */ + /* Component's size in DCT blocks. + * Any dummy blocks added to complete an MCU are not counted; therefore + * these values do not depend on whether a scan is interleaved or not. + */ + JDIMENSION width_in_blocks; + JDIMENSION height_in_blocks; + /* Size of a DCT block in samples. Always DCTSIZE for compression. + * For decompression this is the size of the output from one DCT block, + * reflecting any scaling we choose to apply during the IDCT step. + * Values of 1,2,4,8 are likely to be supported. Note that different + * components may receive different IDCT scalings. + */ +#if JPEG_LIB_VERSION >= 70 + int DCT_h_scaled_size; + int DCT_v_scaled_size; +#else + int DCT_scaled_size; +#endif + /* The downsampled dimensions are the component's actual, unpadded number + * of samples at the main buffer (preprocessing/compression interface), thus + * downsampled_width = ceil(image_width * Hi/Hmax) + * and similarly for height. For decompression, IDCT scaling is included, so + * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE) + */ + JDIMENSION downsampled_width; /* actual width in samples */ + JDIMENSION downsampled_height; /* actual height in samples */ + /* This flag is used only for decompression. In cases where some of the + * components will be ignored (eg grayscale output from YCbCr image), + * we can skip most computations for the unused components. + */ + boolean component_needed; /* do we need the value of this component? */ + + /* These values are computed before starting a scan of the component. */ + /* The decompressor output side may not use these variables. */ + int MCU_width; /* number of blocks per MCU, horizontally */ + int MCU_height; /* number of blocks per MCU, vertically */ + int MCU_blocks; /* MCU_width * MCU_height */ + int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */ + int last_col_width; /* # of non-dummy blocks across in last MCU */ + int last_row_height; /* # of non-dummy blocks down in last MCU */ + + /* Saved quantization table for component; NULL if none yet saved. + * See jdinput.c comments about the need for this information. + * This field is currently used only for decompression. + */ + JQUANT_TBL * quant_table; + + /* Private per-component storage for DCT or IDCT subsystem. */ + void * dct_table; +} jpeg_component_info; + + +/* The script for encoding a multiple-scan file is an array of these: */ + +typedef struct { + int comps_in_scan; /* number of components encoded in this scan */ + int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */ + int Ss, Se; /* progressive JPEG spectral selection parms */ + int Ah, Al; /* progressive JPEG successive approx. parms */ +} jpeg_scan_info; + +/* The decompressor can save APPn and COM markers in a list of these: */ + +typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr; + +struct jpeg_marker_struct { + jpeg_saved_marker_ptr next; /* next in list, or NULL */ + UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */ + unsigned int original_length; /* # bytes of data in the file */ + unsigned int data_length; /* # bytes of data saved at data[] */ + JOCTET FAR * data; /* the data contained in the marker */ + /* the marker length word is not counted in data_length or original_length */ +}; + +/* Known color spaces. */ + +#define JCS_EXTENSIONS 1 +#define JCS_ALPHA_EXTENSIONS 1 + +typedef enum { + JCS_UNKNOWN, /* error/unspecified */ + JCS_GRAYSCALE, /* monochrome */ + JCS_RGB, /* red/green/blue as specified by the RGB_RED, RGB_GREEN, + RGB_BLUE, and RGB_PIXELSIZE macros */ + JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ + JCS_CMYK, /* C/M/Y/K */ + JCS_YCCK, /* Y/Cb/Cr/K */ + JCS_EXT_RGB, /* red/green/blue */ + JCS_EXT_RGBX, /* red/green/blue/x */ + JCS_EXT_BGR, /* blue/green/red */ + JCS_EXT_BGRX, /* blue/green/red/x */ + JCS_EXT_XBGR, /* x/blue/green/red */ + JCS_EXT_XRGB, /* x/red/green/blue */ + /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, + JCS_EXT_XBGR, or JCS_EXT_XRGB during decompression, the X byte is + undefined, and in order to ensure the best performance, + libjpeg-turbo can set that byte to whatever value it wishes. Use + the following colorspace constants to ensure that the X byte is set + to 0xFF, so that it can be interpreted as an opaque alpha + channel. */ + JCS_EXT_RGBA, /* red/green/blue/alpha */ + JCS_EXT_BGRA, /* blue/green/red/alpha */ + JCS_EXT_ABGR, /* alpha/blue/green/red */ + JCS_EXT_ARGB /* alpha/red/green/blue */ +} J_COLOR_SPACE; + +/* DCT/IDCT algorithm options. */ + +typedef enum { + JDCT_ISLOW, /* slow but accurate integer algorithm */ + JDCT_IFAST, /* faster, less accurate integer method */ + JDCT_FLOAT /* floating-point: accurate, fast on fast HW */ +} J_DCT_METHOD; + +#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */ +#define JDCT_DEFAULT JDCT_ISLOW +#endif +#ifndef JDCT_FASTEST /* may be overridden in jconfig.h */ +#define JDCT_FASTEST JDCT_IFAST +#endif + +/* Dithering options for decompression. */ + +typedef enum { + JDITHER_NONE, /* no dithering */ + JDITHER_ORDERED, /* simple ordered dither */ + JDITHER_FS /* Floyd-Steinberg error diffusion dither */ +} J_DITHER_MODE; + + +/* Common fields between JPEG compression and decompression master structs. */ + +#define jpeg_common_fields \ + struct jpeg_error_mgr * err; /* Error handler module */\ + struct jpeg_memory_mgr * mem; /* Memory manager module */\ + struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\ + void * client_data; /* Available for use by application */\ + boolean is_decompressor; /* So common code can tell which is which */\ + int global_state /* For checking call sequence validity */ + +/* Routines that are to be used by both halves of the library are declared + * to receive a pointer to this structure. There are no actual instances of + * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct. + */ +struct jpeg_common_struct { + jpeg_common_fields; /* Fields common to both master struct types */ + /* Additional fields follow in an actual jpeg_compress_struct or + * jpeg_decompress_struct. All three structs must agree on these + * initial fields! (This would be a lot cleaner in C++.) + */ +}; + +typedef struct jpeg_common_struct * j_common_ptr; +typedef struct jpeg_compress_struct * j_compress_ptr; +typedef struct jpeg_decompress_struct * j_decompress_ptr; + + +/* Master record for a compression instance */ + +struct jpeg_compress_struct { + jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */ + + /* Destination for compressed data */ + struct jpeg_destination_mgr * dest; + + /* Description of source image --- these fields must be filled in by + * outer application before starting compression. in_color_space must + * be correct before you can even call jpeg_set_defaults(). + */ + + JDIMENSION image_width; /* input image width */ + JDIMENSION image_height; /* input image height */ + int input_components; /* # of color components in input image */ + J_COLOR_SPACE in_color_space; /* colorspace of input image */ + + double input_gamma; /* image gamma of input image */ + + /* Compression parameters --- these fields must be set before calling + * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to + * initialize everything to reasonable defaults, then changing anything + * the application specifically wants to change. That way you won't get + * burnt when new parameters are added. Also note that there are several + * helper routines to simplify changing parameters. + */ + +#if JPEG_LIB_VERSION >= 70 + unsigned int scale_num, scale_denom; /* fraction by which to scale image */ + + JDIMENSION jpeg_width; /* scaled JPEG image width */ + JDIMENSION jpeg_height; /* scaled JPEG image height */ + /* Dimensions of actual JPEG image that will be written to file, + * derived from input dimensions by scaling factors above. + * These fields are computed by jpeg_start_compress(). + * You can also use jpeg_calc_jpeg_dimensions() to determine these values + * in advance of calling jpeg_start_compress(). + */ +#endif + + int data_precision; /* bits of precision in image data */ + + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; +#if JPEG_LIB_VERSION >= 70 + int q_scale_factor[NUM_QUANT_TBLS]; +#endif + /* ptrs to coefficient quantization tables, or NULL if not defined, + * and corresponding scale factors (percentage, initialized 100). + */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + int num_scans; /* # of entries in scan_info array */ + const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */ + /* The default value of scan_info is NULL, which causes a single-scan + * sequential JPEG file to be emitted. To create a multi-scan file, + * set num_scans and scan_info to point to an array of scan definitions. + */ + + boolean raw_data_in; /* TRUE=caller supplies downsampled data */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + boolean optimize_coding; /* TRUE=optimize entropy encoding parms */ + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ +#if JPEG_LIB_VERSION >= 70 + boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */ +#endif + int smoothing_factor; /* 1..100, or 0 for no input smoothing */ + J_DCT_METHOD dct_method; /* DCT algorithm selector */ + + /* The restart interval can be specified in absolute MCUs by setting + * restart_interval, or in MCU rows by setting restart_in_rows + * (in which case the correct restart_interval will be figured + * for each scan). + */ + unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */ + int restart_in_rows; /* if > 0, MCU rows per restart interval */ + + /* Parameters controlling emission of special markers. */ + + boolean write_JFIF_header; /* should a JFIF marker be written? */ + UINT8 JFIF_major_version; /* What to write for the JFIF version number */ + UINT8 JFIF_minor_version; + /* These three values are not used by the JPEG code, merely copied */ + /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */ + /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */ + /* ratio is defined by X_density/Y_density even when density_unit=0. */ + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean write_Adobe_marker; /* should an Adobe marker be written? */ + + /* State variable: index of next scanline to be written to + * jpeg_write_scanlines(). Application may use this to control its + * processing loop, e.g., "while (next_scanline < image_height)". + */ + + JDIMENSION next_scanline; /* 0 .. image_height-1 */ + + /* Remaining fields are known throughout compressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during compression startup + */ + boolean progressive_mode; /* TRUE if scan script uses progressive mode */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + +#if JPEG_LIB_VERSION >= 70 + int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ + int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ +#endif + + JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ + /* The coefficient controller receives data in units of MCU rows as defined + * for fully interleaved scans (whether the JPEG file is interleaved or not). + * There are v_samp_factor * DCTSIZE sample rows of each component in an + * "iMCU" (interleaved MCU) row. + */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[C_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + +#if JPEG_LIB_VERSION >= 80 + int block_size; /* the basic DCT block size: 1..16 */ + const int * natural_order; /* natural-order position array */ + int lim_Se; /* min( Se, DCTSIZE2-1 ) */ +#endif + + /* + * Links to compression subobjects (methods and private variables of modules) + */ + struct jpeg_comp_master * master; + struct jpeg_c_main_controller * main; + struct jpeg_c_prep_controller * prep; + struct jpeg_c_coef_controller * coef; + struct jpeg_marker_writer * marker; + struct jpeg_color_converter * cconvert; + struct jpeg_downsampler * downsample; + struct jpeg_forward_dct * fdct; + struct jpeg_entropy_encoder * entropy; + jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */ + int script_space_size; +}; + + +/* Master record for a decompression instance */ + +struct jpeg_decompress_struct { + jpeg_common_fields; /* Fields shared with jpeg_compress_struct */ + + /* Source of compressed data */ + struct jpeg_source_mgr * src; + + /* Basic description of image --- filled in by jpeg_read_header(). */ + /* Application may inspect these values to decide how to process image. */ + + JDIMENSION image_width; /* nominal image width (from SOF marker) */ + JDIMENSION image_height; /* nominal image height */ + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + /* Decompression processing parameters --- these fields must be set before + * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes + * them to default values. + */ + + J_COLOR_SPACE out_color_space; /* colorspace for output */ + + unsigned int scale_num, scale_denom; /* fraction by which to scale image */ + + double output_gamma; /* image gamma wanted in output */ + + boolean buffered_image; /* TRUE=multiple output passes */ + boolean raw_data_out; /* TRUE=downsampled data wanted */ + + J_DCT_METHOD dct_method; /* IDCT algorithm selector */ + boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */ + boolean do_block_smoothing; /* TRUE=apply interblock smoothing */ + + boolean quantize_colors; /* TRUE=colormapped output wanted */ + /* the following are ignored if not quantize_colors: */ + J_DITHER_MODE dither_mode; /* type of color dithering to use */ + boolean two_pass_quantize; /* TRUE=use two-pass color quantization */ + int desired_number_of_colors; /* max # colors to use in created colormap */ + /* these are significant only in buffered-image mode: */ + boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */ + boolean enable_external_quant;/* enable future use of external colormap */ + boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */ + + /* Description of actual output image that will be returned to application. + * These fields are computed by jpeg_start_decompress(). + * You can also use jpeg_calc_output_dimensions() to determine these values + * in advance of calling jpeg_start_decompress(). + */ + + JDIMENSION output_width; /* scaled image width */ + JDIMENSION output_height; /* scaled image height */ + int out_color_components; /* # of color components in out_color_space */ + int output_components; /* # of color components returned */ + /* output_components is 1 (a colormap index) when quantizing colors; + * otherwise it equals out_color_components. + */ + int rec_outbuf_height; /* min recommended height of scanline buffer */ + /* If the buffer passed to jpeg_read_scanlines() is less than this many rows + * high, space and time will be wasted due to unnecessary data copying. + * Usually rec_outbuf_height will be 1 or 2, at most 4. + */ + + /* When quantizing colors, the output colormap is described by these fields. + * The application can supply a colormap by setting colormap non-NULL before + * calling jpeg_start_decompress; otherwise a colormap is created during + * jpeg_start_decompress or jpeg_start_output. + * The map has out_color_components rows and actual_number_of_colors columns. + */ + int actual_number_of_colors; /* number of entries in use */ + JSAMPARRAY colormap; /* The color map as a 2-D pixel array */ + + /* State variables: these variables indicate the progress of decompression. + * The application may examine these but must not modify them. + */ + + /* Row index of next scanline to be read from jpeg_read_scanlines(). + * Application may use this to control its processing loop, e.g., + * "while (output_scanline < output_height)". + */ + JDIMENSION output_scanline; /* 0 .. output_height-1 */ + + /* Current input scan number and number of iMCU rows completed in scan. + * These indicate the progress of the decompressor input side. + */ + int input_scan_number; /* Number of SOS markers seen so far */ + JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */ + + /* The "output scan number" is the notional scan being displayed by the + * output side. The decompressor will not allow output scan/row number + * to get ahead of input scan/row, but it can fall arbitrarily far behind. + */ + int output_scan_number; /* Nominal scan number being displayed */ + JDIMENSION output_iMCU_row; /* Number of iMCU rows read */ + + /* Current progression status. coef_bits[c][i] indicates the precision + * with which component c's DCT coefficient i (in zigzag order) is known. + * It is -1 when no data has yet been received, otherwise it is the point + * transform (shift) value for the most recent scan of the coefficient + * (thus, 0 at completion of the progression). + * This pointer is NULL when reading a non-progressive file. + */ + int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */ + + /* Internal JPEG parameters --- the application usually need not look at + * these fields. Note that the decompressor output side may not use + * any parameters that can change between scans. + */ + + /* Quantization and Huffman tables are carried forward across input + * datastreams when processing abbreviated JPEG datastreams. + */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; + /* ptrs to coefficient quantization tables, or NULL if not defined */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + /* These parameters are never carried across datastreams, since they + * are given in SOF/SOS markers or defined to be reset by SOI. + */ + + int data_precision; /* bits of precision in image data */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + +#if JPEG_LIB_VERSION >= 80 + boolean is_baseline; /* TRUE if Baseline SOF0 encountered */ +#endif + boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */ + + /* These fields record data obtained from optional markers recognized by + * the JPEG library. + */ + boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */ + /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */ + UINT8 JFIF_major_version; /* JFIF version number */ + UINT8 JFIF_minor_version; + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */ + UINT8 Adobe_transform; /* Color transform code from Adobe marker */ + + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ + + /* Aside from the specific data retained from APPn markers known to the + * library, the uninterpreted contents of any or all APPn and COM markers + * can be saved in a list for examination by the application. + */ + jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */ + + /* Remaining fields are known throughout decompressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during decompression startup + */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + +#if JPEG_LIB_VERSION >= 70 + int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ + int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ +#else + int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */ +#endif + + JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */ + /* The coefficient controller's input and output progress is measured in + * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows + * in fully interleaved JPEG scans, but are used whether the scan is + * interleaved or not. We define an iMCU row as v_samp_factor DCT block + * rows of each component. Therefore, the IDCT output contains + * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row. + */ + + JSAMPLE * sample_range_limit; /* table for fast range-limiting */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + * Note that the decompressor output side must not use these fields. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[D_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + +#if JPEG_LIB_VERSION >= 80 + /* These fields are derived from Se of first SOS marker. + */ + int block_size; /* the basic DCT block size: 1..16 */ + const int * natural_order; /* natural-order position array for entropy decode */ + int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */ +#endif + + /* This field is shared between entropy decoder and marker parser. + * It is either zero or the code of a JPEG marker that has been + * read from the data source, but has not yet been processed. + */ + int unread_marker; + + /* + * Links to decompression subobjects (methods, private variables of modules) + */ + struct jpeg_decomp_master * master; + struct jpeg_d_main_controller * main; + struct jpeg_d_coef_controller * coef; + struct jpeg_d_post_controller * post; + struct jpeg_input_controller * inputctl; + struct jpeg_marker_reader * marker; + struct jpeg_entropy_decoder * entropy; + struct jpeg_inverse_dct * idct; + struct jpeg_upsampler * upsample; + struct jpeg_color_deconverter * cconvert; + struct jpeg_color_quantizer * cquantize; +}; + + +/* "Object" declarations for JPEG modules that may be supplied or called + * directly by the surrounding application. + * As with all objects in the JPEG library, these structs only define the + * publicly visible methods and state variables of a module. Additional + * private fields may exist after the public ones. + */ + + +/* Error handler object */ + +struct jpeg_error_mgr { + /* Error exit handler: does not return to caller */ + JMETHOD(void, error_exit, (j_common_ptr cinfo)); + /* Conditionally emit a trace or warning message */ + JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); + /* Routine that actually outputs a trace or error message */ + JMETHOD(void, output_message, (j_common_ptr cinfo)); + /* Format a message string for the most recent JPEG error or message */ + JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer)); +#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */ + /* Reset error state variables at start of a new image */ + JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); + + /* The message ID code and any parameters are saved here. + * A message can have one string parameter or up to 8 int parameters. + */ + int msg_code; +#define JMSG_STR_PARM_MAX 80 + union { + int i[8]; + char s[JMSG_STR_PARM_MAX]; + } msg_parm; + + /* Standard state variables for error facility */ + + int trace_level; /* max msg_level that will be displayed */ + + /* For recoverable corrupt-data errors, we emit a warning message, + * but keep going unless emit_message chooses to abort. emit_message + * should count warnings in num_warnings. The surrounding application + * can check for bad data by seeing if num_warnings is nonzero at the + * end of processing. + */ + long num_warnings; /* number of corrupt-data warnings */ + + /* These fields point to the table(s) of error message strings. + * An application can change the table pointer to switch to a different + * message list (typically, to change the language in which errors are + * reported). Some applications may wish to add additional error codes + * that will be handled by the JPEG library error mechanism; the second + * table pointer is used for this purpose. + * + * First table includes all errors generated by JPEG library itself. + * Error code 0 is reserved for a "no such error string" message. + */ + const char * const * jpeg_message_table; /* Library errors */ + int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */ + /* Second table can be added by application (see cjpeg/djpeg for example). + * It contains strings numbered first_addon_message..last_addon_message. + */ + const char * const * addon_message_table; /* Non-library errors */ + int first_addon_message; /* code for first string in addon table */ + int last_addon_message; /* code for last string in addon table */ +}; + + +/* Progress monitor object */ + +struct jpeg_progress_mgr { + JMETHOD(void, progress_monitor, (j_common_ptr cinfo)); + + long pass_counter; /* work units completed in this pass */ + long pass_limit; /* total number of work units in this pass */ + int completed_passes; /* passes completed so far */ + int total_passes; /* total number of passes expected */ +}; + + +/* Data destination object for compression */ + +struct jpeg_destination_mgr { + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + + JMETHOD(void, init_destination, (j_compress_ptr cinfo)); + JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo)); + JMETHOD(void, term_destination, (j_compress_ptr cinfo)); +}; + + +/* Data source object for decompression */ + +struct jpeg_source_mgr { + const JOCTET * next_input_byte; /* => next byte to read from buffer */ + size_t bytes_in_buffer; /* # of bytes remaining in buffer */ + + JMETHOD(void, init_source, (j_decompress_ptr cinfo)); + JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo)); + JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes)); + JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired)); + JMETHOD(void, term_source, (j_decompress_ptr cinfo)); +}; + + +/* Memory manager object. + * Allocates "small" objects (a few K total), "large" objects (tens of K), + * and "really big" objects (virtual arrays with backing store if needed). + * The memory manager does not allow individual objects to be freed; rather, + * each created object is assigned to a pool, and whole pools can be freed + * at once. This is faster and more convenient than remembering exactly what + * to free, especially where malloc()/free() are not too speedy. + * NB: alloc routines never return NULL. They exit to error_exit if not + * successful. + */ + +#define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */ +#define JPOOL_IMAGE 1 /* lasts until done with image/datastream */ +#define JPOOL_NUMPOOLS 2 + +typedef struct jvirt_sarray_control * jvirt_sarray_ptr; +typedef struct jvirt_barray_control * jvirt_barray_ptr; + + +struct jpeg_memory_mgr { + /* Method pointers */ + JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, + JDIMENSION samplesperrow, + JDIMENSION numrows)); + JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, + JDIMENSION blocksperrow, + JDIMENSION numrows)); + JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION samplesperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION blocksperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo)); + JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, + jvirt_sarray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, + jvirt_barray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id)); + JMETHOD(void, self_destruct, (j_common_ptr cinfo)); + + /* Limit on memory allocation for this JPEG object. (Note that this is + * merely advisory, not a guaranteed maximum; it only affects the space + * used for virtual-array buffers.) May be changed by outer application + * after creating the JPEG object. + */ + long max_memory_to_use; + + /* Maximum allocation request accepted by alloc_large. */ + long max_alloc_chunk; +}; + + +/* Routine signature for application-supplied marker processing methods. + * Need not pass marker code since it is stored in cinfo->unread_marker. + */ +typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo)); + + +/* Declarations for routines called by application. + * The JPP macro hides prototype parameters from compilers that can't cope. + * Note JPP requires double parentheses. + */ + +#ifdef HAVE_PROTOTYPES +#define JPP(arglist) arglist +#else +#define JPP(arglist) () +#endif + + +/* Short forms of external names for systems with brain-damaged linkers. + * We shorten external names to be unique in the first six letters, which + * is good enough for all known systems. + * (If your compiler itself needs names to be unique in less than 15 + * characters, you are out of luck. Get a better compiler.) + */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_std_error jStdError +#define jpeg_CreateCompress jCreaCompress +#define jpeg_CreateDecompress jCreaDecompress +#define jpeg_destroy_compress jDestCompress +#define jpeg_destroy_decompress jDestDecompress +#define jpeg_stdio_dest jStdDest +#define jpeg_stdio_src jStdSrc +#if JPEG_LIB_VERSION >= 80 +#define jpeg_mem_dest jMemDest +#define jpeg_mem_src jMemSrc +#endif +#define jpeg_set_defaults jSetDefaults +#define jpeg_set_colorspace jSetColorspace +#define jpeg_default_colorspace jDefColorspace +#define jpeg_set_quality jSetQuality +#define jpeg_set_linear_quality jSetLQuality +#if JPEG_LIB_VERSION >= 70 +#define jpeg_default_qtables jDefQTables +#endif +#define jpeg_add_quant_table jAddQuantTable +#define jpeg_quality_scaling jQualityScaling +#define jpeg_simple_progression jSimProgress +#define jpeg_suppress_tables jSuppressTables +#define jpeg_alloc_quant_table jAlcQTable +#define jpeg_alloc_huff_table jAlcHTable +#define jpeg_start_compress jStrtCompress +#define jpeg_write_scanlines jWrtScanlines +#define jpeg_finish_compress jFinCompress +#if JPEG_LIB_VERSION >= 70 +#define jpeg_calc_jpeg_dimensions jCjpegDimensions +#endif +#define jpeg_write_raw_data jWrtRawData +#define jpeg_write_marker jWrtMarker +#define jpeg_write_m_header jWrtMHeader +#define jpeg_write_m_byte jWrtMByte +#define jpeg_write_tables jWrtTables +#define jpeg_read_header jReadHeader +#define jpeg_start_decompress jStrtDecompress +#define jpeg_read_scanlines jReadScanlines +#define jpeg_finish_decompress jFinDecompress +#define jpeg_read_raw_data jReadRawData +#define jpeg_has_multiple_scans jHasMultScn +#define jpeg_start_output jStrtOutput +#define jpeg_finish_output jFinOutput +#define jpeg_input_complete jInComplete +#define jpeg_new_colormap jNewCMap +#define jpeg_consume_input jConsumeInput +#if JPEG_LIB_VERSION >= 80 +#define jpeg_core_output_dimensions jCoreDimensions +#endif +#define jpeg_calc_output_dimensions jCalcDimensions +#define jpeg_save_markers jSaveMarkers +#define jpeg_set_marker_processor jSetMarker +#define jpeg_read_coefficients jReadCoefs +#define jpeg_write_coefficients jWrtCoefs +#define jpeg_copy_critical_parameters jCopyCrit +#define jpeg_abort_compress jAbrtCompress +#define jpeg_abort_decompress jAbrtDecompress +#define jpeg_abort jAbort +#define jpeg_destroy jDestroy +#define jpeg_resync_to_restart jResyncRestart +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + + +/* Default error-management setup */ +EXTERN(struct jpeg_error_mgr *) jpeg_std_error + JPP((struct jpeg_error_mgr * err)); + +/* Initialization of JPEG compression objects. + * jpeg_create_compress() and jpeg_create_decompress() are the exported + * names that applications should call. These expand to calls on + * jpeg_CreateCompress and jpeg_CreateDecompress with additional information + * passed for version mismatch checking. + * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. + */ +#define jpeg_create_compress(cinfo) \ + jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_compress_struct)) +#define jpeg_create_decompress(cinfo) \ + jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_decompress_struct)) +EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo, + int version, size_t structsize)); +EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo, + int version, size_t structsize)); +/* Destruction of JPEG compression objects */ +EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); + +/* Standard data source and destination managers: stdio streams. */ +/* Caller is responsible for opening the file before and closing after. */ +EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); +EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); + +#if JPEG_LIB_VERSION >= 80 +/* Data source and destination managers: memory buffers. */ +EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo, + unsigned char ** outbuffer, + unsigned long * outsize)); +EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo, + unsigned char * inbuffer, + unsigned long insize)); +#endif + +/* Default parameter setup for compression */ +EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); +/* Compression parameter setup aids */ +EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, + J_COLOR_SPACE colorspace)); +EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, + boolean force_baseline)); +EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, + int scale_factor, + boolean force_baseline)); +#if JPEG_LIB_VERSION >= 70 +EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo, + boolean force_baseline)); +#endif +EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, + const unsigned int *basic_table, + int scale_factor, + boolean force_baseline)); +EXTERN(int) jpeg_quality_scaling JPP((int quality)); +EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, + boolean suppress)); +EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo)); +EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo)); + +/* Main entry points for compression */ +EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, + boolean write_all_tables)); +EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION num_lines)); +EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); + +#if JPEG_LIB_VERSION >= 70 +/* Precalculate JPEG dimensions for current compression parameters. */ +EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo)); +#endif + +/* Replaces jpeg_write_scanlines when writing raw downsampled data. */ +EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION num_lines)); + +/* Write a special marker. See libjpeg.txt concerning safe usage. */ +EXTERN(void) jpeg_write_marker + JPP((j_compress_ptr cinfo, int marker, + const JOCTET * dataptr, unsigned int datalen)); +/* Same, but piecemeal. */ +EXTERN(void) jpeg_write_m_header + JPP((j_compress_ptr cinfo, int marker, unsigned int datalen)); +EXTERN(void) jpeg_write_m_byte + JPP((j_compress_ptr cinfo, int val)); + +/* Alternate compression function: just write an abbreviated table file */ +EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo)); + +/* Decompression startup: read start of JPEG datastream to see what's there */ +EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo, + boolean require_image)); +/* Return value is one of: */ +#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ +#define JPEG_HEADER_OK 1 /* Found valid image datastream */ +#define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */ +/* If you pass require_image = TRUE (normal case), you need not check for + * a TABLES_ONLY return code; an abbreviated file will cause an error exit. + * JPEG_SUSPENDED is only possible if you use a data source module that can + * give a suspension return (the stdio source module doesn't). + */ + +/* Main entry points for decompression */ +EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo)); +EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION max_lines)); +EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo)); + +/* Replaces jpeg_read_scanlines when reading raw downsampled data. */ +EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION max_lines)); + +/* Additional entry points for buffered-image mode. */ +EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo)); +EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo, + int scan_number)); +EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo)); +EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo)); +EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo)); +EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo)); +/* Return value is one of: */ +/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ +#define JPEG_REACHED_SOS 1 /* Reached start of new scan */ +#define JPEG_REACHED_EOI 2 /* Reached end of image */ +#define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */ +#define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */ + +/* Precalculate output dimensions for current decompression parameters. */ +#if JPEG_LIB_VERSION >= 80 +EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo)); +#endif +EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); + +/* Control saving of COM and APPn markers into marker_list. */ +EXTERN(void) jpeg_save_markers + JPP((j_decompress_ptr cinfo, int marker_code, + unsigned int length_limit)); + +/* Install a special processing method for COM or APPn markers. */ +EXTERN(void) jpeg_set_marker_processor + JPP((j_decompress_ptr cinfo, int marker_code, + jpeg_marker_parser_method routine)); + +/* Read or write raw DCT coefficients --- useful for lossless transcoding. */ +EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo)); +EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays)); +EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo, + j_compress_ptr dstinfo)); + +/* If you choose to abort compression or decompression before completing + * jpeg_finish_(de)compress, then you need to clean up to release memory, + * temporary files, etc. You can just call jpeg_destroy_(de)compress + * if you're done with the JPEG object, but if you want to clean it up and + * reuse it, call this: + */ +EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo)); + +/* Generic versions of jpeg_abort and jpeg_destroy that work on either + * flavor of JPEG object. These may be more convenient in some places. + */ +EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo)); +EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo)); + +/* Default restart-marker-resync procedure for use by data source modules */ +EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo, + int desired)); + + +/* These marker codes are exported since applications and data source modules + * are likely to want to use them. + */ + +#define JPEG_RST0 0xD0 /* RST0 marker code */ +#define JPEG_EOI 0xD9 /* EOI marker code */ +#define JPEG_APP0 0xE0 /* APP0 marker code */ +#define JPEG_COM 0xFE /* COM marker code */ + + +/* If we have a brain-damaged compiler that emits warnings (or worse, errors) + * for structure definitions that are never filled in, keep it quiet by + * supplying dummy definitions for the various substructures. + */ + +#ifdef INCOMPLETE_TYPES_BROKEN +#ifndef JPEG_INTERNALS /* will be defined in jpegint.h */ +struct jvirt_sarray_control { long dummy; }; +struct jvirt_barray_control { long dummy; }; +struct jpeg_comp_master { long dummy; }; +struct jpeg_c_main_controller { long dummy; }; +struct jpeg_c_prep_controller { long dummy; }; +struct jpeg_c_coef_controller { long dummy; }; +struct jpeg_marker_writer { long dummy; }; +struct jpeg_color_converter { long dummy; }; +struct jpeg_downsampler { long dummy; }; +struct jpeg_forward_dct { long dummy; }; +struct jpeg_entropy_encoder { long dummy; }; +struct jpeg_decomp_master { long dummy; }; +struct jpeg_d_main_controller { long dummy; }; +struct jpeg_d_coef_controller { long dummy; }; +struct jpeg_d_post_controller { long dummy; }; +struct jpeg_input_controller { long dummy; }; +struct jpeg_marker_reader { long dummy; }; +struct jpeg_entropy_decoder { long dummy; }; +struct jpeg_inverse_dct { long dummy; }; +struct jpeg_upsampler { long dummy; }; +struct jpeg_color_deconverter { long dummy; }; +struct jpeg_color_quantizer { long dummy; }; +#endif /* JPEG_INTERNALS */ +#endif /* INCOMPLETE_TYPES_BROKEN */ + + +/* + * The JPEG library modules define JPEG_INTERNALS before including this file. + * The internal structure declarations are read only when that is true. + * Applications using the library should not include jpegint.h, but may wish + * to include jerror.h. + */ + +#ifdef JPEG_INTERNALS +#include "jpegint.h" /* fetch private declarations */ +#include "jerror.h" /* fetch error codes too */ +#endif + +#ifdef __cplusplus +#ifndef DONT_USE_EXTERN_C +} +#endif +#endif + +#endif /* JPEGLIB_H */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jquant1.c b/lib-third-party/libturbojpeg-ios/libjpeg/jquant1.c new file mode 100755 index 0000000..362bb1e --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jquant1.c @@ -0,0 +1,860 @@ +/* + * jquant1.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * Copyright (C) 2009, D. R. Commander + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains 1-pass color quantization (color mapping) routines. + * These routines provide mapping to a fixed color map using equally spaced + * color values. Optional Floyd-Steinberg or ordered dithering is available. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + +#ifdef QUANT_1PASS_SUPPORTED + + +/* + * The main purpose of 1-pass quantization is to provide a fast, if not very + * high quality, colormapped output capability. A 2-pass quantizer usually + * gives better visual quality; however, for quantized grayscale output this + * quantizer is perfectly adequate. Dithering is highly recommended with this + * quantizer, though you can turn it off if you really want to. + * + * In 1-pass quantization the colormap must be chosen in advance of seeing the + * image. We use a map consisting of all combinations of Ncolors[i] color + * values for the i'th component. The Ncolors[] values are chosen so that + * their product, the total number of colors, is no more than that requested. + * (In most cases, the product will be somewhat less.) + * + * Since the colormap is orthogonal, the representative value for each color + * component can be determined without considering the other components; + * then these indexes can be combined into a colormap index by a standard + * N-dimensional-array-subscript calculation. Most of the arithmetic involved + * can be precalculated and stored in the lookup table colorindex[]. + * colorindex[i][j] maps pixel value j in component i to the nearest + * representative value (grid plane) for that component; this index is + * multiplied by the array stride for component i, so that the + * index of the colormap entry closest to a given pixel value is just + * sum( colorindex[component-number][pixel-component-value] ) + * Aside from being fast, this scheme allows for variable spacing between + * representative values with no additional lookup cost. + * + * If gamma correction has been applied in color conversion, it might be wise + * to adjust the color grid spacing so that the representative colors are + * equidistant in linear space. At this writing, gamma correction is not + * implemented by jdcolor, so nothing is done here. + */ + + +/* Declarations for ordered dithering. + * + * We use a standard 16x16 ordered dither array. The basic concept of ordered + * dithering is described in many references, for instance Dale Schumacher's + * chapter II.2 of Graphics Gems II (James Arvo, ed. Academic Press, 1991). + * In place of Schumacher's comparisons against a "threshold" value, we add a + * "dither" value to the input pixel and then round the result to the nearest + * output value. The dither value is equivalent to (0.5 - threshold) times + * the distance between output values. For ordered dithering, we assume that + * the output colors are equally spaced; if not, results will probably be + * worse, since the dither may be too much or too little at a given point. + * + * The normal calculation would be to form pixel value + dither, range-limit + * this to 0..MAXJSAMPLE, and then index into the colorindex table as usual. + * We can skip the separate range-limiting step by extending the colorindex + * table in both directions. + */ + +#define ODITHER_SIZE 16 /* dimension of dither matrix */ +/* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */ +#define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */ +#define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */ + +typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE]; +typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE]; + +static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = { + /* Bayer's order-4 dither array. Generated by the code given in + * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I. + * The values in this array must range from 0 to ODITHER_CELLS-1. + */ + { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }, + { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 }, + { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 }, + { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 }, + { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 }, + { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 }, + { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 }, + { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 }, + { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 }, + { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 }, + { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 }, + { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 }, + { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 }, + { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 }, + { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 }, + { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 } +}; + + +/* Declarations for Floyd-Steinberg dithering. + * + * Errors are accumulated into the array fserrors[], at a resolution of + * 1/16th of a pixel count. The error at a given pixel is propagated + * to its not-yet-processed neighbors using the standard F-S fractions, + * ... (here) 7/16 + * 3/16 5/16 1/16 + * We work left-to-right on even rows, right-to-left on odd rows. + * + * We can get away with a single array (holding one row's worth of errors) + * by using it to store the current row's errors at pixel columns not yet + * processed, but the next row's errors at columns already processed. We + * need only a few extra variables to hold the errors immediately around the + * current column. (If we are lucky, those variables are in registers, but + * even if not, they're probably cheaper to access than array elements are.) + * + * The fserrors[] array is indexed [component#][position]. + * We provide (#columns + 2) entries per component; the extra entry at each + * end saves us from special-casing the first and last pixels. + * + * Note: on a wide image, we might not have enough room in a PC's near data + * segment to hold the error array; so it is allocated with alloc_large. + */ + +#if BITS_IN_JSAMPLE == 8 +typedef INT16 FSERROR; /* 16 bits should be enough */ +typedef int LOCFSERROR; /* use 'int' for calculation temps */ +#else +typedef INT32 FSERROR; /* may need more than 16 bits */ +typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */ +#endif + +typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */ + + +/* Private subobject */ + +#define MAX_Q_COMPS 4 /* max components I can handle */ + +typedef struct { + struct jpeg_color_quantizer pub; /* public fields */ + + /* Initially allocated colormap is saved here */ + JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */ + int sv_actual; /* number of entries in use */ + + JSAMPARRAY colorindex; /* Precomputed mapping for speed */ + /* colorindex[i][j] = index of color closest to pixel value j in component i, + * premultiplied as described above. Since colormap indexes must fit into + * JSAMPLEs, the entries of this array will too. + */ + boolean is_padded; /* is the colorindex padded for odither? */ + + int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */ + + /* Variables for ordered dithering */ + int row_index; /* cur row's vertical index in dither matrix */ + ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */ + + /* Variables for Floyd-Steinberg dithering */ + FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ + boolean on_odd_row; /* flag to remember which row we are on */ +} my_cquantizer; + +typedef my_cquantizer * my_cquantize_ptr; + + +/* + * Policy-making subroutines for create_colormap and create_colorindex. + * These routines determine the colormap to be used. The rest of the module + * only assumes that the colormap is orthogonal. + * + * * select_ncolors decides how to divvy up the available colors + * among the components. + * * output_value defines the set of representative values for a component. + * * largest_input_value defines the mapping from input values to + * representative values for a component. + * Note that the latter two routines may impose different policies for + * different components, though this is not currently done. + */ + + +LOCAL(int) +select_ncolors (j_decompress_ptr cinfo, int Ncolors[]) +/* Determine allocation of desired colors to components, */ +/* and fill in Ncolors[] array to indicate choice. */ +/* Return value is total number of colors (product of Ncolors[] values). */ +{ + int nc = cinfo->out_color_components; /* number of color components */ + int max_colors = cinfo->desired_number_of_colors; + int total_colors, iroot, i, j; + boolean changed; + long temp; + int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE }; + RGB_order[0] = rgb_green[cinfo->out_color_space]; + RGB_order[1] = rgb_red[cinfo->out_color_space]; + RGB_order[2] = rgb_blue[cinfo->out_color_space]; + + /* We can allocate at least the nc'th root of max_colors per component. */ + /* Compute floor(nc'th root of max_colors). */ + iroot = 1; + do { + iroot++; + temp = iroot; /* set temp = iroot ** nc */ + for (i = 1; i < nc; i++) + temp *= iroot; + } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */ + iroot--; /* now iroot = floor(root) */ + + /* Must have at least 2 color values per component */ + if (iroot < 2) + ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp); + + /* Initialize to iroot color values for each component */ + total_colors = 1; + for (i = 0; i < nc; i++) { + Ncolors[i] = iroot; + total_colors *= iroot; + } + /* We may be able to increment the count for one or more components without + * exceeding max_colors, though we know not all can be incremented. + * Sometimes, the first component can be incremented more than once! + * (Example: for 16 colors, we start at 2*2*2, go to 3*2*2, then 4*2*2.) + * In RGB colorspace, try to increment G first, then R, then B. + */ + do { + changed = FALSE; + for (i = 0; i < nc; i++) { + j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i); + /* calculate new total_colors if Ncolors[j] is incremented */ + temp = total_colors / Ncolors[j]; + temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */ + if (temp > (long) max_colors) + break; /* won't fit, done with this pass */ + Ncolors[j]++; /* OK, apply the increment */ + total_colors = (int) temp; + changed = TRUE; + } + } while (changed); + + return total_colors; +} + + +LOCAL(int) +output_value (j_decompress_ptr cinfo, int ci, int j, int maxj) +/* Return j'th output value, where j will range from 0 to maxj */ +/* The output values must fall in 0..MAXJSAMPLE in increasing order */ +{ + /* We always provide values 0 and MAXJSAMPLE for each component; + * any additional values are equally spaced between these limits. + * (Forcing the upper and lower values to the limits ensures that + * dithering can't produce a color outside the selected gamut.) + */ + return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj); +} + + +LOCAL(int) +largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj) +/* Return largest input value that should map to j'th output value */ +/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */ +{ + /* Breakpoints are halfway between values returned by output_value */ + return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj)); +} + + +/* + * Create the colormap. + */ + +LOCAL(void) +create_colormap (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + JSAMPARRAY colormap; /* Created colormap */ + int total_colors; /* Number of distinct output colors */ + int i,j,k, nci, blksize, blkdist, ptr, val; + + /* Select number of colors for each component */ + total_colors = select_ncolors(cinfo, cquantize->Ncolors); + + /* Report selected color counts */ + if (cinfo->out_color_components == 3) + TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS, + total_colors, cquantize->Ncolors[0], + cquantize->Ncolors[1], cquantize->Ncolors[2]); + else + TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors); + + /* Allocate and fill in the colormap. */ + /* The colors are ordered in the map in standard row-major order, */ + /* i.e. rightmost (highest-indexed) color changes most rapidly. */ + + colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components); + + /* blksize is number of adjacent repeated entries for a component */ + /* blkdist is distance between groups of identical entries for a component */ + blkdist = total_colors; + + for (i = 0; i < cinfo->out_color_components; i++) { + /* fill in colormap entries for i'th color component */ + nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ + blksize = blkdist / nci; + for (j = 0; j < nci; j++) { + /* Compute j'th output value (out of nci) for component */ + val = output_value(cinfo, i, j, nci-1); + /* Fill in all colormap entries that have this value of this component */ + for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) { + /* fill in blksize entries beginning at ptr */ + for (k = 0; k < blksize; k++) + colormap[i][ptr+k] = (JSAMPLE) val; + } + } + blkdist = blksize; /* blksize of this color is blkdist of next */ + } + + /* Save the colormap in private storage, + * where it will survive color quantization mode changes. + */ + cquantize->sv_colormap = colormap; + cquantize->sv_actual = total_colors; +} + + +/* + * Create the color index table. + */ + +LOCAL(void) +create_colorindex (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + JSAMPROW indexptr; + int i,j,k, nci, blksize, val, pad; + + /* For ordered dither, we pad the color index tables by MAXJSAMPLE in + * each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE). + * This is not necessary in the other dithering modes. However, we + * flag whether it was done in case user changes dithering mode. + */ + if (cinfo->dither_mode == JDITHER_ORDERED) { + pad = MAXJSAMPLE*2; + cquantize->is_padded = TRUE; + } else { + pad = 0; + cquantize->is_padded = FALSE; + } + + cquantize->colorindex = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (MAXJSAMPLE+1 + pad), + (JDIMENSION) cinfo->out_color_components); + + /* blksize is number of adjacent repeated entries for a component */ + blksize = cquantize->sv_actual; + + for (i = 0; i < cinfo->out_color_components; i++) { + /* fill in colorindex entries for i'th color component */ + nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ + blksize = blksize / nci; + + /* adjust colorindex pointers to provide padding at negative indexes. */ + if (pad) + cquantize->colorindex[i] += MAXJSAMPLE; + + /* in loop, val = index of current output value, */ + /* and k = largest j that maps to current val */ + indexptr = cquantize->colorindex[i]; + val = 0; + k = largest_input_value(cinfo, i, 0, nci-1); + for (j = 0; j <= MAXJSAMPLE; j++) { + while (j > k) /* advance val if past boundary */ + k = largest_input_value(cinfo, i, ++val, nci-1); + /* premultiply so that no multiplication needed in main processing */ + indexptr[j] = (JSAMPLE) (val * blksize); + } + /* Pad at both ends if necessary */ + if (pad) + for (j = 1; j <= MAXJSAMPLE; j++) { + indexptr[-j] = indexptr[0]; + indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE]; + } + } +} + + +/* + * Create an ordered-dither array for a component having ncolors + * distinct output values. + */ + +LOCAL(ODITHER_MATRIX_PTR) +make_odither_array (j_decompress_ptr cinfo, int ncolors) +{ + ODITHER_MATRIX_PTR odither; + int j,k; + INT32 num,den; + + odither = (ODITHER_MATRIX_PTR) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(ODITHER_MATRIX)); + /* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1). + * Hence the dither value for the matrix cell with fill order f + * (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1). + * On 16-bit-int machine, be careful to avoid overflow. + */ + den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1)); + for (j = 0; j < ODITHER_SIZE; j++) { + for (k = 0; k < ODITHER_SIZE; k++) { + num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k]))) + * MAXJSAMPLE; + /* Ensure round towards zero despite C's lack of consistency + * about rounding negative values in integer division... + */ + odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den); + } + } + return odither; +} + + +/* + * Create the ordered-dither tables. + * Components having the same number of representative colors may + * share a dither table. + */ + +LOCAL(void) +create_odither_tables (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + ODITHER_MATRIX_PTR odither; + int i, j, nci; + + for (i = 0; i < cinfo->out_color_components; i++) { + nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ + odither = NULL; /* search for matching prior component */ + for (j = 0; j < i; j++) { + if (nci == cquantize->Ncolors[j]) { + odither = cquantize->odither[j]; + break; + } + } + if (odither == NULL) /* need a new table? */ + odither = make_odither_array(cinfo, nci); + cquantize->odither[i] = odither; + } +} + + +/* + * Map some rows of pixels to the output colormapped representation. + */ + +METHODDEF(void) +color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) +/* General case, no dithering */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + JSAMPARRAY colorindex = cquantize->colorindex; + register int pixcode, ci; + register JSAMPROW ptrin, ptrout; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + register int nc = cinfo->out_color_components; + + for (row = 0; row < num_rows; row++) { + ptrin = input_buf[row]; + ptrout = output_buf[row]; + for (col = width; col > 0; col--) { + pixcode = 0; + for (ci = 0; ci < nc; ci++) { + pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]); + } + *ptrout++ = (JSAMPLE) pixcode; + } + } +} + + +METHODDEF(void) +color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) +/* Fast path for out_color_components==3, no dithering */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register int pixcode; + register JSAMPROW ptrin, ptrout; + JSAMPROW colorindex0 = cquantize->colorindex[0]; + JSAMPROW colorindex1 = cquantize->colorindex[1]; + JSAMPROW colorindex2 = cquantize->colorindex[2]; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + ptrin = input_buf[row]; + ptrout = output_buf[row]; + for (col = width; col > 0; col--) { + pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]); + pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]); + pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]); + *ptrout++ = (JSAMPLE) pixcode; + } + } +} + + +METHODDEF(void) +quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) +/* General case, with ordered dithering */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register JSAMPROW input_ptr; + register JSAMPROW output_ptr; + JSAMPROW colorindex_ci; + int * dither; /* points to active row of dither matrix */ + int row_index, col_index; /* current indexes into dither matrix */ + int nc = cinfo->out_color_components; + int ci; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + /* Initialize output values to 0 so can process components separately */ + jzero_far((void FAR *) output_buf[row], + (size_t) (width * SIZEOF(JSAMPLE))); + row_index = cquantize->row_index; + for (ci = 0; ci < nc; ci++) { + input_ptr = input_buf[row] + ci; + output_ptr = output_buf[row]; + colorindex_ci = cquantize->colorindex[ci]; + dither = cquantize->odither[ci][row_index]; + col_index = 0; + + for (col = width; col > 0; col--) { + /* Form pixel value + dither, range-limit to 0..MAXJSAMPLE, + * select output value, accumulate into output code for this pixel. + * Range-limiting need not be done explicitly, as we have extended + * the colorindex table to produce the right answers for out-of-range + * inputs. The maximum dither is +- MAXJSAMPLE; this sets the + * required amount of padding. + */ + *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]]; + input_ptr += nc; + output_ptr++; + col_index = (col_index + 1) & ODITHER_MASK; + } + } + /* Advance row index for next row */ + row_index = (row_index + 1) & ODITHER_MASK; + cquantize->row_index = row_index; + } +} + + +METHODDEF(void) +quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) +/* Fast path for out_color_components==3, with ordered dithering */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register int pixcode; + register JSAMPROW input_ptr; + register JSAMPROW output_ptr; + JSAMPROW colorindex0 = cquantize->colorindex[0]; + JSAMPROW colorindex1 = cquantize->colorindex[1]; + JSAMPROW colorindex2 = cquantize->colorindex[2]; + int * dither0; /* points to active row of dither matrix */ + int * dither1; + int * dither2; + int row_index, col_index; /* current indexes into dither matrix */ + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + row_index = cquantize->row_index; + input_ptr = input_buf[row]; + output_ptr = output_buf[row]; + dither0 = cquantize->odither[0][row_index]; + dither1 = cquantize->odither[1][row_index]; + dither2 = cquantize->odither[2][row_index]; + col_index = 0; + + for (col = width; col > 0; col--) { + pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) + + dither0[col_index]]); + pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) + + dither1[col_index]]); + pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) + + dither2[col_index]]); + *output_ptr++ = (JSAMPLE) pixcode; + col_index = (col_index + 1) & ODITHER_MASK; + } + row_index = (row_index + 1) & ODITHER_MASK; + cquantize->row_index = row_index; + } +} + + +METHODDEF(void) +quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) +/* General case, with Floyd-Steinberg dithering */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register LOCFSERROR cur; /* current error or pixel value */ + LOCFSERROR belowerr; /* error for pixel below cur */ + LOCFSERROR bpreverr; /* error for below/prev col */ + LOCFSERROR bnexterr; /* error for below/next col */ + LOCFSERROR delta; + register FSERRPTR errorptr; /* => fserrors[] at column before current */ + register JSAMPROW input_ptr; + register JSAMPROW output_ptr; + JSAMPROW colorindex_ci; + JSAMPROW colormap_ci; + int pixcode; + int nc = cinfo->out_color_components; + int dir; /* 1 for left-to-right, -1 for right-to-left */ + int dirnc; /* dir * nc */ + int ci; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + JSAMPLE *range_limit = cinfo->sample_range_limit; + SHIFT_TEMPS + + for (row = 0; row < num_rows; row++) { + /* Initialize output values to 0 so can process components separately */ + jzero_far((void FAR *) output_buf[row], + (size_t) (width * SIZEOF(JSAMPLE))); + for (ci = 0; ci < nc; ci++) { + input_ptr = input_buf[row] + ci; + output_ptr = output_buf[row]; + if (cquantize->on_odd_row) { + /* work right to left in this row */ + input_ptr += (width-1) * nc; /* so point to rightmost pixel */ + output_ptr += width-1; + dir = -1; + dirnc = -nc; + errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */ + } else { + /* work left to right in this row */ + dir = 1; + dirnc = nc; + errorptr = cquantize->fserrors[ci]; /* => entry before first column */ + } + colorindex_ci = cquantize->colorindex[ci]; + colormap_ci = cquantize->sv_colormap[ci]; + /* Preset error values: no error propagated to first pixel from left */ + cur = 0; + /* and no error propagated to row below yet */ + belowerr = bpreverr = 0; + + for (col = width; col > 0; col--) { + /* cur holds the error propagated from the previous pixel on the + * current line. Add the error propagated from the previous line + * to form the complete error correction term for this pixel, and + * round the error term (which is expressed * 16) to an integer. + * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct + * for either sign of the error value. + * Note: errorptr points to *previous* column's array entry. + */ + cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4); + /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. + * The maximum error is +- MAXJSAMPLE; this sets the required size + * of the range_limit array. + */ + cur += GETJSAMPLE(*input_ptr); + cur = GETJSAMPLE(range_limit[cur]); + /* Select output value, accumulate into output code for this pixel */ + pixcode = GETJSAMPLE(colorindex_ci[cur]); + *output_ptr += (JSAMPLE) pixcode; + /* Compute actual representation error at this pixel */ + /* Note: we can do this even though we don't have the final */ + /* pixel code, because the colormap is orthogonal. */ + cur -= GETJSAMPLE(colormap_ci[pixcode]); + /* Compute error fractions to be propagated to adjacent pixels. + * Add these into the running sums, and simultaneously shift the + * next-line error sums left by 1 column. + */ + bnexterr = cur; + delta = cur * 2; + cur += delta; /* form error * 3 */ + errorptr[0] = (FSERROR) (bpreverr + cur); + cur += delta; /* form error * 5 */ + bpreverr = belowerr + cur; + belowerr = bnexterr; + cur += delta; /* form error * 7 */ + /* At this point cur contains the 7/16 error value to be propagated + * to the next pixel on the current line, and all the errors for the + * next line have been shifted over. We are therefore ready to move on. + */ + input_ptr += dirnc; /* advance input ptr to next column */ + output_ptr += dir; /* advance output ptr to next column */ + errorptr += dir; /* advance errorptr to current column */ + } + /* Post-loop cleanup: we must unload the final error value into the + * final fserrors[] entry. Note we need not unload belowerr because + * it is for the dummy column before or after the actual array. + */ + errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */ + } + cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE); + } +} + + +/* + * Allocate workspace for Floyd-Steinberg errors. + */ + +LOCAL(void) +alloc_fs_workspace (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + size_t arraysize; + int i; + + arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); + for (i = 0; i < cinfo->out_color_components; i++) { + cquantize->fserrors[i] = (FSERRPTR) + (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); + } +} + + +/* + * Initialize for one-pass color quantization. + */ + +METHODDEF(void) +start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + size_t arraysize; + int i; + + /* Install my colormap. */ + cinfo->colormap = cquantize->sv_colormap; + cinfo->actual_number_of_colors = cquantize->sv_actual; + + /* Initialize for desired dithering mode. */ + switch (cinfo->dither_mode) { + case JDITHER_NONE: + if (cinfo->out_color_components == 3) + cquantize->pub.color_quantize = color_quantize3; + else + cquantize->pub.color_quantize = color_quantize; + break; + case JDITHER_ORDERED: + if (cinfo->out_color_components == 3) + cquantize->pub.color_quantize = quantize3_ord_dither; + else + cquantize->pub.color_quantize = quantize_ord_dither; + cquantize->row_index = 0; /* initialize state for ordered dither */ + /* If user changed to ordered dither from another mode, + * we must recreate the color index table with padding. + * This will cost extra space, but probably isn't very likely. + */ + if (! cquantize->is_padded) + create_colorindex(cinfo); + /* Create ordered-dither tables if we didn't already. */ + if (cquantize->odither[0] == NULL) + create_odither_tables(cinfo); + break; + case JDITHER_FS: + cquantize->pub.color_quantize = quantize_fs_dither; + cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */ + /* Allocate Floyd-Steinberg workspace if didn't already. */ + if (cquantize->fserrors[0] == NULL) + alloc_fs_workspace(cinfo); + /* Initialize the propagated errors to zero. */ + arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); + for (i = 0; i < cinfo->out_color_components; i++) + jzero_far((void FAR *) cquantize->fserrors[i], arraysize); + break; + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } +} + + +/* + * Finish up at the end of the pass. + */ + +METHODDEF(void) +finish_pass_1_quant (j_decompress_ptr cinfo) +{ + /* no work in 1-pass case */ +} + + +/* + * Switch to a new external colormap between output passes. + * Shouldn't get to this module! + */ + +METHODDEF(void) +new_color_map_1_quant (j_decompress_ptr cinfo) +{ + ERREXIT(cinfo, JERR_MODE_CHANGE); +} + + +/* + * Module initialization routine for 1-pass color quantization. + */ + +GLOBAL(void) +jinit_1pass_quantizer (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize; + + cquantize = (my_cquantize_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_cquantizer)); + cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; + cquantize->pub.start_pass = start_pass_1_quant; + cquantize->pub.finish_pass = finish_pass_1_quant; + cquantize->pub.new_color_map = new_color_map_1_quant; + cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */ + cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */ + + /* Make sure my internal arrays won't overflow */ + if (cinfo->out_color_components > MAX_Q_COMPS) + ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS); + /* Make sure colormap indexes can be represented by JSAMPLEs */ + if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1)) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1); + + /* Create the colormap and color index table. */ + create_colormap(cinfo); + create_colorindex(cinfo); + + /* Allocate Floyd-Steinberg workspace now if requested. + * We do this now since it is FAR storage and may affect the memory + * manager's space calculations. If the user changes to FS dither + * mode in a later pass, we will allocate the space then, and will + * possibly overrun the max_memory_to_use setting. + */ + if (cinfo->dither_mode == JDITHER_FS) + alloc_fs_workspace(cinfo); +} + +#endif /* QUANT_1PASS_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jquant2.c b/lib-third-party/libturbojpeg-ios/libjpeg/jquant2.c new file mode 100755 index 0000000..da964f7 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jquant2.c @@ -0,0 +1,1293 @@ +/* + * jquant2.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * Copyright (C) 2009, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains 2-pass color quantization (color mapping) routines. + * These routines provide selection of a custom color map for an image, + * followed by mapping of the image to that color map, with optional + * Floyd-Steinberg dithering. + * It is also possible to use just the second pass to map to an arbitrary + * externally-given color map. + * + * Note: ordered dithering is not supported, since there isn't any fast + * way to compute intercolor distances; it's unclear that ordered dither's + * fundamental assumptions even hold with an irregularly spaced color map. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + +#ifdef QUANT_2PASS_SUPPORTED + + +/* + * This module implements the well-known Heckbert paradigm for color + * quantization. Most of the ideas used here can be traced back to + * Heckbert's seminal paper + * Heckbert, Paul. "Color Image Quantization for Frame Buffer Display", + * Proc. SIGGRAPH '82, Computer Graphics v.16 #3 (July 1982), pp 297-304. + * + * In the first pass over the image, we accumulate a histogram showing the + * usage count of each possible color. To keep the histogram to a reasonable + * size, we reduce the precision of the input; typical practice is to retain + * 5 or 6 bits per color, so that 8 or 4 different input values are counted + * in the same histogram cell. + * + * Next, the color-selection step begins with a box representing the whole + * color space, and repeatedly splits the "largest" remaining box until we + * have as many boxes as desired colors. Then the mean color in each + * remaining box becomes one of the possible output colors. + * + * The second pass over the image maps each input pixel to the closest output + * color (optionally after applying a Floyd-Steinberg dithering correction). + * This mapping is logically trivial, but making it go fast enough requires + * considerable care. + * + * Heckbert-style quantizers vary a good deal in their policies for choosing + * the "largest" box and deciding where to cut it. The particular policies + * used here have proved out well in experimental comparisons, but better ones + * may yet be found. + * + * In earlier versions of the IJG code, this module quantized in YCbCr color + * space, processing the raw upsampled data without a color conversion step. + * This allowed the color conversion math to be done only once per colormap + * entry, not once per pixel. However, that optimization precluded other + * useful optimizations (such as merging color conversion with upsampling) + * and it also interfered with desired capabilities such as quantizing to an + * externally-supplied colormap. We have therefore abandoned that approach. + * The present code works in the post-conversion color space, typically RGB. + * + * To improve the visual quality of the results, we actually work in scaled + * RGB space, giving G distances more weight than R, and R in turn more than + * B. To do everything in integer math, we must use integer scale factors. + * The 2/3/1 scale factors used here correspond loosely to the relative + * weights of the colors in the NTSC grayscale equation. + * If you want to use this code to quantize a non-RGB color space, you'll + * probably need to change these scale factors. + */ + +#define R_SCALE 2 /* scale R distances by this much */ +#define G_SCALE 3 /* scale G distances by this much */ +#define B_SCALE 1 /* and B by this much */ + +static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE}; +#define C0_SCALE c_scales[rgb_red[cinfo->out_color_space]] +#define C1_SCALE c_scales[rgb_green[cinfo->out_color_space]] +#define C2_SCALE c_scales[rgb_blue[cinfo->out_color_space]] + +/* + * First we have the histogram data structure and routines for creating it. + * + * The number of bits of precision can be adjusted by changing these symbols. + * We recommend keeping 6 bits for G and 5 each for R and B. + * If you have plenty of memory and cycles, 6 bits all around gives marginally + * better results; if you are short of memory, 5 bits all around will save + * some space but degrade the results. + * To maintain a fully accurate histogram, we'd need to allocate a "long" + * (preferably unsigned long) for each cell. In practice this is overkill; + * we can get by with 16 bits per cell. Few of the cell counts will overflow, + * and clamping those that do overflow to the maximum value will give close- + * enough results. This reduces the recommended histogram size from 256Kb + * to 128Kb, which is a useful savings on PC-class machines. + * (In the second pass the histogram space is re-used for pixel mapping data; + * in that capacity, each cell must be able to store zero to the number of + * desired colors. 16 bits/cell is plenty for that too.) + * Since the JPEG code is intended to run in small memory model on 80x86 + * machines, we can't just allocate the histogram in one chunk. Instead + * of a true 3-D array, we use a row of pointers to 2-D arrays. Each + * pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and + * each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries. Note that + * on 80x86 machines, the pointer row is in near memory but the actual + * arrays are in far memory (same arrangement as we use for image arrays). + */ + +#define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */ + +/* These will do the right thing for either R,G,B or B,G,R color order, + * but you may not like the results for other color orders. + */ +#define HIST_C0_BITS 5 /* bits of precision in R/B histogram */ +#define HIST_C1_BITS 6 /* bits of precision in G histogram */ +#define HIST_C2_BITS 5 /* bits of precision in B/R histogram */ + +/* Number of elements along histogram axes. */ +#define HIST_C0_ELEMS (1<cquantize; + register JSAMPROW ptr; + register histptr histp; + register hist3d histogram = cquantize->histogram; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + ptr = input_buf[row]; + for (col = width; col > 0; col--) { + /* get pixel value and index into the histogram */ + histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT] + [GETJSAMPLE(ptr[1]) >> C1_SHIFT] + [GETJSAMPLE(ptr[2]) >> C2_SHIFT]; + /* increment, check for overflow and undo increment if so. */ + if (++(*histp) <= 0) + (*histp)--; + ptr += 3; + } + } +} + + +/* + * Next we have the really interesting routines: selection of a colormap + * given the completed histogram. + * These routines work with a list of "boxes", each representing a rectangular + * subset of the input color space (to histogram precision). + */ + +typedef struct { + /* The bounds of the box (inclusive); expressed as histogram indexes */ + int c0min, c0max; + int c1min, c1max; + int c2min, c2max; + /* The volume (actually 2-norm) of the box */ + INT32 volume; + /* The number of nonzero histogram cells within this box */ + long colorcount; +} box; + +typedef box * boxptr; + + +LOCAL(boxptr) +find_biggest_color_pop (boxptr boxlist, int numboxes) +/* Find the splittable box with the largest color population */ +/* Returns NULL if no splittable boxes remain */ +{ + register boxptr boxp; + register int i; + register long maxc = 0; + boxptr which = NULL; + + for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) { + if (boxp->colorcount > maxc && boxp->volume > 0) { + which = boxp; + maxc = boxp->colorcount; + } + } + return which; +} + + +LOCAL(boxptr) +find_biggest_volume (boxptr boxlist, int numboxes) +/* Find the splittable box with the largest (scaled) volume */ +/* Returns NULL if no splittable boxes remain */ +{ + register boxptr boxp; + register int i; + register INT32 maxv = 0; + boxptr which = NULL; + + for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) { + if (boxp->volume > maxv) { + which = boxp; + maxv = boxp->volume; + } + } + return which; +} + + +LOCAL(void) +update_box (j_decompress_ptr cinfo, boxptr boxp) +/* Shrink the min/max bounds of a box to enclose only nonzero elements, */ +/* and recompute its volume and population */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + histptr histp; + int c0,c1,c2; + int c0min,c0max,c1min,c1max,c2min,c2max; + INT32 dist0,dist1,dist2; + long ccount; + + c0min = boxp->c0min; c0max = boxp->c0max; + c1min = boxp->c1min; c1max = boxp->c1max; + c2min = boxp->c2min; c2max = boxp->c2max; + + if (c0max > c0min) + for (c0 = c0min; c0 <= c0max; c0++) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c0min = c0min = c0; + goto have_c0min; + } + } + have_c0min: + if (c0max > c0min) + for (c0 = c0max; c0 >= c0min; c0--) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c0max = c0max = c0; + goto have_c0max; + } + } + have_c0max: + if (c1max > c1min) + for (c1 = c1min; c1 <= c1max; c1++) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c1min = c1min = c1; + goto have_c1min; + } + } + have_c1min: + if (c1max > c1min) + for (c1 = c1max; c1 >= c1min; c1--) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c1max = c1max = c1; + goto have_c1max; + } + } + have_c1max: + if (c2max > c2min) + for (c2 = c2min; c2 <= c2max; c2++) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1min][c2]; + for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) + if (*histp != 0) { + boxp->c2min = c2min = c2; + goto have_c2min; + } + } + have_c2min: + if (c2max > c2min) + for (c2 = c2max; c2 >= c2min; c2--) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1min][c2]; + for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) + if (*histp != 0) { + boxp->c2max = c2max = c2; + goto have_c2max; + } + } + have_c2max: + + /* Update box volume. + * We use 2-norm rather than real volume here; this biases the method + * against making long narrow boxes, and it has the side benefit that + * a box is splittable iff norm > 0. + * Since the differences are expressed in histogram-cell units, + * we have to shift back to JSAMPLE units to get consistent distances; + * after which, we scale according to the selected distance scale factors. + */ + dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE; + dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE; + dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE; + boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2; + + /* Now scan remaining volume of box and compute population */ + ccount = 0; + for (c0 = c0min; c0 <= c0max; c0++) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++, histp++) + if (*histp != 0) { + ccount++; + } + } + boxp->colorcount = ccount; +} + + +LOCAL(int) +median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes, + int desired_colors) +/* Repeatedly select and split the largest box until we have enough boxes */ +{ + int n,lb; + int c0,c1,c2,cmax; + register boxptr b1,b2; + + while (numboxes < desired_colors) { + /* Select box to split. + * Current algorithm: by population for first half, then by volume. + */ + if (numboxes*2 <= desired_colors) { + b1 = find_biggest_color_pop(boxlist, numboxes); + } else { + b1 = find_biggest_volume(boxlist, numboxes); + } + if (b1 == NULL) /* no splittable boxes left! */ + break; + b2 = &boxlist[numboxes]; /* where new box will go */ + /* Copy the color bounds to the new box. */ + b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max; + b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min; + /* Choose which axis to split the box on. + * Current algorithm: longest scaled axis. + * See notes in update_box about scaling distances. + */ + c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE; + c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE; + c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE; + /* We want to break any ties in favor of green, then red, blue last. + * This code does the right thing for R,G,B or B,G,R color orders only. + */ + if (rgb_red[cinfo->out_color_space] == 0) { + cmax = c1; n = 1; + if (c0 > cmax) { cmax = c0; n = 0; } + if (c2 > cmax) { n = 2; } + } + else { + cmax = c1; n = 1; + if (c2 > cmax) { cmax = c2; n = 2; } + if (c0 > cmax) { n = 0; } + } + /* Choose split point along selected axis, and update box bounds. + * Current algorithm: split at halfway point. + * (Since the box has been shrunk to minimum volume, + * any split will produce two nonempty subboxes.) + * Note that lb value is max for lower box, so must be < old max. + */ + switch (n) { + case 0: + lb = (b1->c0max + b1->c0min) / 2; + b1->c0max = lb; + b2->c0min = lb+1; + break; + case 1: + lb = (b1->c1max + b1->c1min) / 2; + b1->c1max = lb; + b2->c1min = lb+1; + break; + case 2: + lb = (b1->c2max + b1->c2min) / 2; + b1->c2max = lb; + b2->c2min = lb+1; + break; + } + /* Update stats for boxes */ + update_box(cinfo, b1); + update_box(cinfo, b2); + numboxes++; + } + return numboxes; +} + + +LOCAL(void) +compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor) +/* Compute representative color for a box, put it in colormap[icolor] */ +{ + /* Current algorithm: mean weighted by pixels (not colors) */ + /* Note it is important to get the rounding correct! */ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + histptr histp; + int c0,c1,c2; + int c0min,c0max,c1min,c1max,c2min,c2max; + long count; + long total = 0; + long c0total = 0; + long c1total = 0; + long c2total = 0; + + c0min = boxp->c0min; c0max = boxp->c0max; + c1min = boxp->c1min; c1max = boxp->c1max; + c2min = boxp->c2min; c2max = boxp->c2max; + + for (c0 = c0min; c0 <= c0max; c0++) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) { + if ((count = *histp++) != 0) { + total += count; + c0total += ((c0 << C0_SHIFT) + ((1<>1)) * count; + c1total += ((c1 << C1_SHIFT) + ((1<>1)) * count; + c2total += ((c2 << C2_SHIFT) + ((1<>1)) * count; + } + } + } + + cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total); + cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total); + cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total); +} + + +LOCAL(void) +select_colors (j_decompress_ptr cinfo, int desired_colors) +/* Master routine for color selection */ +{ + boxptr boxlist; + int numboxes; + int i; + + /* Allocate workspace for box list */ + boxlist = (boxptr) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box)); + /* Initialize one box containing whole space */ + numboxes = 1; + boxlist[0].c0min = 0; + boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT; + boxlist[0].c1min = 0; + boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT; + boxlist[0].c2min = 0; + boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT; + /* Shrink it to actually-used volume and set its statistics */ + update_box(cinfo, & boxlist[0]); + /* Perform median-cut to produce final box list */ + numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors); + /* Compute the representative color for each box, fill colormap */ + for (i = 0; i < numboxes; i++) + compute_color(cinfo, & boxlist[i], i); + cinfo->actual_number_of_colors = numboxes; + TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes); +} + + +/* + * These routines are concerned with the time-critical task of mapping input + * colors to the nearest color in the selected colormap. + * + * We re-use the histogram space as an "inverse color map", essentially a + * cache for the results of nearest-color searches. All colors within a + * histogram cell will be mapped to the same colormap entry, namely the one + * closest to the cell's center. This may not be quite the closest entry to + * the actual input color, but it's almost as good. A zero in the cache + * indicates we haven't found the nearest color for that cell yet; the array + * is cleared to zeroes before starting the mapping pass. When we find the + * nearest color for a cell, its colormap index plus one is recorded in the + * cache for future use. The pass2 scanning routines call fill_inverse_cmap + * when they need to use an unfilled entry in the cache. + * + * Our method of efficiently finding nearest colors is based on the "locally + * sorted search" idea described by Heckbert and on the incremental distance + * calculation described by Spencer W. Thomas in chapter III.1 of Graphics + * Gems II (James Arvo, ed. Academic Press, 1991). Thomas points out that + * the distances from a given colormap entry to each cell of the histogram can + * be computed quickly using an incremental method: the differences between + * distances to adjacent cells themselves differ by a constant. This allows a + * fairly fast implementation of the "brute force" approach of computing the + * distance from every colormap entry to every histogram cell. Unfortunately, + * it needs a work array to hold the best-distance-so-far for each histogram + * cell (because the inner loop has to be over cells, not colormap entries). + * The work array elements have to be INT32s, so the work array would need + * 256Kb at our recommended precision. This is not feasible in DOS machines. + * + * To get around these problems, we apply Thomas' method to compute the + * nearest colors for only the cells within a small subbox of the histogram. + * The work array need be only as big as the subbox, so the memory usage + * problem is solved. Furthermore, we need not fill subboxes that are never + * referenced in pass2; many images use only part of the color gamut, so a + * fair amount of work is saved. An additional advantage of this + * approach is that we can apply Heckbert's locality criterion to quickly + * eliminate colormap entries that are far away from the subbox; typically + * three-fourths of the colormap entries are rejected by Heckbert's criterion, + * and we need not compute their distances to individual cells in the subbox. + * The speed of this approach is heavily influenced by the subbox size: too + * small means too much overhead, too big loses because Heckbert's criterion + * can't eliminate as many colormap entries. Empirically the best subbox + * size seems to be about 1/512th of the histogram (1/8th in each direction). + * + * Thomas' article also describes a refined method which is asymptotically + * faster than the brute-force method, but it is also far more complex and + * cannot efficiently be applied to small subboxes. It is therefore not + * useful for programs intended to be portable to DOS machines. On machines + * with plenty of memory, filling the whole histogram in one shot with Thomas' + * refined method might be faster than the present code --- but then again, + * it might not be any faster, and it's certainly more complicated. + */ + + +/* log2(histogram cells in update box) for each axis; this can be adjusted */ +#define BOX_C0_LOG (HIST_C0_BITS-3) +#define BOX_C1_LOG (HIST_C1_BITS-3) +#define BOX_C2_LOG (HIST_C2_BITS-3) + +#define BOX_C0_ELEMS (1<actual_number_of_colors; + int maxc0, maxc1, maxc2; + int centerc0, centerc1, centerc2; + int i, x, ncolors; + INT32 minmaxdist, min_dist, max_dist, tdist; + INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */ + + /* Compute true coordinates of update box's upper corner and center. + * Actually we compute the coordinates of the center of the upper-corner + * histogram cell, which are the upper bounds of the volume we care about. + * Note that since ">>" rounds down, the "center" values may be closer to + * min than to max; hence comparisons to them must be "<=", not "<". + */ + maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT)); + centerc0 = (minc0 + maxc0) >> 1; + maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT)); + centerc1 = (minc1 + maxc1) >> 1; + maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT)); + centerc2 = (minc2 + maxc2) >> 1; + + /* For each color in colormap, find: + * 1. its minimum squared-distance to any point in the update box + * (zero if color is within update box); + * 2. its maximum squared-distance to any point in the update box. + * Both of these can be found by considering only the corners of the box. + * We save the minimum distance for each color in mindist[]; + * only the smallest maximum distance is of interest. + */ + minmaxdist = 0x7FFFFFFFL; + + for (i = 0; i < numcolors; i++) { + /* We compute the squared-c0-distance term, then add in the other two. */ + x = GETJSAMPLE(cinfo->colormap[0][i]); + if (x < minc0) { + tdist = (x - minc0) * C0_SCALE; + min_dist = tdist*tdist; + tdist = (x - maxc0) * C0_SCALE; + max_dist = tdist*tdist; + } else if (x > maxc0) { + tdist = (x - maxc0) * C0_SCALE; + min_dist = tdist*tdist; + tdist = (x - minc0) * C0_SCALE; + max_dist = tdist*tdist; + } else { + /* within cell range so no contribution to min_dist */ + min_dist = 0; + if (x <= centerc0) { + tdist = (x - maxc0) * C0_SCALE; + max_dist = tdist*tdist; + } else { + tdist = (x - minc0) * C0_SCALE; + max_dist = tdist*tdist; + } + } + + x = GETJSAMPLE(cinfo->colormap[1][i]); + if (x < minc1) { + tdist = (x - minc1) * C1_SCALE; + min_dist += tdist*tdist; + tdist = (x - maxc1) * C1_SCALE; + max_dist += tdist*tdist; + } else if (x > maxc1) { + tdist = (x - maxc1) * C1_SCALE; + min_dist += tdist*tdist; + tdist = (x - minc1) * C1_SCALE; + max_dist += tdist*tdist; + } else { + /* within cell range so no contribution to min_dist */ + if (x <= centerc1) { + tdist = (x - maxc1) * C1_SCALE; + max_dist += tdist*tdist; + } else { + tdist = (x - minc1) * C1_SCALE; + max_dist += tdist*tdist; + } + } + + x = GETJSAMPLE(cinfo->colormap[2][i]); + if (x < minc2) { + tdist = (x - minc2) * C2_SCALE; + min_dist += tdist*tdist; + tdist = (x - maxc2) * C2_SCALE; + max_dist += tdist*tdist; + } else if (x > maxc2) { + tdist = (x - maxc2) * C2_SCALE; + min_dist += tdist*tdist; + tdist = (x - minc2) * C2_SCALE; + max_dist += tdist*tdist; + } else { + /* within cell range so no contribution to min_dist */ + if (x <= centerc2) { + tdist = (x - maxc2) * C2_SCALE; + max_dist += tdist*tdist; + } else { + tdist = (x - minc2) * C2_SCALE; + max_dist += tdist*tdist; + } + } + + mindist[i] = min_dist; /* save away the results */ + if (max_dist < minmaxdist) + minmaxdist = max_dist; + } + + /* Now we know that no cell in the update box is more than minmaxdist + * away from some colormap entry. Therefore, only colors that are + * within minmaxdist of some part of the box need be considered. + */ + ncolors = 0; + for (i = 0; i < numcolors; i++) { + if (mindist[i] <= minmaxdist) + colorlist[ncolors++] = (JSAMPLE) i; + } + return ncolors; +} + + +LOCAL(void) +find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, + int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[]) +/* Find the closest colormap entry for each cell in the update box, + * given the list of candidate colors prepared by find_nearby_colors. + * Return the indexes of the closest entries in the bestcolor[] array. + * This routine uses Thomas' incremental distance calculation method to + * find the distance from a colormap entry to successive cells in the box. + */ +{ + int ic0, ic1, ic2; + int i, icolor; + register INT32 * bptr; /* pointer into bestdist[] array */ + JSAMPLE * cptr; /* pointer into bestcolor[] array */ + INT32 dist0, dist1; /* initial distance values */ + register INT32 dist2; /* current distance in inner loop */ + INT32 xx0, xx1; /* distance increments */ + register INT32 xx2; + INT32 inc0, inc1, inc2; /* initial values for increments */ + /* This array holds the distance to the nearest-so-far color for each cell */ + INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; + + /* Initialize best-distance for each cell of the update box */ + bptr = bestdist; + for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--) + *bptr++ = 0x7FFFFFFFL; + + /* For each color selected by find_nearby_colors, + * compute its distance to the center of each cell in the box. + * If that's less than best-so-far, update best distance and color number. + */ + + /* Nominal steps between cell centers ("x" in Thomas article) */ +#define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE) +#define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE) +#define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE) + + for (i = 0; i < numcolors; i++) { + icolor = GETJSAMPLE(colorlist[i]); + /* Compute (square of) distance from minc0/c1/c2 to this color */ + inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE; + dist0 = inc0*inc0; + inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE; + dist0 += inc1*inc1; + inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE; + dist0 += inc2*inc2; + /* Form the initial difference increments */ + inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0; + inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1; + inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2; + /* Now loop over all cells in box, updating distance per Thomas method */ + bptr = bestdist; + cptr = bestcolor; + xx0 = inc0; + for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) { + dist1 = dist0; + xx1 = inc1; + for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) { + dist2 = dist1; + xx2 = inc2; + for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) { + if (dist2 < *bptr) { + *bptr = dist2; + *cptr = (JSAMPLE) icolor; + } + dist2 += xx2; + xx2 += 2 * STEP_C2 * STEP_C2; + bptr++; + cptr++; + } + dist1 += xx1; + xx1 += 2 * STEP_C1 * STEP_C1; + } + dist0 += xx0; + xx0 += 2 * STEP_C0 * STEP_C0; + } + } +} + + +LOCAL(void) +fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2) +/* Fill the inverse-colormap entries in the update box that contains */ +/* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */ +/* we can fill as many others as we wish.) */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + int minc0, minc1, minc2; /* lower left corner of update box */ + int ic0, ic1, ic2; + register JSAMPLE * cptr; /* pointer into bestcolor[] array */ + register histptr cachep; /* pointer into main cache array */ + /* This array lists the candidate colormap indexes. */ + JSAMPLE colorlist[MAXNUMCOLORS]; + int numcolors; /* number of candidate colors */ + /* This array holds the actually closest colormap index for each cell. */ + JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; + + /* Convert cell coordinates to update box ID */ + c0 >>= BOX_C0_LOG; + c1 >>= BOX_C1_LOG; + c2 >>= BOX_C2_LOG; + + /* Compute true coordinates of update box's origin corner. + * Actually we compute the coordinates of the center of the corner + * histogram cell, which are the lower bounds of the volume we care about. + */ + minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1); + minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1); + minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1); + + /* Determine which colormap entries are close enough to be candidates + * for the nearest entry to some cell in the update box. + */ + numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist); + + /* Determine the actually nearest colors. */ + find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist, + bestcolor); + + /* Save the best color numbers (plus 1) in the main cache array */ + c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */ + c1 <<= BOX_C1_LOG; + c2 <<= BOX_C2_LOG; + cptr = bestcolor; + for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) { + for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) { + cachep = & histogram[c0+ic0][c1+ic1][c2]; + for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) { + *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1); + } + } + } +} + + +/* + * Map some rows of pixels to the output colormapped representation. + */ + +METHODDEF(void) +pass2_no_dither (j_decompress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) +/* This version performs no dithering */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + register JSAMPROW inptr, outptr; + register histptr cachep; + register int c0, c1, c2; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + inptr = input_buf[row]; + outptr = output_buf[row]; + for (col = width; col > 0; col--) { + /* get pixel value and index into the cache */ + c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT; + c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT; + c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT; + cachep = & histogram[c0][c1][c2]; + /* If we have not seen this color before, find nearest colormap entry */ + /* and update the cache */ + if (*cachep == 0) + fill_inverse_cmap(cinfo, c0,c1,c2); + /* Now emit the colormap index for this cell */ + *outptr++ = (JSAMPLE) (*cachep - 1); + } + } +} + + +METHODDEF(void) +pass2_fs_dither (j_decompress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) +/* This version performs Floyd-Steinberg dithering */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */ + LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */ + LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */ + register FSERRPTR errorptr; /* => fserrors[] at column before current */ + JSAMPROW inptr; /* => current input pixel */ + JSAMPROW outptr; /* => current output pixel */ + histptr cachep; + int dir; /* +1 or -1 depending on direction */ + int dir3; /* 3*dir, for advancing inptr & errorptr */ + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + JSAMPLE *range_limit = cinfo->sample_range_limit; + int *error_limit = cquantize->error_limiter; + JSAMPROW colormap0 = cinfo->colormap[0]; + JSAMPROW colormap1 = cinfo->colormap[1]; + JSAMPROW colormap2 = cinfo->colormap[2]; + SHIFT_TEMPS + + for (row = 0; row < num_rows; row++) { + inptr = input_buf[row]; + outptr = output_buf[row]; + if (cquantize->on_odd_row) { + /* work right to left in this row */ + inptr += (width-1) * 3; /* so point to rightmost pixel */ + outptr += width-1; + dir = -1; + dir3 = -3; + errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */ + cquantize->on_odd_row = FALSE; /* flip for next time */ + } else { + /* work left to right in this row */ + dir = 1; + dir3 = 3; + errorptr = cquantize->fserrors; /* => entry before first real column */ + cquantize->on_odd_row = TRUE; /* flip for next time */ + } + /* Preset error values: no error propagated to first pixel from left */ + cur0 = cur1 = cur2 = 0; + /* and no error propagated to row below yet */ + belowerr0 = belowerr1 = belowerr2 = 0; + bpreverr0 = bpreverr1 = bpreverr2 = 0; + + for (col = width; col > 0; col--) { + /* curN holds the error propagated from the previous pixel on the + * current line. Add the error propagated from the previous line + * to form the complete error correction term for this pixel, and + * round the error term (which is expressed * 16) to an integer. + * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct + * for either sign of the error value. + * Note: errorptr points to *previous* column's array entry. + */ + cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4); + cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4); + cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4); + /* Limit the error using transfer function set by init_error_limit. + * See comments with init_error_limit for rationale. + */ + cur0 = error_limit[cur0]; + cur1 = error_limit[cur1]; + cur2 = error_limit[cur2]; + /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. + * The maximum error is +- MAXJSAMPLE (or less with error limiting); + * this sets the required size of the range_limit array. + */ + cur0 += GETJSAMPLE(inptr[0]); + cur1 += GETJSAMPLE(inptr[1]); + cur2 += GETJSAMPLE(inptr[2]); + cur0 = GETJSAMPLE(range_limit[cur0]); + cur1 = GETJSAMPLE(range_limit[cur1]); + cur2 = GETJSAMPLE(range_limit[cur2]); + /* Index into the cache with adjusted pixel value */ + cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT]; + /* If we have not seen this color before, find nearest colormap */ + /* entry and update the cache */ + if (*cachep == 0) + fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT); + /* Now emit the colormap index for this cell */ + { register int pixcode = *cachep - 1; + *outptr = (JSAMPLE) pixcode; + /* Compute representation error for this pixel */ + cur0 -= GETJSAMPLE(colormap0[pixcode]); + cur1 -= GETJSAMPLE(colormap1[pixcode]); + cur2 -= GETJSAMPLE(colormap2[pixcode]); + } + /* Compute error fractions to be propagated to adjacent pixels. + * Add these into the running sums, and simultaneously shift the + * next-line error sums left by 1 column. + */ + { register LOCFSERROR bnexterr, delta; + + bnexterr = cur0; /* Process component 0 */ + delta = cur0 * 2; + cur0 += delta; /* form error * 3 */ + errorptr[0] = (FSERROR) (bpreverr0 + cur0); + cur0 += delta; /* form error * 5 */ + bpreverr0 = belowerr0 + cur0; + belowerr0 = bnexterr; + cur0 += delta; /* form error * 7 */ + bnexterr = cur1; /* Process component 1 */ + delta = cur1 * 2; + cur1 += delta; /* form error * 3 */ + errorptr[1] = (FSERROR) (bpreverr1 + cur1); + cur1 += delta; /* form error * 5 */ + bpreverr1 = belowerr1 + cur1; + belowerr1 = bnexterr; + cur1 += delta; /* form error * 7 */ + bnexterr = cur2; /* Process component 2 */ + delta = cur2 * 2; + cur2 += delta; /* form error * 3 */ + errorptr[2] = (FSERROR) (bpreverr2 + cur2); + cur2 += delta; /* form error * 5 */ + bpreverr2 = belowerr2 + cur2; + belowerr2 = bnexterr; + cur2 += delta; /* form error * 7 */ + } + /* At this point curN contains the 7/16 error value to be propagated + * to the next pixel on the current line, and all the errors for the + * next line have been shifted over. We are therefore ready to move on. + */ + inptr += dir3; /* Advance pixel pointers to next column */ + outptr += dir; + errorptr += dir3; /* advance errorptr to current column */ + } + /* Post-loop cleanup: we must unload the final error values into the + * final fserrors[] entry. Note we need not unload belowerrN because + * it is for the dummy column before or after the actual array. + */ + errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */ + errorptr[1] = (FSERROR) bpreverr1; + errorptr[2] = (FSERROR) bpreverr2; + } +} + + +/* + * Initialize the error-limiting transfer function (lookup table). + * The raw F-S error computation can potentially compute error values of up to + * +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be + * much less, otherwise obviously wrong pixels will be created. (Typical + * effects include weird fringes at color-area boundaries, isolated bright + * pixels in a dark area, etc.) The standard advice for avoiding this problem + * is to ensure that the "corners" of the color cube are allocated as output + * colors; then repeated errors in the same direction cannot cause cascading + * error buildup. However, that only prevents the error from getting + * completely out of hand; Aaron Giles reports that error limiting improves + * the results even with corner colors allocated. + * A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty + * well, but the smoother transfer function used below is even better. Thanks + * to Aaron Giles for this idea. + */ + +LOCAL(void) +init_error_limit (j_decompress_ptr cinfo) +/* Allocate and fill in the error_limiter table */ +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + int * table; + int in, out; + + table = (int *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int)); + table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */ + cquantize->error_limiter = table; + +#define STEPSIZE ((MAXJSAMPLE+1)/16) + /* Map errors 1:1 up to +- MAXJSAMPLE/16 */ + out = 0; + for (in = 0; in < STEPSIZE; in++, out++) { + table[in] = out; table[-in] = -out; + } + /* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */ + for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) { + table[in] = out; table[-in] = -out; + } + /* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */ + for (; in <= MAXJSAMPLE; in++) { + table[in] = out; table[-in] = -out; + } +#undef STEPSIZE +} + + +/* + * Finish up at the end of each pass. + */ + +METHODDEF(void) +finish_pass1 (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + + /* Select the representative colors and fill in cinfo->colormap */ + cinfo->colormap = cquantize->sv_colormap; + select_colors(cinfo, cquantize->desired); + /* Force next pass to zero the color index table */ + cquantize->needs_zeroed = TRUE; +} + + +METHODDEF(void) +finish_pass2 (j_decompress_ptr cinfo) +{ + /* no work */ +} + + +/* + * Initialize for each processing pass. + */ + +METHODDEF(void) +start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + int i; + + /* Only F-S dithering or no dithering is supported. */ + /* If user asks for ordered dither, give him F-S. */ + if (cinfo->dither_mode != JDITHER_NONE) + cinfo->dither_mode = JDITHER_FS; + + if (is_pre_scan) { + /* Set up method pointers */ + cquantize->pub.color_quantize = prescan_quantize; + cquantize->pub.finish_pass = finish_pass1; + cquantize->needs_zeroed = TRUE; /* Always zero histogram */ + } else { + /* Set up method pointers */ + if (cinfo->dither_mode == JDITHER_FS) + cquantize->pub.color_quantize = pass2_fs_dither; + else + cquantize->pub.color_quantize = pass2_no_dither; + cquantize->pub.finish_pass = finish_pass2; + + /* Make sure color count is acceptable */ + i = cinfo->actual_number_of_colors; + if (i < 1) + ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1); + if (i > MAXNUMCOLORS) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); + + if (cinfo->dither_mode == JDITHER_FS) { + size_t arraysize = (size_t) ((cinfo->output_width + 2) * + (3 * SIZEOF(FSERROR))); + /* Allocate Floyd-Steinberg workspace if we didn't already. */ + if (cquantize->fserrors == NULL) + cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) + ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); + /* Initialize the propagated errors to zero. */ + jzero_far((void FAR *) cquantize->fserrors, arraysize); + /* Make the error-limit table if we didn't already. */ + if (cquantize->error_limiter == NULL) + init_error_limit(cinfo); + cquantize->on_odd_row = FALSE; + } + + } + /* Zero the histogram or inverse color map, if necessary */ + if (cquantize->needs_zeroed) { + for (i = 0; i < HIST_C0_ELEMS; i++) { + jzero_far((void FAR *) histogram[i], + HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell)); + } + cquantize->needs_zeroed = FALSE; + } +} + + +/* + * Switch to a new external colormap between output passes. + */ + +METHODDEF(void) +new_color_map_2_quant (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + + /* Reset the inverse color map */ + cquantize->needs_zeroed = TRUE; +} + + +/* + * Module initialization routine for 2-pass color quantization. + */ + +GLOBAL(void) +jinit_2pass_quantizer (j_decompress_ptr cinfo) +{ + my_cquantize_ptr cquantize; + int i; + + cquantize = (my_cquantize_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_cquantizer)); + cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; + cquantize->pub.start_pass = start_pass_2_quant; + cquantize->pub.new_color_map = new_color_map_2_quant; + cquantize->fserrors = NULL; /* flag optional arrays not allocated */ + cquantize->error_limiter = NULL; + + /* Make sure jdmaster didn't give me a case I can't handle */ + if (cinfo->out_color_components != 3) + ERREXIT(cinfo, JERR_NOTIMPL); + + /* Allocate the histogram/inverse colormap storage */ + cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d)); + for (i = 0; i < HIST_C0_ELEMS; i++) { + cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell)); + } + cquantize->needs_zeroed = TRUE; /* histogram is garbage now */ + + /* Allocate storage for the completed colormap, if required. + * We do this now since it is FAR storage and may affect + * the memory manager's space calculations. + */ + if (cinfo->enable_2pass_quant) { + /* Make sure color count is acceptable */ + int desired = cinfo->desired_number_of_colors; + /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */ + if (desired < 8) + ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8); + /* Make sure colormap indexes can be represented by JSAMPLEs */ + if (desired > MAXNUMCOLORS) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); + cquantize->sv_colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3); + cquantize->desired = desired; + } else + cquantize->sv_colormap = NULL; + + /* Only F-S dithering or no dithering is supported. */ + /* If user asks for ordered dither, give him F-S. */ + if (cinfo->dither_mode != JDITHER_NONE) + cinfo->dither_mode = JDITHER_FS; + + /* Allocate Floyd-Steinberg workspace if necessary. + * This isn't really needed until pass 2, but again it is FAR storage. + * Although we will cope with a later change in dither_mode, + * we do not promise to honor max_memory_to_use if dither_mode changes. + */ + if (cinfo->dither_mode == JDITHER_FS) { + cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR)))); + /* Might as well create the error-limiting table too. */ + init_error_limit(cinfo); + } +} + +#endif /* QUANT_2PASS_SUPPORTED */ diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jsimd.h b/lib-third-party/libturbojpeg-ios/libjpeg/jsimd.h new file mode 100755 index 0000000..3fa2c43 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jsimd.h @@ -0,0 +1,98 @@ +/* + * jsimd.h + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + */ + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jsimd_can_rgb_ycc jSCanRgbYcc +#define jsimd_can_rgb_gray jSCanRgbGry +#define jsimd_can_ycc_rgb jSCanYccRgb +#define jsimd_rgb_ycc_convert jSRgbYccConv +#define jsimd_rgb_gray_convert jSRgbGryConv +#define jsimd_ycc_rgb_convert jSYccRgbConv +#define jsimd_can_h2v2_downsample jSCanH2V2Down +#define jsimd_can_h2v1_downsample jSCanH2V1Down +#define jsimd_h2v2_downsample jSH2V2Down +#define jsimd_h2v1_downsample jSH2V1Down +#define jsimd_can_h2v2_upsample jSCanH2V2Up +#define jsimd_can_h2v1_upsample jSCanH2V1Up +#define jsimd_h2v2_upsample jSH2V2Up +#define jsimd_h2v1_upsample jSH2V1Up +#define jsimd_can_h2v2_fancy_upsample jSCanH2V2FUp +#define jsimd_can_h2v1_fancy_upsample jSCanH2V1FUp +#define jsimd_h2v2_fancy_upsample jSH2V2FUp +#define jsimd_h2v1_fancy_upsample jSH2V1FUp +#define jsimd_can_h2v2_merged_upsample jSCanH2V2MUp +#define jsimd_can_h2v1_merged_upsample jSCanH2V1MUp +#define jsimd_h2v2_merged_upsample jSH2V2MUp +#define jsimd_h2v1_merged_upsample jSH2V1MUp +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +EXTERN(int) jsimd_can_rgb_ycc JPP((void)); +EXTERN(int) jsimd_can_rgb_gray JPP((void)); +EXTERN(int) jsimd_can_ycc_rgb JPP((void)); + +EXTERN(void) jsimd_rgb_ycc_convert + JPP((j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_rgb_gray_convert + JPP((j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_ycc_rgb_convert + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +EXTERN(int) jsimd_can_h2v2_downsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_downsample JPP((void)); + +EXTERN(void) jsimd_h2v2_downsample + JPP((j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample + JPP((j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +EXTERN(int) jsimd_can_h2v2_upsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_upsample JPP((void)); + +EXTERN(void) jsimd_h2v2_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(int) jsimd_can_h2v2_fancy_upsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_fancy_upsample JPP((void)); + +EXTERN(void) jsimd_h2v2_fancy_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(int) jsimd_can_h2v2_merged_upsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_merged_upsample JPP((void)); + +EXTERN(void) jsimd_h2v2_merged_upsample + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf)); + diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jsimddct.h b/lib-third-party/libturbojpeg-ios/libjpeg/jsimddct.h new file mode 100755 index 0000000..a1c7440 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jsimddct.h @@ -0,0 +1,102 @@ +/* + * jsimddct.h + * + * Copyright 2009 Pierre Ossman for Cendio AB + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + */ + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jsimd_can_convsamp jSCanConv +#define jsimd_can_convsamp_float jSCanConvF +#define jsimd_convsamp jSConv +#define jsimd_convsamp_float jSConvF +#define jsimd_can_fdct_islow jSCanFDCTIS +#define jsimd_can_fdct_ifast jSCanFDCTIF +#define jsimd_can_fdct_float jSCanFDCTFl +#define jsimd_fdct_islow jSFDCTIS +#define jsimd_fdct_ifast jSFDCTIF +#define jsimd_fdct_float jSFDCTFl +#define jsimd_can_quantize jSCanQuant +#define jsimd_can_quantize_float jSCanQuantF +#define jsimd_quantize jSQuant +#define jsimd_quantize_float jSQuantF +#define jsimd_can_idct_2x2 jSCanIDCT22 +#define jsimd_can_idct_4x4 jSCanIDCT44 +#define jsimd_idct_2x2 jSIDCT22 +#define jsimd_idct_4x4 jSIDCT44 +#define jsimd_can_idct_islow jSCanIDCTIS +#define jsimd_can_idct_ifast jSCanIDCTIF +#define jsimd_can_idct_float jSCanIDCTFl +#define jsimd_idct_islow jSIDCTIS +#define jsimd_idct_ifast jSIDCTIF +#define jsimd_idct_float jSIDCTFl +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +EXTERN(int) jsimd_can_convsamp JPP((void)); +EXTERN(int) jsimd_can_convsamp_float JPP((void)); + +EXTERN(void) jsimd_convsamp JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); +EXTERN(void) jsimd_convsamp_float JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(int) jsimd_can_fdct_islow JPP((void)); +EXTERN(int) jsimd_can_fdct_ifast JPP((void)); +EXTERN(int) jsimd_can_fdct_float JPP((void)); + +EXTERN(void) jsimd_fdct_islow JPP((DCTELEM * data)); +EXTERN(void) jsimd_fdct_ifast JPP((DCTELEM * data)); +EXTERN(void) jsimd_fdct_float JPP((FAST_FLOAT * data)); + +EXTERN(int) jsimd_can_quantize JPP((void)); +EXTERN(int) jsimd_can_quantize_float JPP((void)); + +EXTERN(void) jsimd_quantize JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); +EXTERN(void) jsimd_quantize_float JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(int) jsimd_can_idct_2x2 JPP((void)); +EXTERN(int) jsimd_can_idct_4x4 JPP((void)); + +EXTERN(void) jsimd_idct_2x2 JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4 JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(int) jsimd_can_idct_islow JPP((void)); +EXTERN(int) jsimd_can_idct_ifast JPP((void)); +EXTERN(int) jsimd_can_idct_float JPP((void)); + +EXTERN(void) jsimd_idct_islow JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_float JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jutils.c b/lib-third-party/libturbojpeg-ios/libjpeg/jutils.c new file mode 100755 index 0000000..d18a955 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jutils.c @@ -0,0 +1,179 @@ +/* + * jutils.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains tables and miscellaneous utility routines needed + * for both compression and decompression. + * Note we prefix all global names with "j" to minimize conflicts with + * a surrounding application. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" + + +/* + * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element + * of a DCT block read in natural order (left to right, top to bottom). + */ + +#if 0 /* This table is not actually needed in v6a */ + +const int jpeg_zigzag_order[DCTSIZE2] = { + 0, 1, 5, 6, 14, 15, 27, 28, + 2, 4, 7, 13, 16, 26, 29, 42, + 3, 8, 12, 17, 25, 30, 41, 43, + 9, 11, 18, 24, 31, 40, 44, 53, + 10, 19, 23, 32, 39, 45, 52, 54, + 20, 22, 33, 38, 46, 51, 55, 60, + 21, 34, 37, 47, 50, 56, 59, 61, + 35, 36, 48, 49, 57, 58, 62, 63 +}; + +#endif + +/* + * jpeg_natural_order[i] is the natural-order position of the i'th element + * of zigzag order. + * + * When reading corrupted data, the Huffman decoders could attempt + * to reference an entry beyond the end of this array (if the decoded + * zero run length reaches past the end of the block). To prevent + * wild stores without adding an inner-loop test, we put some extra + * "63"s after the real entries. This will cause the extra coefficient + * to be stored in location 63 of the block, not somewhere random. + * The worst case would be a run-length of 15, which means we need 16 + * fake entries. + */ + +const int jpeg_natural_order[DCTSIZE2+16] = { + 0, 1, 8, 16, 9, 2, 3, 10, + 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, + 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, + 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, + 53, 60, 61, 54, 47, 55, 62, 63, + 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ + 63, 63, 63, 63, 63, 63, 63, 63 +}; + + +/* + * Arithmetic utilities + */ + +GLOBAL(long) +jdiv_round_up (long a, long b) +/* Compute a/b rounded up to next integer, ie, ceil(a/b) */ +/* Assumes a >= 0, b > 0 */ +{ + return (a + b - 1L) / b; +} + + +GLOBAL(long) +jround_up (long a, long b) +/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ +/* Assumes a >= 0, b > 0 */ +{ + a += b - 1L; + return a - (a % b); +} + + +/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays + * and coefficient-block arrays. This won't work on 80x86 because the arrays + * are FAR and we're assuming a small-pointer memory model. However, some + * DOS compilers provide far-pointer versions of memcpy() and memset() even + * in the small-model libraries. These will be used if USE_FMEM is defined. + * Otherwise, the routines below do it the hard way. (The performance cost + * is not all that great, because these routines aren't very heavily used.) + */ + +#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ +#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) +#define FMEMZERO(target,size) MEMZERO(target,size) +#else /* 80x86 case, define if we can */ +#ifdef USE_FMEM +#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) +#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) +#endif +#endif + + +GLOBAL(void) +jcopy_sample_rows (JSAMPARRAY input_array, int source_row, + JSAMPARRAY output_array, int dest_row, + int num_rows, JDIMENSION num_cols) +/* Copy some rows of samples from one place to another. + * num_rows rows are copied from input_array[source_row++] + * to output_array[dest_row++]; these areas may overlap for duplication. + * The source and destination arrays must be at least as wide as num_cols. + */ +{ + register JSAMPROW inptr, outptr; +#ifdef FMEMCOPY + register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE)); +#else + register JDIMENSION count; +#endif + register int row; + + input_array += source_row; + output_array += dest_row; + + for (row = num_rows; row > 0; row--) { + inptr = *input_array++; + outptr = *output_array++; +#ifdef FMEMCOPY + FMEMCOPY(outptr, inptr, count); +#else + for (count = num_cols; count > 0; count--) + *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ +#endif + } +} + + +GLOBAL(void) +jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, + JDIMENSION num_blocks) +/* Copy a row of coefficient blocks from one place to another. */ +{ +#ifdef FMEMCOPY + FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); +#else + register JCOEFPTR inptr, outptr; + register long count; + + inptr = (JCOEFPTR) input_row; + outptr = (JCOEFPTR) output_row; + for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) { + *outptr++ = *inptr++; + } +#endif +} + + +GLOBAL(void) +jzero_far (void FAR * target, size_t bytestozero) +/* Zero out a chunk of FAR memory. */ +/* This might be sample-array data, block-array data, or alloc_large data. */ +{ +#ifdef FMEMZERO + FMEMZERO(target, bytestozero); +#else + register char FAR * ptr = (char FAR *) target; + register size_t count; + + for (count = bytestozero; count > 0; count--) { + *ptr++ = 0; + } +#endif +} diff --git a/lib-third-party/libturbojpeg-ios/libjpeg/jversion.h b/lib-third-party/libturbojpeg-ios/libjpeg/jversion.h new file mode 100755 index 0000000..71d7b91 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libjpeg/jversion.h @@ -0,0 +1,31 @@ +/* + * jversion.h + * + * Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding. + * Copyright (C) 2010, 2012, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains software version identification. + */ + + +#if JPEG_LIB_VERSION >= 80 + +#define JVERSION "8b 16-May-2010" + +#elif JPEG_LIB_VERSION >= 70 + +#define JVERSION "7 27-Jun-2009" + +#else + +#define JVERSION "6b 27-Mar-1998" + +#endif + +#define JCOPYRIGHT "Copyright (C) 1991-2010 Thomas G. Lane, Guido Vollbeding\n" \ + "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ + "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \ + "Copyright (C) 2009-2012 D. R. Commander\n" \ + "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jconfig.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/jconfig.h new file mode 100755 index 0000000..29aa100 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jconfig.h @@ -0,0 +1,58 @@ +/* jconfig.h. Generated from jconfig.h.in by configure. */ +/* Version ID for the JPEG library. + * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". + */ +#define JPEG_LIB_VERSION 62 + +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 1.2.80 + +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 + +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 + +/* Compiler supports function prototypes. */ +#define HAVE_PROTOTYPES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Compiler supports 'unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 + +/* Compiler supports 'unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 + +/* Compiler does not support pointers to unspecified structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* Compiler has rather than standard . */ +/* #undef NEED_BSD_STRINGS */ + +/* Linker requires that global names be unique in first 15 characters. */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ + +/* Need to include in order to obtain size_t. */ +#define NEED_SYS_TYPES_H 1 + +/* Broken compiler shifts signed values as an unsigned shift. */ +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ + +/* Use accelerated SIMD routines. */ +#define WITH_SIMD 1 + +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +/* # undef __CHAR_UNSIGNED__ */ +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jdatadst-tj.c b/lib-third-party/libturbojpeg-ios/libturbojpeg/jdatadst-tj.c new file mode 100755 index 0000000..cb674dc --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jdatadst-tj.c @@ -0,0 +1,188 @@ +/* + * jdatadst.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Modified 2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains compression data destination routines for the case of + * emitting JPEG data to memory or to a file (or any stdio stream). + * While these routines are sufficient for most applications, + * some will want to use a different destination manager. + * IMPORTANT: we assume that fwrite() will correctly transcribe an array of + * JOCTETs into 8-bit-wide elements on external storage. If char is wider + * than 8 bits on your machine, you may need to do some tweaking. + */ + +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#include "jinclude.h" +#include "jpeglib.h" +#include "jerror.h" + +#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ +extern void * malloc JPP((size_t size)); +extern void free JPP((void *ptr)); +#endif + + +#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ + + +/* Expanded data destination object for memory output */ + +typedef struct { + struct jpeg_destination_mgr pub; /* public fields */ + + unsigned char ** outbuffer; /* target buffer */ + unsigned long * outsize; + unsigned char * newbuffer; /* newly allocated buffer */ + JOCTET * buffer; /* start of buffer */ + size_t bufsize; + boolean alloc; +} my_mem_destination_mgr; + +typedef my_mem_destination_mgr * my_mem_dest_ptr; + + +/* + * Initialize destination --- called by jpeg_start_compress + * before any data is actually written. + */ + +METHODDEF(void) +init_mem_destination (j_compress_ptr cinfo) +{ + /* no work necessary here */ +} + + +/* + * Empty the output buffer --- called whenever buffer fills up. + * + * In typical applications, this should write the entire output buffer + * (ignoring the current state of next_output_byte & free_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been dumped. + * + * In applications that need to be able to suspend compression due to output + * overrun, a FALSE return indicates that the buffer cannot be emptied now. + * In this situation, the compressor will return to its caller (possibly with + * an indication that it has not accepted all the supplied scanlines). The + * application should resume compression after it has made more room in the + * output buffer. Note that there are substantial restrictions on the use of + * suspension --- see the documentation. + * + * When suspending, the compressor will back up to a convenient restart point + * (typically the start of the current MCU). next_output_byte & free_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point will be regenerated after resumption, so do not + * write it out when emptying the buffer externally. + */ + +METHODDEF(boolean) +empty_mem_output_buffer (j_compress_ptr cinfo) +{ + size_t nextsize; + JOCTET * nextbuffer; + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; + + if (!dest->alloc) ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* Try to allocate new buffer with double size */ + nextsize = dest->bufsize * 2; + nextbuffer = malloc(nextsize); + + if (nextbuffer == NULL) + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); + + MEMCOPY(nextbuffer, dest->buffer, dest->bufsize); + + if (dest->newbuffer != NULL) + free(dest->newbuffer); + + dest->newbuffer = nextbuffer; + + dest->pub.next_output_byte = nextbuffer + dest->bufsize; + dest->pub.free_in_buffer = dest->bufsize; + + dest->buffer = nextbuffer; + dest->bufsize = nextsize; + + return TRUE; +} + + +/* + * Terminate destination --- called by jpeg_finish_compress + * after all data has been written. Usually needs to flush buffer. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ + +METHODDEF(void) +term_mem_destination (j_compress_ptr cinfo) +{ + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; + + if(dest->alloc) *dest->outbuffer = dest->buffer; + *dest->outsize = (unsigned long)(dest->bufsize - dest->pub.free_in_buffer); +} + + +/* + * Prepare for output to a memory buffer. + * The caller may supply an own initial buffer with appropriate size. + * Otherwise, or when the actual data output exceeds the given size, + * the library adapts the buffer size as necessary. + * The standard library functions malloc/free are used for allocating + * larger memory, so the buffer is available to the application after + * finishing compression, and then the application is responsible for + * freeing the requested memory. + */ + +GLOBAL(void) +jpeg_mem_dest_tj (j_compress_ptr cinfo, + unsigned char ** outbuffer, unsigned long * outsize, + boolean alloc) +{ + my_mem_dest_ptr dest; + + if (outbuffer == NULL || outsize == NULL) /* sanity check */ + ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same buffer without re-executing jpeg_mem_dest. + */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_mem_destination_mgr)); + dest = (my_mem_dest_ptr) cinfo->dest; + dest->newbuffer = NULL; + } + + dest = (my_mem_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_mem_destination; + dest->pub.empty_output_buffer = empty_mem_output_buffer; + dest->pub.term_destination = term_mem_destination; + dest->outbuffer = outbuffer; + dest->outsize = outsize; + dest->alloc = alloc; + + if (*outbuffer == NULL || *outsize == 0) { + if (alloc) { + /* Allocate initial buffer */ + dest->newbuffer = *outbuffer = malloc(OUTPUT_BUF_SIZE); + if (dest->newbuffer == NULL) + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); + *outsize = OUTPUT_BUF_SIZE; + } + else ERREXIT(cinfo, JERR_BUFFER_SIZE); + } + + dest->pub.next_output_byte = dest->buffer = *outbuffer; + dest->pub.free_in_buffer = dest->bufsize = *outsize; +} diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jdatasrc-tj.c b/lib-third-party/libturbojpeg-ios/libturbojpeg/jdatasrc-tj.c new file mode 100755 index 0000000..d860a02 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jdatasrc-tj.c @@ -0,0 +1,182 @@ +/* + * jdatasrc.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Modified 2009-2010 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains decompression data source routines for the case of + * reading JPEG data from memory or from a file (or any stdio stream). + * While these routines are sufficient for most applications, + * some will want to use a different source manager. + * IMPORTANT: we assume that fread() will correctly transcribe an array of + * JOCTETs from 8-bit-wide elements on external storage. If char is wider + * than 8 bits on your machine, you may need to do some tweaking. + */ + +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#include "jinclude.h" +#include "jpeglib.h" +#include "jerror.h" + + +/* + * Initialize source --- called by jpeg_read_header + * before any data is actually read. + */ + +METHODDEF(void) +init_mem_source (j_decompress_ptr cinfo) +{ + /* no work necessary here */ +} + + +/* + * Fill the input buffer --- called whenever buffer is emptied. + * + * In typical applications, this should read fresh data into the buffer + * (ignoring the current state of next_input_byte & bytes_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been reloaded. It is not necessary to + * fill the buffer entirely, only to obtain at least one more byte. + * + * There is no such thing as an EOF return. If the end of the file has been + * reached, the routine has a choice of ERREXIT() or inserting fake data into + * the buffer. In most cases, generating a warning message and inserting a + * fake EOI marker is the best course of action --- this will allow the + * decompressor to output however much of the image is there. However, + * the resulting error message is misleading if the real problem is an empty + * input file, so we handle that case specially. + * + * In applications that need to be able to suspend compression due to input + * not being available yet, a FALSE return indicates that no more data can be + * obtained right now, but more may be forthcoming later. In this situation, + * the decompressor will return to its caller (with an indication of the + * number of scanlines it has read, if any). The application should resume + * decompression after it has loaded more data into the input buffer. Note + * that there are substantial restrictions on the use of suspension --- see + * the documentation. + * + * When suspending, the decompressor will back up to a convenient restart point + * (typically the start of the current MCU). next_input_byte & bytes_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point must be rescanned after resumption, so move it to + * the front of the buffer rather than discarding it. + */ + +METHODDEF(boolean) +fill_mem_input_buffer (j_decompress_ptr cinfo) +{ + static JOCTET mybuffer[4]; + + /* The whole JPEG data is expected to reside in the supplied memory + * buffer, so any request for more data beyond the given buffer size + * is treated as an error. + */ + WARNMS(cinfo, JWRN_JPEG_EOF); + /* Insert a fake EOI marker */ + mybuffer[0] = (JOCTET) 0xFF; + mybuffer[1] = (JOCTET) JPEG_EOI; + + cinfo->src->next_input_byte = mybuffer; + cinfo->src->bytes_in_buffer = 2; + + return TRUE; +} + + +/* + * Skip data --- used to skip over a potentially large amount of + * uninteresting data (such as an APPn marker). + * + * Writers of suspendable-input applications must note that skip_input_data + * is not granted the right to give a suspension return. If the skip extends + * beyond the data currently in the buffer, the buffer can be marked empty so + * that the next read will cause a fill_input_buffer call that can suspend. + * Arranging for additional bytes to be discarded before reloading the input + * buffer is the application writer's problem. + */ + +METHODDEF(void) +skip_input_data (j_decompress_ptr cinfo, long num_bytes) +{ + struct jpeg_source_mgr * src = cinfo->src; + + /* Just a dumb implementation for now. Could use fseek() except + * it doesn't work on pipes. Not clear that being smart is worth + * any trouble anyway --- large skips are infrequent. + */ + if (num_bytes > 0) { + while (num_bytes > (long) src->bytes_in_buffer) { + num_bytes -= (long) src->bytes_in_buffer; + (void) (*src->fill_input_buffer) (cinfo); + /* note we assume that fill_input_buffer will never return FALSE, + * so suspension need not be handled. + */ + } + src->next_input_byte += (size_t) num_bytes; + src->bytes_in_buffer -= (size_t) num_bytes; + } +} + + +/* + * An additional method that can be provided by data source modules is the + * resync_to_restart method for error recovery in the presence of RST markers. + * For the moment, this source module just uses the default resync method + * provided by the JPEG library. That method assumes that no backtracking + * is possible. + */ + + +/* + * Terminate source --- called by jpeg_finish_decompress + * after all data has been read. Often a no-op. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ + +METHODDEF(void) +term_source (j_decompress_ptr cinfo) +{ + /* no work necessary here */ +} + + +/* + * Prepare for input from a supplied memory buffer. + * The buffer must contain the whole JPEG data. + */ + +GLOBAL(void) +jpeg_mem_src_tj (j_decompress_ptr cinfo, + unsigned char * inbuffer, unsigned long insize) +{ + struct jpeg_source_mgr * src; + + if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */ + ERREXIT(cinfo, JERR_INPUT_EMPTY); + + /* The source object is made permanent so that a series of JPEG images + * can be read from the same buffer by calling jpeg_mem_src only before + * the first one. + */ + if (cinfo->src == NULL) { /* first time for this JPEG object? */ + cinfo->src = (struct jpeg_source_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(struct jpeg_source_mgr)); + } + + src = cinfo->src; + src->init_source = init_mem_source; + src->fill_input_buffer = fill_mem_input_buffer; + src->skip_input_data = skip_input_data; + src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ + src->term_source = term_source; + src->bytes_in_buffer = (size_t) insize; + src->next_input_byte = (JOCTET *) inbuffer; +} diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jdct.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/jdct.h new file mode 100755 index 0000000..3637448 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jdct.h @@ -0,0 +1,232 @@ +/* + * jdct.h + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This include file contains common declarations for the forward and + * inverse DCT modules. These declarations are private to the DCT managers + * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms. + * The individual DCT algorithms are kept in separate files to ease + * machine-dependent tuning (e.g., assembly coding). + */ + + +/* + * A forward DCT routine is given a pointer to a work area of type DCTELEM[]; + * the DCT is to be performed in-place in that buffer. Type DCTELEM is int + * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT + * implementations use an array of type FAST_FLOAT, instead.) + * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE). + * The DCT outputs are returned scaled up by a factor of 8; they therefore + * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This + * convention improves accuracy in integer implementations and saves some + * work in floating-point ones. + * Quantization of the output coefficients is done by jcdctmgr.c. This + * step requires an unsigned type and also one with twice the bits. + */ + +#if BITS_IN_JSAMPLE == 8 +#ifndef WITH_SIMD +typedef int DCTELEM; /* 16 or 32 bits is fine */ +typedef unsigned int UDCTELEM; +typedef unsigned long long UDCTELEM2; +#else +typedef short DCTELEM; /* prefer 16 bit with SIMD for parellelism */ +typedef unsigned short UDCTELEM; +typedef unsigned int UDCTELEM2; +#endif +#else +typedef INT32 DCTELEM; /* must have 32 bits */ +typedef UINT32 UDCTELEM; +typedef unsigned long long UDCTELEM2; +#endif + + +/* + * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer + * to an output sample array. The routine must dequantize the input data as + * well as perform the IDCT; for dequantization, it uses the multiplier table + * pointed to by compptr->dct_table. The output data is to be placed into the + * sample array starting at a specified column. (Any row offset needed will + * be applied to the array pointer before it is passed to the IDCT code.) + * Note that the number of samples emitted by the IDCT routine is + * DCT_scaled_size * DCT_scaled_size. + */ + +/* typedef inverse_DCT_method_ptr is declared in jpegint.h */ + +/* + * Each IDCT routine has its own ideas about the best dct_table element type. + */ + +typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */ +#if BITS_IN_JSAMPLE == 8 +typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */ +#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */ +#else +typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */ +#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */ +#endif +typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */ + + +/* + * Each IDCT routine is responsible for range-limiting its results and + * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could + * be quite far out of range if the input data is corrupt, so a bulletproof + * range-limiting step is required. We use a mask-and-table-lookup method + * to do the combined operations quickly. See the comments with + * prepare_range_limit_table (in jdmaster.c) for more info. + */ + +#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE) + +#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ + + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_fdct_islow jFDislow +#define jpeg_fdct_ifast jFDifast +#define jpeg_fdct_float jFDfloat +#define jpeg_idct_islow jRDislow +#define jpeg_idct_ifast jRDifast +#define jpeg_idct_float jRDfloat +#define jpeg_idct_7x7 jRD7x7 +#define jpeg_idct_6x6 jRD6x6 +#define jpeg_idct_5x5 jRD5x5 +#define jpeg_idct_4x4 jRD4x4 +#define jpeg_idct_3x3 jRD3x3 +#define jpeg_idct_2x2 jRD2x2 +#define jpeg_idct_1x1 jRD1x1 +#define jpeg_idct_9x9 jRD9x9 +#define jpeg_idct_10x10 jRD10x10 +#define jpeg_idct_11x11 jRD11x11 +#define jpeg_idct_12x12 jRD12x12 +#define jpeg_idct_13x13 jRD13x13 +#define jpeg_idct_14x14 jRD14x14 +#define jpeg_idct_15x15 jRD15x15 +#define jpeg_idct_16x16 jRD16x16 +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +/* Extern declarations for the forward and inverse DCT routines. */ + +EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data)); +EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data)); +EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data)); + +EXTERN(void) jpeg_idct_islow + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_ifast + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_float + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_7x7 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_6x6 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_5x5 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_4x4 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_3x3 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_2x2 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_1x1 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_9x9 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_10x10 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_11x11 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_12x12 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_13x13 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_14x14 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_15x15 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); +EXTERN(void) jpeg_idct_16x16 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + + +/* + * Macros for handling fixed-point arithmetic; these are used by many + * but not all of the DCT/IDCT modules. + * + * All values are expected to be of type INT32. + * Fractional constants are scaled left by CONST_BITS bits. + * CONST_BITS is defined within each module using these macros, + * and may differ from one module to the next. + */ + +#define ONE ((INT32) 1) +#define CONST_SCALE (ONE << CONST_BITS) + +/* Convert a positive real constant to an integer scaled by CONST_SCALE. + * Caution: some C compilers fail to reduce "FIX(constant)" at compile time, + * thus causing a lot of useless floating-point operations at run time. + */ + +#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) + +/* Descale and correctly round an INT32 value that's scaled by N bits. + * We assume RIGHT_SHIFT rounds towards minus infinity, so adding + * the fudge factor is correct for either sign of X. + */ + +#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) + +/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * This macro is used only when the two inputs will actually be no more than + * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a + * full 32x32 multiply. This provides a useful speedup on many machines. + * Unfortunately there is no way to specify a 16x16->32 multiply portably + * in C, but some C compilers will do the right thing if you provide the + * correct combination of casts. + */ + +#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ +#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const))) +#endif +#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ +#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const))) +#endif + +#ifndef MULTIPLY16C16 /* default definition */ +#define MULTIPLY16C16(var,const) ((var) * (const)) +#endif + +/* Same except both inputs are variables. */ + +#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ +#define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2))) +#endif + +#ifndef MULTIPLY16V16 /* default definition */ +#define MULTIPLY16V16(var1,var2) ((var1) * (var2)) +#endif diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jinclude.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/jinclude.h new file mode 100755 index 0000000..0a4f151 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jinclude.h @@ -0,0 +1,91 @@ +/* + * jinclude.h + * + * Copyright (C) 1991-1994, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file exists to provide a single place to fix any problems with + * including the wrong system include files. (Common problems are taken + * care of by the standard jconfig symbols, but on really weird systems + * you may have to edit this file.) + * + * NOTE: this file is NOT intended to be included by applications using the + * JPEG library. Most applications need only include jpeglib.h. + */ + + +/* Include auto-config file to find out which system include files we need. */ + +#include "jconfig.h" /* auto configuration options */ +#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ + +/* + * We need the NULL macro and size_t typedef. + * On an ANSI-conforming system it is sufficient to include . + * Otherwise, we get them from or ; we may have to + * pull in as well. + * Note that the core JPEG library does not require ; + * only the default error handler and data source/destination modules do. + * But we must pull it in because of the references to FILE in jpeglib.h. + * You can remove those references if you want to compile without . + */ + +#ifdef HAVE_STDDEF_H +#include +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef NEED_SYS_TYPES_H +#include +#endif + +#include + +/* + * We need memory copying and zeroing functions, plus strncpy(). + * ANSI and System V implementations declare these in . + * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). + * Some systems may declare memset and memcpy in . + * + * NOTE: we assume the size parameters to these functions are of type size_t. + * Change the casts in these macros if not! + */ + +#ifdef NEED_BSD_STRINGS + +#include +#define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) +#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) + +#else /* not BSD, assume ANSI/SysV string lib */ + +#include +#define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) +#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) + +#endif + +/* + * In ANSI C, and indeed any rational implementation, size_t is also the + * type returned by sizeof(). However, it seems there are some irrational + * implementations out there, in which sizeof() returns an int even though + * size_t is defined as long or unsigned long. To ensure consistent results + * we always use this SIZEOF() macro in place of using sizeof() directly. + */ + +#define SIZEOF(object) ((size_t) sizeof(object)) + +/* + * The modules that use fread() and fwrite() always invoke them through + * these macros. On some systems you may need to twiddle the argument casts. + * CAUTION: argument order is different from underlying functions! + */ + +#define JFREAD(file,buf,sizeofbuf) \ + ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) +#define JFWRITE(file,buf,sizeofbuf) \ + ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jmorecfg.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/jmorecfg.h new file mode 100755 index 0000000..f22c4f3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jmorecfg.h @@ -0,0 +1,404 @@ +/* + * jmorecfg.h + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Copyright (C) 2009, 2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains additional configuration options that customize the + * JPEG software for special applications or support machine-dependent + * optimizations. Most users will not need to touch this file. + */ + + +/* + * Define BITS_IN_JSAMPLE as either + * 8 for 8-bit sample values (the usual setting) + * 12 for 12-bit sample values + * Only 8 and 12 are legal data precisions for lossy JPEG according to the + * JPEG standard, and the IJG code does not support anything else! + * We do not support run-time selection of data precision, sorry. + */ + +#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ + + +/* + * Maximum number of components (color channels) allowed in JPEG image. + * To meet the letter of the JPEG spec, set this to 255. However, darn + * few applications need more than 4 channels (maybe 5 for CMYK + alpha + * mask). We recommend 10 as a reasonable compromise; use 4 if you are + * really short on memory. (Each allowed component costs a hundred or so + * bytes of storage, whether actually used in an image or not.) + */ + +#define MAX_COMPONENTS 10 /* maximum number of image components */ + + +/* + * Basic data types. + * You may need to change these if you have a machine with unusual data + * type sizes; for example, "char" not 8 bits, "short" not 16 bits, + * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits, + * but it had better be at least 16. + */ + +/* Representation of a single sample (pixel element value). + * We frequently allocate large arrays of these, so it's important to keep + * them small. But if you have memory to burn and access to char or short + * arrays is very slow on your hardware, you might want to change these. + */ + +#if BITS_IN_JSAMPLE == 8 +/* JSAMPLE should be the smallest type that will hold the values 0..255. + * You can use a signed char by having GETJSAMPLE mask it with 0xFF. + */ + +#ifdef HAVE_UNSIGNED_CHAR + +typedef unsigned char JSAMPLE; +#define GETJSAMPLE(value) ((int) (value)) + +#else /* not HAVE_UNSIGNED_CHAR */ + +typedef char JSAMPLE; +#ifdef __CHAR_UNSIGNED__ +#define GETJSAMPLE(value) ((int) (value)) +#else +#define GETJSAMPLE(value) ((int) (value) & 0xFF) +#endif /* __CHAR_UNSIGNED__ */ + +#endif /* HAVE_UNSIGNED_CHAR */ + +#define MAXJSAMPLE 255 +#define CENTERJSAMPLE 128 + +#endif /* BITS_IN_JSAMPLE == 8 */ + + +#if BITS_IN_JSAMPLE == 12 +/* JSAMPLE should be the smallest type that will hold the values 0..4095. + * On nearly all machines "short" will do nicely. + */ + +typedef short JSAMPLE; +#define GETJSAMPLE(value) ((int) (value)) + +#define MAXJSAMPLE 4095 +#define CENTERJSAMPLE 2048 + +#endif /* BITS_IN_JSAMPLE == 12 */ + + +/* Representation of a DCT frequency coefficient. + * This should be a signed value of at least 16 bits; "short" is usually OK. + * Again, we allocate large arrays of these, but you can change to int + * if you have memory to burn and "short" is really slow. + */ + +typedef short JCOEF; + + +/* Compressed datastreams are represented as arrays of JOCTET. + * These must be EXACTLY 8 bits wide, at least once they are written to + * external storage. Note that when using the stdio data source/destination + * managers, this is also the data type passed to fread/fwrite. + */ + +#ifdef HAVE_UNSIGNED_CHAR + +typedef unsigned char JOCTET; +#define GETJOCTET(value) (value) + +#else /* not HAVE_UNSIGNED_CHAR */ + +typedef char JOCTET; +#ifdef __CHAR_UNSIGNED__ +#define GETJOCTET(value) (value) +#else +#define GETJOCTET(value) ((value) & 0xFF) +#endif /* __CHAR_UNSIGNED__ */ + +#endif /* HAVE_UNSIGNED_CHAR */ + + +/* These typedefs are used for various table entries and so forth. + * They must be at least as wide as specified; but making them too big + * won't cost a huge amount of memory, so we don't provide special + * extraction code like we did for JSAMPLE. (In other words, these + * typedefs live at a different point on the speed/space tradeoff curve.) + */ + +/* UINT8 must hold at least the values 0..255. */ + +#ifdef HAVE_UNSIGNED_CHAR +typedef unsigned char UINT8; +#else /* not HAVE_UNSIGNED_CHAR */ +#ifdef __CHAR_UNSIGNED__ +typedef char UINT8; +#else /* not __CHAR_UNSIGNED__ */ +typedef short UINT8; +#endif /* __CHAR_UNSIGNED__ */ +#endif /* HAVE_UNSIGNED_CHAR */ + +/* UINT16 must hold at least the values 0..65535. */ + +#ifdef HAVE_UNSIGNED_SHORT +typedef unsigned short UINT16; +#else /* not HAVE_UNSIGNED_SHORT */ +typedef unsigned int UINT16; +#endif /* HAVE_UNSIGNED_SHORT */ + +/* INT16 must hold at least the values -32768..32767. */ + +#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ +typedef short INT16; +#endif + +/* INT32 must hold at least signed 32-bit values. */ + +#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ +typedef long INT32; +#endif + +/* Datatype used for image dimensions. The JPEG standard only supports + * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore + * "unsigned int" is sufficient on all machines. However, if you need to + * handle larger images and you don't mind deviating from the spec, you + * can change this datatype. + */ + +typedef unsigned int JDIMENSION; + +#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */ + + +/* These macros are used in all function definitions and extern declarations. + * You could modify them if you need to change function linkage conventions; + * in particular, you'll need to do that to make the library a Windows DLL. + * Another application is to make all functions global for use with debuggers + * or code profilers that require it. + */ + +/* a function called through method pointers: */ +#define METHODDEF(type) static type +/* a function used only in its module: */ +#define LOCAL(type) static type +/* a function referenced thru EXTERNs: */ +#define GLOBAL(type) type +/* a reference to a GLOBAL function: */ +#define EXTERN(type) extern type + + +/* This macro is used to declare a "method", that is, a function pointer. + * We want to supply prototype parameters if the compiler can cope. + * Note that the arglist parameter must be parenthesized! + * Again, you can customize this if you need special linkage keywords. + */ + +#ifdef HAVE_PROTOTYPES +#define JMETHOD(type,methodname,arglist) type (*methodname) arglist +#else +#define JMETHOD(type,methodname,arglist) type (*methodname) () +#endif + + +/* Here is the pseudo-keyword for declaring pointers that must be "far" + * on 80x86 machines. Most of the specialized coding for 80x86 is handled + * by just saying "FAR *" where such a pointer is needed. In a few places + * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol. + */ + +#ifdef NEED_FAR_POINTERS +#define FAR far +#else +#define FAR +#endif + + +/* + * On a few systems, type boolean and/or its values FALSE, TRUE may appear + * in standard header files. Or you may have conflicts with application- + * specific header files that you want to include together with these files. + * Defining HAVE_BOOLEAN before including jpeglib.h should make it work. + */ + +#ifndef HAVE_BOOLEAN +typedef int boolean; +#endif +#ifndef FALSE /* in case these macros already exist */ +#define FALSE 0 /* values of boolean */ +#endif +#ifndef TRUE +#define TRUE 1 +#endif + + +/* + * The remaining options affect code selection within the JPEG library, + * but they don't need to be visible to most applications using the library. + * To minimize application namespace pollution, the symbols won't be + * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined. + */ + +#ifdef JPEG_INTERNALS +#define JPEG_INTERNAL_OPTIONS +#endif + +#ifdef JPEG_INTERNAL_OPTIONS + + +/* + * These defines indicate whether to include various optional functions. + * Undefining some of these symbols will produce a smaller but less capable + * library. Note that you can leave certain source files out of the + * compilation/linking process if you've #undef'd the corresponding symbols. + * (You may HAVE to do that if your compiler doesn't like null source files.) + */ + +/* Capability options common to encoder and decoder: */ + +#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ +#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ +#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ + +/* Encoder capability options: */ + +#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ +#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ +#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ +/* Note: if you selected 12-bit data precision, it is dangerous to turn off + * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit + * precision, so jchuff.c normally uses entropy optimization to compute + * usable tables for higher precision. If you don't want to do optimization, + * you'll have to supply different default Huffman tables. + * The exact same statements apply for progressive JPEG: the default tables + * don't work for progressive mode. (This may get fixed, however.) + */ +#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */ + +/* Decoder capability options: */ + +#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ +#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ +#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ +#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ +#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ +#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ +#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ +#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ +#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ + +/* more capability options later, no doubt */ + + +/* + * Ordering of RGB data in scanlines passed to or from the application. + * If your application wants to deal with data in the order B,G,R, just + * change these macros. You can also deal with formats such as R,G,B,X + * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing + * the offsets will also change the order in which colormap data is organized. + * RESTRICTIONS: + * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. + * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not + * useful if you are using JPEG color spaces other than YCbCr or grayscale. + * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE + * is not 3 (they don't understand about dummy color components!). So you + * can't use color quantization if you change that value. + */ + +#define RGB_RED 0 /* Offset of Red in an RGB scanline element */ +#define RGB_GREEN 1 /* Offset of Green */ +#define RGB_BLUE 2 /* Offset of Blue */ +#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ + +#define JPEG_NUMCS 16 + +#define EXT_RGB_RED 0 +#define EXT_RGB_GREEN 1 +#define EXT_RGB_BLUE 2 +#define EXT_RGB_PIXELSIZE 3 + +#define EXT_RGBX_RED 0 +#define EXT_RGBX_GREEN 1 +#define EXT_RGBX_BLUE 2 +#define EXT_RGBX_PIXELSIZE 4 + +#define EXT_BGR_RED 2 +#define EXT_BGR_GREEN 1 +#define EXT_BGR_BLUE 0 +#define EXT_BGR_PIXELSIZE 3 + +#define EXT_BGRX_RED 2 +#define EXT_BGRX_GREEN 1 +#define EXT_BGRX_BLUE 0 +#define EXT_BGRX_PIXELSIZE 4 + +#define EXT_XBGR_RED 3 +#define EXT_XBGR_GREEN 2 +#define EXT_XBGR_BLUE 1 +#define EXT_XBGR_PIXELSIZE 4 + +#define EXT_XRGB_RED 1 +#define EXT_XRGB_GREEN 2 +#define EXT_XRGB_BLUE 3 +#define EXT_XRGB_PIXELSIZE 4 + +static const int rgb_red[JPEG_NUMCS] = { + -1, -1, RGB_RED, -1, -1, -1, EXT_RGB_RED, EXT_RGBX_RED, + EXT_BGR_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED, + EXT_RGBX_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED +}; + +static const int rgb_green[JPEG_NUMCS] = { + -1, -1, RGB_GREEN, -1, -1, -1, EXT_RGB_GREEN, EXT_RGBX_GREEN, + EXT_BGR_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN, + EXT_RGBX_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN +}; + +static const int rgb_blue[JPEG_NUMCS] = { + -1, -1, RGB_BLUE, -1, -1, -1, EXT_RGB_BLUE, EXT_RGBX_BLUE, + EXT_BGR_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE, + EXT_RGBX_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE +}; + +static const int rgb_pixelsize[JPEG_NUMCS] = { + -1, -1, RGB_PIXELSIZE, -1, -1, -1, EXT_RGB_PIXELSIZE, EXT_RGBX_PIXELSIZE, + EXT_BGR_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE, + EXT_RGBX_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE +}; + +/* Definitions for speed-related optimizations. */ + +/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying + * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER + * as short on such a machine. MULTIPLIER must be at least 16 bits wide. + */ + +#ifndef MULTIPLIER +#ifndef WITH_SIMD +#define MULTIPLIER int /* type for fastest integer multiply */ +#else +#define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */ +#endif +#endif + + +/* FAST_FLOAT should be either float or double, whichever is done faster + * by your compiler. (Note that this type is only used in the floating point + * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) + * Typically, float is faster in ANSI C compilers, while double is faster in + * pre-ANSI compilers (because they insist on converting to double anyway). + * The code below therefore chooses float if we have ANSI-style prototypes. + */ + +#ifndef FAST_FLOAT +#ifdef HAVE_PROTOTYPES +#define FAST_FLOAT float +#else +#define FAST_FLOAT double +#endif +#endif + +#endif /* JPEG_INTERNAL_OPTIONS */ diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jpeglib.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/jpeglib.h new file mode 100755 index 0000000..d19a3ef --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jpeglib.h @@ -0,0 +1,1213 @@ +/* + * jpeglib.h + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Modified 2002-2009 by Guido Vollbeding. + * Copyright (C) 2009-2011, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the application interface for the JPEG library. + * Most applications using the library need only include this file, + * and perhaps jerror.h if they want to know the exact error codes. + */ + +#ifndef JPEGLIB_H +#define JPEGLIB_H + +/* + * First we include the configuration files that record how this + * installation of the JPEG library is set up. jconfig.h can be + * generated automatically for many systems. jmorecfg.h contains + * manual configuration options that most people need not worry about. + */ + +#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ +#include "jconfig.h" /* widely used configuration options */ +#endif +#include "jmorecfg.h" /* seldom changed options */ + + +#ifdef __cplusplus +#ifndef DONT_USE_EXTERN_C +extern "C" { +#endif +#endif + + +/* Various constants determining the sizes of things. + * All of these are specified by the JPEG standard, so don't change them + * if you want to be compatible. + */ + +#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ +#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ +#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */ +#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */ +#define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */ +#define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */ +#define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */ +/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard; + * the PostScript DCT filter can emit files with many more than 10 blocks/MCU. + * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU + * to handle it. We even let you do this from the jconfig.h file. However, + * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe + * sometimes emits noncompliant files doesn't mean you should too. + */ +#define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */ +#ifndef D_MAX_BLOCKS_IN_MCU +#define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */ +#endif + + +/* Data structures for images (arrays of samples and of DCT coefficients). + * On 80x86 machines, the image arrays are too big for near pointers, + * but the pointer arrays can fit in near memory. + */ + +typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */ +typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ +typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ + +typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ +typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */ +typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */ +typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */ + +typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */ + + +/* Types for JPEG compression parameters and working tables. */ + + +/* DCT coefficient quantization tables. */ + +typedef struct { + /* This array gives the coefficient quantizers in natural array order + * (not the zigzag order in which they are stored in a JPEG DQT marker). + * CAUTION: IJG versions prior to v6a kept this array in zigzag order. + */ + UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ +} JQUANT_TBL; + + +/* Huffman coding tables. */ + +typedef struct { + /* These two fields directly represent the contents of a JPEG DHT marker */ + UINT8 bits[17]; /* bits[k] = # of symbols with codes of */ + /* length k bits; bits[0] is unused */ + UINT8 huffval[256]; /* The symbols, in order of incr code length */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ +} JHUFF_TBL; + + +/* Basic info about one component (color channel). */ + +typedef struct { + /* These values are fixed over the whole image. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOF marker. */ + int component_id; /* identifier for this component (0..255) */ + int component_index; /* its index in SOF or cinfo->comp_info[] */ + int h_samp_factor; /* horizontal sampling factor (1..4) */ + int v_samp_factor; /* vertical sampling factor (1..4) */ + int quant_tbl_no; /* quantization table selector (0..3) */ + /* These values may vary between scans. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOS marker. */ + /* The decompressor output side may not use these variables. */ + int dc_tbl_no; /* DC entropy table selector (0..3) */ + int ac_tbl_no; /* AC entropy table selector (0..3) */ + + /* Remaining fields should be treated as private by applications. */ + + /* These values are computed during compression or decompression startup: */ + /* Component's size in DCT blocks. + * Any dummy blocks added to complete an MCU are not counted; therefore + * these values do not depend on whether a scan is interleaved or not. + */ + JDIMENSION width_in_blocks; + JDIMENSION height_in_blocks; + /* Size of a DCT block in samples. Always DCTSIZE for compression. + * For decompression this is the size of the output from one DCT block, + * reflecting any scaling we choose to apply during the IDCT step. + * Values of 1,2,4,8 are likely to be supported. Note that different + * components may receive different IDCT scalings. + */ +#if JPEG_LIB_VERSION >= 70 + int DCT_h_scaled_size; + int DCT_v_scaled_size; +#else + int DCT_scaled_size; +#endif + /* The downsampled dimensions are the component's actual, unpadded number + * of samples at the main buffer (preprocessing/compression interface), thus + * downsampled_width = ceil(image_width * Hi/Hmax) + * and similarly for height. For decompression, IDCT scaling is included, so + * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE) + */ + JDIMENSION downsampled_width; /* actual width in samples */ + JDIMENSION downsampled_height; /* actual height in samples */ + /* This flag is used only for decompression. In cases where some of the + * components will be ignored (eg grayscale output from YCbCr image), + * we can skip most computations for the unused components. + */ + boolean component_needed; /* do we need the value of this component? */ + + /* These values are computed before starting a scan of the component. */ + /* The decompressor output side may not use these variables. */ + int MCU_width; /* number of blocks per MCU, horizontally */ + int MCU_height; /* number of blocks per MCU, vertically */ + int MCU_blocks; /* MCU_width * MCU_height */ + int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */ + int last_col_width; /* # of non-dummy blocks across in last MCU */ + int last_row_height; /* # of non-dummy blocks down in last MCU */ + + /* Saved quantization table for component; NULL if none yet saved. + * See jdinput.c comments about the need for this information. + * This field is currently used only for decompression. + */ + JQUANT_TBL * quant_table; + + /* Private per-component storage for DCT or IDCT subsystem. */ + void * dct_table; +} jpeg_component_info; + + +/* The script for encoding a multiple-scan file is an array of these: */ + +typedef struct { + int comps_in_scan; /* number of components encoded in this scan */ + int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */ + int Ss, Se; /* progressive JPEG spectral selection parms */ + int Ah, Al; /* progressive JPEG successive approx. parms */ +} jpeg_scan_info; + +/* The decompressor can save APPn and COM markers in a list of these: */ + +typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr; + +struct jpeg_marker_struct { + jpeg_saved_marker_ptr next; /* next in list, or NULL */ + UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */ + unsigned int original_length; /* # bytes of data in the file */ + unsigned int data_length; /* # bytes of data saved at data[] */ + JOCTET FAR * data; /* the data contained in the marker */ + /* the marker length word is not counted in data_length or original_length */ +}; + +/* Known color spaces. */ + +#define JCS_EXTENSIONS 1 +#define JCS_ALPHA_EXTENSIONS 1 + +typedef enum { + JCS_UNKNOWN, /* error/unspecified */ + JCS_GRAYSCALE, /* monochrome */ + JCS_RGB, /* red/green/blue as specified by the RGB_RED, RGB_GREEN, + RGB_BLUE, and RGB_PIXELSIZE macros */ + JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ + JCS_CMYK, /* C/M/Y/K */ + JCS_YCCK, /* Y/Cb/Cr/K */ + JCS_EXT_RGB, /* red/green/blue */ + JCS_EXT_RGBX, /* red/green/blue/x */ + JCS_EXT_BGR, /* blue/green/red */ + JCS_EXT_BGRX, /* blue/green/red/x */ + JCS_EXT_XBGR, /* x/blue/green/red */ + JCS_EXT_XRGB, /* x/red/green/blue */ + /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, + JCS_EXT_XBGR, or JCS_EXT_XRGB during decompression, the X byte is + undefined, and in order to ensure the best performance, + libjpeg-turbo can set that byte to whatever value it wishes. Use + the following colorspace constants to ensure that the X byte is set + to 0xFF, so that it can be interpreted as an opaque alpha + channel. */ + JCS_EXT_RGBA, /* red/green/blue/alpha */ + JCS_EXT_BGRA, /* blue/green/red/alpha */ + JCS_EXT_ABGR, /* alpha/blue/green/red */ + JCS_EXT_ARGB /* alpha/red/green/blue */ +} J_COLOR_SPACE; + +/* DCT/IDCT algorithm options. */ + +typedef enum { + JDCT_ISLOW, /* slow but accurate integer algorithm */ + JDCT_IFAST, /* faster, less accurate integer method */ + JDCT_FLOAT /* floating-point: accurate, fast on fast HW */ +} J_DCT_METHOD; + +#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */ +#define JDCT_DEFAULT JDCT_ISLOW +#endif +#ifndef JDCT_FASTEST /* may be overridden in jconfig.h */ +#define JDCT_FASTEST JDCT_IFAST +#endif + +/* Dithering options for decompression. */ + +typedef enum { + JDITHER_NONE, /* no dithering */ + JDITHER_ORDERED, /* simple ordered dither */ + JDITHER_FS /* Floyd-Steinberg error diffusion dither */ +} J_DITHER_MODE; + + +/* Common fields between JPEG compression and decompression master structs. */ + +#define jpeg_common_fields \ + struct jpeg_error_mgr * err; /* Error handler module */\ + struct jpeg_memory_mgr * mem; /* Memory manager module */\ + struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\ + void * client_data; /* Available for use by application */\ + boolean is_decompressor; /* So common code can tell which is which */\ + int global_state /* For checking call sequence validity */ + +/* Routines that are to be used by both halves of the library are declared + * to receive a pointer to this structure. There are no actual instances of + * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct. + */ +struct jpeg_common_struct { + jpeg_common_fields; /* Fields common to both master struct types */ + /* Additional fields follow in an actual jpeg_compress_struct or + * jpeg_decompress_struct. All three structs must agree on these + * initial fields! (This would be a lot cleaner in C++.) + */ +}; + +typedef struct jpeg_common_struct * j_common_ptr; +typedef struct jpeg_compress_struct * j_compress_ptr; +typedef struct jpeg_decompress_struct * j_decompress_ptr; + + +/* Master record for a compression instance */ + +struct jpeg_compress_struct { + jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */ + + /* Destination for compressed data */ + struct jpeg_destination_mgr * dest; + + /* Description of source image --- these fields must be filled in by + * outer application before starting compression. in_color_space must + * be correct before you can even call jpeg_set_defaults(). + */ + + JDIMENSION image_width; /* input image width */ + JDIMENSION image_height; /* input image height */ + int input_components; /* # of color components in input image */ + J_COLOR_SPACE in_color_space; /* colorspace of input image */ + + double input_gamma; /* image gamma of input image */ + + /* Compression parameters --- these fields must be set before calling + * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to + * initialize everything to reasonable defaults, then changing anything + * the application specifically wants to change. That way you won't get + * burnt when new parameters are added. Also note that there are several + * helper routines to simplify changing parameters. + */ + +#if JPEG_LIB_VERSION >= 70 + unsigned int scale_num, scale_denom; /* fraction by which to scale image */ + + JDIMENSION jpeg_width; /* scaled JPEG image width */ + JDIMENSION jpeg_height; /* scaled JPEG image height */ + /* Dimensions of actual JPEG image that will be written to file, + * derived from input dimensions by scaling factors above. + * These fields are computed by jpeg_start_compress(). + * You can also use jpeg_calc_jpeg_dimensions() to determine these values + * in advance of calling jpeg_start_compress(). + */ +#endif + + int data_precision; /* bits of precision in image data */ + + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; +#if JPEG_LIB_VERSION >= 70 + int q_scale_factor[NUM_QUANT_TBLS]; +#endif + /* ptrs to coefficient quantization tables, or NULL if not defined, + * and corresponding scale factors (percentage, initialized 100). + */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + int num_scans; /* # of entries in scan_info array */ + const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */ + /* The default value of scan_info is NULL, which causes a single-scan + * sequential JPEG file to be emitted. To create a multi-scan file, + * set num_scans and scan_info to point to an array of scan definitions. + */ + + boolean raw_data_in; /* TRUE=caller supplies downsampled data */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + boolean optimize_coding; /* TRUE=optimize entropy encoding parms */ + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ +#if JPEG_LIB_VERSION >= 70 + boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */ +#endif + int smoothing_factor; /* 1..100, or 0 for no input smoothing */ + J_DCT_METHOD dct_method; /* DCT algorithm selector */ + + /* The restart interval can be specified in absolute MCUs by setting + * restart_interval, or in MCU rows by setting restart_in_rows + * (in which case the correct restart_interval will be figured + * for each scan). + */ + unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */ + int restart_in_rows; /* if > 0, MCU rows per restart interval */ + + /* Parameters controlling emission of special markers. */ + + boolean write_JFIF_header; /* should a JFIF marker be written? */ + UINT8 JFIF_major_version; /* What to write for the JFIF version number */ + UINT8 JFIF_minor_version; + /* These three values are not used by the JPEG code, merely copied */ + /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */ + /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */ + /* ratio is defined by X_density/Y_density even when density_unit=0. */ + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean write_Adobe_marker; /* should an Adobe marker be written? */ + + /* State variable: index of next scanline to be written to + * jpeg_write_scanlines(). Application may use this to control its + * processing loop, e.g., "while (next_scanline < image_height)". + */ + + JDIMENSION next_scanline; /* 0 .. image_height-1 */ + + /* Remaining fields are known throughout compressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during compression startup + */ + boolean progressive_mode; /* TRUE if scan script uses progressive mode */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + +#if JPEG_LIB_VERSION >= 70 + int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ + int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ +#endif + + JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ + /* The coefficient controller receives data in units of MCU rows as defined + * for fully interleaved scans (whether the JPEG file is interleaved or not). + * There are v_samp_factor * DCTSIZE sample rows of each component in an + * "iMCU" (interleaved MCU) row. + */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[C_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + +#if JPEG_LIB_VERSION >= 80 + int block_size; /* the basic DCT block size: 1..16 */ + const int * natural_order; /* natural-order position array */ + int lim_Se; /* min( Se, DCTSIZE2-1 ) */ +#endif + + /* + * Links to compression subobjects (methods and private variables of modules) + */ + struct jpeg_comp_master * master; + struct jpeg_c_main_controller * main; + struct jpeg_c_prep_controller * prep; + struct jpeg_c_coef_controller * coef; + struct jpeg_marker_writer * marker; + struct jpeg_color_converter * cconvert; + struct jpeg_downsampler * downsample; + struct jpeg_forward_dct * fdct; + struct jpeg_entropy_encoder * entropy; + jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */ + int script_space_size; +}; + + +/* Master record for a decompression instance */ + +struct jpeg_decompress_struct { + jpeg_common_fields; /* Fields shared with jpeg_compress_struct */ + + /* Source of compressed data */ + struct jpeg_source_mgr * src; + + /* Basic description of image --- filled in by jpeg_read_header(). */ + /* Application may inspect these values to decide how to process image. */ + + JDIMENSION image_width; /* nominal image width (from SOF marker) */ + JDIMENSION image_height; /* nominal image height */ + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + /* Decompression processing parameters --- these fields must be set before + * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes + * them to default values. + */ + + J_COLOR_SPACE out_color_space; /* colorspace for output */ + + unsigned int scale_num, scale_denom; /* fraction by which to scale image */ + + double output_gamma; /* image gamma wanted in output */ + + boolean buffered_image; /* TRUE=multiple output passes */ + boolean raw_data_out; /* TRUE=downsampled data wanted */ + + J_DCT_METHOD dct_method; /* IDCT algorithm selector */ + boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */ + boolean do_block_smoothing; /* TRUE=apply interblock smoothing */ + + boolean quantize_colors; /* TRUE=colormapped output wanted */ + /* the following are ignored if not quantize_colors: */ + J_DITHER_MODE dither_mode; /* type of color dithering to use */ + boolean two_pass_quantize; /* TRUE=use two-pass color quantization */ + int desired_number_of_colors; /* max # colors to use in created colormap */ + /* these are significant only in buffered-image mode: */ + boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */ + boolean enable_external_quant;/* enable future use of external colormap */ + boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */ + + /* Description of actual output image that will be returned to application. + * These fields are computed by jpeg_start_decompress(). + * You can also use jpeg_calc_output_dimensions() to determine these values + * in advance of calling jpeg_start_decompress(). + */ + + JDIMENSION output_width; /* scaled image width */ + JDIMENSION output_height; /* scaled image height */ + int out_color_components; /* # of color components in out_color_space */ + int output_components; /* # of color components returned */ + /* output_components is 1 (a colormap index) when quantizing colors; + * otherwise it equals out_color_components. + */ + int rec_outbuf_height; /* min recommended height of scanline buffer */ + /* If the buffer passed to jpeg_read_scanlines() is less than this many rows + * high, space and time will be wasted due to unnecessary data copying. + * Usually rec_outbuf_height will be 1 or 2, at most 4. + */ + + /* When quantizing colors, the output colormap is described by these fields. + * The application can supply a colormap by setting colormap non-NULL before + * calling jpeg_start_decompress; otherwise a colormap is created during + * jpeg_start_decompress or jpeg_start_output. + * The map has out_color_components rows and actual_number_of_colors columns. + */ + int actual_number_of_colors; /* number of entries in use */ + JSAMPARRAY colormap; /* The color map as a 2-D pixel array */ + + /* State variables: these variables indicate the progress of decompression. + * The application may examine these but must not modify them. + */ + + /* Row index of next scanline to be read from jpeg_read_scanlines(). + * Application may use this to control its processing loop, e.g., + * "while (output_scanline < output_height)". + */ + JDIMENSION output_scanline; /* 0 .. output_height-1 */ + + /* Current input scan number and number of iMCU rows completed in scan. + * These indicate the progress of the decompressor input side. + */ + int input_scan_number; /* Number of SOS markers seen so far */ + JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */ + + /* The "output scan number" is the notional scan being displayed by the + * output side. The decompressor will not allow output scan/row number + * to get ahead of input scan/row, but it can fall arbitrarily far behind. + */ + int output_scan_number; /* Nominal scan number being displayed */ + JDIMENSION output_iMCU_row; /* Number of iMCU rows read */ + + /* Current progression status. coef_bits[c][i] indicates the precision + * with which component c's DCT coefficient i (in zigzag order) is known. + * It is -1 when no data has yet been received, otherwise it is the point + * transform (shift) value for the most recent scan of the coefficient + * (thus, 0 at completion of the progression). + * This pointer is NULL when reading a non-progressive file. + */ + int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */ + + /* Internal JPEG parameters --- the application usually need not look at + * these fields. Note that the decompressor output side may not use + * any parameters that can change between scans. + */ + + /* Quantization and Huffman tables are carried forward across input + * datastreams when processing abbreviated JPEG datastreams. + */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; + /* ptrs to coefficient quantization tables, or NULL if not defined */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + /* These parameters are never carried across datastreams, since they + * are given in SOF/SOS markers or defined to be reset by SOI. + */ + + int data_precision; /* bits of precision in image data */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + +#if JPEG_LIB_VERSION >= 80 + boolean is_baseline; /* TRUE if Baseline SOF0 encountered */ +#endif + boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */ + + /* These fields record data obtained from optional markers recognized by + * the JPEG library. + */ + boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */ + /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */ + UINT8 JFIF_major_version; /* JFIF version number */ + UINT8 JFIF_minor_version; + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */ + UINT8 Adobe_transform; /* Color transform code from Adobe marker */ + + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ + + /* Aside from the specific data retained from APPn markers known to the + * library, the uninterpreted contents of any or all APPn and COM markers + * can be saved in a list for examination by the application. + */ + jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */ + + /* Remaining fields are known throughout decompressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during decompression startup + */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + +#if JPEG_LIB_VERSION >= 70 + int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ + int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ +#else + int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */ +#endif + + JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */ + /* The coefficient controller's input and output progress is measured in + * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows + * in fully interleaved JPEG scans, but are used whether the scan is + * interleaved or not. We define an iMCU row as v_samp_factor DCT block + * rows of each component. Therefore, the IDCT output contains + * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row. + */ + + JSAMPLE * sample_range_limit; /* table for fast range-limiting */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + * Note that the decompressor output side must not use these fields. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[D_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + +#if JPEG_LIB_VERSION >= 80 + /* These fields are derived from Se of first SOS marker. + */ + int block_size; /* the basic DCT block size: 1..16 */ + const int * natural_order; /* natural-order position array for entropy decode */ + int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */ +#endif + + /* This field is shared between entropy decoder and marker parser. + * It is either zero or the code of a JPEG marker that has been + * read from the data source, but has not yet been processed. + */ + int unread_marker; + + /* + * Links to decompression subobjects (methods, private variables of modules) + */ + struct jpeg_decomp_master * master; + struct jpeg_d_main_controller * main; + struct jpeg_d_coef_controller * coef; + struct jpeg_d_post_controller * post; + struct jpeg_input_controller * inputctl; + struct jpeg_marker_reader * marker; + struct jpeg_entropy_decoder * entropy; + struct jpeg_inverse_dct * idct; + struct jpeg_upsampler * upsample; + struct jpeg_color_deconverter * cconvert; + struct jpeg_color_quantizer * cquantize; +}; + + +/* "Object" declarations for JPEG modules that may be supplied or called + * directly by the surrounding application. + * As with all objects in the JPEG library, these structs only define the + * publicly visible methods and state variables of a module. Additional + * private fields may exist after the public ones. + */ + + +/* Error handler object */ + +struct jpeg_error_mgr { + /* Error exit handler: does not return to caller */ + JMETHOD(void, error_exit, (j_common_ptr cinfo)); + /* Conditionally emit a trace or warning message */ + JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); + /* Routine that actually outputs a trace or error message */ + JMETHOD(void, output_message, (j_common_ptr cinfo)); + /* Format a message string for the most recent JPEG error or message */ + JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer)); +#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */ + /* Reset error state variables at start of a new image */ + JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); + + /* The message ID code and any parameters are saved here. + * A message can have one string parameter or up to 8 int parameters. + */ + int msg_code; +#define JMSG_STR_PARM_MAX 80 + union { + int i[8]; + char s[JMSG_STR_PARM_MAX]; + } msg_parm; + + /* Standard state variables for error facility */ + + int trace_level; /* max msg_level that will be displayed */ + + /* For recoverable corrupt-data errors, we emit a warning message, + * but keep going unless emit_message chooses to abort. emit_message + * should count warnings in num_warnings. The surrounding application + * can check for bad data by seeing if num_warnings is nonzero at the + * end of processing. + */ + long num_warnings; /* number of corrupt-data warnings */ + + /* These fields point to the table(s) of error message strings. + * An application can change the table pointer to switch to a different + * message list (typically, to change the language in which errors are + * reported). Some applications may wish to add additional error codes + * that will be handled by the JPEG library error mechanism; the second + * table pointer is used for this purpose. + * + * First table includes all errors generated by JPEG library itself. + * Error code 0 is reserved for a "no such error string" message. + */ + const char * const * jpeg_message_table; /* Library errors */ + int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */ + /* Second table can be added by application (see cjpeg/djpeg for example). + * It contains strings numbered first_addon_message..last_addon_message. + */ + const char * const * addon_message_table; /* Non-library errors */ + int first_addon_message; /* code for first string in addon table */ + int last_addon_message; /* code for last string in addon table */ +}; + + +/* Progress monitor object */ + +struct jpeg_progress_mgr { + JMETHOD(void, progress_monitor, (j_common_ptr cinfo)); + + long pass_counter; /* work units completed in this pass */ + long pass_limit; /* total number of work units in this pass */ + int completed_passes; /* passes completed so far */ + int total_passes; /* total number of passes expected */ +}; + + +/* Data destination object for compression */ + +struct jpeg_destination_mgr { + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + + JMETHOD(void, init_destination, (j_compress_ptr cinfo)); + JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo)); + JMETHOD(void, term_destination, (j_compress_ptr cinfo)); +}; + + +/* Data source object for decompression */ + +struct jpeg_source_mgr { + const JOCTET * next_input_byte; /* => next byte to read from buffer */ + size_t bytes_in_buffer; /* # of bytes remaining in buffer */ + + JMETHOD(void, init_source, (j_decompress_ptr cinfo)); + JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo)); + JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes)); + JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired)); + JMETHOD(void, term_source, (j_decompress_ptr cinfo)); +}; + + +/* Memory manager object. + * Allocates "small" objects (a few K total), "large" objects (tens of K), + * and "really big" objects (virtual arrays with backing store if needed). + * The memory manager does not allow individual objects to be freed; rather, + * each created object is assigned to a pool, and whole pools can be freed + * at once. This is faster and more convenient than remembering exactly what + * to free, especially where malloc()/free() are not too speedy. + * NB: alloc routines never return NULL. They exit to error_exit if not + * successful. + */ + +#define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */ +#define JPOOL_IMAGE 1 /* lasts until done with image/datastream */ +#define JPOOL_NUMPOOLS 2 + +typedef struct jvirt_sarray_control * jvirt_sarray_ptr; +typedef struct jvirt_barray_control * jvirt_barray_ptr; + + +struct jpeg_memory_mgr { + /* Method pointers */ + JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, + JDIMENSION samplesperrow, + JDIMENSION numrows)); + JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, + JDIMENSION blocksperrow, + JDIMENSION numrows)); + JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION samplesperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION blocksperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo)); + JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, + jvirt_sarray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, + jvirt_barray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id)); + JMETHOD(void, self_destruct, (j_common_ptr cinfo)); + + /* Limit on memory allocation for this JPEG object. (Note that this is + * merely advisory, not a guaranteed maximum; it only affects the space + * used for virtual-array buffers.) May be changed by outer application + * after creating the JPEG object. + */ + long max_memory_to_use; + + /* Maximum allocation request accepted by alloc_large. */ + long max_alloc_chunk; +}; + + +/* Routine signature for application-supplied marker processing methods. + * Need not pass marker code since it is stored in cinfo->unread_marker. + */ +typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo)); + + +/* Declarations for routines called by application. + * The JPP macro hides prototype parameters from compilers that can't cope. + * Note JPP requires double parentheses. + */ + +#ifdef HAVE_PROTOTYPES +#define JPP(arglist) arglist +#else +#define JPP(arglist) () +#endif + + +/* Short forms of external names for systems with brain-damaged linkers. + * We shorten external names to be unique in the first six letters, which + * is good enough for all known systems. + * (If your compiler itself needs names to be unique in less than 15 + * characters, you are out of luck. Get a better compiler.) + */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_std_error jStdError +#define jpeg_CreateCompress jCreaCompress +#define jpeg_CreateDecompress jCreaDecompress +#define jpeg_destroy_compress jDestCompress +#define jpeg_destroy_decompress jDestDecompress +#define jpeg_stdio_dest jStdDest +#define jpeg_stdio_src jStdSrc +#if JPEG_LIB_VERSION >= 80 +#define jpeg_mem_dest jMemDest +#define jpeg_mem_src jMemSrc +#endif +#define jpeg_set_defaults jSetDefaults +#define jpeg_set_colorspace jSetColorspace +#define jpeg_default_colorspace jDefColorspace +#define jpeg_set_quality jSetQuality +#define jpeg_set_linear_quality jSetLQuality +#if JPEG_LIB_VERSION >= 70 +#define jpeg_default_qtables jDefQTables +#endif +#define jpeg_add_quant_table jAddQuantTable +#define jpeg_quality_scaling jQualityScaling +#define jpeg_simple_progression jSimProgress +#define jpeg_suppress_tables jSuppressTables +#define jpeg_alloc_quant_table jAlcQTable +#define jpeg_alloc_huff_table jAlcHTable +#define jpeg_start_compress jStrtCompress +#define jpeg_write_scanlines jWrtScanlines +#define jpeg_finish_compress jFinCompress +#if JPEG_LIB_VERSION >= 70 +#define jpeg_calc_jpeg_dimensions jCjpegDimensions +#endif +#define jpeg_write_raw_data jWrtRawData +#define jpeg_write_marker jWrtMarker +#define jpeg_write_m_header jWrtMHeader +#define jpeg_write_m_byte jWrtMByte +#define jpeg_write_tables jWrtTables +#define jpeg_read_header jReadHeader +#define jpeg_start_decompress jStrtDecompress +#define jpeg_read_scanlines jReadScanlines +#define jpeg_finish_decompress jFinDecompress +#define jpeg_read_raw_data jReadRawData +#define jpeg_has_multiple_scans jHasMultScn +#define jpeg_start_output jStrtOutput +#define jpeg_finish_output jFinOutput +#define jpeg_input_complete jInComplete +#define jpeg_new_colormap jNewCMap +#define jpeg_consume_input jConsumeInput +#if JPEG_LIB_VERSION >= 80 +#define jpeg_core_output_dimensions jCoreDimensions +#endif +#define jpeg_calc_output_dimensions jCalcDimensions +#define jpeg_save_markers jSaveMarkers +#define jpeg_set_marker_processor jSetMarker +#define jpeg_read_coefficients jReadCoefs +#define jpeg_write_coefficients jWrtCoefs +#define jpeg_copy_critical_parameters jCopyCrit +#define jpeg_abort_compress jAbrtCompress +#define jpeg_abort_decompress jAbrtDecompress +#define jpeg_abort jAbort +#define jpeg_destroy jDestroy +#define jpeg_resync_to_restart jResyncRestart +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + + +/* Default error-management setup */ +EXTERN(struct jpeg_error_mgr *) jpeg_std_error + JPP((struct jpeg_error_mgr * err)); + +/* Initialization of JPEG compression objects. + * jpeg_create_compress() and jpeg_create_decompress() are the exported + * names that applications should call. These expand to calls on + * jpeg_CreateCompress and jpeg_CreateDecompress with additional information + * passed for version mismatch checking. + * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. + */ +#define jpeg_create_compress(cinfo) \ + jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_compress_struct)) +#define jpeg_create_decompress(cinfo) \ + jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_decompress_struct)) +EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo, + int version, size_t structsize)); +EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo, + int version, size_t structsize)); +/* Destruction of JPEG compression objects */ +EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); + +/* Standard data source and destination managers: stdio streams. */ +/* Caller is responsible for opening the file before and closing after. */ +EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); +EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); + +#if JPEG_LIB_VERSION >= 80 +/* Data source and destination managers: memory buffers. */ +EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo, + unsigned char ** outbuffer, + unsigned long * outsize)); +EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo, + unsigned char * inbuffer, + unsigned long insize)); +#endif + +/* Default parameter setup for compression */ +EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); +/* Compression parameter setup aids */ +EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, + J_COLOR_SPACE colorspace)); +EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, + boolean force_baseline)); +EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, + int scale_factor, + boolean force_baseline)); +#if JPEG_LIB_VERSION >= 70 +EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo, + boolean force_baseline)); +#endif +EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, + const unsigned int *basic_table, + int scale_factor, + boolean force_baseline)); +EXTERN(int) jpeg_quality_scaling JPP((int quality)); +EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, + boolean suppress)); +EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo)); +EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo)); + +/* Main entry points for compression */ +EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, + boolean write_all_tables)); +EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION num_lines)); +EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); + +#if JPEG_LIB_VERSION >= 70 +/* Precalculate JPEG dimensions for current compression parameters. */ +EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo)); +#endif + +/* Replaces jpeg_write_scanlines when writing raw downsampled data. */ +EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION num_lines)); + +/* Write a special marker. See libjpeg.txt concerning safe usage. */ +EXTERN(void) jpeg_write_marker + JPP((j_compress_ptr cinfo, int marker, + const JOCTET * dataptr, unsigned int datalen)); +/* Same, but piecemeal. */ +EXTERN(void) jpeg_write_m_header + JPP((j_compress_ptr cinfo, int marker, unsigned int datalen)); +EXTERN(void) jpeg_write_m_byte + JPP((j_compress_ptr cinfo, int val)); + +/* Alternate compression function: just write an abbreviated table file */ +EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo)); + +/* Decompression startup: read start of JPEG datastream to see what's there */ +EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo, + boolean require_image)); +/* Return value is one of: */ +#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ +#define JPEG_HEADER_OK 1 /* Found valid image datastream */ +#define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */ +/* If you pass require_image = TRUE (normal case), you need not check for + * a TABLES_ONLY return code; an abbreviated file will cause an error exit. + * JPEG_SUSPENDED is only possible if you use a data source module that can + * give a suspension return (the stdio source module doesn't). + */ + +/* Main entry points for decompression */ +EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo)); +EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION max_lines)); +EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo)); + +/* Replaces jpeg_read_scanlines when reading raw downsampled data. */ +EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION max_lines)); + +/* Additional entry points for buffered-image mode. */ +EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo)); +EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo, + int scan_number)); +EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo)); +EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo)); +EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo)); +EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo)); +/* Return value is one of: */ +/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ +#define JPEG_REACHED_SOS 1 /* Reached start of new scan */ +#define JPEG_REACHED_EOI 2 /* Reached end of image */ +#define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */ +#define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */ + +/* Precalculate output dimensions for current decompression parameters. */ +#if JPEG_LIB_VERSION >= 80 +EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo)); +#endif +EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); + +/* Control saving of COM and APPn markers into marker_list. */ +EXTERN(void) jpeg_save_markers + JPP((j_decompress_ptr cinfo, int marker_code, + unsigned int length_limit)); + +/* Install a special processing method for COM or APPn markers. */ +EXTERN(void) jpeg_set_marker_processor + JPP((j_decompress_ptr cinfo, int marker_code, + jpeg_marker_parser_method routine)); + +/* Read or write raw DCT coefficients --- useful for lossless transcoding. */ +EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo)); +EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays)); +EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo, + j_compress_ptr dstinfo)); + +/* If you choose to abort compression or decompression before completing + * jpeg_finish_(de)compress, then you need to clean up to release memory, + * temporary files, etc. You can just call jpeg_destroy_(de)compress + * if you're done with the JPEG object, but if you want to clean it up and + * reuse it, call this: + */ +EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo)); + +/* Generic versions of jpeg_abort and jpeg_destroy that work on either + * flavor of JPEG object. These may be more convenient in some places. + */ +EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo)); +EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo)); + +/* Default restart-marker-resync procedure for use by data source modules */ +EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo, + int desired)); + + +/* These marker codes are exported since applications and data source modules + * are likely to want to use them. + */ + +#define JPEG_RST0 0xD0 /* RST0 marker code */ +#define JPEG_EOI 0xD9 /* EOI marker code */ +#define JPEG_APP0 0xE0 /* APP0 marker code */ +#define JPEG_COM 0xFE /* COM marker code */ + + +/* If we have a brain-damaged compiler that emits warnings (or worse, errors) + * for structure definitions that are never filled in, keep it quiet by + * supplying dummy definitions for the various substructures. + */ + +#ifdef INCOMPLETE_TYPES_BROKEN +#ifndef JPEG_INTERNALS /* will be defined in jpegint.h */ +struct jvirt_sarray_control { long dummy; }; +struct jvirt_barray_control { long dummy; }; +struct jpeg_comp_master { long dummy; }; +struct jpeg_c_main_controller { long dummy; }; +struct jpeg_c_prep_controller { long dummy; }; +struct jpeg_c_coef_controller { long dummy; }; +struct jpeg_marker_writer { long dummy; }; +struct jpeg_color_converter { long dummy; }; +struct jpeg_downsampler { long dummy; }; +struct jpeg_forward_dct { long dummy; }; +struct jpeg_entropy_encoder { long dummy; }; +struct jpeg_decomp_master { long dummy; }; +struct jpeg_d_main_controller { long dummy; }; +struct jpeg_d_coef_controller { long dummy; }; +struct jpeg_d_post_controller { long dummy; }; +struct jpeg_input_controller { long dummy; }; +struct jpeg_marker_reader { long dummy; }; +struct jpeg_entropy_decoder { long dummy; }; +struct jpeg_inverse_dct { long dummy; }; +struct jpeg_upsampler { long dummy; }; +struct jpeg_color_deconverter { long dummy; }; +struct jpeg_color_quantizer { long dummy; }; +#endif /* JPEG_INTERNALS */ +#endif /* INCOMPLETE_TYPES_BROKEN */ + + +/* + * The JPEG library modules define JPEG_INTERNALS before including this file. + * The internal structure declarations are read only when that is true. + * Applications using the library should not include jpegint.h, but may wish + * to include jerror.h. + */ + +#ifdef JPEG_INTERNALS +#include "jpegint.h" /* fetch private declarations */ +#include "jerror.h" /* fetch error codes too */ +#endif + +#ifdef __cplusplus +#ifndef DONT_USE_EXTERN_C +} +#endif +#endif + +#endif /* JPEGLIB_H */ diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jsimd.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/jsimd.h new file mode 100755 index 0000000..3fa2c43 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jsimd.h @@ -0,0 +1,98 @@ +/* + * jsimd.h + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + */ + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jsimd_can_rgb_ycc jSCanRgbYcc +#define jsimd_can_rgb_gray jSCanRgbGry +#define jsimd_can_ycc_rgb jSCanYccRgb +#define jsimd_rgb_ycc_convert jSRgbYccConv +#define jsimd_rgb_gray_convert jSRgbGryConv +#define jsimd_ycc_rgb_convert jSYccRgbConv +#define jsimd_can_h2v2_downsample jSCanH2V2Down +#define jsimd_can_h2v1_downsample jSCanH2V1Down +#define jsimd_h2v2_downsample jSH2V2Down +#define jsimd_h2v1_downsample jSH2V1Down +#define jsimd_can_h2v2_upsample jSCanH2V2Up +#define jsimd_can_h2v1_upsample jSCanH2V1Up +#define jsimd_h2v2_upsample jSH2V2Up +#define jsimd_h2v1_upsample jSH2V1Up +#define jsimd_can_h2v2_fancy_upsample jSCanH2V2FUp +#define jsimd_can_h2v1_fancy_upsample jSCanH2V1FUp +#define jsimd_h2v2_fancy_upsample jSH2V2FUp +#define jsimd_h2v1_fancy_upsample jSH2V1FUp +#define jsimd_can_h2v2_merged_upsample jSCanH2V2MUp +#define jsimd_can_h2v1_merged_upsample jSCanH2V1MUp +#define jsimd_h2v2_merged_upsample jSH2V2MUp +#define jsimd_h2v1_merged_upsample jSH2V1MUp +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +EXTERN(int) jsimd_can_rgb_ycc JPP((void)); +EXTERN(int) jsimd_can_rgb_gray JPP((void)); +EXTERN(int) jsimd_can_ycc_rgb JPP((void)); + +EXTERN(void) jsimd_rgb_ycc_convert + JPP((j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_rgb_gray_convert + JPP((j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_ycc_rgb_convert + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +EXTERN(int) jsimd_can_h2v2_downsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_downsample JPP((void)); + +EXTERN(void) jsimd_h2v2_downsample + JPP((j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample + JPP((j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +EXTERN(int) jsimd_can_h2v2_upsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_upsample JPP((void)); + +EXTERN(void) jsimd_h2v2_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(int) jsimd_can_h2v2_fancy_upsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_fancy_upsample JPP((void)); + +EXTERN(void) jsimd_h2v2_fancy_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(int) jsimd_can_h2v2_merged_upsample JPP((void)); +EXTERN(int) jsimd_can_h2v1_merged_upsample JPP((void)); + +EXTERN(void) jsimd_h2v2_merged_upsample + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf)); + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/jsimddct.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/jsimddct.h new file mode 100755 index 0000000..a1c7440 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/jsimddct.h @@ -0,0 +1,102 @@ +/* + * jsimddct.h + * + * Copyright 2009 Pierre Ossman for Cendio AB + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + */ + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jsimd_can_convsamp jSCanConv +#define jsimd_can_convsamp_float jSCanConvF +#define jsimd_convsamp jSConv +#define jsimd_convsamp_float jSConvF +#define jsimd_can_fdct_islow jSCanFDCTIS +#define jsimd_can_fdct_ifast jSCanFDCTIF +#define jsimd_can_fdct_float jSCanFDCTFl +#define jsimd_fdct_islow jSFDCTIS +#define jsimd_fdct_ifast jSFDCTIF +#define jsimd_fdct_float jSFDCTFl +#define jsimd_can_quantize jSCanQuant +#define jsimd_can_quantize_float jSCanQuantF +#define jsimd_quantize jSQuant +#define jsimd_quantize_float jSQuantF +#define jsimd_can_idct_2x2 jSCanIDCT22 +#define jsimd_can_idct_4x4 jSCanIDCT44 +#define jsimd_idct_2x2 jSIDCT22 +#define jsimd_idct_4x4 jSIDCT44 +#define jsimd_can_idct_islow jSCanIDCTIS +#define jsimd_can_idct_ifast jSCanIDCTIF +#define jsimd_can_idct_float jSCanIDCTFl +#define jsimd_idct_islow jSIDCTIS +#define jsimd_idct_ifast jSIDCTIF +#define jsimd_idct_float jSIDCTFl +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +EXTERN(int) jsimd_can_convsamp JPP((void)); +EXTERN(int) jsimd_can_convsamp_float JPP((void)); + +EXTERN(void) jsimd_convsamp JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); +EXTERN(void) jsimd_convsamp_float JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(int) jsimd_can_fdct_islow JPP((void)); +EXTERN(int) jsimd_can_fdct_ifast JPP((void)); +EXTERN(int) jsimd_can_fdct_float JPP((void)); + +EXTERN(void) jsimd_fdct_islow JPP((DCTELEM * data)); +EXTERN(void) jsimd_fdct_ifast JPP((DCTELEM * data)); +EXTERN(void) jsimd_fdct_float JPP((FAST_FLOAT * data)); + +EXTERN(int) jsimd_can_quantize JPP((void)); +EXTERN(int) jsimd_can_quantize_float JPP((void)); + +EXTERN(void) jsimd_quantize JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); +EXTERN(void) jsimd_quantize_float JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(int) jsimd_can_idct_2x2 JPP((void)); +EXTERN(int) jsimd_can_idct_4x4 JPP((void)); + +EXTERN(void) jsimd_idct_2x2 JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4 JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(int) jsimd_can_idct_islow JPP((void)); +EXTERN(int) jsimd_can_idct_ifast JPP((void)); +EXTERN(int) jsimd_can_idct_float JPP((void)); + +EXTERN(void) jsimd_idct_islow JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_float JPP((j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd.h new file mode 100755 index 0000000..3d4751f --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd.h @@ -0,0 +1,670 @@ +/* + * simd/jsimd.h + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + */ + +/* Bitmask for supported acceleration methods */ + +#define JSIMD_NONE 0x00 +#define JSIMD_MMX 0x01 +#define JSIMD_3DNOW 0x02 +#define JSIMD_SSE 0x04 +#define JSIMD_SSE2 0x08 +#define JSIMD_ARM_NEON 0x10 + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_simd_cpu_support jSiCpuSupport +#define jsimd_rgb_ycc_convert_mmx jSRGBYCCM +#define jsimd_extrgb_ycc_convert_mmx jSEXTRGBYCCM +#define jsimd_extrgbx_ycc_convert_mmx jSEXTRGBXYCCM +#define jsimd_extbgr_ycc_convert_mmx jSEXTBGRYCCM +#define jsimd_extbgrx_ycc_convert_mmx jSEXTBGRXYCCM +#define jsimd_extxbgr_ycc_convert_mmx jSEXTXBGRYCCM +#define jsimd_extxrgb_ycc_convert_mmx jSEXTXRGBYCCM +#define jsimd_rgb_gray_convert_mmx jSRGBGRYM +#define jsimd_extrgb_gray_convert_mmx jSEXTRGBGRYM +#define jsimd_extrgbx_gray_convert_mmx jSEXTRGBXGRYM +#define jsimd_extbgr_gray_convert_mmx jSEXTBGRGRYM +#define jsimd_extbgrx_gray_convert_mmx jSEXTBGRXGRYM +#define jsimd_extxbgr_gray_convert_mmx jSEXTXBGRGRYM +#define jsimd_extxrgb_gray_convert_mmx jSEXTXRGBGRYM +#define jsimd_ycc_rgb_convert_mmx jSYCCRGBM +#define jsimd_ycc_extrgb_convert_mmx jSYCCEXTRGBM +#define jsimd_ycc_extrgbx_convert_mmx jSYCCEXTRGBXM +#define jsimd_ycc_extbgr_convert_mmx jSYCCEXTBGRM +#define jsimd_ycc_extbgrx_convert_mmx jSYCCEXTBGRXM +#define jsimd_ycc_extxbgr_convert_mmx jSYCCEXTXBGRM +#define jsimd_ycc_extxrgb_convert_mmx jSYCCEXTXRGBM +#define jconst_rgb_ycc_convert_sse2 jSCRGBYCCS2 +#define jsimd_rgb_ycc_convert_sse2 jSRGBYCCS2 +#define jsimd_extrgb_ycc_convert_sse2 jSEXTRGBYCCS2 +#define jsimd_extrgbx_ycc_convert_sse2 jSEXTRGBXYCCS2 +#define jsimd_extbgr_ycc_convert_sse2 jSEXTBGRYCCS2 +#define jsimd_extbgrx_ycc_convert_sse2 jSEXTBGRXYCCS2 +#define jsimd_extxbgr_ycc_convert_sse2 jSEXTXBGRYCCS2 +#define jsimd_extxrgb_ycc_convert_sse2 jSEXTXRGBYCCS2 +#define jconst_rgb_gray_convert_sse2 jSCRGBGRYS2 +#define jsimd_rgb_gray_convert_sse2 jSRGBGRYS2 +#define jsimd_extrgb_gray_convert_sse2 jSEXTRGBGRYS2 +#define jsimd_extrgbx_gray_convert_sse2 jSEXTRGBXGRYS2 +#define jsimd_extbgr_gray_convert_sse2 jSEXTBGRGRYS2 +#define jsimd_extbgrx_gray_convert_sse2 jSEXTBGRXGRYS2 +#define jsimd_extxbgr_gray_convert_sse2 jSEXTXBGRGRYS2 +#define jsimd_extxrgb_gray_convert_sse2 jSEXTXRGBGRYS2 +#define jconst_ycc_rgb_convert_sse2 jSCYCCRGBS2 +#define jsimd_ycc_rgb_convert_sse2 jSYCCRGBS2 +#define jsimd_ycc_extrgb_convert_sse2 jSYCCEXTRGBS2 +#define jsimd_ycc_extrgbx_convert_sse2 jSYCCEXTRGBXS2 +#define jsimd_ycc_extbgr_convert_sse2 jSYCCEXTBGRS2 +#define jsimd_ycc_extbgrx_convert_sse2 jSYCCEXTBGRXS2 +#define jsimd_ycc_extxbgr_convert_sse2 jSYCCEXTXBGRS2 +#define jsimd_ycc_extxrgb_convert_sse2 jSYCCEXTXRGBS2 +#define jsimd_h2v2_downsample_mmx jSDnH2V2M +#define jsimd_h2v1_downsample_mmx jSDnH2V1M +#define jsimd_h2v2_downsample_sse2 jSDnH2V2S2 +#define jsimd_h2v1_downsample_sse2 jSDnH2V1S2 +#define jsimd_h2v2_upsample_mmx jSUpH2V2M +#define jsimd_h2v1_upsample_mmx jSUpH2V1M +#define jsimd_h2v2_fancy_upsample_mmx jSFUpH2V2M +#define jsimd_h2v1_fancy_upsample_mmx jSFUpH2V1M +#define jsimd_h2v2_merged_upsample_mmx jSMUpH2V2M +#define jsimd_h2v2_extrgb_merged_upsample_mmx jSMUpH2V2EXTRGBM +#define jsimd_h2v2_extrgbx_merged_upsample_mmx jSMUpH2V2EXTRGBXM +#define jsimd_h2v2_extbgr_merged_upsample_mmx jSMUpH2V2EXTBGRM +#define jsimd_h2v2_extbgrx_merged_upsample_mmx jSMUpH2V2EXTBGRXM +#define jsimd_h2v2_extxbgr_merged_upsample_mmx jSMUpH2V2EXTXBGRM +#define jsimd_h2v2_extxrgb_merged_upsample_mmx jSMUpH2V2EXTXRGBM +#define jsimd_h2v1_merged_upsample_mmx jSMUpH2V1M +#define jsimd_h2v1_extrgb_merged_upsample_mmx jSMUpH2V1EXTRGBM +#define jsimd_h2v1_extrgbx_merged_upsample_mmx jSMUpH2V1EXTRGBXM +#define jsimd_h2v1_extbgr_merged_upsample_mmx jSMUpH2V1EXTBGRM +#define jsimd_h2v1_extbgrx_merged_upsample_mmx jSMUpH2V1EXTBGRXM +#define jsimd_h2v1_extxbgr_merged_upsample_mmx jSMUpH2V1EXTXBGRM +#define jsimd_h2v1_extxrgb_merged_upsample_mmx jSMUpH2V1EXTXRGBM +#define jsimd_h2v2_upsample_sse2 jSUpH2V2S2 +#define jsimd_h2v1_upsample_sse2 jSUpH2V1S2 +#define jconst_fancy_upsample_sse2 jSCFUpS2 +#define jsimd_h2v2_fancy_upsample_sse2 jSFUpH2V2S2 +#define jsimd_h2v1_fancy_upsample_sse2 jSFUpH2V1S2 +#define jconst_merged_upsample_sse2 jSCMUpS2 +#define jsimd_h2v2_merged_upsample_sse2 jSMUpH2V2S2 +#define jsimd_h2v2_extrgb_merged_upsample_sse2 jSMUpH2V2EXTRGBS2 +#define jsimd_h2v2_extrgbx_merged_upsample_sse2 jSMUpH2V2EXTRGBXS2 +#define jsimd_h2v2_extbgr_merged_upsample_sse2 jSMUpH2V2EXTBGRS2 +#define jsimd_h2v2_extbgrx_merged_upsample_sse2 jSMUpH2V2EXTBGRXS2 +#define jsimd_h2v2_extxbgr_merged_upsample_sse2 jSMUpH2V2EXTXBGRS2 +#define jsimd_h2v2_extxrgb_merged_upsample_sse2 jSMUpH2V2EXTXRGBS2 +#define jsimd_h2v1_merged_upsample_sse2 jSMUpH2V1S2 +#define jsimd_h2v1_extrgb_merged_upsample_sse2 jSMUpH2V1EXTRGBS2 +#define jsimd_h2v1_extrgbx_merged_upsample_sse2 jSMUpH2V1EXTRGBXS2 +#define jsimd_h2v1_extbgr_merged_upsample_sse2 jSMUpH2V1EXTBGRS2 +#define jsimd_h2v1_extbgrx_merged_upsample_sse2 jSMUpH2V1EXTBGRXS2 +#define jsimd_h2v1_extxbgr_merged_upsample_sse2 jSMUpH2V1EXTXBGRS2 +#define jsimd_h2v1_extxrgb_merged_upsample_sse2 jSMUpH2V1EXTXRGBS2 +#define jsimd_convsamp_mmx jSConvM +#define jsimd_convsamp_sse2 jSConvS2 +#define jsimd_convsamp_float_3dnow jSConvF3D +#define jsimd_convsamp_float_sse jSConvFS +#define jsimd_convsamp_float_sse2 jSConvFS2 +#define jsimd_fdct_islow_mmx jSFDMIS +#define jsimd_fdct_ifast_mmx jSFDMIF +#define jconst_fdct_islow_sse2 jSCFDS2IS +#define jsimd_fdct_islow_sse2 jSFDS2IS +#define jconst_fdct_ifast_sse2 jSCFDS2IF +#define jsimd_fdct_ifast_sse2 jSFDS2IF +#define jsimd_fdct_float_3dnow jSFD3DF +#define jconst_fdct_float_sse jSCFDSF +#define jsimd_fdct_float_sse jSFDSF +#define jsimd_quantize_mmx jSQuantM +#define jsimd_quantize_sse2 jSQuantS2 +#define jsimd_quantize_float_3dnow jSQuantF3D +#define jsimd_quantize_float_sse jSQuantFS +#define jsimd_quantize_float_sse2 jSQuantFS2 +#define jsimd_idct_2x2_mmx jSIDM22 +#define jsimd_idct_4x4_mmx jSIDM44 +#define jconst_idct_red_sse2 jSCIDS2R +#define jsimd_idct_2x2_sse2 jSIDS222 +#define jsimd_idct_4x4_sse2 jSIDS244 +#define jsimd_idct_islow_mmx jSIDMIS +#define jsimd_idct_ifast_mmx jSIDMIF +#define jconst_idct_islow_sse2 jSCIDS2IS +#define jsimd_idct_islow_sse2 jSIDS2IS +#define jconst_idct_ifast_sse2 jSCIDS2IF +#define jsimd_idct_ifast_sse2 jSIDS2IF +#define jsimd_idct_float_3dnow jSID3DF +#define jconst_fdct_float_sse jSCIDSF +#define jsimd_idct_float_sse jSIDSF +#define jconst_fdct_float_sse2 jSCIDS2F +#define jsimd_idct_float_sse2 jSIDS2F +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +/* SIMD Ext: retrieve SIMD/CPU information */ +EXTERN(unsigned int) jpeg_simd_cpu_support JPP((void)); + +/* SIMD Color Space Conversion */ +EXTERN(void) jsimd_rgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_rgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_ycc_rgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +extern const int jconst_rgb_ycc_convert_sse2[]; +EXTERN(void) jsimd_rgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +extern const int jconst_rgb_gray_convert_sse2[]; +EXTERN(void) jsimd_rgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +extern const int jconst_ycc_rgb_convert_sse2[]; +EXTERN(void) jsimd_ycc_rgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +EXTERN(void) jsimd_rgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_ycc_rgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +/* SIMD Downsample */ +EXTERN(void) jsimd_h2v2_downsample_mmx + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample_mmx + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +EXTERN(void) jsimd_h2v2_downsample_sse2 + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample_sse2 + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +/* SIMD Upsample */ +EXTERN(void) jsimd_h2v2_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(void) jsimd_h2v2_fancy_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(void) jsimd_h2v2_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); + +EXTERN(void) jsimd_h2v2_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +extern const int jconst_fancy_upsample_sse2[]; +EXTERN(void) jsimd_h2v2_fancy_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +extern const int jconst_merged_upsample_sse2[]; +EXTERN(void) jsimd_h2v2_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); + +EXTERN(void) jsimd_h2v1_fancy_upsample_neon + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +/* SIMD Sample Conversion */ +EXTERN(void) jsimd_convsamp_mmx JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_sse2 JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_neon JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_float_3dnow JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_convsamp_float_sse JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_convsamp_float_sse2 JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +/* SIMD Forward DCT */ +EXTERN(void) jsimd_fdct_islow_mmx JPP((DCTELEM * data)); +EXTERN(void) jsimd_fdct_ifast_mmx JPP((DCTELEM * data)); + +extern const int jconst_fdct_ifast_sse2[]; +EXTERN(void) jsimd_fdct_islow_sse2 JPP((DCTELEM * data)); +extern const int jconst_fdct_islow_sse2[]; +EXTERN(void) jsimd_fdct_ifast_sse2 JPP((DCTELEM * data)); + +EXTERN(void) jsimd_fdct_ifast_neon JPP((DCTELEM * data)); + +EXTERN(void) jsimd_fdct_float_3dnow JPP((FAST_FLOAT * data)); + +extern const int jconst_fdct_float_sse[]; +EXTERN(void) jsimd_fdct_float_sse JPP((FAST_FLOAT * data)); + +/* SIMD Quantization */ +EXTERN(void) jsimd_quantize_mmx JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_sse2 JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_neon JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_float_3dnow JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_quantize_float_sse JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_quantize_float_sse2 JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +/* SIMD Reduced Inverse DCT */ +EXTERN(void) jsimd_idct_2x2_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_red_sse2[]; +EXTERN(void) jsimd_idct_2x2_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_2x2_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +/* SIMD Inverse DCT */ +EXTERN(void) jsimd_idct_islow_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_islow_sse2[]; +EXTERN(void) jsimd_idct_islow_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +extern const int jconst_idct_ifast_sse2[]; +EXTERN(void) jsimd_idct_ifast_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_islow_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_float_3dnow JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_float_sse[]; +EXTERN(void) jsimd_idct_float_sse JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_float_sse2[]; +EXTERN(void) jsimd_idct_float_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd_arm.c b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd_arm.c new file mode 100755 index 0000000..cae84df --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd_arm.c @@ -0,0 +1,682 @@ +/* + * jsimd_arm.c + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2009-2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + * This file contains the interface between the "normal" portions + * of the library and the SIMD implementations when running on + * ARM architecture. + * + * Based on the stubs from 'jsimd_none.c' + */ + +#define JPEG_INTERNALS +#include "../jinclude.h" +#include "../jpeglib.h" +#include "../jsimd.h" +#include "../jdct.h" +#include "../jsimddct.h" +#include "jsimd.h" + +#include +#include +#include + +static unsigned int simd_support = ~0; + +#if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) + +#define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024) + +LOCAL(int) +check_feature (char *buffer, char *feature) +{ + char *p; + if (*feature == 0) + return 0; + if (strncmp(buffer, "Features", 8) != 0) + return 0; + buffer += 8; + while (isspace(*buffer)) + buffer++; + + /* Check if 'feature' is present in the buffer as a separate word */ + while ((p = strstr(buffer, feature))) { + if (p > buffer && !isspace(*(p - 1))) { + buffer++; + continue; + } + p += strlen(feature); + if (*p != 0 && !isspace(*p)) { + buffer++; + continue; + } + return 1; + } + return 0; +} + +LOCAL(int) +parse_proc_cpuinfo (int bufsize) +{ + char *buffer = (char *)malloc(bufsize); + FILE *fd; + simd_support = 0; + + if (!buffer) + return 0; + + fd = fopen("/proc/cpuinfo", "r"); + if (fd) { + while (fgets(buffer, bufsize, fd)) { + if (!strchr(buffer, '\n') && !feof(fd)) { + /* "impossible" happened - insufficient size of the buffer! */ + fclose(fd); + free(buffer); + return 0; + } + if (check_feature(buffer, "neon")) + simd_support |= JSIMD_ARM_NEON; + } + fclose(fd); + } + free(buffer); + return 1; +} + +#endif + +/* + * Check what SIMD accelerations are supported. + * + * FIXME: This code is racy under a multi-threaded environment. + */ +LOCAL(void) +init_simd (void) +{ + char *env = NULL; +#if !defined(__ARM_NEON__) && defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) + int bufsize = 1024; /* an initial guess for the line buffer size limit */ +#endif + + if (simd_support != ~0U) + return; + + simd_support = 0; + +#if defined(__ARM_NEON__) + simd_support |= JSIMD_ARM_NEON; +#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) + /* We still have a chance to use NEON regardless of globally used + * -mcpu/-mfpu options passed to gcc by performing runtime detection via + * /proc/cpuinfo parsing on linux/android */ + while (!parse_proc_cpuinfo(bufsize)) { + bufsize *= 2; + if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT) + break; + } +#endif + + /* Force different settings through environment variables */ + env = getenv("JSIMD_FORCE_ARM_NEON"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support &= JSIMD_ARM_NEON; + env = getenv("JSIMD_FORCE_NO_SIMD"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support = 0; +} + +GLOBAL(int) +jsimd_can_rgb_ycc (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_rgb_gray (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_ycc_rgb (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_rgb_ycc_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + void (*neonfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); + + switch(cinfo->in_color_space) + { + case JCS_EXT_RGB: + neonfct=jsimd_extrgb_ycc_convert_neon; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + neonfct=jsimd_extrgbx_ycc_convert_neon; + break; + case JCS_EXT_BGR: + neonfct=jsimd_extbgr_ycc_convert_neon; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + neonfct=jsimd_extbgrx_ycc_convert_neon; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + neonfct=jsimd_extxbgr_ycc_convert_neon; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + neonfct=jsimd_extxrgb_ycc_convert_neon; + break; + default: + neonfct=jsimd_extrgb_ycc_convert_neon; + break; + } + + if (simd_support & JSIMD_ARM_NEON) + neonfct(cinfo->image_width, input_buf, + output_buf, output_row, num_rows); +} + +GLOBAL(void) +jsimd_rgb_gray_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ +} + +GLOBAL(void) +jsimd_ycc_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + void (*neonfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + neonfct=jsimd_ycc_extrgb_convert_neon; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + neonfct=jsimd_ycc_extrgbx_convert_neon; + break; + case JCS_EXT_BGR: + neonfct=jsimd_ycc_extbgr_convert_neon; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + neonfct=jsimd_ycc_extbgrx_convert_neon; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + neonfct=jsimd_ycc_extxbgr_convert_neon; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + neonfct=jsimd_ycc_extxrgb_convert_neon; + break; + default: + neonfct=jsimd_ycc_extrgb_convert_neon; + break; + } + + if (simd_support & JSIMD_ARM_NEON) + neonfct(cinfo->output_width, input_buf, + input_row, output_buf, num_rows); +} + +GLOBAL(int) +jsimd_can_h2v2_downsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_downsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ +} + +GLOBAL(void) +jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ +} + +GLOBAL(int) +jsimd_can_h2v2_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ +} + +GLOBAL(void) +jsimd_h2v1_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ +} + +GLOBAL(int) +jsimd_can_h2v2_fancy_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_fancy_upsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ +} + +GLOBAL(void) +jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + if (simd_support & JSIMD_ARM_NEON) + jsimd_h2v1_fancy_upsample_neon(cinfo->max_v_samp_factor, + compptr->downsampled_width, input_data, output_data_ptr); +} + +GLOBAL(int) +jsimd_can_h2v2_merged_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_merged_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ +} + +GLOBAL(void) +jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ +} + +GLOBAL(int) +jsimd_can_convsamp (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_convsamp_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, + DCTELEM * workspace) +{ + if (simd_support & JSIMD_ARM_NEON) + jsimd_convsamp_neon(sample_data, start_col, workspace); +} + +GLOBAL(void) +jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, + FAST_FLOAT * workspace) +{ +} + +GLOBAL(int) +jsimd_can_fdct_islow (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_fdct_ifast (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_fdct_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_fdct_islow (DCTELEM * data) +{ +} + +GLOBAL(void) +jsimd_fdct_ifast (DCTELEM * data) +{ + if (simd_support & JSIMD_ARM_NEON) + jsimd_fdct_ifast_neon(data); +} + +GLOBAL(void) +jsimd_fdct_float (FAST_FLOAT * data) +{ +} + +GLOBAL(int) +jsimd_can_quantize (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_quantize_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors, + DCTELEM * workspace) +{ + if (simd_support & JSIMD_ARM_NEON) + jsimd_quantize_neon(coef_block, divisors, workspace); +} + +GLOBAL(void) +jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, + FAST_FLOAT * workspace) +{ +} + +GLOBAL(int) +jsimd_can_idct_2x2 (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if ((simd_support & JSIMD_ARM_NEON)) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_4x4 (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if ((simd_support & JSIMD_ARM_NEON)) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_2x2_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_4x4_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(int) +jsimd_can_idct_islow (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_ifast (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(IFAST_MULT_TYPE) != 2) + return 0; + if (IFAST_SCALE_BITS != 2) + return 0; + + if ((simd_support & JSIMD_ARM_NEON)) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_islow_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_ifast_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ +} + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd_arm_neon.S b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd_arm_neon.S new file mode 100755 index 0000000..9962b8a --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-arm/jsimd_arm_neon.S @@ -0,0 +1,2397 @@ +/* + * ARM NEON optimizations for libjpeg-turbo + * + * Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * Author: Siarhei Siamashka + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#if defined(__linux__) && defined(__ELF__) +.section .note.GNU-stack,"",%progbits /* mark stack as non-executable */ +#endif + +.text +.fpu neon +.arch armv7a +.object_arch armv4 +.arm + + +#define RESPECT_STRICT_ALIGNMENT 1 + +/*****************************************************************************/ + +/* Supplementary macro for setting function attributes */ +.macro asm_function fname +#ifdef __APPLE__ + .func _\fname + .globl _\fname +_\fname: +#else + .func \fname + .global \fname +#ifdef __ELF__ + .hidden \fname + .type \fname, %function +#endif +\fname: +#endif +.endm + +/* Transpose a block of 4x4 coefficients in four 64-bit registers */ +.macro transpose_4x4 x0, x1, x2, x3 + vtrn.16 \x0, \x1 + vtrn.16 \x2, \x3 + vtrn.32 \x0, \x2 + vtrn.32 \x1, \x3 +.endm + +#define CENTERJSAMPLE 128 + +/*****************************************************************************/ + +/* + * Perform dequantization and inverse DCT on one block of coefficients. + * + * GLOBAL(void) + * jsimd_idct_islow_neon (void * dct_table, JCOEFPTR coef_block, + * JSAMPARRAY output_buf, JDIMENSION output_col) + */ + +#define FIX_0_298631336 (2446) +#define FIX_0_390180644 (3196) +#define FIX_0_541196100 (4433) +#define FIX_0_765366865 (6270) +#define FIX_0_899976223 (7373) +#define FIX_1_175875602 (9633) +#define FIX_1_501321110 (12299) +#define FIX_1_847759065 (15137) +#define FIX_1_961570560 (16069) +#define FIX_2_053119869 (16819) +#define FIX_2_562915447 (20995) +#define FIX_3_072711026 (25172) + +#define FIX_1_175875602_MINUS_1_961570560 (FIX_1_175875602 - FIX_1_961570560) +#define FIX_1_175875602_MINUS_0_390180644 (FIX_1_175875602 - FIX_0_390180644) +#define FIX_0_541196100_MINUS_1_847759065 (FIX_0_541196100 - FIX_1_847759065) +#define FIX_3_072711026_MINUS_2_562915447 (FIX_3_072711026 - FIX_2_562915447) +#define FIX_0_298631336_MINUS_0_899976223 (FIX_0_298631336 - FIX_0_899976223) +#define FIX_1_501321110_MINUS_0_899976223 (FIX_1_501321110 - FIX_0_899976223) +#define FIX_2_053119869_MINUS_2_562915447 (FIX_2_053119869 - FIX_2_562915447) +#define FIX_0_541196100_PLUS_0_765366865 (FIX_0_541196100 + FIX_0_765366865) + +/* + * Reference SIMD-friendly 1-D ISLOW iDCT C implementation. + * Uses some ideas from the comments in 'simd/jiss2int-64.asm' + */ +#define REF_1D_IDCT(xrow0, xrow1, xrow2, xrow3, xrow4, xrow5, xrow6, xrow7) \ +{ \ + DCTELEM row0, row1, row2, row3, row4, row5, row6, row7; \ + INT32 q1, q2, q3, q4, q5, q6, q7; \ + INT32 tmp11_plus_tmp2, tmp11_minus_tmp2; \ + \ + /* 1-D iDCT input data */ \ + row0 = xrow0; \ + row1 = xrow1; \ + row2 = xrow2; \ + row3 = xrow3; \ + row4 = xrow4; \ + row5 = xrow5; \ + row6 = xrow6; \ + row7 = xrow7; \ + \ + q5 = row7 + row3; \ + q4 = row5 + row1; \ + q6 = MULTIPLY(q5, FIX_1_175875602_MINUS_1_961570560) + \ + MULTIPLY(q4, FIX_1_175875602); \ + q7 = MULTIPLY(q5, FIX_1_175875602) + \ + MULTIPLY(q4, FIX_1_175875602_MINUS_0_390180644); \ + q2 = MULTIPLY(row2, FIX_0_541196100) + \ + MULTIPLY(row6, FIX_0_541196100_MINUS_1_847759065); \ + q4 = q6; \ + q3 = ((INT32) row0 - (INT32) row4) << 13; \ + q6 += MULTIPLY(row5, -FIX_2_562915447) + \ + MULTIPLY(row3, FIX_3_072711026_MINUS_2_562915447); \ + /* now we can use q1 (reloadable constants have been used up) */ \ + q1 = q3 + q2; \ + q4 += MULTIPLY(row7, FIX_0_298631336_MINUS_0_899976223) + \ + MULTIPLY(row1, -FIX_0_899976223); \ + q5 = q7; \ + q1 = q1 + q6; \ + q7 += MULTIPLY(row7, -FIX_0_899976223) + \ + MULTIPLY(row1, FIX_1_501321110_MINUS_0_899976223); \ + \ + /* (tmp11 + tmp2) has been calculated (out_row1 before descale) */ \ + tmp11_plus_tmp2 = q1; \ + row1 = 0; \ + \ + q1 = q1 - q6; \ + q5 += MULTIPLY(row5, FIX_2_053119869_MINUS_2_562915447) + \ + MULTIPLY(row3, -FIX_2_562915447); \ + q1 = q1 - q6; \ + q6 = MULTIPLY(row2, FIX_0_541196100_PLUS_0_765366865) + \ + MULTIPLY(row6, FIX_0_541196100); \ + q3 = q3 - q2; \ + \ + /* (tmp11 - tmp2) has been calculated (out_row6 before descale) */ \ + tmp11_minus_tmp2 = q1; \ + \ + q1 = ((INT32) row0 + (INT32) row4) << 13; \ + q2 = q1 + q6; \ + q1 = q1 - q6; \ + \ + /* pick up the results */ \ + tmp0 = q4; \ + tmp1 = q5; \ + tmp2 = (tmp11_plus_tmp2 - tmp11_minus_tmp2) / 2; \ + tmp3 = q7; \ + tmp10 = q2; \ + tmp11 = (tmp11_plus_tmp2 + tmp11_minus_tmp2) / 2; \ + tmp12 = q3; \ + tmp13 = q1; \ +} + +#define XFIX_0_899976223 d0[0] +#define XFIX_0_541196100 d0[1] +#define XFIX_2_562915447 d0[2] +#define XFIX_0_298631336_MINUS_0_899976223 d0[3] +#define XFIX_1_501321110_MINUS_0_899976223 d1[0] +#define XFIX_2_053119869_MINUS_2_562915447 d1[1] +#define XFIX_0_541196100_PLUS_0_765366865 d1[2] +#define XFIX_1_175875602 d1[3] +#define XFIX_1_175875602_MINUS_0_390180644 d2[0] +#define XFIX_0_541196100_MINUS_1_847759065 d2[1] +#define XFIX_3_072711026_MINUS_2_562915447 d2[2] +#define XFIX_1_175875602_MINUS_1_961570560 d2[3] + +.balign 16 +jsimd_idct_islow_neon_consts: + .short FIX_0_899976223 /* d0[0] */ + .short FIX_0_541196100 /* d0[1] */ + .short FIX_2_562915447 /* d0[2] */ + .short FIX_0_298631336_MINUS_0_899976223 /* d0[3] */ + .short FIX_1_501321110_MINUS_0_899976223 /* d1[0] */ + .short FIX_2_053119869_MINUS_2_562915447 /* d1[1] */ + .short FIX_0_541196100_PLUS_0_765366865 /* d1[2] */ + .short FIX_1_175875602 /* d1[3] */ + /* reloadable constants */ + .short FIX_1_175875602_MINUS_0_390180644 /* d2[0] */ + .short FIX_0_541196100_MINUS_1_847759065 /* d2[1] */ + .short FIX_3_072711026_MINUS_2_562915447 /* d2[2] */ + .short FIX_1_175875602_MINUS_1_961570560 /* d2[3] */ + +asm_function jsimd_idct_islow_neon + + DCT_TABLE .req r0 + COEF_BLOCK .req r1 + OUTPUT_BUF .req r2 + OUTPUT_COL .req r3 + TMP1 .req r0 + TMP2 .req r1 + TMP3 .req r2 + TMP4 .req ip + + ROW0L .req d16 + ROW0R .req d17 + ROW1L .req d18 + ROW1R .req d19 + ROW2L .req d20 + ROW2R .req d21 + ROW3L .req d22 + ROW3R .req d23 + ROW4L .req d24 + ROW4R .req d25 + ROW5L .req d26 + ROW5R .req d27 + ROW6L .req d28 + ROW6R .req d29 + ROW7L .req d30 + ROW7R .req d31 + + /* Load and dequantize coefficients into NEON registers + * with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | d16 | d17 ( q8 ) + * 1 | d18 | d19 ( q9 ) + * 2 | d20 | d21 ( q10 ) + * 3 | d22 | d23 ( q11 ) + * 4 | d24 | d25 ( q12 ) + * 5 | d26 | d27 ( q13 ) + * 6 | d28 | d29 ( q14 ) + * 7 | d30 | d31 ( q15 ) + */ + adr ip, jsimd_idct_islow_neon_consts + vld1.16 {d16, d17, d18, d19}, [COEF_BLOCK, :128]! + vld1.16 {d0, d1, d2, d3}, [DCT_TABLE, :128]! + vld1.16 {d20, d21, d22, d23}, [COEF_BLOCK, :128]! + vmul.s16 q8, q8, q0 + vld1.16 {d4, d5, d6, d7}, [DCT_TABLE, :128]! + vmul.s16 q9, q9, q1 + vld1.16 {d24, d25, d26, d27}, [COEF_BLOCK, :128]! + vmul.s16 q10, q10, q2 + vld1.16 {d0, d1, d2, d3}, [DCT_TABLE, :128]! + vmul.s16 q11, q11, q3 + vld1.16 {d28, d29, d30, d31}, [COEF_BLOCK, :128] + vmul.s16 q12, q12, q0 + vld1.16 {d4, d5, d6, d7}, [DCT_TABLE, :128]! + vmul.s16 q14, q14, q2 + vmul.s16 q13, q13, q1 + vld1.16 {d0, d1, d2, d3}, [ip, :128] /* load constants */ + add ip, ip, #16 + vmul.s16 q15, q15, q3 + vpush {d8-d15} /* save NEON registers */ + /* 1-D IDCT, pass 1, left 4x8 half */ + vadd.s16 d4, ROW7L, ROW3L + vadd.s16 d5, ROW5L, ROW1L + vmull.s16 q6, d4, XFIX_1_175875602_MINUS_1_961570560 + vmlal.s16 q6, d5, XFIX_1_175875602 + vmull.s16 q7, d4, XFIX_1_175875602 + /* Check for the zero coefficients in the right 4x8 half */ + push {r4, r5} + vmlal.s16 q7, d5, XFIX_1_175875602_MINUS_0_390180644 + vsubl.s16 q3, ROW0L, ROW4L + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 1 * 8))] + vmull.s16 q2, ROW2L, XFIX_0_541196100 + vmlal.s16 q2, ROW6L, XFIX_0_541196100_MINUS_1_847759065 + orr r0, r4, r5 + vmov q4, q6 + vmlsl.s16 q6, ROW5L, XFIX_2_562915447 + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 2 * 8))] + vmlal.s16 q6, ROW3L, XFIX_3_072711026_MINUS_2_562915447 + vshl.s32 q3, q3, #13 + orr r0, r0, r4 + vmlsl.s16 q4, ROW1L, XFIX_0_899976223 + orr r0, r0, r5 + vadd.s32 q1, q3, q2 + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 3 * 8))] + vmov q5, q7 + vadd.s32 q1, q1, q6 + orr r0, r0, r4 + vmlsl.s16 q7, ROW7L, XFIX_0_899976223 + orr r0, r0, r5 + vmlal.s16 q7, ROW1L, XFIX_1_501321110_MINUS_0_899976223 + vrshrn.s32 ROW1L, q1, #11 + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 4 * 8))] + vsub.s32 q1, q1, q6 + vmlal.s16 q5, ROW5L, XFIX_2_053119869_MINUS_2_562915447 + orr r0, r0, r4 + vmlsl.s16 q5, ROW3L, XFIX_2_562915447 + orr r0, r0, r5 + vsub.s32 q1, q1, q6 + vmull.s16 q6, ROW2L, XFIX_0_541196100_PLUS_0_765366865 + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 5 * 8))] + vmlal.s16 q6, ROW6L, XFIX_0_541196100 + vsub.s32 q3, q3, q2 + orr r0, r0, r4 + vrshrn.s32 ROW6L, q1, #11 + orr r0, r0, r5 + vadd.s32 q1, q3, q5 + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 6 * 8))] + vsub.s32 q3, q3, q5 + vaddl.s16 q5, ROW0L, ROW4L + orr r0, r0, r4 + vrshrn.s32 ROW2L, q1, #11 + orr r0, r0, r5 + vrshrn.s32 ROW5L, q3, #11 + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 7 * 8))] + vshl.s32 q5, q5, #13 + vmlal.s16 q4, ROW7L, XFIX_0_298631336_MINUS_0_899976223 + orr r0, r0, r4 + vadd.s32 q2, q5, q6 + orrs r0, r0, r5 + vsub.s32 q1, q5, q6 + vadd.s32 q6, q2, q7 + ldrd r4, [COEF_BLOCK, #(-96 + 2 * (4 + 0 * 8))] + vsub.s32 q2, q2, q7 + vadd.s32 q5, q1, q4 + orr r0, r4, r5 + vsub.s32 q3, q1, q4 + pop {r4, r5} + vrshrn.s32 ROW7L, q2, #11 + vrshrn.s32 ROW3L, q5, #11 + vrshrn.s32 ROW0L, q6, #11 + vrshrn.s32 ROW4L, q3, #11 + + beq 3f /* Go to do some special handling for the sparse right 4x8 half */ + + /* 1-D IDCT, pass 1, right 4x8 half */ + vld1.s16 {d2}, [ip, :64] /* reload constants */ + vadd.s16 d10, ROW7R, ROW3R + vadd.s16 d8, ROW5R, ROW1R + /* Transpose left 4x8 half */ + vtrn.16 ROW6L, ROW7L + vmull.s16 q6, d10, XFIX_1_175875602_MINUS_1_961570560 + vmlal.s16 q6, d8, XFIX_1_175875602 + vtrn.16 ROW2L, ROW3L + vmull.s16 q7, d10, XFIX_1_175875602 + vmlal.s16 q7, d8, XFIX_1_175875602_MINUS_0_390180644 + vtrn.16 ROW0L, ROW1L + vsubl.s16 q3, ROW0R, ROW4R + vmull.s16 q2, ROW2R, XFIX_0_541196100 + vmlal.s16 q2, ROW6R, XFIX_0_541196100_MINUS_1_847759065 + vtrn.16 ROW4L, ROW5L + vmov q4, q6 + vmlsl.s16 q6, ROW5R, XFIX_2_562915447 + vmlal.s16 q6, ROW3R, XFIX_3_072711026_MINUS_2_562915447 + vtrn.32 ROW1L, ROW3L + vshl.s32 q3, q3, #13 + vmlsl.s16 q4, ROW1R, XFIX_0_899976223 + vtrn.32 ROW4L, ROW6L + vadd.s32 q1, q3, q2 + vmov q5, q7 + vadd.s32 q1, q1, q6 + vtrn.32 ROW0L, ROW2L + vmlsl.s16 q7, ROW7R, XFIX_0_899976223 + vmlal.s16 q7, ROW1R, XFIX_1_501321110_MINUS_0_899976223 + vrshrn.s32 ROW1R, q1, #11 + vtrn.32 ROW5L, ROW7L + vsub.s32 q1, q1, q6 + vmlal.s16 q5, ROW5R, XFIX_2_053119869_MINUS_2_562915447 + vmlsl.s16 q5, ROW3R, XFIX_2_562915447 + vsub.s32 q1, q1, q6 + vmull.s16 q6, ROW2R, XFIX_0_541196100_PLUS_0_765366865 + vmlal.s16 q6, ROW6R, XFIX_0_541196100 + vsub.s32 q3, q3, q2 + vrshrn.s32 ROW6R, q1, #11 + vadd.s32 q1, q3, q5 + vsub.s32 q3, q3, q5 + vaddl.s16 q5, ROW0R, ROW4R + vrshrn.s32 ROW2R, q1, #11 + vrshrn.s32 ROW5R, q3, #11 + vshl.s32 q5, q5, #13 + vmlal.s16 q4, ROW7R, XFIX_0_298631336_MINUS_0_899976223 + vadd.s32 q2, q5, q6 + vsub.s32 q1, q5, q6 + vadd.s32 q6, q2, q7 + vsub.s32 q2, q2, q7 + vadd.s32 q5, q1, q4 + vsub.s32 q3, q1, q4 + vrshrn.s32 ROW7R, q2, #11 + vrshrn.s32 ROW3R, q5, #11 + vrshrn.s32 ROW0R, q6, #11 + vrshrn.s32 ROW4R, q3, #11 + /* Transpose right 4x8 half */ + vtrn.16 ROW6R, ROW7R + vtrn.16 ROW2R, ROW3R + vtrn.16 ROW0R, ROW1R + vtrn.16 ROW4R, ROW5R + vtrn.32 ROW1R, ROW3R + vtrn.32 ROW4R, ROW6R + vtrn.32 ROW0R, ROW2R + vtrn.32 ROW5R, ROW7R + +1: /* 1-D IDCT, pass 2 (normal variant), left 4x8 half */ + vld1.s16 {d2}, [ip, :64] /* reload constants */ + vmull.s16 q6, ROW1R, XFIX_1_175875602 /* ROW5L <-> ROW1R */ + vmlal.s16 q6, ROW1L, XFIX_1_175875602 + vmlal.s16 q6, ROW3R, XFIX_1_175875602_MINUS_1_961570560 /* ROW7L <-> ROW3R */ + vmlal.s16 q6, ROW3L, XFIX_1_175875602_MINUS_1_961570560 + vmull.s16 q7, ROW3R, XFIX_1_175875602 /* ROW7L <-> ROW3R */ + vmlal.s16 q7, ROW3L, XFIX_1_175875602 + vmlal.s16 q7, ROW1R, XFIX_1_175875602_MINUS_0_390180644 /* ROW5L <-> ROW1R */ + vmlal.s16 q7, ROW1L, XFIX_1_175875602_MINUS_0_390180644 + vsubl.s16 q3, ROW0L, ROW0R /* ROW4L <-> ROW0R */ + vmull.s16 q2, ROW2L, XFIX_0_541196100 + vmlal.s16 q2, ROW2R, XFIX_0_541196100_MINUS_1_847759065 /* ROW6L <-> ROW2R */ + vmov q4, q6 + vmlsl.s16 q6, ROW1R, XFIX_2_562915447 /* ROW5L <-> ROW1R */ + vmlal.s16 q6, ROW3L, XFIX_3_072711026_MINUS_2_562915447 + vshl.s32 q3, q3, #13 + vmlsl.s16 q4, ROW1L, XFIX_0_899976223 + vadd.s32 q1, q3, q2 + vmov q5, q7 + vadd.s32 q1, q1, q6 + vmlsl.s16 q7, ROW3R, XFIX_0_899976223 /* ROW7L <-> ROW3R */ + vmlal.s16 q7, ROW1L, XFIX_1_501321110_MINUS_0_899976223 + vshrn.s32 ROW1L, q1, #16 + vsub.s32 q1, q1, q6 + vmlal.s16 q5, ROW1R, XFIX_2_053119869_MINUS_2_562915447 /* ROW5L <-> ROW1R */ + vmlsl.s16 q5, ROW3L, XFIX_2_562915447 + vsub.s32 q1, q1, q6 + vmull.s16 q6, ROW2L, XFIX_0_541196100_PLUS_0_765366865 + vmlal.s16 q6, ROW2R, XFIX_0_541196100 /* ROW6L <-> ROW2R */ + vsub.s32 q3, q3, q2 + vshrn.s32 ROW2R, q1, #16 /* ROW6L <-> ROW2R */ + vadd.s32 q1, q3, q5 + vsub.s32 q3, q3, q5 + vaddl.s16 q5, ROW0L, ROW0R /* ROW4L <-> ROW0R */ + vshrn.s32 ROW2L, q1, #16 + vshrn.s32 ROW1R, q3, #16 /* ROW5L <-> ROW1R */ + vshl.s32 q5, q5, #13 + vmlal.s16 q4, ROW3R, XFIX_0_298631336_MINUS_0_899976223 /* ROW7L <-> ROW3R */ + vadd.s32 q2, q5, q6 + vsub.s32 q1, q5, q6 + vadd.s32 q6, q2, q7 + vsub.s32 q2, q2, q7 + vadd.s32 q5, q1, q4 + vsub.s32 q3, q1, q4 + vshrn.s32 ROW3R, q2, #16 /* ROW7L <-> ROW3R */ + vshrn.s32 ROW3L, q5, #16 + vshrn.s32 ROW0L, q6, #16 + vshrn.s32 ROW0R, q3, #16 /* ROW4L <-> ROW0R */ + /* 1-D IDCT, pass 2, right 4x8 half */ + vld1.s16 {d2}, [ip, :64] /* reload constants */ + vmull.s16 q6, ROW5R, XFIX_1_175875602 + vmlal.s16 q6, ROW5L, XFIX_1_175875602 /* ROW5L <-> ROW1R */ + vmlal.s16 q6, ROW7R, XFIX_1_175875602_MINUS_1_961570560 + vmlal.s16 q6, ROW7L, XFIX_1_175875602_MINUS_1_961570560 /* ROW7L <-> ROW3R */ + vmull.s16 q7, ROW7R, XFIX_1_175875602 + vmlal.s16 q7, ROW7L, XFIX_1_175875602 /* ROW7L <-> ROW3R */ + vmlal.s16 q7, ROW5R, XFIX_1_175875602_MINUS_0_390180644 + vmlal.s16 q7, ROW5L, XFIX_1_175875602_MINUS_0_390180644 /* ROW5L <-> ROW1R */ + vsubl.s16 q3, ROW4L, ROW4R /* ROW4L <-> ROW0R */ + vmull.s16 q2, ROW6L, XFIX_0_541196100 /* ROW6L <-> ROW2R */ + vmlal.s16 q2, ROW6R, XFIX_0_541196100_MINUS_1_847759065 + vmov q4, q6 + vmlsl.s16 q6, ROW5R, XFIX_2_562915447 + vmlal.s16 q6, ROW7L, XFIX_3_072711026_MINUS_2_562915447 /* ROW7L <-> ROW3R */ + vshl.s32 q3, q3, #13 + vmlsl.s16 q4, ROW5L, XFIX_0_899976223 /* ROW5L <-> ROW1R */ + vadd.s32 q1, q3, q2 + vmov q5, q7 + vadd.s32 q1, q1, q6 + vmlsl.s16 q7, ROW7R, XFIX_0_899976223 + vmlal.s16 q7, ROW5L, XFIX_1_501321110_MINUS_0_899976223 /* ROW5L <-> ROW1R */ + vshrn.s32 ROW5L, q1, #16 /* ROW5L <-> ROW1R */ + vsub.s32 q1, q1, q6 + vmlal.s16 q5, ROW5R, XFIX_2_053119869_MINUS_2_562915447 + vmlsl.s16 q5, ROW7L, XFIX_2_562915447 /* ROW7L <-> ROW3R */ + vsub.s32 q1, q1, q6 + vmull.s16 q6, ROW6L, XFIX_0_541196100_PLUS_0_765366865 /* ROW6L <-> ROW2R */ + vmlal.s16 q6, ROW6R, XFIX_0_541196100 + vsub.s32 q3, q3, q2 + vshrn.s32 ROW6R, q1, #16 + vadd.s32 q1, q3, q5 + vsub.s32 q3, q3, q5 + vaddl.s16 q5, ROW4L, ROW4R /* ROW4L <-> ROW0R */ + vshrn.s32 ROW6L, q1, #16 /* ROW6L <-> ROW2R */ + vshrn.s32 ROW5R, q3, #16 + vshl.s32 q5, q5, #13 + vmlal.s16 q4, ROW7R, XFIX_0_298631336_MINUS_0_899976223 + vadd.s32 q2, q5, q6 + vsub.s32 q1, q5, q6 + vadd.s32 q6, q2, q7 + vsub.s32 q2, q2, q7 + vadd.s32 q5, q1, q4 + vsub.s32 q3, q1, q4 + vshrn.s32 ROW7R, q2, #16 + vshrn.s32 ROW7L, q5, #16 /* ROW7L <-> ROW3R */ + vshrn.s32 ROW4L, q6, #16 /* ROW4L <-> ROW0R */ + vshrn.s32 ROW4R, q3, #16 + +2: /* Descale to 8-bit and range limit */ + vqrshrn.s16 d16, q8, #2 + vqrshrn.s16 d17, q9, #2 + vqrshrn.s16 d18, q10, #2 + vqrshrn.s16 d19, q11, #2 + vpop {d8-d15} /* restore NEON registers */ + vqrshrn.s16 d20, q12, #2 + /* Transpose the final 8-bit samples and do signed->unsigned conversion */ + vtrn.16 q8, q9 + vqrshrn.s16 d21, q13, #2 + vqrshrn.s16 d22, q14, #2 + vmov.u8 q0, #(CENTERJSAMPLE) + vqrshrn.s16 d23, q15, #2 + vtrn.8 d16, d17 + vtrn.8 d18, d19 + vadd.u8 q8, q8, q0 + vadd.u8 q9, q9, q0 + vtrn.16 q10, q11 + /* Store results to the output buffer */ + ldmia OUTPUT_BUF!, {TMP1, TMP2} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + vst1.8 {d16}, [TMP1] + vtrn.8 d20, d21 + vst1.8 {d17}, [TMP2] + ldmia OUTPUT_BUF!, {TMP1, TMP2} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + vst1.8 {d18}, [TMP1] + vadd.u8 q10, q10, q0 + vst1.8 {d19}, [TMP2] + ldmia OUTPUT_BUF, {TMP1, TMP2, TMP3, TMP4} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + add TMP3, TMP3, OUTPUT_COL + add TMP4, TMP4, OUTPUT_COL + vtrn.8 d22, d23 + vst1.8 {d20}, [TMP1] + vadd.u8 q11, q11, q0 + vst1.8 {d21}, [TMP2] + vst1.8 {d22}, [TMP3] + vst1.8 {d23}, [TMP4] + bx lr + +3: /* Left 4x8 half is done, right 4x8 half contains mostly zeros */ + + /* Transpose left 4x8 half */ + vtrn.16 ROW6L, ROW7L + vtrn.16 ROW2L, ROW3L + vtrn.16 ROW0L, ROW1L + vtrn.16 ROW4L, ROW5L + vshl.s16 ROW0R, ROW0R, #2 /* PASS1_BITS */ + vtrn.32 ROW1L, ROW3L + vtrn.32 ROW4L, ROW6L + vtrn.32 ROW0L, ROW2L + vtrn.32 ROW5L, ROW7L + + cmp r0, #0 + beq 4f /* Right 4x8 half has all zeros, go to 'sparse' second pass */ + + /* Only row 0 is non-zero for the right 4x8 half */ + vdup.s16 ROW1R, ROW0R[1] + vdup.s16 ROW2R, ROW0R[2] + vdup.s16 ROW3R, ROW0R[3] + vdup.s16 ROW4R, ROW0R[0] + vdup.s16 ROW5R, ROW0R[1] + vdup.s16 ROW6R, ROW0R[2] + vdup.s16 ROW7R, ROW0R[3] + vdup.s16 ROW0R, ROW0R[0] + b 1b /* Go to 'normal' second pass */ + +4: /* 1-D IDCT, pass 2 (sparse variant with zero rows 4-7), left 4x8 half */ + vld1.s16 {d2}, [ip, :64] /* reload constants */ + vmull.s16 q6, ROW1L, XFIX_1_175875602 + vmlal.s16 q6, ROW3L, XFIX_1_175875602_MINUS_1_961570560 + vmull.s16 q7, ROW3L, XFIX_1_175875602 + vmlal.s16 q7, ROW1L, XFIX_1_175875602_MINUS_0_390180644 + vmull.s16 q2, ROW2L, XFIX_0_541196100 + vshll.s16 q3, ROW0L, #13 + vmov q4, q6 + vmlal.s16 q6, ROW3L, XFIX_3_072711026_MINUS_2_562915447 + vmlsl.s16 q4, ROW1L, XFIX_0_899976223 + vadd.s32 q1, q3, q2 + vmov q5, q7 + vmlal.s16 q7, ROW1L, XFIX_1_501321110_MINUS_0_899976223 + vadd.s32 q1, q1, q6 + vadd.s32 q6, q6, q6 + vmlsl.s16 q5, ROW3L, XFIX_2_562915447 + vshrn.s32 ROW1L, q1, #16 + vsub.s32 q1, q1, q6 + vmull.s16 q6, ROW2L, XFIX_0_541196100_PLUS_0_765366865 + vsub.s32 q3, q3, q2 + vshrn.s32 ROW2R, q1, #16 /* ROW6L <-> ROW2R */ + vadd.s32 q1, q3, q5 + vsub.s32 q3, q3, q5 + vshll.s16 q5, ROW0L, #13 + vshrn.s32 ROW2L, q1, #16 + vshrn.s32 ROW1R, q3, #16 /* ROW5L <-> ROW1R */ + vadd.s32 q2, q5, q6 + vsub.s32 q1, q5, q6 + vadd.s32 q6, q2, q7 + vsub.s32 q2, q2, q7 + vadd.s32 q5, q1, q4 + vsub.s32 q3, q1, q4 + vshrn.s32 ROW3R, q2, #16 /* ROW7L <-> ROW3R */ + vshrn.s32 ROW3L, q5, #16 + vshrn.s32 ROW0L, q6, #16 + vshrn.s32 ROW0R, q3, #16 /* ROW4L <-> ROW0R */ + /* 1-D IDCT, pass 2 (sparse variant with zero rows 4-7), right 4x8 half */ + vld1.s16 {d2}, [ip, :64] /* reload constants */ + vmull.s16 q6, ROW5L, XFIX_1_175875602 + vmlal.s16 q6, ROW7L, XFIX_1_175875602_MINUS_1_961570560 + vmull.s16 q7, ROW7L, XFIX_1_175875602 + vmlal.s16 q7, ROW5L, XFIX_1_175875602_MINUS_0_390180644 + vmull.s16 q2, ROW6L, XFIX_0_541196100 + vshll.s16 q3, ROW4L, #13 + vmov q4, q6 + vmlal.s16 q6, ROW7L, XFIX_3_072711026_MINUS_2_562915447 + vmlsl.s16 q4, ROW5L, XFIX_0_899976223 + vadd.s32 q1, q3, q2 + vmov q5, q7 + vmlal.s16 q7, ROW5L, XFIX_1_501321110_MINUS_0_899976223 + vadd.s32 q1, q1, q6 + vadd.s32 q6, q6, q6 + vmlsl.s16 q5, ROW7L, XFIX_2_562915447 + vshrn.s32 ROW5L, q1, #16 /* ROW5L <-> ROW1R */ + vsub.s32 q1, q1, q6 + vmull.s16 q6, ROW6L, XFIX_0_541196100_PLUS_0_765366865 + vsub.s32 q3, q3, q2 + vshrn.s32 ROW6R, q1, #16 + vadd.s32 q1, q3, q5 + vsub.s32 q3, q3, q5 + vshll.s16 q5, ROW4L, #13 + vshrn.s32 ROW6L, q1, #16 /* ROW6L <-> ROW2R */ + vshrn.s32 ROW5R, q3, #16 + vadd.s32 q2, q5, q6 + vsub.s32 q1, q5, q6 + vadd.s32 q6, q2, q7 + vsub.s32 q2, q2, q7 + vadd.s32 q5, q1, q4 + vsub.s32 q3, q1, q4 + vshrn.s32 ROW7R, q2, #16 + vshrn.s32 ROW7L, q5, #16 /* ROW7L <-> ROW3R */ + vshrn.s32 ROW4L, q6, #16 /* ROW4L <-> ROW0R */ + vshrn.s32 ROW4R, q3, #16 + b 2b /* Go to epilogue */ + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 + .unreq TMP3 + .unreq TMP4 + + .unreq ROW0L + .unreq ROW0R + .unreq ROW1L + .unreq ROW1R + .unreq ROW2L + .unreq ROW2R + .unreq ROW3L + .unreq ROW3R + .unreq ROW4L + .unreq ROW4R + .unreq ROW5L + .unreq ROW5R + .unreq ROW6L + .unreq ROW6R + .unreq ROW7L + .unreq ROW7R +.endfunc + +/*****************************************************************************/ + +/* + * jsimd_idct_ifast_neon + * + * This function contains a fast, not so accurate integer implementation of + * the inverse DCT (Discrete Cosine Transform). It uses the same calculations + * and produces exactly the same output as IJG's original 'jpeg_idct_ifast' + * function from jidctfst.c + * + * Normally 1-D AAN DCT needs 5 multiplications and 29 additions. + * But in ARM NEON case some extra additions are required because VQDMULH + * instruction can't handle the constants larger than 1. So the expressions + * like "x * 1.082392200" have to be converted to "x * 0.082392200 + x", + * which introduces an extra addition. Overall, there are 6 extra additions + * per 1-D IDCT pass, totalling to 5 VQDMULH and 35 VADD/VSUB instructions. + */ + +#define XFIX_1_082392200 d0[0] +#define XFIX_1_414213562 d0[1] +#define XFIX_1_847759065 d0[2] +#define XFIX_2_613125930 d0[3] + +.balign 16 +jsimd_idct_ifast_neon_consts: + .short (277 * 128 - 256 * 128) /* XFIX_1_082392200 */ + .short (362 * 128 - 256 * 128) /* XFIX_1_414213562 */ + .short (473 * 128 - 256 * 128) /* XFIX_1_847759065 */ + .short (669 * 128 - 512 * 128) /* XFIX_2_613125930 */ + +asm_function jsimd_idct_ifast_neon + + DCT_TABLE .req r0 + COEF_BLOCK .req r1 + OUTPUT_BUF .req r2 + OUTPUT_COL .req r3 + TMP1 .req r0 + TMP2 .req r1 + TMP3 .req r2 + TMP4 .req ip + + /* Load and dequantize coefficients into NEON registers + * with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | d16 | d17 ( q8 ) + * 1 | d18 | d19 ( q9 ) + * 2 | d20 | d21 ( q10 ) + * 3 | d22 | d23 ( q11 ) + * 4 | d24 | d25 ( q12 ) + * 5 | d26 | d27 ( q13 ) + * 6 | d28 | d29 ( q14 ) + * 7 | d30 | d31 ( q15 ) + */ + adr ip, jsimd_idct_ifast_neon_consts + vld1.16 {d16, d17, d18, d19}, [COEF_BLOCK, :128]! + vld1.16 {d0, d1, d2, d3}, [DCT_TABLE, :128]! + vld1.16 {d20, d21, d22, d23}, [COEF_BLOCK, :128]! + vmul.s16 q8, q8, q0 + vld1.16 {d4, d5, d6, d7}, [DCT_TABLE, :128]! + vmul.s16 q9, q9, q1 + vld1.16 {d24, d25, d26, d27}, [COEF_BLOCK, :128]! + vmul.s16 q10, q10, q2 + vld1.16 {d0, d1, d2, d3}, [DCT_TABLE, :128]! + vmul.s16 q11, q11, q3 + vld1.16 {d28, d29, d30, d31}, [COEF_BLOCK, :128] + vmul.s16 q12, q12, q0 + vld1.16 {d4, d5, d6, d7}, [DCT_TABLE, :128]! + vmul.s16 q14, q14, q2 + vmul.s16 q13, q13, q1 + vld1.16 {d0}, [ip, :64] /* load constants */ + vmul.s16 q15, q15, q3 + vpush {d8-d13} /* save NEON registers */ + /* 1-D IDCT, pass 1 */ + vsub.s16 q2, q10, q14 + vadd.s16 q14, q10, q14 + vsub.s16 q1, q11, q13 + vadd.s16 q13, q11, q13 + vsub.s16 q5, q9, q15 + vadd.s16 q15, q9, q15 + vqdmulh.s16 q4, q2, XFIX_1_414213562 + vqdmulh.s16 q6, q1, XFIX_2_613125930 + vadd.s16 q3, q1, q1 + vsub.s16 q1, q5, q1 + vadd.s16 q10, q2, q4 + vqdmulh.s16 q4, q1, XFIX_1_847759065 + vsub.s16 q2, q15, q13 + vadd.s16 q3, q3, q6 + vqdmulh.s16 q6, q2, XFIX_1_414213562 + vadd.s16 q1, q1, q4 + vqdmulh.s16 q4, q5, XFIX_1_082392200 + vsub.s16 q10, q10, q14 + vadd.s16 q2, q2, q6 + vsub.s16 q6, q8, q12 + vadd.s16 q12, q8, q12 + vadd.s16 q9, q5, q4 + vadd.s16 q5, q6, q10 + vsub.s16 q10, q6, q10 + vadd.s16 q6, q15, q13 + vadd.s16 q8, q12, q14 + vsub.s16 q3, q6, q3 + vsub.s16 q12, q12, q14 + vsub.s16 q3, q3, q1 + vsub.s16 q1, q9, q1 + vadd.s16 q2, q3, q2 + vsub.s16 q15, q8, q6 + vadd.s16 q1, q1, q2 + vadd.s16 q8, q8, q6 + vadd.s16 q14, q5, q3 + vsub.s16 q9, q5, q3 + vsub.s16 q13, q10, q2 + vadd.s16 q10, q10, q2 + /* Transpose */ + vtrn.16 q8, q9 + vsub.s16 q11, q12, q1 + vtrn.16 q14, q15 + vadd.s16 q12, q12, q1 + vtrn.16 q10, q11 + vtrn.16 q12, q13 + vtrn.32 q9, q11 + vtrn.32 q12, q14 + vtrn.32 q8, q10 + vtrn.32 q13, q15 + vswp d28, d21 + vswp d26, d19 + /* 1-D IDCT, pass 2 */ + vsub.s16 q2, q10, q14 + vswp d30, d23 + vadd.s16 q14, q10, q14 + vswp d24, d17 + vsub.s16 q1, q11, q13 + vadd.s16 q13, q11, q13 + vsub.s16 q5, q9, q15 + vadd.s16 q15, q9, q15 + vqdmulh.s16 q4, q2, XFIX_1_414213562 + vqdmulh.s16 q6, q1, XFIX_2_613125930 + vadd.s16 q3, q1, q1 + vsub.s16 q1, q5, q1 + vadd.s16 q10, q2, q4 + vqdmulh.s16 q4, q1, XFIX_1_847759065 + vsub.s16 q2, q15, q13 + vadd.s16 q3, q3, q6 + vqdmulh.s16 q6, q2, XFIX_1_414213562 + vadd.s16 q1, q1, q4 + vqdmulh.s16 q4, q5, XFIX_1_082392200 + vsub.s16 q10, q10, q14 + vadd.s16 q2, q2, q6 + vsub.s16 q6, q8, q12 + vadd.s16 q12, q8, q12 + vadd.s16 q9, q5, q4 + vadd.s16 q5, q6, q10 + vsub.s16 q10, q6, q10 + vadd.s16 q6, q15, q13 + vadd.s16 q8, q12, q14 + vsub.s16 q3, q6, q3 + vsub.s16 q12, q12, q14 + vsub.s16 q3, q3, q1 + vsub.s16 q1, q9, q1 + vadd.s16 q2, q3, q2 + vsub.s16 q15, q8, q6 + vadd.s16 q1, q1, q2 + vadd.s16 q8, q8, q6 + vadd.s16 q14, q5, q3 + vsub.s16 q9, q5, q3 + vsub.s16 q13, q10, q2 + vpop {d8-d13} /* restore NEON registers */ + vadd.s16 q10, q10, q2 + vsub.s16 q11, q12, q1 + vadd.s16 q12, q12, q1 + /* Descale to 8-bit and range limit */ + vmov.u8 q0, #0x80 + vqshrn.s16 d16, q8, #5 + vqshrn.s16 d17, q9, #5 + vqshrn.s16 d18, q10, #5 + vqshrn.s16 d19, q11, #5 + vqshrn.s16 d20, q12, #5 + vqshrn.s16 d21, q13, #5 + vqshrn.s16 d22, q14, #5 + vqshrn.s16 d23, q15, #5 + vadd.u8 q8, q8, q0 + vadd.u8 q9, q9, q0 + vadd.u8 q10, q10, q0 + vadd.u8 q11, q11, q0 + /* Transpose the final 8-bit samples */ + vtrn.16 q8, q9 + vtrn.16 q10, q11 + vtrn.32 q8, q10 + vtrn.32 q9, q11 + vtrn.8 d16, d17 + vtrn.8 d18, d19 + /* Store results to the output buffer */ + ldmia OUTPUT_BUF!, {TMP1, TMP2} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + vst1.8 {d16}, [TMP1] + vst1.8 {d17}, [TMP2] + ldmia OUTPUT_BUF!, {TMP1, TMP2} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + vst1.8 {d18}, [TMP1] + vtrn.8 d20, d21 + vst1.8 {d19}, [TMP2] + ldmia OUTPUT_BUF, {TMP1, TMP2, TMP3, TMP4} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + add TMP3, TMP3, OUTPUT_COL + add TMP4, TMP4, OUTPUT_COL + vst1.8 {d20}, [TMP1] + vtrn.8 d22, d23 + vst1.8 {d21}, [TMP2] + vst1.8 {d22}, [TMP3] + vst1.8 {d23}, [TMP4] + bx lr + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 + .unreq TMP3 + .unreq TMP4 +.endfunc + +/*****************************************************************************/ + +/* + * jsimd_idct_4x4_neon + * + * This function contains inverse-DCT code for getting reduced-size + * 4x4 pixels output from an 8x8 DCT block. It uses the same calculations + * and produces exactly the same output as IJG's original 'jpeg_idct_4x4' + * function from jpeg-6b (jidctred.c). + * + * NOTE: jpeg-8 has an improved implementation of 4x4 inverse-DCT, which + * requires much less arithmetic operations and hence should be faster. + * The primary purpose of this particular NEON optimized function is + * bit exact compatibility with jpeg-6b. + * + * TODO: a bit better instructions scheduling can be achieved by expanding + * idct_helper/transpose_4x4 macros and reordering instructions, + * but readability will suffer somewhat. + */ + +#define CONST_BITS 13 + +#define FIX_0_211164243 (1730) /* FIX(0.211164243) */ +#define FIX_0_509795579 (4176) /* FIX(0.509795579) */ +#define FIX_0_601344887 (4926) /* FIX(0.601344887) */ +#define FIX_0_720959822 (5906) /* FIX(0.720959822) */ +#define FIX_0_765366865 (6270) /* FIX(0.765366865) */ +#define FIX_0_850430095 (6967) /* FIX(0.850430095) */ +#define FIX_0_899976223 (7373) /* FIX(0.899976223) */ +#define FIX_1_061594337 (8697) /* FIX(1.061594337) */ +#define FIX_1_272758580 (10426) /* FIX(1.272758580) */ +#define FIX_1_451774981 (11893) /* FIX(1.451774981) */ +#define FIX_1_847759065 (15137) /* FIX(1.847759065) */ +#define FIX_2_172734803 (17799) /* FIX(2.172734803) */ +#define FIX_2_562915447 (20995) /* FIX(2.562915447) */ +#define FIX_3_624509785 (29692) /* FIX(3.624509785) */ + +.balign 16 +jsimd_idct_4x4_neon_consts: + .short FIX_1_847759065 /* d0[0] */ + .short -FIX_0_765366865 /* d0[1] */ + .short -FIX_0_211164243 /* d0[2] */ + .short FIX_1_451774981 /* d0[3] */ + .short -FIX_2_172734803 /* d1[0] */ + .short FIX_1_061594337 /* d1[1] */ + .short -FIX_0_509795579 /* d1[2] */ + .short -FIX_0_601344887 /* d1[3] */ + .short FIX_0_899976223 /* d2[0] */ + .short FIX_2_562915447 /* d2[1] */ + .short 1 << (CONST_BITS+1) /* d2[2] */ + .short 0 /* d2[3] */ + +.macro idct_helper x4, x6, x8, x10, x12, x14, x16, shift, y26, y27, y28, y29 + vmull.s16 q14, \x4, d2[2] + vmlal.s16 q14, \x8, d0[0] + vmlal.s16 q14, \x14, d0[1] + + vmull.s16 q13, \x16, d1[2] + vmlal.s16 q13, \x12, d1[3] + vmlal.s16 q13, \x10, d2[0] + vmlal.s16 q13, \x6, d2[1] + + vmull.s16 q15, \x4, d2[2] + vmlsl.s16 q15, \x8, d0[0] + vmlsl.s16 q15, \x14, d0[1] + + vmull.s16 q12, \x16, d0[2] + vmlal.s16 q12, \x12, d0[3] + vmlal.s16 q12, \x10, d1[0] + vmlal.s16 q12, \x6, d1[1] + + vadd.s32 q10, q14, q13 + vsub.s32 q14, q14, q13 + +.if \shift > 16 + vrshr.s32 q10, q10, #\shift + vrshr.s32 q14, q14, #\shift + vmovn.s32 \y26, q10 + vmovn.s32 \y29, q14 +.else + vrshrn.s32 \y26, q10, #\shift + vrshrn.s32 \y29, q14, #\shift +.endif + + vadd.s32 q10, q15, q12 + vsub.s32 q15, q15, q12 + +.if \shift > 16 + vrshr.s32 q10, q10, #\shift + vrshr.s32 q15, q15, #\shift + vmovn.s32 \y27, q10 + vmovn.s32 \y28, q15 +.else + vrshrn.s32 \y27, q10, #\shift + vrshrn.s32 \y28, q15, #\shift +.endif + +.endm + +asm_function jsimd_idct_4x4_neon + + DCT_TABLE .req r0 + COEF_BLOCK .req r1 + OUTPUT_BUF .req r2 + OUTPUT_COL .req r3 + TMP1 .req r0 + TMP2 .req r1 + TMP3 .req r2 + TMP4 .req ip + + vpush {d8-d15} + + /* Load constants (d3 is just used for padding) */ + adr TMP4, jsimd_idct_4x4_neon_consts + vld1.16 {d0, d1, d2, d3}, [TMP4, :128] + + /* Load all COEF_BLOCK into NEON registers with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | d4 | d5 + * 1 | d6 | d7 + * 2 | d8 | d9 + * 3 | d10 | d11 + * 4 | - | - + * 5 | d12 | d13 + * 6 | d14 | d15 + * 7 | d16 | d17 + */ + vld1.16 {d4, d5, d6, d7}, [COEF_BLOCK, :128]! + vld1.16 {d8, d9, d10, d11}, [COEF_BLOCK, :128]! + add COEF_BLOCK, COEF_BLOCK, #16 + vld1.16 {d12, d13, d14, d15}, [COEF_BLOCK, :128]! + vld1.16 {d16, d17}, [COEF_BLOCK, :128]! + /* dequantize */ + vld1.16 {d18, d19, d20, d21}, [DCT_TABLE, :128]! + vmul.s16 q2, q2, q9 + vld1.16 {d22, d23, d24, d25}, [DCT_TABLE, :128]! + vmul.s16 q3, q3, q10 + vmul.s16 q4, q4, q11 + add DCT_TABLE, DCT_TABLE, #16 + vld1.16 {d26, d27, d28, d29}, [DCT_TABLE, :128]! + vmul.s16 q5, q5, q12 + vmul.s16 q6, q6, q13 + vld1.16 {d30, d31}, [DCT_TABLE, :128]! + vmul.s16 q7, q7, q14 + vmul.s16 q8, q8, q15 + + /* Pass 1 */ + idct_helper d4, d6, d8, d10, d12, d14, d16, 12, d4, d6, d8, d10 + transpose_4x4 d4, d6, d8, d10 + idct_helper d5, d7, d9, d11, d13, d15, d17, 12, d5, d7, d9, d11 + transpose_4x4 d5, d7, d9, d11 + + /* Pass 2 */ + idct_helper d4, d6, d8, d10, d7, d9, d11, 19, d26, d27, d28, d29 + transpose_4x4 d26, d27, d28, d29 + + /* Range limit */ + vmov.u16 q15, #0x80 + vadd.s16 q13, q13, q15 + vadd.s16 q14, q14, q15 + vqmovun.s16 d26, q13 + vqmovun.s16 d27, q14 + + /* Store results to the output buffer */ + ldmia OUTPUT_BUF, {TMP1, TMP2, TMP3, TMP4} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + add TMP3, TMP3, OUTPUT_COL + add TMP4, TMP4, OUTPUT_COL + +#if defined(__ARMEL__) && !RESPECT_STRICT_ALIGNMENT + /* We can use much less instructions on little endian systems if the + * OS kernel is not configured to trap unaligned memory accesses + */ + vst1.32 {d26[0]}, [TMP1]! + vst1.32 {d27[0]}, [TMP3]! + vst1.32 {d26[1]}, [TMP2]! + vst1.32 {d27[1]}, [TMP4]! +#else + vst1.8 {d26[0]}, [TMP1]! + vst1.8 {d27[0]}, [TMP3]! + vst1.8 {d26[1]}, [TMP1]! + vst1.8 {d27[1]}, [TMP3]! + vst1.8 {d26[2]}, [TMP1]! + vst1.8 {d27[2]}, [TMP3]! + vst1.8 {d26[3]}, [TMP1]! + vst1.8 {d27[3]}, [TMP3]! + + vst1.8 {d26[4]}, [TMP2]! + vst1.8 {d27[4]}, [TMP4]! + vst1.8 {d26[5]}, [TMP2]! + vst1.8 {d27[5]}, [TMP4]! + vst1.8 {d26[6]}, [TMP2]! + vst1.8 {d27[6]}, [TMP4]! + vst1.8 {d26[7]}, [TMP2]! + vst1.8 {d27[7]}, [TMP4]! +#endif + + vpop {d8-d15} + bx lr + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 + .unreq TMP3 + .unreq TMP4 +.endfunc + +.purgem idct_helper + +/*****************************************************************************/ + +/* + * jsimd_idct_2x2_neon + * + * This function contains inverse-DCT code for getting reduced-size + * 2x2 pixels output from an 8x8 DCT block. It uses the same calculations + * and produces exactly the same output as IJG's original 'jpeg_idct_2x2' + * function from jpeg-6b (jidctred.c). + * + * NOTE: jpeg-8 has an improved implementation of 2x2 inverse-DCT, which + * requires much less arithmetic operations and hence should be faster. + * The primary purpose of this particular NEON optimized function is + * bit exact compatibility with jpeg-6b. + */ + +.balign 8 +jsimd_idct_2x2_neon_consts: + .short -FIX_0_720959822 /* d0[0] */ + .short FIX_0_850430095 /* d0[1] */ + .short -FIX_1_272758580 /* d0[2] */ + .short FIX_3_624509785 /* d0[3] */ + +.macro idct_helper x4, x6, x10, x12, x16, shift, y26, y27 + vshll.s16 q14, \x4, #15 + vmull.s16 q13, \x6, d0[3] + vmlal.s16 q13, \x10, d0[2] + vmlal.s16 q13, \x12, d0[1] + vmlal.s16 q13, \x16, d0[0] + + vadd.s32 q10, q14, q13 + vsub.s32 q14, q14, q13 + +.if \shift > 16 + vrshr.s32 q10, q10, #\shift + vrshr.s32 q14, q14, #\shift + vmovn.s32 \y26, q10 + vmovn.s32 \y27, q14 +.else + vrshrn.s32 \y26, q10, #\shift + vrshrn.s32 \y27, q14, #\shift +.endif + +.endm + +asm_function jsimd_idct_2x2_neon + + DCT_TABLE .req r0 + COEF_BLOCK .req r1 + OUTPUT_BUF .req r2 + OUTPUT_COL .req r3 + TMP1 .req r0 + TMP2 .req ip + + vpush {d8-d15} + + /* Load constants */ + adr TMP2, jsimd_idct_2x2_neon_consts + vld1.16 {d0}, [TMP2, :64] + + /* Load all COEF_BLOCK into NEON registers with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | d4 | d5 + * 1 | d6 | d7 + * 2 | - | - + * 3 | d10 | d11 + * 4 | - | - + * 5 | d12 | d13 + * 6 | - | - + * 7 | d16 | d17 + */ + vld1.16 {d4, d5, d6, d7}, [COEF_BLOCK, :128]! + add COEF_BLOCK, COEF_BLOCK, #16 + vld1.16 {d10, d11}, [COEF_BLOCK, :128]! + add COEF_BLOCK, COEF_BLOCK, #16 + vld1.16 {d12, d13}, [COEF_BLOCK, :128]! + add COEF_BLOCK, COEF_BLOCK, #16 + vld1.16 {d16, d17}, [COEF_BLOCK, :128]! + /* Dequantize */ + vld1.16 {d18, d19, d20, d21}, [DCT_TABLE, :128]! + vmul.s16 q2, q2, q9 + vmul.s16 q3, q3, q10 + add DCT_TABLE, DCT_TABLE, #16 + vld1.16 {d24, d25}, [DCT_TABLE, :128]! + vmul.s16 q5, q5, q12 + add DCT_TABLE, DCT_TABLE, #16 + vld1.16 {d26, d27}, [DCT_TABLE, :128]! + vmul.s16 q6, q6, q13 + add DCT_TABLE, DCT_TABLE, #16 + vld1.16 {d30, d31}, [DCT_TABLE, :128]! + vmul.s16 q8, q8, q15 + + /* Pass 1 */ +#if 0 + idct_helper d4, d6, d10, d12, d16, 13, d4, d6 + transpose_4x4 d4, d6, d8, d10 + idct_helper d5, d7, d11, d13, d17, 13, d5, d7 + transpose_4x4 d5, d7, d9, d11 +#else + vmull.s16 q13, d6, d0[3] + vmlal.s16 q13, d10, d0[2] + vmlal.s16 q13, d12, d0[1] + vmlal.s16 q13, d16, d0[0] + vmull.s16 q12, d7, d0[3] + vmlal.s16 q12, d11, d0[2] + vmlal.s16 q12, d13, d0[1] + vmlal.s16 q12, d17, d0[0] + vshll.s16 q14, d4, #15 + vshll.s16 q15, d5, #15 + vadd.s32 q10, q14, q13 + vsub.s32 q14, q14, q13 + vrshrn.s32 d4, q10, #13 + vrshrn.s32 d6, q14, #13 + vadd.s32 q10, q15, q12 + vsub.s32 q14, q15, q12 + vrshrn.s32 d5, q10, #13 + vrshrn.s32 d7, q14, #13 + vtrn.16 q2, q3 + vtrn.32 q3, q5 +#endif + + /* Pass 2 */ + idct_helper d4, d6, d10, d7, d11, 20, d26, d27 + + /* Range limit */ + vmov.u16 q15, #0x80 + vadd.s16 q13, q13, q15 + vqmovun.s16 d26, q13 + vqmovun.s16 d27, q13 + + /* Store results to the output buffer */ + ldmia OUTPUT_BUF, {TMP1, TMP2} + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + + vst1.8 {d26[0]}, [TMP1]! + vst1.8 {d27[4]}, [TMP1]! + vst1.8 {d26[1]}, [TMP2]! + vst1.8 {d27[5]}, [TMP2]! + + vpop {d8-d15} + bx lr + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 +.endfunc + +.purgem idct_helper + +/*****************************************************************************/ + +/* + * jsimd_ycc_extrgb_convert_neon + * jsimd_ycc_extbgr_convert_neon + * jsimd_ycc_extrgbx_convert_neon + * jsimd_ycc_extbgrx_convert_neon + * jsimd_ycc_extxbgr_convert_neon + * jsimd_ycc_extxrgb_convert_neon + * + * Colorspace conversion YCbCr -> RGB + */ + + +.macro do_load size + .if \size == 8 + vld1.8 {d4}, [U, :64]! + vld1.8 {d5}, [V, :64]! + vld1.8 {d0}, [Y, :64]! + pld [U, #64] + pld [V, #64] + pld [Y, #64] + .elseif \size == 4 + vld1.8 {d4[0]}, [U]! + vld1.8 {d4[1]}, [U]! + vld1.8 {d4[2]}, [U]! + vld1.8 {d4[3]}, [U]! + vld1.8 {d5[0]}, [V]! + vld1.8 {d5[1]}, [V]! + vld1.8 {d5[2]}, [V]! + vld1.8 {d5[3]}, [V]! + vld1.8 {d0[0]}, [Y]! + vld1.8 {d0[1]}, [Y]! + vld1.8 {d0[2]}, [Y]! + vld1.8 {d0[3]}, [Y]! + .elseif \size == 2 + vld1.8 {d4[4]}, [U]! + vld1.8 {d4[5]}, [U]! + vld1.8 {d5[4]}, [V]! + vld1.8 {d5[5]}, [V]! + vld1.8 {d0[4]}, [Y]! + vld1.8 {d0[5]}, [Y]! + .elseif \size == 1 + vld1.8 {d4[6]}, [U]! + vld1.8 {d5[6]}, [V]! + vld1.8 {d0[6]}, [Y]! + .else + .error unsupported macroblock size + .endif +.endm + +.macro do_store bpp, size + .if \bpp == 24 + .if \size == 8 + vst3.8 {d10, d11, d12}, [RGB]! + .elseif \size == 4 + vst3.8 {d10[0], d11[0], d12[0]}, [RGB]! + vst3.8 {d10[1], d11[1], d12[1]}, [RGB]! + vst3.8 {d10[2], d11[2], d12[2]}, [RGB]! + vst3.8 {d10[3], d11[3], d12[3]}, [RGB]! + .elseif \size == 2 + vst3.8 {d10[4], d11[4], d12[4]}, [RGB]! + vst3.8 {d10[5], d11[5], d12[5]}, [RGB]! + .elseif \size == 1 + vst3.8 {d10[6], d11[6], d12[6]}, [RGB]! + .else + .error unsupported macroblock size + .endif + .elseif \bpp == 32 + .if \size == 8 + vst4.8 {d10, d11, d12, d13}, [RGB]! + .elseif \size == 4 + vst4.8 {d10[0], d11[0], d12[0], d13[0]}, [RGB]! + vst4.8 {d10[1], d11[1], d12[1], d13[1]}, [RGB]! + vst4.8 {d10[2], d11[2], d12[2], d13[2]}, [RGB]! + vst4.8 {d10[3], d11[3], d12[3], d13[3]}, [RGB]! + .elseif \size == 2 + vst4.8 {d10[4], d11[4], d12[4], d13[4]}, [RGB]! + vst4.8 {d10[5], d11[5], d12[5], d13[5]}, [RGB]! + .elseif \size == 1 + vst4.8 {d10[6], d11[6], d12[6], d13[6]}, [RGB]! + .else + .error unsupported macroblock size + .endif + .else + .error unsupported bpp + .endif +.endm + +.macro generate_jsimd_ycc_rgb_convert_neon colorid, bpp, r_offs, g_offs, b_offs + +/* + * 2 stage pipelined YCbCr->RGB conversion + */ + +.macro do_yuv_to_rgb_stage1 + vaddw.u8 q3, q1, d4 /* q3 = u - 128 */ + vaddw.u8 q4, q1, d5 /* q2 = v - 128 */ + vmull.s16 q10, d6, d1[1] /* multiply by -11277 */ + vmlal.s16 q10, d8, d1[2] /* multiply by -23401 */ + vmull.s16 q11, d7, d1[1] /* multiply by -11277 */ + vmlal.s16 q11, d9, d1[2] /* multiply by -23401 */ + vmull.s16 q12, d8, d1[0] /* multiply by 22971 */ + vmull.s16 q13, d9, d1[0] /* multiply by 22971 */ + vmull.s16 q14, d6, d1[3] /* multiply by 29033 */ + vmull.s16 q15, d7, d1[3] /* multiply by 29033 */ +.endm + +.macro do_yuv_to_rgb_stage2 + vrshrn.s32 d20, q10, #15 + vrshrn.s32 d21, q11, #15 + vrshrn.s32 d24, q12, #14 + vrshrn.s32 d25, q13, #14 + vrshrn.s32 d28, q14, #14 + vrshrn.s32 d29, q15, #14 + vaddw.u8 q10, q10, d0 + vaddw.u8 q12, q12, d0 + vaddw.u8 q14, q14, d0 + vqmovun.s16 d1\g_offs, q10 + vqmovun.s16 d1\r_offs, q12 + vqmovun.s16 d1\b_offs, q14 +.endm + +.macro do_yuv_to_rgb_stage2_store_load_stage1 + vld1.8 {d4}, [U, :64]! + vrshrn.s32 d20, q10, #15 + vrshrn.s32 d21, q11, #15 + vrshrn.s32 d24, q12, #14 + vrshrn.s32 d25, q13, #14 + vrshrn.s32 d28, q14, #14 + vld1.8 {d5}, [V, :64]! + vrshrn.s32 d29, q15, #14 + vaddw.u8 q10, q10, d0 + vaddw.u8 q12, q12, d0 + vaddw.u8 q14, q14, d0 + vqmovun.s16 d1\g_offs, q10 + vld1.8 {d0}, [Y, :64]! + vqmovun.s16 d1\r_offs, q12 + pld [U, #64] + pld [V, #64] + pld [Y, #64] + vqmovun.s16 d1\b_offs, q14 + vaddw.u8 q3, q1, d4 /* q3 = u - 128 */ + vaddw.u8 q4, q1, d5 /* q2 = v - 128 */ + do_store \bpp, 8 + vmull.s16 q10, d6, d1[1] /* multiply by -11277 */ + vmlal.s16 q10, d8, d1[2] /* multiply by -23401 */ + vmull.s16 q11, d7, d1[1] /* multiply by -11277 */ + vmlal.s16 q11, d9, d1[2] /* multiply by -23401 */ + vmull.s16 q12, d8, d1[0] /* multiply by 22971 */ + vmull.s16 q13, d9, d1[0] /* multiply by 22971 */ + vmull.s16 q14, d6, d1[3] /* multiply by 29033 */ + vmull.s16 q15, d7, d1[3] /* multiply by 29033 */ +.endm + +.macro do_yuv_to_rgb + do_yuv_to_rgb_stage1 + do_yuv_to_rgb_stage2 +.endm + +/* Apple gas crashes on adrl, work around that by using adr. + * But this requires a copy of these constants for each function. + */ + +.balign 16 +jsimd_ycc_\colorid\()_neon_consts: + .short 0, 0, 0, 0 + .short 22971, -11277, -23401, 29033 + .short -128, -128, -128, -128 + .short -128, -128, -128, -128 + +asm_function jsimd_ycc_\colorid\()_convert_neon + OUTPUT_WIDTH .req r0 + INPUT_BUF .req r1 + INPUT_ROW .req r2 + OUTPUT_BUF .req r3 + NUM_ROWS .req r4 + + INPUT_BUF0 .req r5 + INPUT_BUF1 .req r6 + INPUT_BUF2 .req INPUT_BUF + + RGB .req r7 + Y .req r8 + U .req r9 + V .req r10 + N .req ip + + /* Load constants to d1, d2, d3 (d0 is just used for padding) */ + adr ip, jsimd_ycc_\colorid\()_neon_consts + vld1.16 {d0, d1, d2, d3}, [ip, :128] + + /* Save ARM registers and handle input arguments */ + push {r4, r5, r6, r7, r8, r9, r10, lr} + ldr NUM_ROWS, [sp, #(4 * 8)] + ldr INPUT_BUF0, [INPUT_BUF] + ldr INPUT_BUF1, [INPUT_BUF, #4] + ldr INPUT_BUF2, [INPUT_BUF, #8] + .unreq INPUT_BUF + + /* Save NEON registers */ + vpush {d8-d15} + + /* Initially set d10, d11, d12, d13 to 0xFF */ + vmov.u8 q5, #255 + vmov.u8 q6, #255 + + /* Outer loop over scanlines */ + cmp NUM_ROWS, #1 + blt 9f +0: + ldr Y, [INPUT_BUF0, INPUT_ROW, lsl #2] + ldr U, [INPUT_BUF1, INPUT_ROW, lsl #2] + mov N, OUTPUT_WIDTH + ldr V, [INPUT_BUF2, INPUT_ROW, lsl #2] + add INPUT_ROW, INPUT_ROW, #1 + ldr RGB, [OUTPUT_BUF], #4 + + /* Inner loop over pixels */ + subs N, N, #8 + blt 3f + do_load 8 + do_yuv_to_rgb_stage1 + subs N, N, #8 + blt 2f +1: + do_yuv_to_rgb_stage2_store_load_stage1 + subs N, N, #8 + bge 1b +2: + do_yuv_to_rgb_stage2 + do_store \bpp, 8 + tst N, #7 + beq 8f +3: + tst N, #4 + beq 3f + do_load 4 +3: + tst N, #2 + beq 4f + do_load 2 +4: + tst N, #1 + beq 5f + do_load 1 +5: + do_yuv_to_rgb + tst N, #4 + beq 6f + do_store \bpp, 4 +6: + tst N, #2 + beq 7f + do_store \bpp, 2 +7: + tst N, #1 + beq 8f + do_store \bpp, 1 +8: + subs NUM_ROWS, NUM_ROWS, #1 + bgt 0b +9: + /* Restore all registers and return */ + vpop {d8-d15} + pop {r4, r5, r6, r7, r8, r9, r10, pc} + + .unreq OUTPUT_WIDTH + .unreq INPUT_ROW + .unreq OUTPUT_BUF + .unreq NUM_ROWS + .unreq INPUT_BUF0 + .unreq INPUT_BUF1 + .unreq INPUT_BUF2 + .unreq RGB + .unreq Y + .unreq U + .unreq V + .unreq N +.endfunc + +.purgem do_yuv_to_rgb +.purgem do_yuv_to_rgb_stage1 +.purgem do_yuv_to_rgb_stage2 +.purgem do_yuv_to_rgb_stage2_store_load_stage1 + +.endm + +/*--------------------------------- id ----- bpp R G B */ +generate_jsimd_ycc_rgb_convert_neon extrgb, 24, 0, 1, 2 +generate_jsimd_ycc_rgb_convert_neon extbgr, 24, 2, 1, 0 +generate_jsimd_ycc_rgb_convert_neon extrgbx, 32, 0, 1, 2 +generate_jsimd_ycc_rgb_convert_neon extbgrx, 32, 2, 1, 0 +generate_jsimd_ycc_rgb_convert_neon extxbgr, 32, 3, 2, 1 +generate_jsimd_ycc_rgb_convert_neon extxrgb, 32, 1, 2, 3 + +.purgem do_load +.purgem do_store + +/*****************************************************************************/ + +/* + * jsimd_extrgb_ycc_convert_neon + * jsimd_extbgr_ycc_convert_neon + * jsimd_extrgbx_ycc_convert_neon + * jsimd_extbgrx_ycc_convert_neon + * jsimd_extxbgr_ycc_convert_neon + * jsimd_extxrgb_ycc_convert_neon + * + * Colorspace conversion RGB -> YCbCr + */ + +.macro do_store size + .if \size == 8 + vst1.8 {d20}, [Y]! + vst1.8 {d21}, [U]! + vst1.8 {d22}, [V]! + .elseif \size == 4 + vst1.8 {d20[0]}, [Y]! + vst1.8 {d20[1]}, [Y]! + vst1.8 {d20[2]}, [Y]! + vst1.8 {d20[3]}, [Y]! + vst1.8 {d21[0]}, [U]! + vst1.8 {d21[1]}, [U]! + vst1.8 {d21[2]}, [U]! + vst1.8 {d21[3]}, [U]! + vst1.8 {d22[0]}, [V]! + vst1.8 {d22[1]}, [V]! + vst1.8 {d22[2]}, [V]! + vst1.8 {d22[3]}, [V]! + .elseif \size == 2 + vst1.8 {d20[4]}, [Y]! + vst1.8 {d20[5]}, [Y]! + vst1.8 {d21[4]}, [U]! + vst1.8 {d21[5]}, [U]! + vst1.8 {d22[4]}, [V]! + vst1.8 {d22[5]}, [V]! + .elseif \size == 1 + vst1.8 {d20[6]}, [Y]! + vst1.8 {d21[6]}, [U]! + vst1.8 {d22[6]}, [V]! + .else + .error unsupported macroblock size + .endif +.endm + +.macro do_load bpp, size + .if \bpp == 24 + .if \size == 8 + vld3.8 {d10, d11, d12}, [RGB]! + pld [RGB, #128] + .elseif \size == 4 + vld3.8 {d10[0], d11[0], d12[0]}, [RGB]! + vld3.8 {d10[1], d11[1], d12[1]}, [RGB]! + vld3.8 {d10[2], d11[2], d12[2]}, [RGB]! + vld3.8 {d10[3], d11[3], d12[3]}, [RGB]! + .elseif \size == 2 + vld3.8 {d10[4], d11[4], d12[4]}, [RGB]! + vld3.8 {d10[5], d11[5], d12[5]}, [RGB]! + .elseif \size == 1 + vld3.8 {d10[6], d11[6], d12[6]}, [RGB]! + .else + .error unsupported macroblock size + .endif + .elseif \bpp == 32 + .if \size == 8 + vld4.8 {d10, d11, d12, d13}, [RGB]! + pld [RGB, #128] + .elseif \size == 4 + vld4.8 {d10[0], d11[0], d12[0], d13[0]}, [RGB]! + vld4.8 {d10[1], d11[1], d12[1], d13[1]}, [RGB]! + vld4.8 {d10[2], d11[2], d12[2], d13[2]}, [RGB]! + vld4.8 {d10[3], d11[3], d12[3], d13[3]}, [RGB]! + .elseif \size == 2 + vld4.8 {d10[4], d11[4], d12[4], d13[4]}, [RGB]! + vld4.8 {d10[5], d11[5], d12[5], d13[5]}, [RGB]! + .elseif \size == 1 + vld4.8 {d10[6], d11[6], d12[6], d13[6]}, [RGB]! + .else + .error unsupported macroblock size + .endif + .else + .error unsupported bpp + .endif +.endm + +.macro generate_jsimd_rgb_ycc_convert_neon colorid, bpp, r_offs, g_offs, b_offs + +/* + * 2 stage pipelined RGB->YCbCr conversion + */ + +.macro do_rgb_to_yuv_stage1 + vmovl.u8 q2, d1\r_offs /* r = { d4, d5 } */ + vmovl.u8 q3, d1\g_offs /* g = { d6, d7 } */ + vmovl.u8 q4, d1\b_offs /* b = { d8, d9 } */ + vmull.u16 q7, d4, d0[0] + vmlal.u16 q7, d6, d0[1] + vmlal.u16 q7, d8, d0[2] + vmull.u16 q8, d5, d0[0] + vmlal.u16 q8, d7, d0[1] + vmlal.u16 q8, d9, d0[2] + vrev64.32 q9, q1 + vrev64.32 q13, q1 + vmlsl.u16 q9, d4, d0[3] + vmlsl.u16 q9, d6, d1[0] + vmlal.u16 q9, d8, d1[1] + vmlsl.u16 q13, d5, d0[3] + vmlsl.u16 q13, d7, d1[0] + vmlal.u16 q13, d9, d1[1] + vrev64.32 q14, q1 + vrev64.32 q15, q1 + vmlal.u16 q14, d4, d1[1] + vmlsl.u16 q14, d6, d1[2] + vmlsl.u16 q14, d8, d1[3] + vmlal.u16 q15, d5, d1[1] + vmlsl.u16 q15, d7, d1[2] + vmlsl.u16 q15, d9, d1[3] +.endm + +.macro do_rgb_to_yuv_stage2 + vrshrn.u32 d20, q7, #16 + vrshrn.u32 d21, q8, #16 + vshrn.u32 d22, q9, #16 + vshrn.u32 d23, q13, #16 + vshrn.u32 d24, q14, #16 + vshrn.u32 d25, q15, #16 + vmovn.u16 d20, q10 /* d20 = y */ + vmovn.u16 d21, q11 /* d21 = u */ + vmovn.u16 d22, q12 /* d22 = v */ +.endm + +.macro do_rgb_to_yuv + do_rgb_to_yuv_stage1 + do_rgb_to_yuv_stage2 +.endm + +.macro do_rgb_to_yuv_stage2_store_load_stage1 + vrshrn.u32 d20, q7, #16 + vrshrn.u32 d21, q8, #16 + vshrn.u32 d22, q9, #16 + vrev64.32 q9, q1 + vshrn.u32 d23, q13, #16 + vrev64.32 q13, q1 + vshrn.u32 d24, q14, #16 + vshrn.u32 d25, q15, #16 + do_load \bpp, 8 + vmovn.u16 d20, q10 /* d20 = y */ + vmovl.u8 q2, d1\r_offs /* r = { d4, d5 } */ + vmovn.u16 d21, q11 /* d21 = u */ + vmovl.u8 q3, d1\g_offs /* g = { d6, d7 } */ + vmovn.u16 d22, q12 /* d22 = v */ + vmovl.u8 q4, d1\b_offs /* b = { d8, d9 } */ + vmull.u16 q7, d4, d0[0] + vmlal.u16 q7, d6, d0[1] + vmlal.u16 q7, d8, d0[2] + vst1.8 {d20}, [Y]! + vmull.u16 q8, d5, d0[0] + vmlal.u16 q8, d7, d0[1] + vmlal.u16 q8, d9, d0[2] + vmlsl.u16 q9, d4, d0[3] + vmlsl.u16 q9, d6, d1[0] + vmlal.u16 q9, d8, d1[1] + vst1.8 {d21}, [U]! + vmlsl.u16 q13, d5, d0[3] + vmlsl.u16 q13, d7, d1[0] + vmlal.u16 q13, d9, d1[1] + vrev64.32 q14, q1 + vrev64.32 q15, q1 + vmlal.u16 q14, d4, d1[1] + vmlsl.u16 q14, d6, d1[2] + vmlsl.u16 q14, d8, d1[3] + vst1.8 {d22}, [V]! + vmlal.u16 q15, d5, d1[1] + vmlsl.u16 q15, d7, d1[2] + vmlsl.u16 q15, d9, d1[3] +.endm + +.balign 16 +jsimd_\colorid\()_ycc_neon_consts: + .short 19595, 38470, 7471, 11059 + .short 21709, 32768, 27439, 5329 + .short 32767, 128, 32767, 128 + .short 32767, 128, 32767, 128 + +asm_function jsimd_\colorid\()_ycc_convert_neon + OUTPUT_WIDTH .req r0 + INPUT_BUF .req r1 + OUTPUT_BUF .req r2 + OUTPUT_ROW .req r3 + NUM_ROWS .req r4 + + OUTPUT_BUF0 .req r5 + OUTPUT_BUF1 .req r6 + OUTPUT_BUF2 .req OUTPUT_BUF + + RGB .req r7 + Y .req r8 + U .req r9 + V .req r10 + N .req ip + + /* Load constants to d0, d1, d2, d3 */ + adr ip, jsimd_\colorid\()_ycc_neon_consts + vld1.16 {d0, d1, d2, d3}, [ip, :128] + + /* Save ARM registers and handle input arguments */ + push {r4, r5, r6, r7, r8, r9, r10, lr} + ldr NUM_ROWS, [sp, #(4 * 8)] + ldr OUTPUT_BUF0, [OUTPUT_BUF] + ldr OUTPUT_BUF1, [OUTPUT_BUF, #4] + ldr OUTPUT_BUF2, [OUTPUT_BUF, #8] + .unreq OUTPUT_BUF + + /* Save NEON registers */ + vpush {d8-d15} + + /* Outer loop over scanlines */ + cmp NUM_ROWS, #1 + blt 9f +0: + ldr Y, [OUTPUT_BUF0, OUTPUT_ROW, lsl #2] + ldr U, [OUTPUT_BUF1, OUTPUT_ROW, lsl #2] + mov N, OUTPUT_WIDTH + ldr V, [OUTPUT_BUF2, OUTPUT_ROW, lsl #2] + add OUTPUT_ROW, OUTPUT_ROW, #1 + ldr RGB, [INPUT_BUF], #4 + + /* Inner loop over pixels */ + subs N, N, #8 + blt 3f + do_load \bpp, 8 + do_rgb_to_yuv_stage1 + subs N, N, #8 + blt 2f +1: + do_rgb_to_yuv_stage2_store_load_stage1 + subs N, N, #8 + bge 1b +2: + do_rgb_to_yuv_stage2 + do_store 8 + tst N, #7 + beq 8f +3: + tst N, #4 + beq 3f + do_load \bpp, 4 +3: + tst N, #2 + beq 4f + do_load \bpp, 2 +4: + tst N, #1 + beq 5f + do_load \bpp, 1 +5: + do_rgb_to_yuv + tst N, #4 + beq 6f + do_store 4 +6: + tst N, #2 + beq 7f + do_store 2 +7: + tst N, #1 + beq 8f + do_store 1 +8: + subs NUM_ROWS, NUM_ROWS, #1 + bgt 0b +9: + /* Restore all registers and return */ + vpop {d8-d15} + pop {r4, r5, r6, r7, r8, r9, r10, pc} + + .unreq OUTPUT_WIDTH + .unreq OUTPUT_ROW + .unreq INPUT_BUF + .unreq NUM_ROWS + .unreq OUTPUT_BUF0 + .unreq OUTPUT_BUF1 + .unreq OUTPUT_BUF2 + .unreq RGB + .unreq Y + .unreq U + .unreq V + .unreq N +.endfunc + +.purgem do_rgb_to_yuv +.purgem do_rgb_to_yuv_stage1 +.purgem do_rgb_to_yuv_stage2 +.purgem do_rgb_to_yuv_stage2_store_load_stage1 + +.endm + +/*--------------------------------- id ----- bpp R G B */ +generate_jsimd_rgb_ycc_convert_neon extrgb, 24, 0, 1, 2 +generate_jsimd_rgb_ycc_convert_neon extbgr, 24, 2, 1, 0 +generate_jsimd_rgb_ycc_convert_neon extrgbx, 32, 0, 1, 2 +generate_jsimd_rgb_ycc_convert_neon extbgrx, 32, 2, 1, 0 +generate_jsimd_rgb_ycc_convert_neon extxbgr, 32, 3, 2, 1 +generate_jsimd_rgb_ycc_convert_neon extxrgb, 32, 1, 2, 3 + +.purgem do_load +.purgem do_store + +/*****************************************************************************/ + +/* + * Load data into workspace, applying unsigned->signed conversion + * + * TODO: can be combined with 'jsimd_fdct_ifast_neon' to get + * rid of VST1.16 instructions + */ + +asm_function jsimd_convsamp_neon + SAMPLE_DATA .req r0 + START_COL .req r1 + WORKSPACE .req r2 + TMP1 .req r3 + TMP2 .req r4 + TMP3 .req r5 + TMP4 .req ip + + push {r4, r5} + vmov.u8 d0, #128 + + ldmia SAMPLE_DATA!, {TMP1, TMP2, TMP3, TMP4} + add TMP1, TMP1, START_COL + add TMP2, TMP2, START_COL + add TMP3, TMP3, START_COL + add TMP4, TMP4, START_COL + vld1.8 {d16}, [TMP1] + vsubl.u8 q8, d16, d0 + vld1.8 {d18}, [TMP2] + vsubl.u8 q9, d18, d0 + vld1.8 {d20}, [TMP3] + vsubl.u8 q10, d20, d0 + vld1.8 {d22}, [TMP4] + ldmia SAMPLE_DATA!, {TMP1, TMP2, TMP3, TMP4} + vsubl.u8 q11, d22, d0 + vst1.16 {d16, d17, d18, d19}, [WORKSPACE, :128]! + add TMP1, TMP1, START_COL + add TMP2, TMP2, START_COL + vst1.16 {d20, d21, d22, d23}, [WORKSPACE, :128]! + add TMP3, TMP3, START_COL + add TMP4, TMP4, START_COL + vld1.8 {d24}, [TMP1] + vsubl.u8 q12, d24, d0 + vld1.8 {d26}, [TMP2] + vsubl.u8 q13, d26, d0 + vld1.8 {d28}, [TMP3] + vsubl.u8 q14, d28, d0 + vld1.8 {d30}, [TMP4] + vsubl.u8 q15, d30, d0 + vst1.16 {d24, d25, d26, d27}, [WORKSPACE, :128]! + vst1.16 {d28, d29, d30, d31}, [WORKSPACE, :128]! + pop {r4, r5} + bx lr + + .unreq SAMPLE_DATA + .unreq START_COL + .unreq WORKSPACE + .unreq TMP1 + .unreq TMP2 + .unreq TMP3 + .unreq TMP4 +.endfunc + +/*****************************************************************************/ + +/* + * jsimd_fdct_ifast_neon + * + * This function contains a fast, not so accurate integer implementation of + * the forward DCT (Discrete Cosine Transform). It uses the same calculations + * and produces exactly the same output as IJG's original 'jpeg_fdct_ifast' + * function from jfdctfst.c + * + * TODO: can be combined with 'jsimd_convsamp_neon' to get + * rid of a bunch of VLD1.16 instructions + */ + +#define XFIX_0_382683433 d0[0] +#define XFIX_0_541196100 d0[1] +#define XFIX_0_707106781 d0[2] +#define XFIX_1_306562965 d0[3] + +.balign 16 +jsimd_fdct_ifast_neon_consts: + .short (98 * 128) /* XFIX_0_382683433 */ + .short (139 * 128) /* XFIX_0_541196100 */ + .short (181 * 128) /* XFIX_0_707106781 */ + .short (334 * 128 - 256 * 128) /* XFIX_1_306562965 */ + +asm_function jsimd_fdct_ifast_neon + + DATA .req r0 + TMP .req ip + + vpush {d8-d15} + + /* Load constants */ + adr TMP, jsimd_fdct_ifast_neon_consts + vld1.16 {d0}, [TMP, :64] + + /* Load all DATA into NEON registers with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | d16 | d17 | q8 + * 1 | d18 | d19 | q9 + * 2 | d20 | d21 | q10 + * 3 | d22 | d23 | q11 + * 4 | d24 | d25 | q12 + * 5 | d26 | d27 | q13 + * 6 | d28 | d29 | q14 + * 7 | d30 | d31 | q15 + */ + + vld1.16 {d16, d17, d18, d19}, [DATA, :128]! + vld1.16 {d20, d21, d22, d23}, [DATA, :128]! + vld1.16 {d24, d25, d26, d27}, [DATA, :128]! + vld1.16 {d28, d29, d30, d31}, [DATA, :128] + sub DATA, DATA, #(128 - 32) + + mov TMP, #2 +1: + /* Transpose */ + vtrn.16 q12, q13 + vtrn.16 q10, q11 + vtrn.16 q8, q9 + vtrn.16 q14, q15 + vtrn.32 q9, q11 + vtrn.32 q13, q15 + vtrn.32 q8, q10 + vtrn.32 q12, q14 + vswp d30, d23 + vswp d24, d17 + vswp d26, d19 + /* 1-D FDCT */ + vadd.s16 q2, q11, q12 + vswp d28, d21 + vsub.s16 q12, q11, q12 + vsub.s16 q6, q10, q13 + vadd.s16 q10, q10, q13 + vsub.s16 q7, q9, q14 + vadd.s16 q9, q9, q14 + vsub.s16 q1, q8, q15 + vadd.s16 q8, q8, q15 + vsub.s16 q4, q9, q10 + vsub.s16 q5, q8, q2 + vadd.s16 q3, q9, q10 + vadd.s16 q4, q4, q5 + vadd.s16 q2, q8, q2 + vqdmulh.s16 q4, q4, XFIX_0_707106781 + vadd.s16 q11, q12, q6 + vadd.s16 q8, q2, q3 + vsub.s16 q12, q2, q3 + vadd.s16 q3, q6, q7 + vadd.s16 q7, q7, q1 + vqdmulh.s16 q3, q3, XFIX_0_707106781 + vsub.s16 q6, q11, q7 + vadd.s16 q10, q5, q4 + vqdmulh.s16 q6, q6, XFIX_0_382683433 + vsub.s16 q14, q5, q4 + vqdmulh.s16 q11, q11, XFIX_0_541196100 + vqdmulh.s16 q5, q7, XFIX_1_306562965 + vadd.s16 q4, q1, q3 + vsub.s16 q3, q1, q3 + vadd.s16 q7, q7, q6 + vadd.s16 q11, q11, q6 + vadd.s16 q7, q7, q5 + vadd.s16 q13, q3, q11 + vsub.s16 q11, q3, q11 + vadd.s16 q9, q4, q7 + vsub.s16 q15, q4, q7 + subs TMP, TMP, #1 + bne 1b + + /* store results */ + vst1.16 {d16, d17, d18, d19}, [DATA, :128]! + vst1.16 {d20, d21, d22, d23}, [DATA, :128]! + vst1.16 {d24, d25, d26, d27}, [DATA, :128]! + vst1.16 {d28, d29, d30, d31}, [DATA, :128] + + vpop {d8-d15} + bx lr + + .unreq DATA + .unreq TMP +.endfunc + +/*****************************************************************************/ + +/* + * GLOBAL(void) + * jsimd_quantize_neon (JCOEFPTR coef_block, DCTELEM * divisors, + * DCTELEM * workspace); + * + * Note: the code uses 2 stage pipelining in order to improve instructions + * scheduling and eliminate stalls (this provides ~15% better + * performance for this function on both ARM Cortex-A8 and + * ARM Cortex-A9 when compared to the non-pipelined variant). + * The instructions which belong to the second stage use different + * indentation for better readiability. + */ +asm_function jsimd_quantize_neon + + COEF_BLOCK .req r0 + DIVISORS .req r1 + WORKSPACE .req r2 + + RECIPROCAL .req DIVISORS + CORRECTION .req r3 + SHIFT .req ip + LOOP_COUNT .req r4 + + vld1.16 {d0, d1, d2, d3}, [WORKSPACE, :128]! + vabs.s16 q12, q0 + add CORRECTION, DIVISORS, #(64 * 2) + add SHIFT, DIVISORS, #(64 * 6) + vld1.16 {d20, d21, d22, d23}, [CORRECTION, :128]! + vabs.s16 q13, q1 + vld1.16 {d16, d17, d18, d19}, [RECIPROCAL, :128]! + vadd.u16 q12, q12, q10 /* add correction */ + vadd.u16 q13, q13, q11 + vmull.u16 q10, d24, d16 /* multiply by reciprocal */ + vmull.u16 q11, d25, d17 + vmull.u16 q8, d26, d18 + vmull.u16 q9, d27, d19 + vld1.16 {d24, d25, d26, d27}, [SHIFT, :128]! + vshrn.u32 d20, q10, #16 + vshrn.u32 d21, q11, #16 + vshrn.u32 d22, q8, #16 + vshrn.u32 d23, q9, #16 + vneg.s16 q12, q12 + vneg.s16 q13, q13 + vshr.s16 q2, q0, #15 /* extract sign */ + vshr.s16 q3, q1, #15 + vshl.u16 q14, q10, q12 /* shift */ + vshl.u16 q15, q11, q13 + + push {r4, r5} + mov LOOP_COUNT, #3 +1: + vld1.16 {d0, d1, d2, d3}, [WORKSPACE, :128]! + veor.u16 q14, q14, q2 /* restore sign */ + vabs.s16 q12, q0 + vld1.16 {d20, d21, d22, d23}, [CORRECTION, :128]! + vabs.s16 q13, q1 + veor.u16 q15, q15, q3 + vld1.16 {d16, d17, d18, d19}, [RECIPROCAL, :128]! + vadd.u16 q12, q12, q10 /* add correction */ + vadd.u16 q13, q13, q11 + vmull.u16 q10, d24, d16 /* multiply by reciprocal */ + vmull.u16 q11, d25, d17 + vmull.u16 q8, d26, d18 + vmull.u16 q9, d27, d19 + vsub.u16 q14, q14, q2 + vld1.16 {d24, d25, d26, d27}, [SHIFT, :128]! + vsub.u16 q15, q15, q3 + vshrn.u32 d20, q10, #16 + vshrn.u32 d21, q11, #16 + vst1.16 {d28, d29, d30, d31}, [COEF_BLOCK, :128]! + vshrn.u32 d22, q8, #16 + vshrn.u32 d23, q9, #16 + vneg.s16 q12, q12 + vneg.s16 q13, q13 + vshr.s16 q2, q0, #15 /* extract sign */ + vshr.s16 q3, q1, #15 + vshl.u16 q14, q10, q12 /* shift */ + vshl.u16 q15, q11, q13 + subs LOOP_COUNT, LOOP_COUNT, #1 + bne 1b + pop {r4, r5} + + veor.u16 q14, q14, q2 /* restore sign */ + veor.u16 q15, q15, q3 + vsub.u16 q14, q14, q2 + vsub.u16 q15, q15, q3 + vst1.16 {d28, d29, d30, d31}, [COEF_BLOCK, :128]! + + bx lr /* return */ + + .unreq COEF_BLOCK + .unreq DIVISORS + .unreq WORKSPACE + .unreq RECIPROCAL + .unreq CORRECTION + .unreq SHIFT + .unreq LOOP_COUNT +.endfunc + +/*****************************************************************************/ + +/* + * GLOBAL(void) + * jsimd_h2v1_fancy_upsample_neon (int max_v_samp_factor, + * JDIMENSION downsampled_width, + * JSAMPARRAY input_data, + * JSAMPARRAY * output_data_ptr); + * + * Note: the use of unaligned writes is the main remaining bottleneck in + * this code, which can be potentially solved to get up to tens + * of percents performance improvement on Cortex-A8/Cortex-A9. + */ + +/* + * Upsample 16 source pixels to 32 destination pixels. The new 16 source + * pixels are loaded to q0. The previous 16 source pixels are in q1. The + * shifted-by-one source pixels are constructed in q2 by using q0 and q1. + * Register d28 is used for multiplication by 3. Register q15 is used + * for adding +1 bias. + */ +.macro upsample16 OUTPTR, INPTR + vld1.8 {q0}, [\INPTR]! + vmovl.u8 q8, d0 + vext.8 q2, q1, q0, #15 + vmovl.u8 q9, d1 + vaddw.u8 q10, q15, d4 + vaddw.u8 q11, q15, d5 + vmlal.u8 q8, d4, d28 + vmlal.u8 q9, d5, d28 + vmlal.u8 q10, d0, d28 + vmlal.u8 q11, d1, d28 + vmov q1, q0 /* backup source pixels to q1 */ + vrshrn.u16 d6, q8, #2 + vrshrn.u16 d7, q9, #2 + vshrn.u16 d8, q10, #2 + vshrn.u16 d9, q11, #2 + vst2.8 {d6, d7, d8, d9}, [\OUTPTR]! +.endm + +/* + * Upsample 32 source pixels to 64 destination pixels. Compared to 'usample16' + * macro, the roles of q0 and q1 registers are reversed for even and odd + * groups of 16 pixels, that's why "vmov q1, q0" instructions are not needed. + * Also this unrolling allows to reorder loads and stores to compensate + * multiplication latency and reduce stalls. + */ +.macro upsample32 OUTPTR, INPTR + /* even 16 pixels group */ + vld1.8 {q0}, [\INPTR]! + vmovl.u8 q8, d0 + vext.8 q2, q1, q0, #15 + vmovl.u8 q9, d1 + vaddw.u8 q10, q15, d4 + vaddw.u8 q11, q15, d5 + vmlal.u8 q8, d4, d28 + vmlal.u8 q9, d5, d28 + vmlal.u8 q10, d0, d28 + vmlal.u8 q11, d1, d28 + /* odd 16 pixels group */ + vld1.8 {q1}, [\INPTR]! + vrshrn.u16 d6, q8, #2 + vrshrn.u16 d7, q9, #2 + vshrn.u16 d8, q10, #2 + vshrn.u16 d9, q11, #2 + vmovl.u8 q8, d2 + vext.8 q2, q0, q1, #15 + vmovl.u8 q9, d3 + vaddw.u8 q10, q15, d4 + vaddw.u8 q11, q15, d5 + vmlal.u8 q8, d4, d28 + vmlal.u8 q9, d5, d28 + vmlal.u8 q10, d2, d28 + vmlal.u8 q11, d3, d28 + vst2.8 {d6, d7, d8, d9}, [\OUTPTR]! + vrshrn.u16 d6, q8, #2 + vrshrn.u16 d7, q9, #2 + vshrn.u16 d8, q10, #2 + vshrn.u16 d9, q11, #2 + vst2.8 {d6, d7, d8, d9}, [\OUTPTR]! +.endm + +/* + * Upsample a row of WIDTH pixels from INPTR to OUTPTR. + */ +.macro upsample_row OUTPTR, INPTR, WIDTH, TMP1 + /* special case for the first and last pixels */ + sub \WIDTH, \WIDTH, #1 + add \OUTPTR, \OUTPTR, #1 + ldrb \TMP1, [\INPTR, \WIDTH] + strb \TMP1, [\OUTPTR, \WIDTH, asl #1] + ldrb \TMP1, [\INPTR], #1 + strb \TMP1, [\OUTPTR, #-1] + vmov.8 d3[7], \TMP1 + + subs \WIDTH, \WIDTH, #32 + blt 5f +0: /* process 32 pixels per iteration */ + upsample32 \OUTPTR, \INPTR + subs \WIDTH, \WIDTH, #32 + bge 0b +5: + adds \WIDTH, \WIDTH, #16 + blt 1f +0: /* process 16 pixels if needed */ + upsample16 \OUTPTR, \INPTR + subs \WIDTH, \WIDTH, #16 +1: + adds \WIDTH, \WIDTH, #16 + beq 9f + + /* load the remaining 1-15 pixels */ + add \INPTR, \INPTR, \WIDTH + tst \WIDTH, #1 + beq 2f + sub \INPTR, \INPTR, #1 + vld1.8 {d0[0]}, [\INPTR] +2: + tst \WIDTH, #2 + beq 2f + vext.8 d0, d0, d0, #6 + sub \INPTR, \INPTR, #1 + vld1.8 {d0[1]}, [\INPTR] + sub \INPTR, \INPTR, #1 + vld1.8 {d0[0]}, [\INPTR] +2: + tst \WIDTH, #4 + beq 2f + vrev64.32 d0, d0 + sub \INPTR, \INPTR, #1 + vld1.8 {d0[3]}, [\INPTR] + sub \INPTR, \INPTR, #1 + vld1.8 {d0[2]}, [\INPTR] + sub \INPTR, \INPTR, #1 + vld1.8 {d0[1]}, [\INPTR] + sub \INPTR, \INPTR, #1 + vld1.8 {d0[0]}, [\INPTR] +2: + tst \WIDTH, #8 + beq 2f + vmov d1, d0 + sub \INPTR, \INPTR, #8 + vld1.8 {d0}, [\INPTR] +2: /* upsample the remaining pixels */ + vmovl.u8 q8, d0 + vext.8 q2, q1, q0, #15 + vmovl.u8 q9, d1 + vaddw.u8 q10, q15, d4 + vaddw.u8 q11, q15, d5 + vmlal.u8 q8, d4, d28 + vmlal.u8 q9, d5, d28 + vmlal.u8 q10, d0, d28 + vmlal.u8 q11, d1, d28 + vrshrn.u16 d10, q8, #2 + vrshrn.u16 d12, q9, #2 + vshrn.u16 d11, q10, #2 + vshrn.u16 d13, q11, #2 + vzip.8 d10, d11 + vzip.8 d12, d13 + /* store the remaining pixels */ + tst \WIDTH, #8 + beq 2f + vst1.8 {d10, d11}, [\OUTPTR]! + vmov q5, q6 +2: + tst \WIDTH, #4 + beq 2f + vst1.8 {d10}, [\OUTPTR]! + vmov d10, d11 +2: + tst \WIDTH, #2 + beq 2f + vst1.8 {d10[0]}, [\OUTPTR]! + vst1.8 {d10[1]}, [\OUTPTR]! + vst1.8 {d10[2]}, [\OUTPTR]! + vst1.8 {d10[3]}, [\OUTPTR]! + vext.8 d10, d10, d10, #4 +2: + tst \WIDTH, #1 + beq 2f + vst1.8 {d10[0]}, [\OUTPTR]! + vst1.8 {d10[1]}, [\OUTPTR]! +2: +9: +.endm + +asm_function jsimd_h2v1_fancy_upsample_neon + + MAX_V_SAMP_FACTOR .req r0 + DOWNSAMPLED_WIDTH .req r1 + INPUT_DATA .req r2 + OUTPUT_DATA_PTR .req r3 + OUTPUT_DATA .req OUTPUT_DATA_PTR + + OUTPTR .req r4 + INPTR .req r5 + WIDTH .req ip + TMP .req lr + + push {r4, r5, r6, lr} + vpush {d8-d15} + + ldr OUTPUT_DATA, [OUTPUT_DATA_PTR] + cmp MAX_V_SAMP_FACTOR, #0 + ble 99f + + /* initialize constants */ + vmov.u8 d28, #3 + vmov.u16 q15, #1 +11: + ldr INPTR, [INPUT_DATA], #4 + ldr OUTPTR, [OUTPUT_DATA], #4 + mov WIDTH, DOWNSAMPLED_WIDTH + upsample_row OUTPTR, INPTR, WIDTH, TMP + subs MAX_V_SAMP_FACTOR, MAX_V_SAMP_FACTOR, #1 + bgt 11b + +99: + vpop {d8-d15} + pop {r4, r5, r6, pc} + + .unreq MAX_V_SAMP_FACTOR + .unreq DOWNSAMPLED_WIDTH + .unreq INPUT_DATA + .unreq OUTPUT_DATA_PTR + .unreq OUTPUT_DATA + + .unreq OUTPTR + .unreq INPTR + .unreq WIDTH + .unreq TMP + +.endfunc + +.purgem upsample16 +.purgem upsample32 +.purgem upsample_row diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/Makefile b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/Makefile new file mode 100755 index 0000000..8f5b62b --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/Makefile @@ -0,0 +1,43 @@ +.DEFAULT_GOAL: libsimd + +libsimd_objects = jsimdcpu.o \ + jccolmmx.o jdcolmmx.o jcgrammx.o \ + jcsammmx.o jdsammmx.o jdmermmx.o \ + jcqntmmx.o jfmmxfst.o jfmmxint.o \ + jimmxred.o jimmxint.o jimmxfst.o \ + jcqnt3dn.o jf3dnflt.o ji3dnflt.o \ + jcqntsse.o jfsseflt.o jisseflt.o \ + jccolss2.o jdcolss2.o jcgrass2.o \ + jcsamss2.o jdsamss2.o jdmerss2.o \ + jcqnts2i.o jfss2fst.o jfss2int.o \ + jiss2red.o jiss2int.o jiss2fst.o \ + jcqnts2f.o jiss2flt.o + +BUILD_DIR=build + +libsimd: prepare build/jsimdcfg.inc jsimd_i386 + cd build && ar -r libsimd-i386.a $(libsimd_objects) "jsimd_i386.o" + +.PHONY: clean + +clean: + rm -rf "$(BUILD_DIR)" + +prepare: + mkdir -p "$(BUILD_DIR)" + +jsimd_i386: $(libsimd_objects) + xcrun llvm-gcc -m32 -march=i386 -I".." -I"../.." -I"../../libjpeg" -c "jsimd_i386.c" -o "$(BUILD_DIR)/jsimd_i386.o" + +build/jsimdcfg.inc: jsimdcfg.inc.h ../jpeglib.h ../jconfig.h ../jmorecfg.h + xcrun cpp -I"../../libjpeg" $< | egrep "^[\;%]|^\ %" | sed 's%_cpp_protection_%%' | sed 's@% define@%define@g' >"$@" + +%.o: %.asm + /usr/local/bin/nasm -fmacho -DMACHO -DPIC -I. -I"$(BUILD_DIR)/" -o "$(BUILD_DIR)/$@" "$<" + +jccolmmx.o: jcclrmmx.asm +jccolss2.o: jcclrss2.asm +jcgrammx.o: jcgrymmx.asm +jcgrass2.o: jcgryss2.asm +jdmermmx.o: jdmrgmmx.asm +jdmerss2.o: jdmrgss2.asm diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcclrmmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcclrmmx.asm new file mode 100755 index 0000000..e095253 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcclrmmx.asm @@ -0,0 +1,477 @@ +; +; jcclrmmx.asm - colorspace conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_rgb_ycc_convert_mmx (JDIMENSION img_width, +; JSAMPARRAY input_buf, JSAMPIMAGE output_buf, +; JDIMENSION output_row, int num_rows); +; + +%define img_width(b) (b)+8 ; JDIMENSION img_width +%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf +%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf +%define output_row(b) (b)+20 ; JDIMENSION output_row +%define num_rows(b) (b)+24 ; int num_rows + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 8 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_rgb_ycc_convert_mmx) + +EXTN(jsimd_rgb_ycc_convert_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [img_width(eax)] ; num_cols + test ecx,ecx + jz near .return + + push ecx + + mov esi, JSAMPIMAGE [output_buf(eax)] + mov ecx, JDIMENSION [output_row(eax)] + mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY] + lea edi, [edi+ecx*SIZEOF_JSAMPROW] + lea ebx, [ebx+ecx*SIZEOF_JSAMPROW] + lea edx, [edx+ecx*SIZEOF_JSAMPROW] + + pop ecx + + mov esi, JSAMPARRAY [input_buf(eax)] + mov eax, INT [num_rows(eax)] + test eax,eax + jle near .return + alignx 16,7 +.rowloop: + pushpic eax + push edx + push ebx + push edi + push esi + push ecx ; col + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr0 + mov ebx, JSAMPROW [ebx] ; outptr1 + mov edx, JSAMPROW [edx] ; outptr2 + movpic eax, POINTER [gotptr] ; load GOT address (eax) + + cmp ecx, byte SIZEOF_MMWORD + jae short .columnloop + alignx 16,7 + +%if RGB_PIXELSIZE == 3 ; --------------- + +.column_ld1: + push eax + push edx + lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE + test cl, SIZEOF_BYTE + jz short .column_ld2 + sub ecx, byte SIZEOF_BYTE + xor eax,eax + mov al, BYTE [esi+ecx] +.column_ld2: + test cl, SIZEOF_WORD + jz short .column_ld4 + sub ecx, byte SIZEOF_WORD + xor edx,edx + mov dx, WORD [esi+ecx] + shl eax, WORD_BIT + or eax,edx +.column_ld4: + movd mmA,eax + pop edx + pop eax + test cl, SIZEOF_DWORD + jz short .column_ld8 + sub ecx, byte SIZEOF_DWORD + movd mmG, DWORD [esi+ecx] + psllq mmA, DWORD_BIT + por mmA,mmG +.column_ld8: + test cl, SIZEOF_MMWORD + jz short .column_ld16 + movq mmG,mmA + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + mov ecx, SIZEOF_MMWORD + jmp short .rgb_ycc_cnv +.column_ld16: + test cl, 2*SIZEOF_MMWORD + mov ecx, SIZEOF_MMWORD + jz short .rgb_ycc_cnv + movq mmF,mmA + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] + jmp short .rgb_ycc_cnv + alignx 16,7 + +.columnloop: + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] + movq mmF, MMWORD [esi+2*SIZEOF_MMWORD] + +.rgb_ycc_cnv: + ; mmA=(00 10 20 01 11 21 02 12) + ; mmG=(22 03 13 23 04 14 24 05) + ; mmF=(15 25 06 16 26 07 17 27) + + movq mmD,mmA + psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01) + psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --) + + punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05) + psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23) + + punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16) + punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27) + + movq mmE,mmA + psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14) + psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --) + + punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) + psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25) + + punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07) + punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27) + + pxor mmH,mmH + + movq mmC,mmA + punpcklbw mmA,mmH ; mmA=(00 02 04 06) + punpckhbw mmC,mmH ; mmC=(10 12 14 16) + + movq mmB,mmE + punpcklbw mmE,mmH ; mmE=(20 22 24 26) + punpckhbw mmB,mmH ; mmB=(01 03 05 07) + + movq mmF,mmD + punpcklbw mmD,mmH ; mmD=(11 13 15 17) + punpckhbw mmF,mmH ; mmF=(21 23 25 27) + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +.column_ld1: + test cl, SIZEOF_MMWORD/8 + jz short .column_ld2 + sub ecx, byte SIZEOF_MMWORD/8 + movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld2: + test cl, SIZEOF_MMWORD/4 + jz short .column_ld4 + sub ecx, byte SIZEOF_MMWORD/4 + movq mmF,mmA + movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld4: + test cl, SIZEOF_MMWORD/2 + mov ecx, SIZEOF_MMWORD + jz short .rgb_ycc_cnv + movq mmD,mmA + movq mmC,mmF + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] + jmp short .rgb_ycc_cnv + alignx 16,7 + +.columnloop: + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] + movq mmD, MMWORD [esi+2*SIZEOF_MMWORD] + movq mmC, MMWORD [esi+3*SIZEOF_MMWORD] + +.rgb_ycc_cnv: + ; mmA=(00 10 20 30 01 11 21 31) + ; mmF=(02 12 22 32 03 13 23 33) + ; mmD=(04 14 24 34 05 15 25 35) + ; mmC=(06 16 26 36 07 17 27 37) + + movq mmB,mmA + punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32) + punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33) + + movq mmG,mmD + punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36) + punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37) + + movq mmE,mmA + punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) + punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36) + + movq mmH,mmB + punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17) + punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37) + + pxor mmF,mmF + + movq mmC,mmA + punpcklbw mmA,mmF ; mmA=(00 02 04 06) + punpckhbw mmC,mmF ; mmC=(10 12 14 16) + + movq mmD,mmB + punpcklbw mmB,mmF ; mmB=(01 03 05 07) + punpckhbw mmD,mmF ; mmD=(11 13 15 17) + + movq mmG,mmE + punpcklbw mmE,mmF ; mmE=(20 22 24 26) + punpckhbw mmG,mmF ; mmG=(30 32 34 36) + + punpcklbw mmF,mmH + punpckhbw mmH,mmH + psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27) + psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37) + +%endif ; RGB_PIXELSIZE ; --------------- + + ; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE + ; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO + + ; (Original) + ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + ; + ; (This implementation) + ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G + ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + + movq MMWORD [wk(0)], mm0 ; wk(0)=RE + movq MMWORD [wk(1)], mm1 ; wk(1)=RO + movq MMWORD [wk(2)], mm4 ; wk(2)=BE + movq MMWORD [wk(3)], mm5 ; wk(3)=BO + + movq mm6,mm1 + punpcklwd mm1,mm3 + punpckhwd mm6,mm3 + movq mm7,mm1 + movq mm4,mm6 + pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337) + pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337) + pmaddwd mm7,[GOTOFF(eax,PW_MF016_MF033)] ; mm7=ROL*-FIX(0.168)+GOL*-FIX(0.331) + pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=ROH*-FIX(0.168)+GOH*-FIX(0.331) + + movq MMWORD [wk(4)], mm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337) + movq MMWORD [wk(5)], mm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337) + + pxor mm1,mm1 + pxor mm6,mm6 + punpcklwd mm1,mm5 ; mm1=BOL + punpckhwd mm6,mm5 ; mm6=BOH + psrld mm1,1 ; mm1=BOL*FIX(0.500) + psrld mm6,1 ; mm6=BOH*FIX(0.500) + + movq mm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm5=[PD_ONEHALFM1_CJ] + + paddd mm7,mm1 + paddd mm4,mm6 + paddd mm7,mm5 + paddd mm4,mm5 + psrld mm7,SCALEBITS ; mm7=CbOL + psrld mm4,SCALEBITS ; mm4=CbOH + packssdw mm7,mm4 ; mm7=CbO + + movq mm1, MMWORD [wk(2)] ; mm1=BE + + movq mm6,mm0 + punpcklwd mm0,mm2 + punpckhwd mm6,mm2 + movq mm5,mm0 + movq mm4,mm6 + pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337) + pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337) + pmaddwd mm5,[GOTOFF(eax,PW_MF016_MF033)] ; mm5=REL*-FIX(0.168)+GEL*-FIX(0.331) + pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=REH*-FIX(0.168)+GEH*-FIX(0.331) + + movq MMWORD [wk(6)], mm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337) + movq MMWORD [wk(7)], mm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337) + + pxor mm0,mm0 + pxor mm6,mm6 + punpcklwd mm0,mm1 ; mm0=BEL + punpckhwd mm6,mm1 ; mm6=BEH + psrld mm0,1 ; mm0=BEL*FIX(0.500) + psrld mm6,1 ; mm6=BEH*FIX(0.500) + + movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ] + + paddd mm5,mm0 + paddd mm4,mm6 + paddd mm5,mm1 + paddd mm4,mm1 + psrld mm5,SCALEBITS ; mm5=CbEL + psrld mm4,SCALEBITS ; mm4=CbEH + packssdw mm5,mm4 ; mm5=CbE + + psllw mm7,BYTE_BIT + por mm5,mm7 ; mm5=Cb + movq MMWORD [ebx], mm5 ; Save Cb + + movq mm0, MMWORD [wk(3)] ; mm0=BO + movq mm6, MMWORD [wk(2)] ; mm6=BE + movq mm1, MMWORD [wk(1)] ; mm1=RO + + movq mm4,mm0 + punpcklwd mm0,mm3 + punpckhwd mm4,mm3 + movq mm7,mm0 + movq mm5,mm4 + pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250) + pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250) + pmaddwd mm7,[GOTOFF(eax,PW_MF008_MF041)] ; mm7=BOL*-FIX(0.081)+GOL*-FIX(0.418) + pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BOH*-FIX(0.081)+GOH*-FIX(0.418) + + movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF] + + paddd mm0, MMWORD [wk(4)] + paddd mm4, MMWORD [wk(5)] + paddd mm0,mm3 + paddd mm4,mm3 + psrld mm0,SCALEBITS ; mm0=YOL + psrld mm4,SCALEBITS ; mm4=YOH + packssdw mm0,mm4 ; mm0=YO + + pxor mm3,mm3 + pxor mm4,mm4 + punpcklwd mm3,mm1 ; mm3=ROL + punpckhwd mm4,mm1 ; mm4=ROH + psrld mm3,1 ; mm3=ROL*FIX(0.500) + psrld mm4,1 ; mm4=ROH*FIX(0.500) + + movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ] + + paddd mm7,mm3 + paddd mm5,mm4 + paddd mm7,mm1 + paddd mm5,mm1 + psrld mm7,SCALEBITS ; mm7=CrOL + psrld mm5,SCALEBITS ; mm5=CrOH + packssdw mm7,mm5 ; mm7=CrO + + movq mm3, MMWORD [wk(0)] ; mm3=RE + + movq mm4,mm6 + punpcklwd mm6,mm2 + punpckhwd mm4,mm2 + movq mm1,mm6 + movq mm5,mm4 + pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250) + pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250) + pmaddwd mm1,[GOTOFF(eax,PW_MF008_MF041)] ; mm1=BEL*-FIX(0.081)+GEL*-FIX(0.418) + pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BEH*-FIX(0.081)+GEH*-FIX(0.418) + + movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF] + + paddd mm6, MMWORD [wk(6)] + paddd mm4, MMWORD [wk(7)] + paddd mm6,mm2 + paddd mm4,mm2 + psrld mm6,SCALEBITS ; mm6=YEL + psrld mm4,SCALEBITS ; mm4=YEH + packssdw mm6,mm4 ; mm6=YE + + psllw mm0,BYTE_BIT + por mm6,mm0 ; mm6=Y + movq MMWORD [edi], mm6 ; Save Y + + pxor mm2,mm2 + pxor mm4,mm4 + punpcklwd mm2,mm3 ; mm2=REL + punpckhwd mm4,mm3 ; mm4=REH + psrld mm2,1 ; mm2=REL*FIX(0.500) + psrld mm4,1 ; mm4=REH*FIX(0.500) + + movq mm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm0=[PD_ONEHALFM1_CJ] + + paddd mm1,mm2 + paddd mm5,mm4 + paddd mm1,mm0 + paddd mm5,mm0 + psrld mm1,SCALEBITS ; mm1=CrEL + psrld mm5,SCALEBITS ; mm5=CrEH + packssdw mm1,mm5 ; mm1=CrE + + psllw mm7,BYTE_BIT + por mm1,mm7 ; mm1=Cr + movq MMWORD [edx], mm1 ; Save Cr + + sub ecx, byte SIZEOF_MMWORD + add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr + add edi, byte SIZEOF_MMWORD ; outptr0 + add ebx, byte SIZEOF_MMWORD ; outptr1 + add edx, byte SIZEOF_MMWORD ; outptr2 + cmp ecx, byte SIZEOF_MMWORD + jae near .columnloop + test ecx,ecx + jnz near .column_ld1 + + pop ecx ; col + pop esi + pop edi + pop ebx + pop edx + poppic eax + + add esi, byte SIZEOF_JSAMPROW ; input_buf + add edi, byte SIZEOF_JSAMPROW + add ebx, byte SIZEOF_JSAMPROW + add edx, byte SIZEOF_JSAMPROW + dec eax ; num_rows + jg near .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcclrss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcclrss2.asm new file mode 100755 index 0000000..517b705 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcclrss2.asm @@ -0,0 +1,503 @@ +; +; jcclrss2.asm - colorspace conversion (SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_rgb_ycc_convert_sse2 (JDIMENSION img_width, +; JSAMPARRAY input_buf, JSAMPIMAGE output_buf, +; JDIMENSION output_row, int num_rows); +; + +%define img_width(b) (b)+8 ; JDIMENSION img_width +%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf +%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf +%define output_row(b) (b)+20 ; JDIMENSION output_row +%define num_rows(b) (b)+24 ; int num_rows + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 8 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + + global EXTN(jsimd_rgb_ycc_convert_sse2) + +EXTN(jsimd_rgb_ycc_convert_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [img_width(eax)] + test ecx,ecx + jz near .return + + push ecx + + mov esi, JSAMPIMAGE [output_buf(eax)] + mov ecx, JDIMENSION [output_row(eax)] + mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY] + lea edi, [edi+ecx*SIZEOF_JSAMPROW] + lea ebx, [ebx+ecx*SIZEOF_JSAMPROW] + lea edx, [edx+ecx*SIZEOF_JSAMPROW] + + pop ecx + + mov esi, JSAMPARRAY [input_buf(eax)] + mov eax, INT [num_rows(eax)] + test eax,eax + jle near .return + alignx 16,7 +.rowloop: + pushpic eax + push edx + push ebx + push edi + push esi + push ecx ; col + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr0 + mov ebx, JSAMPROW [ebx] ; outptr1 + mov edx, JSAMPROW [edx] ; outptr2 + movpic eax, POINTER [gotptr] ; load GOT address (eax) + + cmp ecx, byte SIZEOF_XMMWORD + jae near .columnloop + alignx 16,7 + +%if RGB_PIXELSIZE == 3 ; --------------- + +.column_ld1: + push eax + push edx + lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE + test cl, SIZEOF_BYTE + jz short .column_ld2 + sub ecx, byte SIZEOF_BYTE + movzx eax, BYTE [esi+ecx] +.column_ld2: + test cl, SIZEOF_WORD + jz short .column_ld4 + sub ecx, byte SIZEOF_WORD + movzx edx, WORD [esi+ecx] + shl eax, WORD_BIT + or eax,edx +.column_ld4: + movd xmmA,eax + pop edx + pop eax + test cl, SIZEOF_DWORD + jz short .column_ld8 + sub ecx, byte SIZEOF_DWORD + movd xmmF, XMM_DWORD [esi+ecx] + pslldq xmmA, SIZEOF_DWORD + por xmmA,xmmF +.column_ld8: + test cl, SIZEOF_MMWORD + jz short .column_ld16 + sub ecx, byte SIZEOF_MMWORD + movq xmmB, XMM_MMWORD [esi+ecx] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmB +.column_ld16: + test cl, SIZEOF_XMMWORD + jz short .column_ld32 + movdqa xmmF,xmmA + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + mov ecx, SIZEOF_XMMWORD + jmp short .rgb_ycc_cnv +.column_ld32: + test cl, 2*SIZEOF_XMMWORD + mov ecx, SIZEOF_XMMWORD + jz short .rgb_ycc_cnv + movdqa xmmB,xmmA + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] + jmp short .rgb_ycc_cnv + alignx 16,7 + +.columnloop: + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] + movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD] + +.rgb_ycc_cnv: + ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + movdqa xmmG,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) + psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) + pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) + + punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) + punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) + + movdqa xmmD,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) + psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) + pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) + + punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) + punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) + + movdqa xmmE,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) + psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) + + punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) + + pxor xmmH,xmmH + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmB,xmmE + punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) + + movdqa xmmF,xmmD + punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) + punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +.column_ld1: + test cl, SIZEOF_XMMWORD/16 + jz short .column_ld2 + sub ecx, byte SIZEOF_XMMWORD/16 + movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld2: + test cl, SIZEOF_XMMWORD/8 + jz short .column_ld4 + sub ecx, byte SIZEOF_XMMWORD/8 + movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmE +.column_ld4: + test cl, SIZEOF_XMMWORD/4 + jz short .column_ld8 + sub ecx, byte SIZEOF_XMMWORD/4 + movdqa xmmE,xmmA + movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld8: + test cl, SIZEOF_XMMWORD/2 + mov ecx, SIZEOF_XMMWORD + jz short .rgb_ycc_cnv + movdqa xmmF,xmmA + movdqa xmmH,xmmE + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] + jmp short .rgb_ycc_cnv + alignx 16,7 + +.columnloop: + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD] + movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD] + +.rgb_ycc_cnv: + ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) + punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) + + movdqa xmmC,xmmF + punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) + punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) + + movdqa xmmB,xmmA + punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) + punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) + + movdqa xmmG,xmmD + punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) + punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) + + movdqa xmmE,xmmA + punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) + + movdqa xmmH,xmmB + punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) + punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) + + pxor xmmF,xmmF + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmD,xmmB + punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) + + movdqa xmmG,xmmE + punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) + + punpcklbw xmmF,xmmH + punpckhbw xmmH,xmmH + psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) + psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) + +%endif ; RGB_PIXELSIZE ; --------------- + + ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE + ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO + + ; (Original) + ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + ; + ; (This implementation) + ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G + ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE + movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO + movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE + movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO + + movdqa xmm6,xmm1 + punpcklwd xmm1,xmm3 + punpckhwd xmm6,xmm3 + movdqa xmm7,xmm1 + movdqa xmm4,xmm6 + pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) + pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) + pmaddwd xmm7,[GOTOFF(eax,PW_MF016_MF033)] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331) + pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331) + + movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337) + movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337) + + pxor xmm1,xmm1 + pxor xmm6,xmm6 + punpcklwd xmm1,xmm5 ; xmm1=BOL + punpckhwd xmm6,xmm5 ; xmm6=BOH + psrld xmm1,1 ; xmm1=BOL*FIX(0.500) + psrld xmm6,1 ; xmm6=BOH*FIX(0.500) + + movdqa xmm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm5=[PD_ONEHALFM1_CJ] + + paddd xmm7,xmm1 + paddd xmm4,xmm6 + paddd xmm7,xmm5 + paddd xmm4,xmm5 + psrld xmm7,SCALEBITS ; xmm7=CbOL + psrld xmm4,SCALEBITS ; xmm4=CbOH + packssdw xmm7,xmm4 ; xmm7=CbO + + movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE + + movdqa xmm6,xmm0 + punpcklwd xmm0,xmm2 + punpckhwd xmm6,xmm2 + movdqa xmm5,xmm0 + movdqa xmm4,xmm6 + pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) + pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) + pmaddwd xmm5,[GOTOFF(eax,PW_MF016_MF033)] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331) + pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331) + + movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337) + movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337) + + pxor xmm0,xmm0 + pxor xmm6,xmm6 + punpcklwd xmm0,xmm1 ; xmm0=BEL + punpckhwd xmm6,xmm1 ; xmm6=BEH + psrld xmm0,1 ; xmm0=BEL*FIX(0.500) + psrld xmm6,1 ; xmm6=BEH*FIX(0.500) + + movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ] + + paddd xmm5,xmm0 + paddd xmm4,xmm6 + paddd xmm5,xmm1 + paddd xmm4,xmm1 + psrld xmm5,SCALEBITS ; xmm5=CbEL + psrld xmm4,SCALEBITS ; xmm4=CbEH + packssdw xmm5,xmm4 ; xmm5=CbE + + psllw xmm7,BYTE_BIT + por xmm5,xmm7 ; xmm5=Cb + movdqa XMMWORD [ebx], xmm5 ; Save Cb + + movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO + movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO + + movdqa xmm4,xmm0 + punpcklwd xmm0,xmm3 + punpckhwd xmm4,xmm3 + movdqa xmm7,xmm0 + movdqa xmm5,xmm4 + pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) + pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) + pmaddwd xmm7,[GOTOFF(eax,PW_MF008_MF041)] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418) + pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418) + + movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF] + + paddd xmm0, XMMWORD [wk(4)] + paddd xmm4, XMMWORD [wk(5)] + paddd xmm0,xmm3 + paddd xmm4,xmm3 + psrld xmm0,SCALEBITS ; xmm0=YOL + psrld xmm4,SCALEBITS ; xmm4=YOH + packssdw xmm0,xmm4 ; xmm0=YO + + pxor xmm3,xmm3 + pxor xmm4,xmm4 + punpcklwd xmm3,xmm1 ; xmm3=ROL + punpckhwd xmm4,xmm1 ; xmm4=ROH + psrld xmm3,1 ; xmm3=ROL*FIX(0.500) + psrld xmm4,1 ; xmm4=ROH*FIX(0.500) + + movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ] + + paddd xmm7,xmm3 + paddd xmm5,xmm4 + paddd xmm7,xmm1 + paddd xmm5,xmm1 + psrld xmm7,SCALEBITS ; xmm7=CrOL + psrld xmm5,SCALEBITS ; xmm5=CrOH + packssdw xmm7,xmm5 ; xmm7=CrO + + movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE + + movdqa xmm4,xmm6 + punpcklwd xmm6,xmm2 + punpckhwd xmm4,xmm2 + movdqa xmm1,xmm6 + movdqa xmm5,xmm4 + pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) + pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) + pmaddwd xmm1,[GOTOFF(eax,PW_MF008_MF041)] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418) + pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418) + + movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF] + + paddd xmm6, XMMWORD [wk(6)] + paddd xmm4, XMMWORD [wk(7)] + paddd xmm6,xmm2 + paddd xmm4,xmm2 + psrld xmm6,SCALEBITS ; xmm6=YEL + psrld xmm4,SCALEBITS ; xmm4=YEH + packssdw xmm6,xmm4 ; xmm6=YE + + psllw xmm0,BYTE_BIT + por xmm6,xmm0 ; xmm6=Y + movdqa XMMWORD [edi], xmm6 ; Save Y + + pxor xmm2,xmm2 + pxor xmm4,xmm4 + punpcklwd xmm2,xmm3 ; xmm2=REL + punpckhwd xmm4,xmm3 ; xmm4=REH + psrld xmm2,1 ; xmm2=REL*FIX(0.500) + psrld xmm4,1 ; xmm4=REH*FIX(0.500) + + movdqa xmm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm0=[PD_ONEHALFM1_CJ] + + paddd xmm1,xmm2 + paddd xmm5,xmm4 + paddd xmm1,xmm0 + paddd xmm5,xmm0 + psrld xmm1,SCALEBITS ; xmm1=CrEL + psrld xmm5,SCALEBITS ; xmm5=CrEH + packssdw xmm1,xmm5 ; xmm1=CrE + + psllw xmm7,BYTE_BIT + por xmm1,xmm7 ; xmm1=Cr + movdqa XMMWORD [edx], xmm1 ; Save Cr + + sub ecx, byte SIZEOF_XMMWORD + add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr + add edi, byte SIZEOF_XMMWORD ; outptr0 + add ebx, byte SIZEOF_XMMWORD ; outptr1 + add edx, byte SIZEOF_XMMWORD ; outptr2 + cmp ecx, byte SIZEOF_XMMWORD + jae near .columnloop + test ecx,ecx + jnz near .column_ld1 + + pop ecx ; col + pop esi + pop edi + pop ebx + pop edx + poppic eax + + add esi, byte SIZEOF_JSAMPROW ; input_buf + add edi, byte SIZEOF_JSAMPROW + add ebx, byte SIZEOF_JSAMPROW + add edx, byte SIZEOF_JSAMPROW + dec eax ; num_rows + jg near .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jccolmmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jccolmmx.asm new file mode 100755 index 0000000..9650e47 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jccolmmx.asm @@ -0,0 +1,123 @@ +; +; jccolmmx.asm - colorspace conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_081 equ 5329 ; FIX(0.08131) +F_0_114 equ 7471 ; FIX(0.11400) +F_0_168 equ 11059 ; FIX(0.16874) +F_0_250 equ 16384 ; FIX(0.25000) +F_0_299 equ 19595 ; FIX(0.29900) +F_0_331 equ 21709 ; FIX(0.33126) +F_0_418 equ 27439 ; FIX(0.41869) +F_0_587 equ 38470 ; FIX(0.58700) +F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_rgb_ycc_convert_mmx) + +EXTN(jconst_rgb_ycc_convert_mmx): + +PW_F0299_F0337 times 2 dw F_0_299, F_0_337 +PW_F0114_F0250 times 2 dw F_0_114, F_0_250 +PW_MF016_MF033 times 2 dw -F_0_168,-F_0_331 +PW_MF008_MF041 times 2 dw -F_0_081,-F_0_418 +PD_ONEHALFM1_CJ times 2 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS) +PD_ONEHALF times 2 dd (1 << (SCALEBITS-1)) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jcclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_rgb_ycc_convert_mmx jsimd_extrgb_ycc_convert_mmx +%include "jcclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_rgb_ycc_convert_mmx jsimd_extrgbx_ycc_convert_mmx +%include "jcclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_rgb_ycc_convert_mmx jsimd_extbgr_ycc_convert_mmx +%include "jcclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_rgb_ycc_convert_mmx jsimd_extbgrx_ycc_convert_mmx +%include "jcclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_rgb_ycc_convert_mmx jsimd_extxbgr_ycc_convert_mmx +%include "jcclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_rgb_ycc_convert_mmx jsimd_extxrgb_ycc_convert_mmx +%include "jcclrmmx.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jccolss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jccolss2.asm new file mode 100755 index 0000000..ac001d1 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jccolss2.asm @@ -0,0 +1,120 @@ +; +; jccolss2.asm - colorspace conversion (SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; Copyright (C) 2009, D. R. Commander. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_081 equ 5329 ; FIX(0.08131) +F_0_114 equ 7471 ; FIX(0.11400) +F_0_168 equ 11059 ; FIX(0.16874) +F_0_250 equ 16384 ; FIX(0.25000) +F_0_299 equ 19595 ; FIX(0.29900) +F_0_331 equ 21709 ; FIX(0.33126) +F_0_418 equ 27439 ; FIX(0.41869) +F_0_587 equ 38470 ; FIX(0.58700) +F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_rgb_ycc_convert_sse2) + +EXTN(jconst_rgb_ycc_convert_sse2): + +PW_F0299_F0337 times 4 dw F_0_299, F_0_337 +PW_F0114_F0250 times 4 dw F_0_114, F_0_250 +PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331 +PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418 +PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS) +PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jcclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2 +%include "jcclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2 +%include "jcclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2 +%include "jcclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2 +%include "jcclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2 +%include "jcclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2 +%include "jcclrss2.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrammx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrammx.asm new file mode 100755 index 0000000..b8b8dd3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrammx.asm @@ -0,0 +1,116 @@ +; +; jcgrammx.asm - grayscale colorspace conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2011 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_114 equ 7471 ; FIX(0.11400) +F_0_250 equ 16384 ; FIX(0.25000) +F_0_299 equ 19595 ; FIX(0.29900) +F_0_587 equ 38470 ; FIX(0.58700) +F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_rgb_gray_convert_mmx) + +EXTN(jconst_rgb_gray_convert_mmx): + +PW_F0299_F0337 times 2 dw F_0_299, F_0_337 +PW_F0114_F0250 times 2 dw F_0_114, F_0_250 +PD_ONEHALF times 2 dd (1 << (SCALEBITS-1)) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jcgrymmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_rgb_gray_convert_mmx jsimd_extrgb_gray_convert_mmx +%include "jcgrymmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_rgb_gray_convert_mmx jsimd_extrgbx_gray_convert_mmx +%include "jcgrymmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_rgb_gray_convert_mmx jsimd_extbgr_gray_convert_mmx +%include "jcgrymmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_rgb_gray_convert_mmx jsimd_extbgrx_gray_convert_mmx +%include "jcgrymmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_rgb_gray_convert_mmx jsimd_extxbgr_gray_convert_mmx +%include "jcgrymmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_rgb_gray_convert_mmx jsimd_extxrgb_gray_convert_mmx +%include "jcgrymmx.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrass2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrass2.asm new file mode 100755 index 0000000..998968e --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrass2.asm @@ -0,0 +1,113 @@ +; +; jcgrass2.asm - grayscale colorspace conversion (SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; Copyright (C) 2011, D. R. Commander. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_114 equ 7471 ; FIX(0.11400) +F_0_250 equ 16384 ; FIX(0.25000) +F_0_299 equ 19595 ; FIX(0.29900) +F_0_587 equ 38470 ; FIX(0.58700) +F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_rgb_gray_convert_sse2) + +EXTN(jconst_rgb_gray_convert_sse2): + +PW_F0299_F0337 times 4 dw F_0_299, F_0_337 +PW_F0114_F0250 times 4 dw F_0_114, F_0_250 +PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jcgryss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extrgb_gray_convert_sse2 +%include "jcgryss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extrgbx_gray_convert_sse2 +%include "jcgryss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extbgr_gray_convert_sse2 +%include "jcgryss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extbgrx_gray_convert_sse2 +%include "jcgryss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extxbgr_gray_convert_sse2 +%include "jcgryss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extxrgb_gray_convert_sse2 +%include "jcgryss2.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrymmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrymmx.asm new file mode 100755 index 0000000..bbeea09 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgrymmx.asm @@ -0,0 +1,357 @@ +; +; jcgrymmx.asm - grayscale colorspace conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2011 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_rgb_gray_convert_mmx (JDIMENSION img_width, +; JSAMPARRAY input_buf, JSAMPIMAGE output_buf, +; JDIMENSION output_row, int num_rows); +; + +%define img_width(b) (b)+8 ; JDIMENSION img_width +%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf +%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf +%define output_row(b) (b)+20 ; JDIMENSION output_row +%define num_rows(b) (b)+24 ; int num_rows + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_rgb_gray_convert_mmx) + +EXTN(jsimd_rgb_gray_convert_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [img_width(eax)] ; num_cols + test ecx,ecx + jz near .return + + push ecx + + mov esi, JSAMPIMAGE [output_buf(eax)] + mov ecx, JDIMENSION [output_row(eax)] + mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] + lea edi, [edi+ecx*SIZEOF_JSAMPROW] + + pop ecx + + mov esi, JSAMPARRAY [input_buf(eax)] + mov eax, INT [num_rows(eax)] + test eax,eax + jle near .return + alignx 16,7 +.rowloop: + pushpic eax + push edi + push esi + push ecx ; col + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr0 + movpic eax, POINTER [gotptr] ; load GOT address (eax) + + cmp ecx, byte SIZEOF_MMWORD + jae short .columnloop + alignx 16,7 + +%if RGB_PIXELSIZE == 3 ; --------------- + +.column_ld1: + push eax + push edx + lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE + test cl, SIZEOF_BYTE + jz short .column_ld2 + sub ecx, byte SIZEOF_BYTE + xor eax,eax + mov al, BYTE [esi+ecx] +.column_ld2: + test cl, SIZEOF_WORD + jz short .column_ld4 + sub ecx, byte SIZEOF_WORD + xor edx,edx + mov dx, WORD [esi+ecx] + shl eax, WORD_BIT + or eax,edx +.column_ld4: + movd mmA,eax + pop edx + pop eax + test cl, SIZEOF_DWORD + jz short .column_ld8 + sub ecx, byte SIZEOF_DWORD + movd mmG, DWORD [esi+ecx] + psllq mmA, DWORD_BIT + por mmA,mmG +.column_ld8: + test cl, SIZEOF_MMWORD + jz short .column_ld16 + movq mmG,mmA + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + mov ecx, SIZEOF_MMWORD + jmp short .rgb_gray_cnv +.column_ld16: + test cl, 2*SIZEOF_MMWORD + mov ecx, SIZEOF_MMWORD + jz short .rgb_gray_cnv + movq mmF,mmA + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] + jmp short .rgb_gray_cnv + alignx 16,7 + +.columnloop: + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] + movq mmF, MMWORD [esi+2*SIZEOF_MMWORD] + +.rgb_gray_cnv: + ; mmA=(00 10 20 01 11 21 02 12) + ; mmG=(22 03 13 23 04 14 24 05) + ; mmF=(15 25 06 16 26 07 17 27) + + movq mmD,mmA + psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01) + psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --) + + punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05) + psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23) + + punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16) + punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27) + + movq mmE,mmA + psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14) + psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --) + + punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) + psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25) + + punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07) + punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27) + + pxor mmH,mmH + + movq mmC,mmA + punpcklbw mmA,mmH ; mmA=(00 02 04 06) + punpckhbw mmC,mmH ; mmC=(10 12 14 16) + + movq mmB,mmE + punpcklbw mmE,mmH ; mmE=(20 22 24 26) + punpckhbw mmB,mmH ; mmB=(01 03 05 07) + + movq mmF,mmD + punpcklbw mmD,mmH ; mmD=(11 13 15 17) + punpckhbw mmF,mmH ; mmF=(21 23 25 27) + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +.column_ld1: + test cl, SIZEOF_MMWORD/8 + jz short .column_ld2 + sub ecx, byte SIZEOF_MMWORD/8 + movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld2: + test cl, SIZEOF_MMWORD/4 + jz short .column_ld4 + sub ecx, byte SIZEOF_MMWORD/4 + movq mmF,mmA + movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld4: + test cl, SIZEOF_MMWORD/2 + mov ecx, SIZEOF_MMWORD + jz short .rgb_gray_cnv + movq mmD,mmA + movq mmC,mmF + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] + jmp short .rgb_gray_cnv + alignx 16,7 + +.columnloop: + movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] + movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] + movq mmD, MMWORD [esi+2*SIZEOF_MMWORD] + movq mmC, MMWORD [esi+3*SIZEOF_MMWORD] + +.rgb_gray_cnv: + ; mmA=(00 10 20 30 01 11 21 31) + ; mmF=(02 12 22 32 03 13 23 33) + ; mmD=(04 14 24 34 05 15 25 35) + ; mmC=(06 16 26 36 07 17 27 37) + + movq mmB,mmA + punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32) + punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33) + + movq mmG,mmD + punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36) + punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37) + + movq mmE,mmA + punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) + punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36) + + movq mmH,mmB + punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17) + punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37) + + pxor mmF,mmF + + movq mmC,mmA + punpcklbw mmA,mmF ; mmA=(00 02 04 06) + punpckhbw mmC,mmF ; mmC=(10 12 14 16) + + movq mmD,mmB + punpcklbw mmB,mmF ; mmB=(01 03 05 07) + punpckhbw mmD,mmF ; mmD=(11 13 15 17) + + movq mmG,mmE + punpcklbw mmE,mmF ; mmE=(20 22 24 26) + punpckhbw mmG,mmF ; mmG=(30 32 34 36) + + punpcklbw mmF,mmH + punpckhbw mmH,mmH + psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27) + psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37) + +%endif ; RGB_PIXELSIZE ; --------------- + + ; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE + ; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO + + ; (Original) + ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + ; + ; (This implementation) + ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G + + movq mm6,mm1 + punpcklwd mm1,mm3 + punpckhwd mm6,mm3 + pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337) + pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337) + + movq mm7, mm6 ; mm7=ROH*FIX(0.299)+GOH*FIX(0.337) + + movq mm6,mm0 + punpcklwd mm0,mm2 + punpckhwd mm6,mm2 + pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337) + pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337) + + movq MMWORD [wk(0)], mm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337) + movq MMWORD [wk(1)], mm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337) + + movq mm0, mm5 ; mm0=BO + movq mm6, mm4 ; mm6=BE + + movq mm4,mm0 + punpcklwd mm0,mm3 + punpckhwd mm4,mm3 + pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250) + pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250) + + movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF] + + paddd mm0, mm1 + paddd mm4, mm7 + paddd mm0,mm3 + paddd mm4,mm3 + psrld mm0,SCALEBITS ; mm0=YOL + psrld mm4,SCALEBITS ; mm4=YOH + packssdw mm0,mm4 ; mm0=YO + + movq mm4,mm6 + punpcklwd mm6,mm2 + punpckhwd mm4,mm2 + pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250) + pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250) + + movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF] + + paddd mm6, MMWORD [wk(0)] + paddd mm4, MMWORD [wk(1)] + paddd mm6,mm2 + paddd mm4,mm2 + psrld mm6,SCALEBITS ; mm6=YEL + psrld mm4,SCALEBITS ; mm4=YEH + packssdw mm6,mm4 ; mm6=YE + + psllw mm0,BYTE_BIT + por mm6,mm0 ; mm6=Y + movq MMWORD [edi], mm6 ; Save Y + + sub ecx, byte SIZEOF_MMWORD + add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr + add edi, byte SIZEOF_MMWORD ; outptr0 + cmp ecx, byte SIZEOF_MMWORD + jae near .columnloop + test ecx,ecx + jnz near .column_ld1 + + pop ecx ; col + pop esi + pop edi + poppic eax + + add esi, byte SIZEOF_JSAMPROW ; input_buf + add edi, byte SIZEOF_JSAMPROW + dec eax ; num_rows + jg near .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgryss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgryss2.asm new file mode 100755 index 0000000..c294287 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcgryss2.asm @@ -0,0 +1,383 @@ +; +; jcgryss2.asm - grayscale colorspace conversion (SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; Copyright (C) 2011, D. R. Commander. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_rgb_gray_convert_sse2 (JDIMENSION img_width, +; JSAMPARRAY input_buf, JSAMPIMAGE output_buf, +; JDIMENSION output_row, int num_rows); +; + +%define img_width(b) (b)+8 ; JDIMENSION img_width +%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf +%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf +%define output_row(b) (b)+20 ; JDIMENSION output_row +%define num_rows(b) (b)+24 ; int num_rows + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + + global EXTN(jsimd_rgb_gray_convert_sse2) + +EXTN(jsimd_rgb_gray_convert_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [img_width(eax)] + test ecx,ecx + jz near .return + + push ecx + + mov esi, JSAMPIMAGE [output_buf(eax)] + mov ecx, JDIMENSION [output_row(eax)] + mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] + lea edi, [edi+ecx*SIZEOF_JSAMPROW] + + pop ecx + + mov esi, JSAMPARRAY [input_buf(eax)] + mov eax, INT [num_rows(eax)] + test eax,eax + jle near .return + alignx 16,7 +.rowloop: + pushpic eax + push edi + push esi + push ecx ; col + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr0 + movpic eax, POINTER [gotptr] ; load GOT address (eax) + + cmp ecx, byte SIZEOF_XMMWORD + jae near .columnloop + alignx 16,7 + +%if RGB_PIXELSIZE == 3 ; --------------- + +.column_ld1: + push eax + push edx + lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE + test cl, SIZEOF_BYTE + jz short .column_ld2 + sub ecx, byte SIZEOF_BYTE + movzx eax, BYTE [esi+ecx] +.column_ld2: + test cl, SIZEOF_WORD + jz short .column_ld4 + sub ecx, byte SIZEOF_WORD + movzx edx, WORD [esi+ecx] + shl eax, WORD_BIT + or eax,edx +.column_ld4: + movd xmmA,eax + pop edx + pop eax + test cl, SIZEOF_DWORD + jz short .column_ld8 + sub ecx, byte SIZEOF_DWORD + movd xmmF, XMM_DWORD [esi+ecx] + pslldq xmmA, SIZEOF_DWORD + por xmmA,xmmF +.column_ld8: + test cl, SIZEOF_MMWORD + jz short .column_ld16 + sub ecx, byte SIZEOF_MMWORD + movq xmmB, XMM_MMWORD [esi+ecx] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmB +.column_ld16: + test cl, SIZEOF_XMMWORD + jz short .column_ld32 + movdqa xmmF,xmmA + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + mov ecx, SIZEOF_XMMWORD + jmp short .rgb_gray_cnv +.column_ld32: + test cl, 2*SIZEOF_XMMWORD + mov ecx, SIZEOF_XMMWORD + jz short .rgb_gray_cnv + movdqa xmmB,xmmA + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] + jmp short .rgb_gray_cnv + alignx 16,7 + +.columnloop: + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] + movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD] + +.rgb_gray_cnv: + ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + movdqa xmmG,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) + psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) + pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) + + punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) + punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) + + movdqa xmmD,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) + psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) + pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) + + punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) + punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) + + movdqa xmmE,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) + psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) + + punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) + + pxor xmmH,xmmH + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmB,xmmE + punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) + + movdqa xmmF,xmmD + punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) + punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +.column_ld1: + test cl, SIZEOF_XMMWORD/16 + jz short .column_ld2 + sub ecx, byte SIZEOF_XMMWORD/16 + movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld2: + test cl, SIZEOF_XMMWORD/8 + jz short .column_ld4 + sub ecx, byte SIZEOF_XMMWORD/8 + movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmE +.column_ld4: + test cl, SIZEOF_XMMWORD/4 + jz short .column_ld8 + sub ecx, byte SIZEOF_XMMWORD/4 + movdqa xmmE,xmmA + movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE] +.column_ld8: + test cl, SIZEOF_XMMWORD/2 + mov ecx, SIZEOF_XMMWORD + jz short .rgb_gray_cnv + movdqa xmmF,xmmA + movdqa xmmH,xmmE + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] + jmp short .rgb_gray_cnv + alignx 16,7 + +.columnloop: + movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD] + movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD] + +.rgb_gray_cnv: + ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) + punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) + + movdqa xmmC,xmmF + punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) + punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) + + movdqa xmmB,xmmA + punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) + punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) + + movdqa xmmG,xmmD + punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) + punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) + + movdqa xmmE,xmmA + punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) + + movdqa xmmH,xmmB + punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) + punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) + + pxor xmmF,xmmF + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmD,xmmB + punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) + + movdqa xmmG,xmmE + punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) + + punpcklbw xmmF,xmmH + punpckhbw xmmH,xmmH + psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) + psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) + +%endif ; RGB_PIXELSIZE ; --------------- + + ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE + ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO + + ; (Original) + ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + ; + ; (This implementation) + ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G + + movdqa xmm6,xmm1 + punpcklwd xmm1,xmm3 + punpckhwd xmm6,xmm3 + pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) + pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) + + movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337) + + movdqa xmm6,xmm0 + punpcklwd xmm0,xmm2 + punpckhwd xmm6,xmm2 + pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) + pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) + + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337) + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337) + + movdqa xmm0, xmm5 ; xmm0=BO + movdqa xmm6, xmm4 ; xmm6=BE + + movdqa xmm4,xmm0 + punpcklwd xmm0,xmm3 + punpckhwd xmm4,xmm3 + pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) + pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) + + movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF] + + paddd xmm0, xmm1 + paddd xmm4, xmm7 + paddd xmm0,xmm3 + paddd xmm4,xmm3 + psrld xmm0,SCALEBITS ; xmm0=YOL + psrld xmm4,SCALEBITS ; xmm4=YOH + packssdw xmm0,xmm4 ; xmm0=YO + + movdqa xmm4,xmm6 + punpcklwd xmm6,xmm2 + punpckhwd xmm4,xmm2 + pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) + pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) + + movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF] + + paddd xmm6, XMMWORD [wk(0)] + paddd xmm4, XMMWORD [wk(1)] + paddd xmm6,xmm2 + paddd xmm4,xmm2 + psrld xmm6,SCALEBITS ; xmm6=YEL + psrld xmm4,SCALEBITS ; xmm4=YEH + packssdw xmm6,xmm4 ; xmm6=YE + + psllw xmm0,BYTE_BIT + por xmm6,xmm0 ; xmm6=Y + movdqa XMMWORD [edi], xmm6 ; Save Y + + sub ecx, byte SIZEOF_XMMWORD + add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr + add edi, byte SIZEOF_XMMWORD ; outptr0 + cmp ecx, byte SIZEOF_XMMWORD + jae near .columnloop + test ecx,ecx + jnz near .column_ld1 + + pop ecx ; col + pop esi + pop edi + poppic eax + + add esi, byte SIZEOF_JSAMPROW ; input_buf + add edi, byte SIZEOF_JSAMPROW + dec eax ; num_rows + jg near .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcolsamp.inc b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcolsamp.inc new file mode 100755 index 0000000..79751b7 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcolsamp.inc @@ -0,0 +1,105 @@ +; +; jcolsamp.inc - private declarations for color conversion & up/downsampling +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; [TAB8] + +; -------------------------------------------------------------------------- + +; pseudo-resisters to make ordering of RGB configurable +; +%if RGB_RED == 0 +%define mmA mm0 +%define mmB mm1 +%define xmmA xmm0 +%define xmmB xmm1 +%elif RGB_GREEN == 0 +%define mmA mm2 +%define mmB mm3 +%define xmmA xmm2 +%define xmmB xmm3 +%elif RGB_BLUE == 0 +%define mmA mm4 +%define mmB mm5 +%define xmmA xmm4 +%define xmmB xmm5 +%else +%define mmA mm6 +%define mmB mm7 +%define xmmA xmm6 +%define xmmB xmm7 +%endif + +%if RGB_RED == 1 +%define mmC mm0 +%define mmD mm1 +%define xmmC xmm0 +%define xmmD xmm1 +%elif RGB_GREEN == 1 +%define mmC mm2 +%define mmD mm3 +%define xmmC xmm2 +%define xmmD xmm3 +%elif RGB_BLUE == 1 +%define mmC mm4 +%define mmD mm5 +%define xmmC xmm4 +%define xmmD xmm5 +%else +%define mmC mm6 +%define mmD mm7 +%define xmmC xmm6 +%define xmmD xmm7 +%endif + +%if RGB_RED == 2 +%define mmE mm0 +%define mmF mm1 +%define xmmE xmm0 +%define xmmF xmm1 +%elif RGB_GREEN == 2 +%define mmE mm2 +%define mmF mm3 +%define xmmE xmm2 +%define xmmF xmm3 +%elif RGB_BLUE == 2 +%define mmE mm4 +%define mmF mm5 +%define xmmE xmm4 +%define xmmF xmm5 +%else +%define mmE mm6 +%define mmF mm7 +%define xmmE xmm6 +%define xmmF xmm7 +%endif + +%if RGB_RED == 3 +%define mmG mm0 +%define mmH mm1 +%define xmmG xmm0 +%define xmmH xmm1 +%elif RGB_GREEN == 3 +%define mmG mm2 +%define mmH mm3 +%define xmmG xmm2 +%define xmmH xmm3 +%elif RGB_BLUE == 3 +%define mmG mm4 +%define mmH mm5 +%define xmmG xmm4 +%define xmmH xmm5 +%else +%define mmG mm6 +%define mmH mm7 +%define xmmG xmm6 +%define xmmH xmm7 +%endif + +; -------------------------------------------------------------------------- diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnt3dn.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnt3dn.asm new file mode 100755 index 0000000..182c869 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnt3dn.asm @@ -0,0 +1,233 @@ +; +; jcqnt3dn.asm - sample data conversion and quantization (3DNow! & MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Load data into workspace, applying unsigned->signed conversion +; +; GLOBAL(void) +; jsimd_convsamp_float_3dnow (JSAMPARRAY sample_data, JDIMENSION start_col, +; FAST_FLOAT * workspace); +; + +%define sample_data ebp+8 ; JSAMPARRAY sample_data +%define start_col ebp+12 ; JDIMENSION start_col +%define workspace ebp+16 ; FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_convsamp_float_3dnow) + +EXTN(jsimd_convsamp_float_3dnow): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + pcmpeqw mm7,mm7 + psllw mm7,7 + packsswb mm7,mm7 ; mm7 = PB_CENTERJSAMPLE (0x808080..) + + mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) + mov eax, JDIMENSION [start_col] + mov edi, POINTER [workspace] ; (DCTELEM *) + mov ecx, DCTSIZE/2 + alignx 16,7 +.convloop: + mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE] + movq mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE] + + psubb mm0,mm7 ; mm0=(01234567) + psubb mm1,mm7 ; mm1=(89ABCDEF) + + punpcklbw mm2,mm0 ; mm2=(*0*1*2*3) + punpckhbw mm0,mm0 ; mm0=(*4*5*6*7) + punpcklbw mm3,mm1 ; mm3=(*8*9*A*B) + punpckhbw mm1,mm1 ; mm1=(*C*D*E*F) + + punpcklwd mm4,mm2 ; mm4=(***0***1) + punpckhwd mm2,mm2 ; mm2=(***2***3) + punpcklwd mm5,mm0 ; mm5=(***4***5) + punpckhwd mm0,mm0 ; mm0=(***6***7) + + psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(01) + psrad mm2,(DWORD_BIT-BYTE_BIT) ; mm2=(23) + pi2fd mm4,mm4 + pi2fd mm2,mm2 + psrad mm5,(DWORD_BIT-BYTE_BIT) ; mm5=(45) + psrad mm0,(DWORD_BIT-BYTE_BIT) ; mm0=(67) + pi2fd mm5,mm5 + pi2fd mm0,mm0 + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm4 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm2 + movq MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm5 + movq MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0 + + punpcklwd mm6,mm3 ; mm6=(***8***9) + punpckhwd mm3,mm3 ; mm3=(***A***B) + punpcklwd mm4,mm1 ; mm4=(***C***D) + punpckhwd mm1,mm1 ; mm1=(***E***F) + + psrad mm6,(DWORD_BIT-BYTE_BIT) ; mm6=(89) + psrad mm3,(DWORD_BIT-BYTE_BIT) ; mm3=(AB) + pi2fd mm6,mm6 + pi2fd mm3,mm3 + psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(CD) + psrad mm1,(DWORD_BIT-BYTE_BIT) ; mm1=(EF) + pi2fd mm4,mm4 + pi2fd mm1,mm1 + + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm6 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm3 + movq MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm4 + movq MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm1 + + add esi, byte 2*SIZEOF_JSAMPROW + add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT + dec ecx + jnz near .convloop + + femms ; empty MMX/3DNow! state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + + +; -------------------------------------------------------------------------- +; +; Quantize/descale the coefficients, and store into coef_block +; +; GLOBAL(void) +; jsimd_quantize_float_3dnow (JCOEFPTR coef_block, FAST_FLOAT * divisors, +; FAST_FLOAT * workspace); +; + +%define coef_block ebp+8 ; JCOEFPTR coef_block +%define divisors ebp+12 ; FAST_FLOAT * divisors +%define workspace ebp+16 ; FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_quantize_float_3dnow) + +EXTN(jsimd_quantize_float_3dnow): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + mov eax, 0x4B400000 ; (float)0x00C00000 (rndint_magic) + movd mm7,eax + punpckldq mm7,mm7 ; mm7={12582912.0F 12582912.0F} + + mov esi, POINTER [workspace] + mov edx, POINTER [divisors] + mov edi, JCOEFPTR [coef_block] + mov eax, DCTSIZE2/16 + alignx 16,7 +.quantloop: + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] + movq mm1, MMWORD [MMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)] + pfmul mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] + pfmul mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] + movq mm2, MMWORD [MMBLOCK(0,2,esi,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(0,3,esi,SIZEOF_FAST_FLOAT)] + pfmul mm2, MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)] + pfmul mm3, MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)] + + pfadd mm0,mm7 ; mm0=(00 ** 01 **) + pfadd mm1,mm7 ; mm1=(02 ** 03 **) + pfadd mm2,mm7 ; mm0=(04 ** 05 **) + pfadd mm3,mm7 ; mm1=(06 ** 07 **) + + movq mm4,mm0 + punpcklwd mm0,mm1 ; mm0=(00 02 ** **) + punpckhwd mm4,mm1 ; mm4=(01 03 ** **) + movq mm5,mm2 + punpcklwd mm2,mm3 ; mm2=(04 06 ** **) + punpckhwd mm5,mm3 ; mm5=(05 07 ** **) + + punpcklwd mm0,mm4 ; mm0=(00 01 02 03) + punpcklwd mm2,mm5 ; mm2=(04 05 06 07) + + movq mm6, MMWORD [MMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] + movq mm1, MMWORD [MMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)] + pfmul mm6, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] + pfmul mm1, MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(1,2,esi,SIZEOF_FAST_FLOAT)] + movq mm4, MMWORD [MMBLOCK(1,3,esi,SIZEOF_FAST_FLOAT)] + pfmul mm3, MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)] + pfmul mm4, MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)] + + pfadd mm6,mm7 ; mm0=(10 ** 11 **) + pfadd mm1,mm7 ; mm4=(12 ** 13 **) + pfadd mm3,mm7 ; mm0=(14 ** 15 **) + pfadd mm4,mm7 ; mm4=(16 ** 17 **) + + movq mm5,mm6 + punpcklwd mm6,mm1 ; mm6=(10 12 ** **) + punpckhwd mm5,mm1 ; mm5=(11 13 ** **) + movq mm1,mm3 + punpcklwd mm3,mm4 ; mm3=(14 16 ** **) + punpckhwd mm1,mm4 ; mm1=(15 17 ** **) + + punpcklwd mm6,mm5 ; mm6=(10 11 12 13) + punpcklwd mm3,mm1 ; mm3=(14 15 16 17) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm6 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm3 + + add esi, byte 16*SIZEOF_FAST_FLOAT + add edx, byte 16*SIZEOF_FAST_FLOAT + add edi, byte 16*SIZEOF_JCOEF + dec eax + jnz near .quantloop + + femms ; empty MMX/3DNow! state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused +; pop ebx ; unused + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqntmmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqntmmx.asm new file mode 100755 index 0000000..08b08b7 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqntmmx.asm @@ -0,0 +1,274 @@ +; +; jcqntmmx.asm - sample data conversion and quantization (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Load data into workspace, applying unsigned->signed conversion +; +; GLOBAL(void) +; jsimd_convsamp_mmx (JSAMPARRAY sample_data, JDIMENSION start_col, +; DCTELEM * workspace); +; + +%define sample_data ebp+8 ; JSAMPARRAY sample_data +%define start_col ebp+12 ; JDIMENSION start_col +%define workspace ebp+16 ; DCTELEM * workspace + + align 16 + global EXTN(jsimd_convsamp_mmx) + +EXTN(jsimd_convsamp_mmx): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + pxor mm6,mm6 ; mm6=(all 0's) + pcmpeqw mm7,mm7 + psllw mm7,7 ; mm7={0xFF80 0xFF80 0xFF80 0xFF80} + + mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) + mov eax, JDIMENSION [start_col] + mov edi, POINTER [workspace] ; (DCTELEM *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.convloop: + mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; mm0=(01234567) + movq mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE] ; mm1=(89ABCDEF) + + mov ebx, JSAMPROW [esi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov edx, JSAMPROW [esi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq mm2, MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; mm2=(GHIJKLMN) + movq mm3, MMWORD [edx+eax*SIZEOF_JSAMPLE] ; mm3=(OPQRSTUV) + + movq mm4,mm0 + punpcklbw mm0,mm6 ; mm0=(0123) + punpckhbw mm4,mm6 ; mm4=(4567) + movq mm5,mm1 + punpcklbw mm1,mm6 ; mm1=(89AB) + punpckhbw mm5,mm6 ; mm5=(CDEF) + + paddw mm0,mm7 + paddw mm4,mm7 + paddw mm1,mm7 + paddw mm5,mm7 + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm4 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_DCTELEM)], mm1 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_DCTELEM)], mm5 + + movq mm0,mm2 + punpcklbw mm2,mm6 ; mm2=(GHIJ) + punpckhbw mm0,mm6 ; mm0=(KLMN) + movq mm4,mm3 + punpcklbw mm3,mm6 ; mm3=(OPQR) + punpckhbw mm4,mm6 ; mm4=(STUV) + + paddw mm2,mm7 + paddw mm0,mm7 + paddw mm3,mm7 + paddw mm4,mm7 + + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_DCTELEM)], mm2 + movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_DCTELEM)], mm0 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_DCTELEM)], mm3 + movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_DCTELEM)], mm4 + + add esi, byte 4*SIZEOF_JSAMPROW + add edi, byte 4*DCTSIZE*SIZEOF_DCTELEM + dec ecx + jnz short .convloop + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Quantize/descale the coefficients, and store into coef_block +; +; This implementation is based on an algorithm described in +; "How to optimize for the Pentium family of microprocessors" +; (http://www.agner.org/assem/). +; +; GLOBAL(void) +; jsimd_quantize_mmx (JCOEFPTR coef_block, DCTELEM * divisors, +; DCTELEM * workspace); +; + +%define RECIPROCAL(m,n,b) MMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM) +%define CORRECTION(m,n,b) MMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM) +%define SCALE(m,n,b) MMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM) +%define SHIFT(m,n,b) MMBLOCK(DCTSIZE*3+(m),(n),(b),SIZEOF_DCTELEM) + +%define coef_block ebp+8 ; JCOEFPTR coef_block +%define divisors ebp+12 ; DCTELEM * divisors +%define workspace ebp+16 ; DCTELEM * workspace + + align 16 + global EXTN(jsimd_quantize_mmx) + +EXTN(jsimd_quantize_mmx): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + mov esi, POINTER [workspace] + mov edx, POINTER [divisors] + mov edi, JCOEFPTR [coef_block] + mov ah, 2 + alignx 16,7 +.quantloop1: + mov al, DCTSIZE2/8/2 + alignx 16,7 +.quantloop2: + movq mm2, MMWORD [MMBLOCK(0,0,esi,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(0,1,esi,SIZEOF_DCTELEM)] + + movq mm0,mm2 + movq mm1,mm3 + + psraw mm2,(WORD_BIT-1) ; -1 if value < 0, 0 otherwise + psraw mm3,(WORD_BIT-1) + + pxor mm0,mm2 ; val = -val + pxor mm1,mm3 + psubw mm0,mm2 + psubw mm1,mm3 + + ; + ; MMX is an annoyingly crappy instruction set. It has two + ; misfeatures that are causing problems here: + ; + ; - All multiplications are signed. + ; + ; - The second operand for the shifts is not treated as packed. + ; + ; + ; We work around the first problem by implementing this algorithm: + ; + ; unsigned long unsigned_multiply(unsigned short x, unsigned short y) + ; { + ; enum { SHORT_BIT = 16 }; + ; signed short sx = (signed short) x; + ; signed short sy = (signed short) y; + ; signed long sz; + ; + ; sz = (long) sx * (long) sy; /* signed multiply */ + ; + ; if (sx < 0) sz += (long) sy << SHORT_BIT; + ; if (sy < 0) sz += (long) sx << SHORT_BIT; + ; + ; return (unsigned long) sz; + ; } + ; + ; (note that a negative sx adds _sy_ and vice versa) + ; + ; For the second problem, we replace the shift by a multiplication. + ; Unfortunately that means we have to deal with the signed issue again. + ; + + paddw mm0, MMWORD [CORRECTION(0,0,edx)] ; correction + roundfactor + paddw mm1, MMWORD [CORRECTION(0,1,edx)] + + movq mm4,mm0 ; store current value for later + movq mm5,mm1 + pmulhw mm0, MMWORD [RECIPROCAL(0,0,edx)] ; reciprocal + pmulhw mm1, MMWORD [RECIPROCAL(0,1,edx)] + paddw mm0,mm4 ; reciprocal is always negative (MSB=1), + paddw mm1,mm5 ; so we always need to add the initial value + ; (input value is never negative as we + ; inverted it at the start of this routine) + + ; here it gets a bit tricky as both scale + ; and mm0/mm1 can be negative + movq mm6, MMWORD [SCALE(0,0,edx)] ; scale + movq mm7, MMWORD [SCALE(0,1,edx)] + movq mm4,mm0 + movq mm5,mm1 + pmulhw mm0,mm6 + pmulhw mm1,mm7 + + psraw mm6,(WORD_BIT-1) ; determine if scale is negative + psraw mm7,(WORD_BIT-1) + + pand mm6,mm4 ; and add input if it is + pand mm7,mm5 + paddw mm0,mm6 + paddw mm1,mm7 + + psraw mm4,(WORD_BIT-1) ; then check if negative input + psraw mm5,(WORD_BIT-1) + + pand mm4, MMWORD [SCALE(0,0,edx)] ; and add scale if it is + pand mm5, MMWORD [SCALE(0,1,edx)] + paddw mm0,mm4 + paddw mm1,mm5 + + pxor mm0,mm2 ; val = -val + pxor mm1,mm3 + psubw mm0,mm2 + psubw mm1,mm3 + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm1 + + add esi, byte 8*SIZEOF_DCTELEM + add edx, byte 8*SIZEOF_DCTELEM + add edi, byte 8*SIZEOF_JCOEF + dec al + jnz near .quantloop2 + dec ah + jnz near .quantloop1 ; to avoid branch misprediction + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused +; pop ebx ; unused + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnts2f.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnts2f.asm new file mode 100755 index 0000000..d80ae5d --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnts2f.asm @@ -0,0 +1,171 @@ +; +; jcqnts2f.asm - sample data conversion and quantization (SSE & SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Load data into workspace, applying unsigned->signed conversion +; +; GLOBAL(void) +; jsimd_convsamp_float_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col, +; FAST_FLOAT * workspace); +; + +%define sample_data ebp+8 ; JSAMPARRAY sample_data +%define start_col ebp+12 ; JDIMENSION start_col +%define workspace ebp+16 ; FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_convsamp_float_sse2) + +EXTN(jsimd_convsamp_float_sse2): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + pcmpeqw xmm7,xmm7 + psllw xmm7,7 + packsswb xmm7,xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..) + + mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) + mov eax, JDIMENSION [start_col] + mov edi, POINTER [workspace] ; (DCTELEM *) + mov ecx, DCTSIZE/2 + alignx 16,7 +.convloop: + mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE] + movq xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE] + + psubb xmm0,xmm7 ; xmm0=(01234567) + psubb xmm1,xmm7 ; xmm1=(89ABCDEF) + + punpcklbw xmm0,xmm0 ; xmm0=(*0*1*2*3*4*5*6*7) + punpcklbw xmm1,xmm1 ; xmm1=(*8*9*A*B*C*D*E*F) + + punpcklwd xmm2,xmm0 ; xmm2=(***0***1***2***3) + punpckhwd xmm0,xmm0 ; xmm0=(***4***5***6***7) + punpcklwd xmm3,xmm1 ; xmm3=(***8***9***A***B) + punpckhwd xmm1,xmm1 ; xmm1=(***C***D***E***F) + + psrad xmm2,(DWORD_BIT-BYTE_BIT) ; xmm2=(0123) + psrad xmm0,(DWORD_BIT-BYTE_BIT) ; xmm0=(4567) + cvtdq2ps xmm2,xmm2 ; xmm2=(0123) + cvtdq2ps xmm0,xmm0 ; xmm0=(4567) + psrad xmm3,(DWORD_BIT-BYTE_BIT) ; xmm3=(89AB) + psrad xmm1,(DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF) + cvtdq2ps xmm3,xmm3 ; xmm3=(89AB) + cvtdq2ps xmm1,xmm1 ; xmm1=(CDEF) + + movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1 + + add esi, byte 2*SIZEOF_JSAMPROW + add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT + dec ecx + jnz short .convloop + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + + +; -------------------------------------------------------------------------- +; +; Quantize/descale the coefficients, and store into coef_block +; +; GLOBAL(void) +; jsimd_quantize_float_sse2 (JCOEFPTR coef_block, FAST_FLOAT * divisors, +; FAST_FLOAT * workspace); +; + +%define coef_block ebp+8 ; JCOEFPTR coef_block +%define divisors ebp+12 ; FAST_FLOAT * divisors +%define workspace ebp+16 ; FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_quantize_float_sse2) + +EXTN(jsimd_quantize_float_sse2): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + mov esi, POINTER [workspace] + mov edx, POINTER [divisors] + mov edi, JCOEFPTR [coef_block] + mov eax, DCTSIZE2/16 + alignx 16,7 +.quantloop: + movaps xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)] + mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] + mulps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)] + mulps xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] + mulps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] + + cvtps2dq xmm0,xmm0 + cvtps2dq xmm1,xmm1 + cvtps2dq xmm2,xmm2 + cvtps2dq xmm3,xmm3 + + packssdw xmm0,xmm1 + packssdw xmm2,xmm3 + + movdqa XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_JCOEF)], xmm0 + movdqa XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_JCOEF)], xmm2 + + add esi, byte 16*SIZEOF_FAST_FLOAT + add edx, byte 16*SIZEOF_FAST_FLOAT + add edi, byte 16*SIZEOF_JCOEF + dec eax + jnz short .quantloop + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused +; pop ebx ; unused + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnts2i.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnts2i.asm new file mode 100755 index 0000000..0864d6e --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqnts2i.asm @@ -0,0 +1,200 @@ +; +; jcqnts2i.asm - sample data conversion and quantization (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Load data into workspace, applying unsigned->signed conversion +; +; GLOBAL(void) +; jsimd_convsamp_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col, +; DCTELEM * workspace); +; + +%define sample_data ebp+8 ; JSAMPARRAY sample_data +%define start_col ebp+12 ; JDIMENSION start_col +%define workspace ebp+16 ; DCTELEM * workspace + + align 16 + global EXTN(jsimd_convsamp_sse2) + +EXTN(jsimd_convsamp_sse2): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + pxor xmm6,xmm6 ; xmm6=(all 0's) + pcmpeqw xmm7,xmm7 + psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} + + mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) + mov eax, JDIMENSION [start_col] + mov edi, POINTER [workspace] ; (DCTELEM *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.convloop: + mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; xmm0=(01234567) + movq xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE] ; xmm1=(89ABCDEF) + + mov ebx, JSAMPROW [esi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov edx, JSAMPROW [esi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq xmm2, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; xmm2=(GHIJKLMN) + movq xmm3, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE] ; xmm3=(OPQRSTUV) + + punpcklbw xmm0,xmm6 ; xmm0=(01234567) + punpcklbw xmm1,xmm6 ; xmm1=(89ABCDEF) + paddw xmm0,xmm7 + paddw xmm1,xmm7 + punpcklbw xmm2,xmm6 ; xmm2=(GHIJKLMN) + punpcklbw xmm3,xmm6 ; xmm3=(OPQRSTUV) + paddw xmm2,xmm7 + paddw xmm3,xmm7 + + movdqa XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_DCTELEM)], xmm0 + movdqa XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_DCTELEM)], xmm1 + movdqa XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_DCTELEM)], xmm2 + movdqa XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_DCTELEM)], xmm3 + + add esi, byte 4*SIZEOF_JSAMPROW + add edi, byte 4*DCTSIZE*SIZEOF_DCTELEM + dec ecx + jnz short .convloop + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Quantize/descale the coefficients, and store into coef_block +; +; This implementation is based on an algorithm described in +; "How to optimize for the Pentium family of microprocessors" +; (http://www.agner.org/assem/). +; +; GLOBAL(void) +; jsimd_quantize_sse2 (JCOEFPTR coef_block, DCTELEM * divisors, +; DCTELEM * workspace); +; + +%define RECIPROCAL(m,n,b) XMMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM) +%define CORRECTION(m,n,b) XMMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM) +%define SCALE(m,n,b) XMMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM) + +%define coef_block ebp+8 ; JCOEFPTR coef_block +%define divisors ebp+12 ; DCTELEM * divisors +%define workspace ebp+16 ; DCTELEM * workspace + + align 16 + global EXTN(jsimd_quantize_sse2) + +EXTN(jsimd_quantize_sse2): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + mov esi, POINTER [workspace] + mov edx, POINTER [divisors] + mov edi, JCOEFPTR [coef_block] + mov eax, DCTSIZE2/32 + alignx 16,7 +.quantloop: + movdqa xmm4, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_DCTELEM)] + movdqa xmm5, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_DCTELEM)] + movdqa xmm6, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_DCTELEM)] + movdqa xmm7, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_DCTELEM)] + movdqa xmm0,xmm4 + movdqa xmm1,xmm5 + movdqa xmm2,xmm6 + movdqa xmm3,xmm7 + psraw xmm4,(WORD_BIT-1) + psraw xmm5,(WORD_BIT-1) + psraw xmm6,(WORD_BIT-1) + psraw xmm7,(WORD_BIT-1) + pxor xmm0,xmm4 + pxor xmm1,xmm5 + pxor xmm2,xmm6 + pxor xmm3,xmm7 + psubw xmm0,xmm4 ; if (xmm0 < 0) xmm0 = -xmm0; + psubw xmm1,xmm5 ; if (xmm1 < 0) xmm1 = -xmm1; + psubw xmm2,xmm6 ; if (xmm2 < 0) xmm2 = -xmm2; + psubw xmm3,xmm7 ; if (xmm3 < 0) xmm3 = -xmm3; + + paddw xmm0, XMMWORD [CORRECTION(0,0,edx)] ; correction + roundfactor + paddw xmm1, XMMWORD [CORRECTION(1,0,edx)] + paddw xmm2, XMMWORD [CORRECTION(2,0,edx)] + paddw xmm3, XMMWORD [CORRECTION(3,0,edx)] + pmulhuw xmm0, XMMWORD [RECIPROCAL(0,0,edx)] ; reciprocal + pmulhuw xmm1, XMMWORD [RECIPROCAL(1,0,edx)] + pmulhuw xmm2, XMMWORD [RECIPROCAL(2,0,edx)] + pmulhuw xmm3, XMMWORD [RECIPROCAL(3,0,edx)] + pmulhuw xmm0, XMMWORD [SCALE(0,0,edx)] ; scale + pmulhuw xmm1, XMMWORD [SCALE(1,0,edx)] + pmulhuw xmm2, XMMWORD [SCALE(2,0,edx)] + pmulhuw xmm3, XMMWORD [SCALE(3,0,edx)] + + pxor xmm0,xmm4 + pxor xmm1,xmm5 + pxor xmm2,xmm6 + pxor xmm3,xmm7 + psubw xmm0,xmm4 + psubw xmm1,xmm5 + psubw xmm2,xmm6 + psubw xmm3,xmm7 + movdqa XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_DCTELEM)], xmm0 + movdqa XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_DCTELEM)], xmm1 + movdqa XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_DCTELEM)], xmm2 + movdqa XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_DCTELEM)], xmm3 + + add esi, byte 32*SIZEOF_DCTELEM + add edx, byte 32*SIZEOF_DCTELEM + add edi, byte 32*SIZEOF_JCOEF + dec eax + jnz near .quantloop + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused +; pop ebx ; unused + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqntsse.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqntsse.asm new file mode 100755 index 0000000..3065eca --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcqntsse.asm @@ -0,0 +1,211 @@ +; +; jcqntsse.asm - sample data conversion and quantization (SSE & MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Load data into workspace, applying unsigned->signed conversion +; +; GLOBAL(void) +; jsimd_convsamp_float_sse (JSAMPARRAY sample_data, JDIMENSION start_col, +; FAST_FLOAT * workspace); +; + +%define sample_data ebp+8 ; JSAMPARRAY sample_data +%define start_col ebp+12 ; JDIMENSION start_col +%define workspace ebp+16 ; FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_convsamp_float_sse) + +EXTN(jsimd_convsamp_float_sse): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + pcmpeqw mm7,mm7 + psllw mm7,7 + packsswb mm7,mm7 ; mm7 = PB_CENTERJSAMPLE (0x808080..) + + mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) + mov eax, JDIMENSION [start_col] + mov edi, POINTER [workspace] ; (DCTELEM *) + mov ecx, DCTSIZE/2 + alignx 16,7 +.convloop: + mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE] + movq mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE] + + psubb mm0,mm7 ; mm0=(01234567) + psubb mm1,mm7 ; mm1=(89ABCDEF) + + punpcklbw mm2,mm0 ; mm2=(*0*1*2*3) + punpckhbw mm0,mm0 ; mm0=(*4*5*6*7) + punpcklbw mm3,mm1 ; mm3=(*8*9*A*B) + punpckhbw mm1,mm1 ; mm1=(*C*D*E*F) + + punpcklwd mm4,mm2 ; mm4=(***0***1) + punpckhwd mm2,mm2 ; mm2=(***2***3) + punpcklwd mm5,mm0 ; mm5=(***4***5) + punpckhwd mm0,mm0 ; mm0=(***6***7) + + psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(01) + psrad mm2,(DWORD_BIT-BYTE_BIT) ; mm2=(23) + cvtpi2ps xmm0,mm4 ; xmm0=(01**) + cvtpi2ps xmm1,mm2 ; xmm1=(23**) + psrad mm5,(DWORD_BIT-BYTE_BIT) ; mm5=(45) + psrad mm0,(DWORD_BIT-BYTE_BIT) ; mm0=(67) + cvtpi2ps xmm2,mm5 ; xmm2=(45**) + cvtpi2ps xmm3,mm0 ; xmm3=(67**) + + punpcklwd mm6,mm3 ; mm6=(***8***9) + punpckhwd mm3,mm3 ; mm3=(***A***B) + punpcklwd mm4,mm1 ; mm4=(***C***D) + punpckhwd mm1,mm1 ; mm1=(***E***F) + + psrad mm6,(DWORD_BIT-BYTE_BIT) ; mm6=(89) + psrad mm3,(DWORD_BIT-BYTE_BIT) ; mm3=(AB) + cvtpi2ps xmm4,mm6 ; xmm4=(89**) + cvtpi2ps xmm5,mm3 ; xmm5=(AB**) + psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(CD) + psrad mm1,(DWORD_BIT-BYTE_BIT) ; mm1=(EF) + cvtpi2ps xmm6,mm4 ; xmm6=(CD**) + cvtpi2ps xmm7,mm1 ; xmm7=(EF**) + + movlhps xmm0,xmm1 ; xmm0=(0123) + movlhps xmm2,xmm3 ; xmm2=(4567) + movlhps xmm4,xmm5 ; xmm4=(89AB) + movlhps xmm6,xmm7 ; xmm6=(CDEF) + + movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm4 + movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6 + + add esi, byte 2*SIZEOF_JSAMPROW + add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT + dec ecx + jnz near .convloop + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + + +; -------------------------------------------------------------------------- +; +; Quantize/descale the coefficients, and store into coef_block +; +; GLOBAL(void) +; jsimd_quantize_float_sse (JCOEFPTR coef_block, FAST_FLOAT * divisors, +; FAST_FLOAT * workspace); +; + +%define coef_block ebp+8 ; JCOEFPTR coef_block +%define divisors ebp+12 ; FAST_FLOAT * divisors +%define workspace ebp+16 ; FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_quantize_float_sse) + +EXTN(jsimd_quantize_float_sse): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + mov esi, POINTER [workspace] + mov edx, POINTER [divisors] + mov edi, JCOEFPTR [coef_block] + mov eax, DCTSIZE2/16 + alignx 16,7 +.quantloop: + movaps xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)] + mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] + mulps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)] + mulps xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] + mulps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] + + movhlps xmm4,xmm0 + movhlps xmm5,xmm1 + + cvtps2pi mm0,xmm0 + cvtps2pi mm1,xmm1 + cvtps2pi mm4,xmm4 + cvtps2pi mm5,xmm5 + + movhlps xmm6,xmm2 + movhlps xmm7,xmm3 + + cvtps2pi mm2,xmm2 + cvtps2pi mm3,xmm3 + cvtps2pi mm6,xmm6 + cvtps2pi mm7,xmm7 + + packssdw mm0,mm4 + packssdw mm1,mm5 + packssdw mm2,mm6 + packssdw mm3,mm7 + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm3 + + add esi, byte 16*SIZEOF_FAST_FLOAT + add edx, byte 16*SIZEOF_FAST_FLOAT + add edi, byte 16*SIZEOF_JCOEF + dec eax + jnz short .quantloop + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused +; pop ebx ; unused + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcsammmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcsammmx.asm new file mode 100755 index 0000000..9e43b2f --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcsammmx.asm @@ -0,0 +1,324 @@ +; +; jcsammmx.asm - downsampling (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Downsample pixel values of a single component. +; This version handles the common case of 2:1 horizontal and 1:1 vertical, +; without smoothing. +; +; GLOBAL(void) +; jsimd_h2v1_downsample_mmx (JDIMENSION image_width, int max_v_samp_factor, +; JDIMENSION v_samp_factor, JDIMENSION width_blocks, +; JSAMPARRAY input_data, JSAMPARRAY output_data); +; + +%define img_width(b) (b)+8 ; JDIMENSION image_width +%define max_v_samp(b) (b)+12 ; int max_v_samp_factor +%define v_samp(b) (b)+16 ; JDIMENSION v_samp_factor +%define width_blks(b) (b)+20 ; JDIMENSION width_blocks +%define input_data(b) (b)+24 ; JSAMPARRAY input_data +%define output_data(b) (b)+28 ; JSAMPARRAY output_data + + align 16 + global EXTN(jsimd_h2v1_downsample_mmx) + +EXTN(jsimd_h2v1_downsample_mmx): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov ecx, JDIMENSION [width_blks(ebp)] + shl ecx,3 ; imul ecx,DCTSIZE (ecx = output_cols) + jz near .return + + mov edx, JDIMENSION [img_width(ebp)] + + ; -- expand_right_edge + + push ecx + shl ecx,1 ; output_cols * 2 + sub ecx,edx + jle short .expand_end + + mov eax, INT [max_v_samp(ebp)] + test eax,eax + jle short .expand_end + + cld + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + alignx 16,7 +.expandloop: + push eax + push ecx + + mov edi, JSAMPROW [esi] + add edi,edx + mov al, JSAMPLE [edi-1] + + rep stosb + + pop ecx + pop eax + + add esi, byte SIZEOF_JSAMPROW + dec eax + jg short .expandloop + +.expand_end: + pop ecx ; output_cols + + ; -- h2v1_downsample + + mov eax, JDIMENSION [v_samp(ebp)] ; rowctr + test eax,eax + jle near .return + + mov edx, 0x00010000 ; bias pattern + movd mm7,edx + pcmpeqw mm6,mm6 + punpckldq mm7,mm7 ; mm7={0, 1, 0, 1} + psrlw mm6,BYTE_BIT ; mm6={0xFF 0x00 0xFF 0x00 ..} + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, JSAMPARRAY [output_data(ebp)] ; output_data + alignx 16,7 +.rowloop: + push ecx + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr + alignx 16,7 +.columnloop: + + movq mm0, MMWORD [esi+0*SIZEOF_MMWORD] + movq mm1, MMWORD [esi+1*SIZEOF_MMWORD] + movq mm2,mm0 + movq mm3,mm1 + + pand mm0,mm6 + psrlw mm2,BYTE_BIT + pand mm1,mm6 + psrlw mm3,BYTE_BIT + + paddw mm0,mm2 + paddw mm1,mm3 + paddw mm0,mm7 + paddw mm1,mm7 + psrlw mm0,1 + psrlw mm1,1 + + packuswb mm0,mm1 + + movq MMWORD [edi+0*SIZEOF_MMWORD], mm0 + + add esi, byte 2*SIZEOF_MMWORD ; inptr + add edi, byte 1*SIZEOF_MMWORD ; outptr + sub ecx, byte SIZEOF_MMWORD ; outcol + jnz short .columnloop + + pop esi + pop edi + pop ecx + + add esi, byte SIZEOF_JSAMPROW ; input_data + add edi, byte SIZEOF_JSAMPROW ; output_data + dec eax ; rowctr + jg short .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved +; pop ebx ; unused + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Downsample pixel values of a single component. +; This version handles the standard case of 2:1 horizontal and 2:1 vertical, +; without smoothing. +; +; GLOBAL(void) +; jsimd_h2v2_downsample_mmx (JDIMENSION image_width, int max_v_samp_factor, +; JDIMENSION v_samp_factor, JDIMENSION width_blocks, +; JSAMPARRAY input_data, JSAMPARRAY output_data); +; + +%define img_width(b) (b)+8 ; JDIMENSION image_width +%define max_v_samp(b) (b)+12 ; int max_v_samp_factor +%define v_samp(b) (b)+16 ; JDIMENSION v_samp_factor +%define width_blks(b) (b)+20 ; JDIMENSION width_blocks +%define input_data(b) (b)+24 ; JSAMPARRAY input_data +%define output_data(b) (b)+28 ; JSAMPARRAY output_data + + align 16 + global EXTN(jsimd_h2v2_downsample_mmx) + +EXTN(jsimd_h2v2_downsample_mmx): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov ecx, JDIMENSION [width_blks(ebp)] + shl ecx,3 ; imul ecx,DCTSIZE (ecx = output_cols) + jz near .return + + mov edx, JDIMENSION [img_width(ebp)] + + ; -- expand_right_edge + + push ecx + shl ecx,1 ; output_cols * 2 + sub ecx,edx + jle short .expand_end + + mov eax, INT [max_v_samp(ebp)] + test eax,eax + jle short .expand_end + + cld + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + alignx 16,7 +.expandloop: + push eax + push ecx + + mov edi, JSAMPROW [esi] + add edi,edx + mov al, JSAMPLE [edi-1] + + rep stosb + + pop ecx + pop eax + + add esi, byte SIZEOF_JSAMPROW + dec eax + jg short .expandloop + +.expand_end: + pop ecx ; output_cols + + ; -- h2v2_downsample + + mov eax, JDIMENSION [v_samp(ebp)] ; rowctr + test eax,eax + jle near .return + + mov edx, 0x00020001 ; bias pattern + movd mm7,edx + pcmpeqw mm6,mm6 + punpckldq mm7,mm7 ; mm7={1, 2, 1, 2} + psrlw mm6,BYTE_BIT ; mm6={0xFF 0x00 0xFF 0x00 ..} + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, JSAMPARRAY [output_data(ebp)] ; output_data + alignx 16,7 +.rowloop: + push ecx + push edi + push esi + + mov edx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; inptr0 + mov esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; inptr1 + mov edi, JSAMPROW [edi] ; outptr + alignx 16,7 +.columnloop: + + movq mm0, MMWORD [edx+0*SIZEOF_MMWORD] + movq mm1, MMWORD [esi+0*SIZEOF_MMWORD] + movq mm2, MMWORD [edx+1*SIZEOF_MMWORD] + movq mm3, MMWORD [esi+1*SIZEOF_MMWORD] + + movq mm4,mm0 + movq mm5,mm1 + pand mm0,mm6 + psrlw mm4,BYTE_BIT + pand mm1,mm6 + psrlw mm5,BYTE_BIT + paddw mm0,mm4 + paddw mm1,mm5 + + movq mm4,mm2 + movq mm5,mm3 + pand mm2,mm6 + psrlw mm4,BYTE_BIT + pand mm3,mm6 + psrlw mm5,BYTE_BIT + paddw mm2,mm4 + paddw mm3,mm5 + + paddw mm0,mm1 + paddw mm2,mm3 + paddw mm0,mm7 + paddw mm2,mm7 + psrlw mm0,2 + psrlw mm2,2 + + packuswb mm0,mm2 + + movq MMWORD [edi+0*SIZEOF_MMWORD], mm0 + + add edx, byte 2*SIZEOF_MMWORD ; inptr0 + add esi, byte 2*SIZEOF_MMWORD ; inptr1 + add edi, byte 1*SIZEOF_MMWORD ; outptr + sub ecx, byte SIZEOF_MMWORD ; outcol + jnz near .columnloop + + pop esi + pop edi + pop ecx + + add esi, byte 2*SIZEOF_JSAMPROW ; input_data + add edi, byte 1*SIZEOF_JSAMPROW ; output_data + dec eax ; rowctr + jg near .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved +; pop ebx ; unused + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcsamss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcsamss2.asm new file mode 100755 index 0000000..818e911 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jcsamss2.asm @@ -0,0 +1,351 @@ +; +; jcsamss2.asm - downsampling (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Downsample pixel values of a single component. +; This version handles the common case of 2:1 horizontal and 1:1 vertical, +; without smoothing. +; +; GLOBAL(void) +; jsimd_h2v1_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, +; JDIMENSION v_samp_factor, JDIMENSION width_blocks, +; JSAMPARRAY input_data, JSAMPARRAY output_data); +; + +%define img_width(b) (b)+8 ; JDIMENSION image_width +%define max_v_samp(b) (b)+12 ; int max_v_samp_factor +%define v_samp(b) (b)+16 ; JDIMENSION v_samp_factor +%define width_blks(b) (b)+20 ; JDIMENSION width_blocks +%define input_data(b) (b)+24 ; JSAMPARRAY input_data +%define output_data(b) (b)+28 ; JSAMPARRAY output_data + + align 16 + global EXTN(jsimd_h2v1_downsample_sse2) + +EXTN(jsimd_h2v1_downsample_sse2): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov ecx, JDIMENSION [width_blks(ebp)] + shl ecx,3 ; imul ecx,DCTSIZE (ecx = output_cols) + jz near .return + + mov edx, JDIMENSION [img_width(ebp)] + + ; -- expand_right_edge + + push ecx + shl ecx,1 ; output_cols * 2 + sub ecx,edx + jle short .expand_end + + mov eax, INT [max_v_samp(ebp)] + test eax,eax + jle short .expand_end + + cld + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + alignx 16,7 +.expandloop: + push eax + push ecx + + mov edi, JSAMPROW [esi] + add edi,edx + mov al, JSAMPLE [edi-1] + + rep stosb + + pop ecx + pop eax + + add esi, byte SIZEOF_JSAMPROW + dec eax + jg short .expandloop + +.expand_end: + pop ecx ; output_cols + + ; -- h2v1_downsample + + mov eax, JDIMENSION [v_samp(ebp)] ; rowctr + test eax,eax + jle near .return + + mov edx, 0x00010000 ; bias pattern + movd xmm7,edx + pcmpeqw xmm6,xmm6 + pshufd xmm7,xmm7,0x00 ; xmm7={0, 1, 0, 1, 0, 1, 0, 1} + psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, JSAMPARRAY [output_data(ebp)] ; output_data + alignx 16,7 +.rowloop: + push ecx + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr + + cmp ecx, byte SIZEOF_XMMWORD + jae short .columnloop + alignx 16,7 + +.columnloop_r8: + movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD] + pxor xmm1,xmm1 + mov ecx, SIZEOF_XMMWORD + jmp short .downsample + alignx 16,7 + +.columnloop: + movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqa xmm1, XMMWORD [esi+1*SIZEOF_XMMWORD] + +.downsample: + movdqa xmm2,xmm0 + movdqa xmm3,xmm1 + + pand xmm0,xmm6 + psrlw xmm2,BYTE_BIT + pand xmm1,xmm6 + psrlw xmm3,BYTE_BIT + + paddw xmm0,xmm2 + paddw xmm1,xmm3 + paddw xmm0,xmm7 + paddw xmm1,xmm7 + psrlw xmm0,1 + psrlw xmm1,1 + + packuswb xmm0,xmm1 + + movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0 + + sub ecx, byte SIZEOF_XMMWORD ; outcol + add esi, byte 2*SIZEOF_XMMWORD ; inptr + add edi, byte 1*SIZEOF_XMMWORD ; outptr + cmp ecx, byte SIZEOF_XMMWORD + jae short .columnloop + test ecx,ecx + jnz short .columnloop_r8 + + pop esi + pop edi + pop ecx + + add esi, byte SIZEOF_JSAMPROW ; input_data + add edi, byte SIZEOF_JSAMPROW ; output_data + dec eax ; rowctr + jg near .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved +; pop ebx ; unused + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Downsample pixel values of a single component. +; This version handles the standard case of 2:1 horizontal and 2:1 vertical, +; without smoothing. +; +; GLOBAL(void) +; jsimd_h2v2_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, +; JDIMENSION v_samp_factor, JDIMENSION width_blocks, +; JSAMPARRAY input_data, JSAMPARRAY output_data); +; + +%define img_width(b) (b)+8 ; JDIMENSION image_width +%define max_v_samp(b) (b)+12 ; int max_v_samp_factor +%define v_samp(b) (b)+16 ; JDIMENSION v_samp_factor +%define width_blks(b) (b)+20 ; JDIMENSION width_blocks +%define input_data(b) (b)+24 ; JSAMPARRAY input_data +%define output_data(b) (b)+28 ; JSAMPARRAY output_data + + align 16 + global EXTN(jsimd_h2v2_downsample_sse2) + +EXTN(jsimd_h2v2_downsample_sse2): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov ecx, JDIMENSION [width_blks(ebp)] + shl ecx,3 ; imul ecx,DCTSIZE (ecx = output_cols) + jz near .return + + mov edx, JDIMENSION [img_width(ebp)] + + ; -- expand_right_edge + + push ecx + shl ecx,1 ; output_cols * 2 + sub ecx,edx + jle short .expand_end + + mov eax, INT [max_v_samp(ebp)] + test eax,eax + jle short .expand_end + + cld + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + alignx 16,7 +.expandloop: + push eax + push ecx + + mov edi, JSAMPROW [esi] + add edi,edx + mov al, JSAMPLE [edi-1] + + rep stosb + + pop ecx + pop eax + + add esi, byte SIZEOF_JSAMPROW + dec eax + jg short .expandloop + +.expand_end: + pop ecx ; output_cols + + ; -- h2v2_downsample + + mov eax, JDIMENSION [v_samp(ebp)] ; rowctr + test eax,eax + jle near .return + + mov edx, 0x00020001 ; bias pattern + movd xmm7,edx + pcmpeqw xmm6,xmm6 + pshufd xmm7,xmm7,0x00 ; xmm7={1, 2, 1, 2, 1, 2, 1, 2} + psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, JSAMPARRAY [output_data(ebp)] ; output_data + alignx 16,7 +.rowloop: + push ecx + push edi + push esi + + mov edx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; inptr0 + mov esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; inptr1 + mov edi, JSAMPROW [edi] ; outptr + + cmp ecx, byte SIZEOF_XMMWORD + jae short .columnloop + alignx 16,7 + +.columnloop_r8: + movdqa xmm0, XMMWORD [edx+0*SIZEOF_XMMWORD] + movdqa xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD] + pxor xmm2,xmm2 + pxor xmm3,xmm3 + mov ecx, SIZEOF_XMMWORD + jmp short .downsample + alignx 16,7 + +.columnloop: + movdqa xmm0, XMMWORD [edx+0*SIZEOF_XMMWORD] + movdqa xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqa xmm2, XMMWORD [edx+1*SIZEOF_XMMWORD] + movdqa xmm3, XMMWORD [esi+1*SIZEOF_XMMWORD] + +.downsample: + movdqa xmm4,xmm0 + movdqa xmm5,xmm1 + pand xmm0,xmm6 + psrlw xmm4,BYTE_BIT + pand xmm1,xmm6 + psrlw xmm5,BYTE_BIT + paddw xmm0,xmm4 + paddw xmm1,xmm5 + + movdqa xmm4,xmm2 + movdqa xmm5,xmm3 + pand xmm2,xmm6 + psrlw xmm4,BYTE_BIT + pand xmm3,xmm6 + psrlw xmm5,BYTE_BIT + paddw xmm2,xmm4 + paddw xmm3,xmm5 + + paddw xmm0,xmm1 + paddw xmm2,xmm3 + paddw xmm0,xmm7 + paddw xmm2,xmm7 + psrlw xmm0,2 + psrlw xmm2,2 + + packuswb xmm0,xmm2 + + movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0 + + sub ecx, byte SIZEOF_XMMWORD ; outcol + add edx, byte 2*SIZEOF_XMMWORD ; inptr0 + add esi, byte 2*SIZEOF_XMMWORD ; inptr1 + add edi, byte 1*SIZEOF_XMMWORD ; outptr + cmp ecx, byte SIZEOF_XMMWORD + jae near .columnloop + test ecx,ecx + jnz near .columnloop_r8 + + pop esi + pop edi + pop ecx + + add esi, byte 2*SIZEOF_JSAMPROW ; input_data + add edi, byte 1*SIZEOF_JSAMPROW ; output_data + dec eax ; rowctr + jg near .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved +; pop ebx ; unused + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdclrmmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdclrmmx.asm new file mode 100755 index 0000000..1c255e8 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdclrmmx.asm @@ -0,0 +1,405 @@ +; +; jdclrmmx.asm - colorspace conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_ycc_rgb_convert_mmx (JDIMENSION out_width, +; JSAMPIMAGE input_buf, JDIMENSION input_row, +; JSAMPARRAY output_buf, int num_rows) +; + +%define out_width(b) (b)+8 ; JDIMENSION out_width +%define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf +%define input_row(b) (b)+16 ; JDIMENSION input_row +%define output_buf(b) (b)+20 ; JSAMPARRAY output_buf +%define num_rows(b) (b)+24 ; int num_rows + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_ycc_rgb_convert_mmx) + +EXTN(jsimd_ycc_rgb_convert_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [out_width(eax)] ; num_cols + test ecx,ecx + jz near .return + + push ecx + + mov edi, JSAMPIMAGE [input_buf(eax)] + mov ecx, JDIMENSION [input_row(eax)] + mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] + lea esi, [esi+ecx*SIZEOF_JSAMPROW] + lea ebx, [ebx+ecx*SIZEOF_JSAMPROW] + lea edx, [edx+ecx*SIZEOF_JSAMPROW] + + pop ecx + + mov edi, JSAMPARRAY [output_buf(eax)] + mov eax, INT [num_rows(eax)] + test eax,eax + jle near .return + alignx 16,7 +.rowloop: + push eax + push edi + push edx + push ebx + push esi + push ecx ; col + + mov esi, JSAMPROW [esi] ; inptr0 + mov ebx, JSAMPROW [ebx] ; inptr1 + mov edx, JSAMPROW [edx] ; inptr2 + mov edi, JSAMPROW [edi] ; outptr + movpic eax, POINTER [gotptr] ; load GOT address (eax) + alignx 16,7 +.columnloop: + + movq mm5, MMWORD [ebx] ; mm5=Cb(01234567) + movq mm1, MMWORD [edx] ; mm1=Cr(01234567) + + pcmpeqw mm4,mm4 + pcmpeqw mm7,mm7 + psrlw mm4,BYTE_BIT + psllw mm7,7 ; mm7={0xFF80 0xFF80 0xFF80 0xFF80} + movq mm0,mm4 ; mm0=mm4={0xFF 0x00 0xFF 0x00 ..} + + pand mm4,mm5 ; mm4=Cb(0246)=CbE + psrlw mm5,BYTE_BIT ; mm5=Cb(1357)=CbO + pand mm0,mm1 ; mm0=Cr(0246)=CrE + psrlw mm1,BYTE_BIT ; mm1=Cr(1357)=CrO + + paddw mm4,mm7 + paddw mm5,mm7 + paddw mm0,mm7 + paddw mm1,mm7 + + ; (Original) + ; R = Y + 1.40200 * Cr + ; G = Y - 0.34414 * Cb - 0.71414 * Cr + ; B = Y + 1.77200 * Cb + ; + ; (This implementation) + ; R = Y + 0.40200 * Cr + Cr + ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr + ; B = Y - 0.22800 * Cb + Cb + Cb + + movq mm2,mm4 ; mm2=CbE + movq mm3,mm5 ; mm3=CbO + paddw mm4,mm4 ; mm4=2*CbE + paddw mm5,mm5 ; mm5=2*CbO + movq mm6,mm0 ; mm6=CrE + movq mm7,mm1 ; mm7=CrO + paddw mm0,mm0 ; mm0=2*CrE + paddw mm1,mm1 ; mm1=2*CrO + + pmulhw mm4,[GOTOFF(eax,PW_MF0228)] ; mm4=(2*CbE * -FIX(0.22800)) + pmulhw mm5,[GOTOFF(eax,PW_MF0228)] ; mm5=(2*CbO * -FIX(0.22800)) + pmulhw mm0,[GOTOFF(eax,PW_F0402)] ; mm0=(2*CrE * FIX(0.40200)) + pmulhw mm1,[GOTOFF(eax,PW_F0402)] ; mm1=(2*CrO * FIX(0.40200)) + + paddw mm4,[GOTOFF(eax,PW_ONE)] + paddw mm5,[GOTOFF(eax,PW_ONE)] + psraw mm4,1 ; mm4=(CbE * -FIX(0.22800)) + psraw mm5,1 ; mm5=(CbO * -FIX(0.22800)) + paddw mm0,[GOTOFF(eax,PW_ONE)] + paddw mm1,[GOTOFF(eax,PW_ONE)] + psraw mm0,1 ; mm0=(CrE * FIX(0.40200)) + psraw mm1,1 ; mm1=(CrO * FIX(0.40200)) + + paddw mm4,mm2 + paddw mm5,mm3 + paddw mm4,mm2 ; mm4=(CbE * FIX(1.77200))=(B-Y)E + paddw mm5,mm3 ; mm5=(CbO * FIX(1.77200))=(B-Y)O + paddw mm0,mm6 ; mm0=(CrE * FIX(1.40200))=(R-Y)E + paddw mm1,mm7 ; mm1=(CrO * FIX(1.40200))=(R-Y)O + + movq MMWORD [wk(0)], mm4 ; wk(0)=(B-Y)E + movq MMWORD [wk(1)], mm5 ; wk(1)=(B-Y)O + + movq mm4,mm2 + movq mm5,mm3 + punpcklwd mm2,mm6 + punpckhwd mm4,mm6 + pmaddwd mm2,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd mm4,[GOTOFF(eax,PW_MF0344_F0285)] + punpcklwd mm3,mm7 + punpckhwd mm5,mm7 + pmaddwd mm3,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd mm5,[GOTOFF(eax,PW_MF0344_F0285)] + + paddd mm2,[GOTOFF(eax,PD_ONEHALF)] + paddd mm4,[GOTOFF(eax,PD_ONEHALF)] + psrad mm2,SCALEBITS + psrad mm4,SCALEBITS + paddd mm3,[GOTOFF(eax,PD_ONEHALF)] + paddd mm5,[GOTOFF(eax,PD_ONEHALF)] + psrad mm3,SCALEBITS + psrad mm5,SCALEBITS + + packssdw mm2,mm4 ; mm2=CbE*-FIX(0.344)+CrE*FIX(0.285) + packssdw mm3,mm5 ; mm3=CbO*-FIX(0.344)+CrO*FIX(0.285) + psubw mm2,mm6 ; mm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E + psubw mm3,mm7 ; mm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O + + movq mm5, MMWORD [esi] ; mm5=Y(01234567) + + pcmpeqw mm4,mm4 + psrlw mm4,BYTE_BIT ; mm4={0xFF 0x00 0xFF 0x00 ..} + pand mm4,mm5 ; mm4=Y(0246)=YE + psrlw mm5,BYTE_BIT ; mm5=Y(1357)=YO + + paddw mm0,mm4 ; mm0=((R-Y)E+YE)=RE=(R0 R2 R4 R6) + paddw mm1,mm5 ; mm1=((R-Y)O+YO)=RO=(R1 R3 R5 R7) + packuswb mm0,mm0 ; mm0=(R0 R2 R4 R6 ** ** ** **) + packuswb mm1,mm1 ; mm1=(R1 R3 R5 R7 ** ** ** **) + + paddw mm2,mm4 ; mm2=((G-Y)E+YE)=GE=(G0 G2 G4 G6) + paddw mm3,mm5 ; mm3=((G-Y)O+YO)=GO=(G1 G3 G5 G7) + packuswb mm2,mm2 ; mm2=(G0 G2 G4 G6 ** ** ** **) + packuswb mm3,mm3 ; mm3=(G1 G3 G5 G7 ** ** ** **) + + paddw mm4, MMWORD [wk(0)] ; mm4=(YE+(B-Y)E)=BE=(B0 B2 B4 B6) + paddw mm5, MMWORD [wk(1)] ; mm5=(YO+(B-Y)O)=BO=(B1 B3 B5 B7) + packuswb mm4,mm4 ; mm4=(B0 B2 B4 B6 ** ** ** **) + packuswb mm5,mm5 ; mm5=(B1 B3 B5 B7 ** ** ** **) + +%if RGB_PIXELSIZE == 3 ; --------------- + + ; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **) + ; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **) + ; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **) + ; mmG=(** ** ** ** ** ** ** **), mmH=(** ** ** ** ** ** ** **) + + punpcklbw mmA,mmC ; mmA=(00 10 02 12 04 14 06 16) + punpcklbw mmE,mmB ; mmE=(20 01 22 03 24 05 26 07) + punpcklbw mmD,mmF ; mmD=(11 21 13 23 15 25 17 27) + + movq mmG,mmA + movq mmH,mmA + punpcklwd mmA,mmE ; mmA=(00 10 20 01 02 12 22 03) + punpckhwd mmG,mmE ; mmG=(04 14 24 05 06 16 26 07) + + psrlq mmH,2*BYTE_BIT ; mmH=(02 12 04 14 06 16 -- --) + psrlq mmE,2*BYTE_BIT ; mmE=(22 03 24 05 26 07 -- --) + + movq mmC,mmD + movq mmB,mmD + punpcklwd mmD,mmH ; mmD=(11 21 02 12 13 23 04 14) + punpckhwd mmC,mmH ; mmC=(15 25 06 16 17 27 -- --) + + psrlq mmB,2*BYTE_BIT ; mmB=(13 23 15 25 17 27 -- --) + + movq mmF,mmE + punpcklwd mmE,mmB ; mmE=(22 03 13 23 24 05 15 25) + punpckhwd mmF,mmB ; mmF=(26 07 17 27 -- -- -- --) + + punpckldq mmA,mmD ; mmA=(00 10 20 01 11 21 02 12) + punpckldq mmE,mmG ; mmE=(22 03 13 23 04 14 24 05) + punpckldq mmC,mmF ; mmC=(15 25 06 16 26 07 17 27) + + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st16 + + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmE + movq MMWORD [edi+2*SIZEOF_MMWORD], mmC + + sub ecx, byte SIZEOF_MMWORD + jz short .nextrow + + add esi, byte SIZEOF_MMWORD ; inptr0 + add ebx, byte SIZEOF_MMWORD ; inptr1 + add edx, byte SIZEOF_MMWORD ; inptr2 + add edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; outptr + jmp near .columnloop + alignx 16,7 + +.column_st16: + lea ecx, [ecx+ecx*2] ; imul ecx, RGB_PIXELSIZE + cmp ecx, byte 2*SIZEOF_MMWORD + jb short .column_st8 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmE + movq mmA,mmC + sub ecx, byte 2*SIZEOF_MMWORD + add edi, byte 2*SIZEOF_MMWORD + jmp short .column_st4 +.column_st8: + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st4 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq mmA,mmE + sub ecx, byte SIZEOF_MMWORD + add edi, byte SIZEOF_MMWORD +.column_st4: + movd eax,mmA + cmp ecx, byte SIZEOF_DWORD + jb short .column_st2 + mov DWORD [edi+0*SIZEOF_DWORD], eax + psrlq mmA,DWORD_BIT + movd eax,mmA + sub ecx, byte SIZEOF_DWORD + add edi, byte SIZEOF_DWORD +.column_st2: + cmp ecx, byte SIZEOF_WORD + jb short .column_st1 + mov WORD [edi+0*SIZEOF_WORD], ax + shr eax,WORD_BIT + sub ecx, byte SIZEOF_WORD + add edi, byte SIZEOF_WORD +.column_st1: + cmp ecx, byte SIZEOF_BYTE + jb short .nextrow + mov BYTE [edi+0*SIZEOF_BYTE], al + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +%ifdef RGBX_FILLER_0XFF + pcmpeqb mm6,mm6 ; mm6=(X0 X2 X4 X6 ** ** ** **) + pcmpeqb mm7,mm7 ; mm7=(X1 X3 X5 X7 ** ** ** **) +%else + pxor mm6,mm6 ; mm6=(X0 X2 X4 X6 ** ** ** **) + pxor mm7,mm7 ; mm7=(X1 X3 X5 X7 ** ** ** **) +%endif + ; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **) + ; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **) + ; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **) + ; mmG=(30 32 34 36 ** ** ** **), mmH=(31 33 35 37 ** ** ** **) + + punpcklbw mmA,mmC ; mmA=(00 10 02 12 04 14 06 16) + punpcklbw mmE,mmG ; mmE=(20 30 22 32 24 34 26 36) + punpcklbw mmB,mmD ; mmB=(01 11 03 13 05 15 07 17) + punpcklbw mmF,mmH ; mmF=(21 31 23 33 25 35 27 37) + + movq mmC,mmA + punpcklwd mmA,mmE ; mmA=(00 10 20 30 02 12 22 32) + punpckhwd mmC,mmE ; mmC=(04 14 24 34 06 16 26 36) + movq mmG,mmB + punpcklwd mmB,mmF ; mmB=(01 11 21 31 03 13 23 33) + punpckhwd mmG,mmF ; mmG=(05 15 25 35 07 17 27 37) + + movq mmD,mmA + punpckldq mmA,mmB ; mmA=(00 10 20 30 01 11 21 31) + punpckhdq mmD,mmB ; mmD=(02 12 22 32 03 13 23 33) + movq mmH,mmC + punpckldq mmC,mmG ; mmC=(04 14 24 34 05 15 25 35) + punpckhdq mmH,mmG ; mmH=(06 16 26 36 07 17 27 37) + + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st16 + + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmD + movq MMWORD [edi+2*SIZEOF_MMWORD], mmC + movq MMWORD [edi+3*SIZEOF_MMWORD], mmH + + sub ecx, byte SIZEOF_MMWORD + jz short .nextrow + + add esi, byte SIZEOF_MMWORD ; inptr0 + add ebx, byte SIZEOF_MMWORD ; inptr1 + add edx, byte SIZEOF_MMWORD ; inptr2 + add edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; outptr + jmp near .columnloop + alignx 16,7 + +.column_st16: + cmp ecx, byte SIZEOF_MMWORD/2 + jb short .column_st8 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmD + movq mmA,mmC + movq mmD,mmH + sub ecx, byte SIZEOF_MMWORD/2 + add edi, byte 2*SIZEOF_MMWORD +.column_st8: + cmp ecx, byte SIZEOF_MMWORD/4 + jb short .column_st4 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq mmA,mmD + sub ecx, byte SIZEOF_MMWORD/4 + add edi, byte 1*SIZEOF_MMWORD +.column_st4: + cmp ecx, byte SIZEOF_MMWORD/8 + jb short .nextrow + movd DWORD [edi+0*SIZEOF_DWORD], mmA + +%endif ; RGB_PIXELSIZE ; --------------- + + alignx 16,7 + +.nextrow: + pop ecx + pop esi + pop ebx + pop edx + pop edi + pop eax + + add esi, byte SIZEOF_JSAMPROW + add ebx, byte SIZEOF_JSAMPROW + add edx, byte SIZEOF_JSAMPROW + add edi, byte SIZEOF_JSAMPROW ; output_buf + dec eax ; num_rows + jg near .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdclrss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdclrss2.asm new file mode 100755 index 0000000..d26a5bb --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdclrss2.asm @@ -0,0 +1,459 @@ +; +; jdclrss2.asm - colorspace conversion (SSE2) +; +; Copyright 2009, 2012 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width, +; JSAMPIMAGE input_buf, JDIMENSION input_row, +; JSAMPARRAY output_buf, int num_rows) +; + +%define out_width(b) (b)+8 ; JDIMENSION out_width +%define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf +%define input_row(b) (b)+16 ; JDIMENSION input_row +%define output_buf(b) (b)+20 ; JSAMPARRAY output_buf +%define num_rows(b) (b)+24 ; int num_rows + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_ycc_rgb_convert_sse2) + +EXTN(jsimd_ycc_rgb_convert_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [out_width(eax)] ; num_cols + test ecx,ecx + jz near .return + + push ecx + + mov edi, JSAMPIMAGE [input_buf(eax)] + mov ecx, JDIMENSION [input_row(eax)] + mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] + lea esi, [esi+ecx*SIZEOF_JSAMPROW] + lea ebx, [ebx+ecx*SIZEOF_JSAMPROW] + lea edx, [edx+ecx*SIZEOF_JSAMPROW] + + pop ecx + + mov edi, JSAMPARRAY [output_buf(eax)] + mov eax, INT [num_rows(eax)] + test eax,eax + jle near .return + alignx 16,7 +.rowloop: + push eax + push edi + push edx + push ebx + push esi + push ecx ; col + + mov esi, JSAMPROW [esi] ; inptr0 + mov ebx, JSAMPROW [ebx] ; inptr1 + mov edx, JSAMPROW [edx] ; inptr2 + mov edi, JSAMPROW [edi] ; outptr + movpic eax, POINTER [gotptr] ; load GOT address (eax) + alignx 16,7 +.columnloop: + + movdqa xmm5, XMMWORD [ebx] ; xmm5=Cb(0123456789ABCDEF) + movdqa xmm1, XMMWORD [edx] ; xmm1=Cr(0123456789ABCDEF) + + pcmpeqw xmm4,xmm4 + pcmpeqw xmm7,xmm7 + psrlw xmm4,BYTE_BIT + psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} + movdqa xmm0,xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..} + + pand xmm4,xmm5 ; xmm4=Cb(02468ACE)=CbE + psrlw xmm5,BYTE_BIT ; xmm5=Cb(13579BDF)=CbO + pand xmm0,xmm1 ; xmm0=Cr(02468ACE)=CrE + psrlw xmm1,BYTE_BIT ; xmm1=Cr(13579BDF)=CrO + + paddw xmm4,xmm7 + paddw xmm5,xmm7 + paddw xmm0,xmm7 + paddw xmm1,xmm7 + + ; (Original) + ; R = Y + 1.40200 * Cr + ; G = Y - 0.34414 * Cb - 0.71414 * Cr + ; B = Y + 1.77200 * Cb + ; + ; (This implementation) + ; R = Y + 0.40200 * Cr + Cr + ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr + ; B = Y - 0.22800 * Cb + Cb + Cb + + movdqa xmm2,xmm4 ; xmm2=CbE + movdqa xmm3,xmm5 ; xmm3=CbO + paddw xmm4,xmm4 ; xmm4=2*CbE + paddw xmm5,xmm5 ; xmm5=2*CbO + movdqa xmm6,xmm0 ; xmm6=CrE + movdqa xmm7,xmm1 ; xmm7=CrO + paddw xmm0,xmm0 ; xmm0=2*CrE + paddw xmm1,xmm1 ; xmm1=2*CrO + + pmulhw xmm4,[GOTOFF(eax,PW_MF0228)] ; xmm4=(2*CbE * -FIX(0.22800)) + pmulhw xmm5,[GOTOFF(eax,PW_MF0228)] ; xmm5=(2*CbO * -FIX(0.22800)) + pmulhw xmm0,[GOTOFF(eax,PW_F0402)] ; xmm0=(2*CrE * FIX(0.40200)) + pmulhw xmm1,[GOTOFF(eax,PW_F0402)] ; xmm1=(2*CrO * FIX(0.40200)) + + paddw xmm4,[GOTOFF(eax,PW_ONE)] + paddw xmm5,[GOTOFF(eax,PW_ONE)] + psraw xmm4,1 ; xmm4=(CbE * -FIX(0.22800)) + psraw xmm5,1 ; xmm5=(CbO * -FIX(0.22800)) + paddw xmm0,[GOTOFF(eax,PW_ONE)] + paddw xmm1,[GOTOFF(eax,PW_ONE)] + psraw xmm0,1 ; xmm0=(CrE * FIX(0.40200)) + psraw xmm1,1 ; xmm1=(CrO * FIX(0.40200)) + + paddw xmm4,xmm2 + paddw xmm5,xmm3 + paddw xmm4,xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E + paddw xmm5,xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O + paddw xmm0,xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E + paddw xmm1,xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E + movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O + + movdqa xmm4,xmm2 + movdqa xmm5,xmm3 + punpcklwd xmm2,xmm6 + punpckhwd xmm4,xmm6 + pmaddwd xmm2,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd xmm4,[GOTOFF(eax,PW_MF0344_F0285)] + punpcklwd xmm3,xmm7 + punpckhwd xmm5,xmm7 + pmaddwd xmm3,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd xmm5,[GOTOFF(eax,PW_MF0344_F0285)] + + paddd xmm2,[GOTOFF(eax,PD_ONEHALF)] + paddd xmm4,[GOTOFF(eax,PD_ONEHALF)] + psrad xmm2,SCALEBITS + psrad xmm4,SCALEBITS + paddd xmm3,[GOTOFF(eax,PD_ONEHALF)] + paddd xmm5,[GOTOFF(eax,PD_ONEHALF)] + psrad xmm3,SCALEBITS + psrad xmm5,SCALEBITS + + packssdw xmm2,xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285) + packssdw xmm3,xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285) + psubw xmm2,xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E + psubw xmm3,xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O + + movdqa xmm5, XMMWORD [esi] ; xmm5=Y(0123456789ABCDEF) + + pcmpeqw xmm4,xmm4 + psrlw xmm4,BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..} + pand xmm4,xmm5 ; xmm4=Y(02468ACE)=YE + psrlw xmm5,BYTE_BIT ; xmm5=Y(13579BDF)=YO + + paddw xmm0,xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE) + paddw xmm1,xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF) + packuswb xmm0,xmm0 ; xmm0=R(02468ACE********) + packuswb xmm1,xmm1 ; xmm1=R(13579BDF********) + + paddw xmm2,xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE) + paddw xmm3,xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF) + packuswb xmm2,xmm2 ; xmm2=G(02468ACE********) + packuswb xmm3,xmm3 ; xmm3=G(13579BDF********) + + paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE) + paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF) + packuswb xmm4,xmm4 ; xmm4=B(02468ACE********) + packuswb xmm5,xmm5 ; xmm5=B(13579BDF********) + +%if RGB_PIXELSIZE == 3 ; --------------- + + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F) + punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F) + + movdqa xmmG,xmmA + movdqa xmmH,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07) + punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F) + + psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --) + psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --) + + movdqa xmmC,xmmD + movdqa xmmB,xmmD + punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18) + punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --) + + psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --) + + movdqa xmmF,xmmE + punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29) + punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --) + + pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03) + movdqa xmmB,xmmE + punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14) + punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07) + punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29) + + pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B) + movdqa xmmB,xmmF + punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C) + punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F) + punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --) + + punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + cmp ecx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test edi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF +.out0: + add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub ecx, byte SIZEOF_XMMWORD + jz near .nextrow + + add esi, byte SIZEOF_XMMWORD ; inptr0 + add ebx, byte SIZEOF_XMMWORD ; inptr1 + add edx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + alignx 16,7 + +.column_st32: + lea ecx, [ecx+ecx*2] ; imul ecx, RGB_PIXELSIZE + cmp ecx, byte 2*SIZEOF_XMMWORD + jb short .column_st16 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + add edi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmF + sub ecx, byte 2*SIZEOF_XMMWORD + jmp short .column_st15 +.column_st16: + cmp ecx, byte SIZEOF_XMMWORD + jb short .column_st15 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + add edi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub ecx, byte SIZEOF_XMMWORD +.column_st15: + ; Store the lower 8 bytes of xmmA to the output when it has enough + ; space. + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st7 + movq MMWORD [edi], xmmA + add edi, byte SIZEOF_MMWORD + sub ecx, byte SIZEOF_MMWORD + psrldq xmmA, SIZEOF_MMWORD +.column_st7: + ; Store the lower 4 bytes of xmmA to the output when it has enough + ; space. + cmp ecx, byte SIZEOF_DWORD + jb short .column_st3 + movd DWORD [edi], xmmA + add edi, byte SIZEOF_DWORD + sub ecx, byte SIZEOF_DWORD + psrldq xmmA, SIZEOF_DWORD +.column_st3: + ; Store the lower 2 bytes of eax to the output when it has enough + ; space. + movd eax, xmmA + cmp ecx, byte SIZEOF_WORD + jb short .column_st1 + mov WORD [edi], ax + add edi, byte SIZEOF_WORD + sub ecx, byte SIZEOF_WORD + shr eax, 16 +.column_st1: + ; Store the lower 1 byte of eax to the output when it has enough + ; space. + test ecx, ecx + jz short .nextrow + mov BYTE [edi], al + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +%ifdef RGBX_FILLER_0XFF + pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%else + pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%endif + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E) + punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F) + punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F) + + movdqa xmmC,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36) + punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E) + movdqa xmmG,xmmB + punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37) + punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + movdqa xmmH,xmmC + punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + cmp ecx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test edi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC + movntdq XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC + movdqu XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH +.out0: + add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub ecx, byte SIZEOF_XMMWORD + jz near .nextrow + + add esi, byte SIZEOF_XMMWORD ; inptr0 + add ebx, byte SIZEOF_XMMWORD ; inptr1 + add edx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + alignx 16,7 + +.column_st32: + cmp ecx, byte SIZEOF_XMMWORD/2 + jb short .column_st16 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + add edi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmC + movdqa xmmD,xmmH + sub ecx, byte SIZEOF_XMMWORD/2 +.column_st16: + cmp ecx, byte SIZEOF_XMMWORD/4 + jb short .column_st15 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + add edi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub ecx, byte SIZEOF_XMMWORD/4 +.column_st15: + ; Store two pixels (8 bytes) of xmmA to the output when it has enough + ; space. + cmp ecx, byte SIZEOF_XMMWORD/8 + jb short .column_st7 + movq MMWORD [edi], xmmA + add edi, byte SIZEOF_XMMWORD/8*4 + sub ecx, byte SIZEOF_XMMWORD/8 + psrldq xmmA, SIZEOF_XMMWORD/8*4 +.column_st7: + ; Store one pixel (4 bytes) of xmmA to the output when it has enough + ; space. + test ecx, ecx + jz short .nextrow + movd DWORD [edi], xmmA + +%endif ; RGB_PIXELSIZE ; --------------- + + alignx 16,7 + +.nextrow: + pop ecx + pop esi + pop ebx + pop edx + pop edi + pop eax + + add esi, byte SIZEOF_JSAMPROW + add ebx, byte SIZEOF_JSAMPROW + add edx, byte SIZEOF_JSAMPROW + add edi, byte SIZEOF_JSAMPROW ; output_buf + dec eax ; num_rows + jg near .rowloop + + sfence ; flush the write buffer + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdcolmmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdcolmmx.asm new file mode 100755 index 0000000..5e4e47d --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdcolmmx.asm @@ -0,0 +1,120 @@ +; +; jdcolmmx.asm - colorspace conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_344 equ 22554 ; FIX(0.34414) +F_0_714 equ 46802 ; FIX(0.71414) +F_1_402 equ 91881 ; FIX(1.40200) +F_1_772 equ 116130 ; FIX(1.77200) +F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) +F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) +F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_ycc_rgb_convert_mmx) + +EXTN(jconst_ycc_rgb_convert_mmx): + +PW_F0402 times 4 dw F_0_402 +PW_MF0228 times 4 dw -F_0_228 +PW_MF0344_F0285 times 2 dw -F_0_344, F_0_285 +PW_ONE times 4 dw 1 +PD_ONEHALF times 2 dd 1 << (SCALEBITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jdclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extrgb_convert_mmx +%include "jdclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extrgbx_convert_mmx +%include "jdclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extbgr_convert_mmx +%include "jdclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extbgrx_convert_mmx +%include "jdclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extxbgr_convert_mmx +%include "jdclrmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extxrgb_convert_mmx +%include "jdclrmmx.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdcolss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdcolss2.asm new file mode 100755 index 0000000..1912d92 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdcolss2.asm @@ -0,0 +1,120 @@ +; +; jdcolss2.asm - colorspace conversion (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_344 equ 22554 ; FIX(0.34414) +F_0_714 equ 46802 ; FIX(0.71414) +F_1_402 equ 91881 ; FIX(1.40200) +F_1_772 equ 116130 ; FIX(1.77200) +F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) +F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) +F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_ycc_rgb_convert_sse2) + +EXTN(jconst_ycc_rgb_convert_sse2): + +PW_F0402 times 8 dw F_0_402 +PW_MF0228 times 8 dw -F_0_228 +PW_MF0344_F0285 times 4 dw -F_0_344, F_0_285 +PW_ONE times 8 dw 1 +PD_ONEHALF times 4 dd 1 << (SCALEBITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jdclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgb_convert_sse2 +%include "jdclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgbx_convert_sse2 +%include "jdclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgr_convert_sse2 +%include "jdclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgrx_convert_sse2 +%include "jdclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxbgr_convert_sse2 +%include "jdclrss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxrgb_convert_sse2 +%include "jdclrss2.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdct.inc b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdct.inc new file mode 100755 index 0000000..cc62704 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdct.inc @@ -0,0 +1,28 @@ +; +; jdct.inc - private declarations for forward & reverse DCT subsystems +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; [TAB8] + +; Each IDCT routine is responsible for range-limiting its results and +; converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could +; be quite far out of range if the input data is corrupt, so a bulletproof +; range-limiting step is required. We use a mask-and-table-lookup method +; to do the combined operations quickly. +; +%define RANGE_MASK (MAXJSAMPLE * 4 + 3) ; 2 bits wider than legal samples + +%define ROW(n,b,s) ((b)+(n)*(s)) +%define COL(n,b,s) ((b)+(n)*(s)*DCTSIZE) + +%define DWBLOCK(m,n,b,s) ((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_DWORD) +%define MMBLOCK(m,n,b,s) ((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_MMWORD) +%define XMMBLOCK(m,n,b,s) ((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_XMMWORD) + +; -------------------------------------------------------------------------- diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmermmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmermmx.asm new file mode 100755 index 0000000..7b86c74 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmermmx.asm @@ -0,0 +1,126 @@ +; +; jdmermmx.asm - merged upsampling/color conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_344 equ 22554 ; FIX(0.34414) +F_0_714 equ 46802 ; FIX(0.71414) +F_1_402 equ 91881 ; FIX(1.40200) +F_1_772 equ 116130 ; FIX(1.77200) +F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) +F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) +F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_merged_upsample_mmx) + +EXTN(jconst_merged_upsample_mmx): + +PW_F0402 times 4 dw F_0_402 +PW_MF0228 times 4 dw -F_0_228 +PW_MF0344_F0285 times 2 dw -F_0_344, F_0_285 +PW_ONE times 4 dw 1 +PD_ONEHALF times 2 dd 1 << (SCALEBITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jdmrgmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extrgb_merged_upsample_mmx +%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extrgb_merged_upsample_mmx +%include "jdmrgmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extrgbx_merged_upsample_mmx +%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extrgbx_merged_upsample_mmx +%include "jdmrgmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extbgr_merged_upsample_mmx +%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extbgr_merged_upsample_mmx +%include "jdmrgmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extbgrx_merged_upsample_mmx +%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extbgrx_merged_upsample_mmx +%include "jdmrgmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extxbgr_merged_upsample_mmx +%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extxbgr_merged_upsample_mmx +%include "jdmrgmmx.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extxrgb_merged_upsample_mmx +%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extxrgb_merged_upsample_mmx +%include "jdmrgmmx.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmerss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmerss2.asm new file mode 100755 index 0000000..e536c80 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmerss2.asm @@ -0,0 +1,126 @@ +; +; jdmerss2.asm - merged upsampling/color conversion (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_344 equ 22554 ; FIX(0.34414) +F_0_714 equ 46802 ; FIX(0.71414) +F_1_402 equ 91881 ; FIX(1.40200) +F_1_772 equ 116130 ; FIX(1.77200) +F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) +F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) +F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_merged_upsample_sse2) + +EXTN(jconst_merged_upsample_sse2): + +PW_F0402 times 8 dw F_0_402 +PW_MF0228 times 8 dw -F_0_228 +PW_MF0344_F0285 times 4 dw -F_0_344, F_0_285 +PW_ONE times 8 dw 1 +PD_ONEHALF times 4 dd 1 << (SCALEBITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 + +%include "jdmrgss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgb_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgb_merged_upsample_sse2 +%include "jdmrgss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgbx_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgbx_merged_upsample_sse2 +%include "jdmrgss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgr_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgr_merged_upsample_sse2 +%include "jdmrgss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgrx_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgrx_merged_upsample_sse2 +%include "jdmrgss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxbgr_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxbgr_merged_upsample_sse2 +%include "jdmrgss2.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxrgb_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxrgb_merged_upsample_sse2 +%include "jdmrgss2.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmrgmmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmrgmmx.asm new file mode 100755 index 0000000..d0800a7 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmrgmmx.asm @@ -0,0 +1,464 @@ +; +; jdmrgmmx.asm - merged upsampling/color conversion (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. +; +; GLOBAL(void) +; jsimd_h2v1_merged_upsample_mmx (JDIMENSION output_width, +; JSAMPIMAGE input_buf, +; JDIMENSION in_row_group_ctr, +; JSAMPARRAY output_buf); +; + +%define output_width(b) (b)+8 ; JDIMENSION output_width +%define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf +%define in_row_group_ctr(b) (b)+16 ; JDIMENSION in_row_group_ctr +%define output_buf(b) (b)+20 ; JSAMPARRAY output_buf + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 3 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_h2v1_merged_upsample_mmx) + +EXTN(jsimd_h2v1_merged_upsample_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [output_width(eax)] ; col + test ecx,ecx + jz near .return + + push ecx + + mov edi, JSAMPIMAGE [input_buf(eax)] + mov ecx, JDIMENSION [in_row_group_ctr(eax)] + mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] + mov edi, JSAMPARRAY [output_buf(eax)] + mov esi, JSAMPROW [esi+ecx*SIZEOF_JSAMPROW] ; inptr0 + mov ebx, JSAMPROW [ebx+ecx*SIZEOF_JSAMPROW] ; inptr1 + mov edx, JSAMPROW [edx+ecx*SIZEOF_JSAMPROW] ; inptr2 + mov edi, JSAMPROW [edi] ; outptr + + pop ecx ; col + + alignx 16,7 +.columnloop: + movpic eax, POINTER [gotptr] ; load GOT address (eax) + + movq mm6, MMWORD [ebx] ; mm6=Cb(01234567) + movq mm7, MMWORD [edx] ; mm7=Cr(01234567) + + pxor mm1,mm1 ; mm1=(all 0's) + pcmpeqw mm3,mm3 + psllw mm3,7 ; mm3={0xFF80 0xFF80 0xFF80 0xFF80} + + movq mm4,mm6 + punpckhbw mm6,mm1 ; mm6=Cb(4567)=CbH + punpcklbw mm4,mm1 ; mm4=Cb(0123)=CbL + movq mm0,mm7 + punpckhbw mm7,mm1 ; mm7=Cr(4567)=CrH + punpcklbw mm0,mm1 ; mm0=Cr(0123)=CrL + + paddw mm6,mm3 + paddw mm4,mm3 + paddw mm7,mm3 + paddw mm0,mm3 + + ; (Original) + ; R = Y + 1.40200 * Cr + ; G = Y - 0.34414 * Cb - 0.71414 * Cr + ; B = Y + 1.77200 * Cb + ; + ; (This implementation) + ; R = Y + 0.40200 * Cr + Cr + ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr + ; B = Y - 0.22800 * Cb + Cb + Cb + + movq mm5,mm6 ; mm5=CbH + movq mm2,mm4 ; mm2=CbL + paddw mm6,mm6 ; mm6=2*CbH + paddw mm4,mm4 ; mm4=2*CbL + movq mm1,mm7 ; mm1=CrH + movq mm3,mm0 ; mm3=CrL + paddw mm7,mm7 ; mm7=2*CrH + paddw mm0,mm0 ; mm0=2*CrL + + pmulhw mm6,[GOTOFF(eax,PW_MF0228)] ; mm6=(2*CbH * -FIX(0.22800)) + pmulhw mm4,[GOTOFF(eax,PW_MF0228)] ; mm4=(2*CbL * -FIX(0.22800)) + pmulhw mm7,[GOTOFF(eax,PW_F0402)] ; mm7=(2*CrH * FIX(0.40200)) + pmulhw mm0,[GOTOFF(eax,PW_F0402)] ; mm0=(2*CrL * FIX(0.40200)) + + paddw mm6,[GOTOFF(eax,PW_ONE)] + paddw mm4,[GOTOFF(eax,PW_ONE)] + psraw mm6,1 ; mm6=(CbH * -FIX(0.22800)) + psraw mm4,1 ; mm4=(CbL * -FIX(0.22800)) + paddw mm7,[GOTOFF(eax,PW_ONE)] + paddw mm0,[GOTOFF(eax,PW_ONE)] + psraw mm7,1 ; mm7=(CrH * FIX(0.40200)) + psraw mm0,1 ; mm0=(CrL * FIX(0.40200)) + + paddw mm6,mm5 + paddw mm4,mm2 + paddw mm6,mm5 ; mm6=(CbH * FIX(1.77200))=(B-Y)H + paddw mm4,mm2 ; mm4=(CbL * FIX(1.77200))=(B-Y)L + paddw mm7,mm1 ; mm7=(CrH * FIX(1.40200))=(R-Y)H + paddw mm0,mm3 ; mm0=(CrL * FIX(1.40200))=(R-Y)L + + movq MMWORD [wk(0)], mm6 ; wk(0)=(B-Y)H + movq MMWORD [wk(1)], mm7 ; wk(1)=(R-Y)H + + movq mm6,mm5 + movq mm7,mm2 + punpcklwd mm5,mm1 + punpckhwd mm6,mm1 + pmaddwd mm5,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd mm6,[GOTOFF(eax,PW_MF0344_F0285)] + punpcklwd mm2,mm3 + punpckhwd mm7,mm3 + pmaddwd mm2,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd mm7,[GOTOFF(eax,PW_MF0344_F0285)] + + paddd mm5,[GOTOFF(eax,PD_ONEHALF)] + paddd mm6,[GOTOFF(eax,PD_ONEHALF)] + psrad mm5,SCALEBITS + psrad mm6,SCALEBITS + paddd mm2,[GOTOFF(eax,PD_ONEHALF)] + paddd mm7,[GOTOFF(eax,PD_ONEHALF)] + psrad mm2,SCALEBITS + psrad mm7,SCALEBITS + + packssdw mm5,mm6 ; mm5=CbH*-FIX(0.344)+CrH*FIX(0.285) + packssdw mm2,mm7 ; mm2=CbL*-FIX(0.344)+CrL*FIX(0.285) + psubw mm5,mm1 ; mm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H + psubw mm2,mm3 ; mm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L + + movq MMWORD [wk(2)], mm5 ; wk(2)=(G-Y)H + + mov al,2 ; Yctr + jmp short .Yloop_1st + alignx 16,7 + +.Yloop_2nd: + movq mm0, MMWORD [wk(1)] ; mm0=(R-Y)H + movq mm2, MMWORD [wk(2)] ; mm2=(G-Y)H + movq mm4, MMWORD [wk(0)] ; mm4=(B-Y)H + alignx 16,7 + +.Yloop_1st: + movq mm7, MMWORD [esi] ; mm7=Y(01234567) + + pcmpeqw mm6,mm6 + psrlw mm6,BYTE_BIT ; mm6={0xFF 0x00 0xFF 0x00 ..} + pand mm6,mm7 ; mm6=Y(0246)=YE + psrlw mm7,BYTE_BIT ; mm7=Y(1357)=YO + + movq mm1,mm0 ; mm1=mm0=(R-Y)(L/H) + movq mm3,mm2 ; mm3=mm2=(G-Y)(L/H) + movq mm5,mm4 ; mm5=mm4=(B-Y)(L/H) + + paddw mm0,mm6 ; mm0=((R-Y)+YE)=RE=(R0 R2 R4 R6) + paddw mm1,mm7 ; mm1=((R-Y)+YO)=RO=(R1 R3 R5 R7) + packuswb mm0,mm0 ; mm0=(R0 R2 R4 R6 ** ** ** **) + packuswb mm1,mm1 ; mm1=(R1 R3 R5 R7 ** ** ** **) + + paddw mm2,mm6 ; mm2=((G-Y)+YE)=GE=(G0 G2 G4 G6) + paddw mm3,mm7 ; mm3=((G-Y)+YO)=GO=(G1 G3 G5 G7) + packuswb mm2,mm2 ; mm2=(G0 G2 G4 G6 ** ** ** **) + packuswb mm3,mm3 ; mm3=(G1 G3 G5 G7 ** ** ** **) + + paddw mm4,mm6 ; mm4=((B-Y)+YE)=BE=(B0 B2 B4 B6) + paddw mm5,mm7 ; mm5=((B-Y)+YO)=BO=(B1 B3 B5 B7) + packuswb mm4,mm4 ; mm4=(B0 B2 B4 B6 ** ** ** **) + packuswb mm5,mm5 ; mm5=(B1 B3 B5 B7 ** ** ** **) + +%if RGB_PIXELSIZE == 3 ; --------------- + + ; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **) + ; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **) + ; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **) + ; mmG=(** ** ** ** ** ** ** **), mmH=(** ** ** ** ** ** ** **) + + punpcklbw mmA,mmC ; mmA=(00 10 02 12 04 14 06 16) + punpcklbw mmE,mmB ; mmE=(20 01 22 03 24 05 26 07) + punpcklbw mmD,mmF ; mmD=(11 21 13 23 15 25 17 27) + + movq mmG,mmA + movq mmH,mmA + punpcklwd mmA,mmE ; mmA=(00 10 20 01 02 12 22 03) + punpckhwd mmG,mmE ; mmG=(04 14 24 05 06 16 26 07) + + psrlq mmH,2*BYTE_BIT ; mmH=(02 12 04 14 06 16 -- --) + psrlq mmE,2*BYTE_BIT ; mmE=(22 03 24 05 26 07 -- --) + + movq mmC,mmD + movq mmB,mmD + punpcklwd mmD,mmH ; mmD=(11 21 02 12 13 23 04 14) + punpckhwd mmC,mmH ; mmC=(15 25 06 16 17 27 -- --) + + psrlq mmB,2*BYTE_BIT ; mmB=(13 23 15 25 17 27 -- --) + + movq mmF,mmE + punpcklwd mmE,mmB ; mmE=(22 03 13 23 24 05 15 25) + punpckhwd mmF,mmB ; mmF=(26 07 17 27 -- -- -- --) + + punpckldq mmA,mmD ; mmA=(00 10 20 01 11 21 02 12) + punpckldq mmE,mmG ; mmE=(22 03 13 23 04 14 24 05) + punpckldq mmC,mmF ; mmC=(15 25 06 16 26 07 17 27) + + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st16 + + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmE + movq MMWORD [edi+2*SIZEOF_MMWORD], mmC + + sub ecx, byte SIZEOF_MMWORD + jz near .endcolumn + + add edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; outptr + add esi, byte SIZEOF_MMWORD ; inptr0 + dec al ; Yctr + jnz near .Yloop_2nd + + add ebx, byte SIZEOF_MMWORD ; inptr1 + add edx, byte SIZEOF_MMWORD ; inptr2 + jmp near .columnloop + alignx 16,7 + +.column_st16: + lea ecx, [ecx+ecx*2] ; imul ecx, RGB_PIXELSIZE + cmp ecx, byte 2*SIZEOF_MMWORD + jb short .column_st8 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmE + movq mmA,mmC + sub ecx, byte 2*SIZEOF_MMWORD + add edi, byte 2*SIZEOF_MMWORD + jmp short .column_st4 +.column_st8: + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st4 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq mmA,mmE + sub ecx, byte SIZEOF_MMWORD + add edi, byte SIZEOF_MMWORD +.column_st4: + movd eax,mmA + cmp ecx, byte SIZEOF_DWORD + jb short .column_st2 + mov DWORD [edi+0*SIZEOF_DWORD], eax + psrlq mmA,DWORD_BIT + movd eax,mmA + sub ecx, byte SIZEOF_DWORD + add edi, byte SIZEOF_DWORD +.column_st2: + cmp ecx, byte SIZEOF_WORD + jb short .column_st1 + mov WORD [edi+0*SIZEOF_WORD], ax + shr eax,WORD_BIT + sub ecx, byte SIZEOF_WORD + add edi, byte SIZEOF_WORD +.column_st1: + cmp ecx, byte SIZEOF_BYTE + jb short .endcolumn + mov BYTE [edi+0*SIZEOF_BYTE], al + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +%ifdef RGBX_FILLER_0XFF + pcmpeqb mm6,mm6 ; mm6=(X0 X2 X4 X6 ** ** ** **) + pcmpeqb mm7,mm7 ; mm7=(X1 X3 X5 X7 ** ** ** **) +%else + pxor mm6,mm6 ; mm6=(X0 X2 X4 X6 ** ** ** **) + pxor mm7,mm7 ; mm7=(X1 X3 X5 X7 ** ** ** **) +%endif + ; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **) + ; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **) + ; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **) + ; mmG=(30 32 34 36 ** ** ** **), mmH=(31 33 35 37 ** ** ** **) + + punpcklbw mmA,mmC ; mmA=(00 10 02 12 04 14 06 16) + punpcklbw mmE,mmG ; mmE=(20 30 22 32 24 34 26 36) + punpcklbw mmB,mmD ; mmB=(01 11 03 13 05 15 07 17) + punpcklbw mmF,mmH ; mmF=(21 31 23 33 25 35 27 37) + + movq mmC,mmA + punpcklwd mmA,mmE ; mmA=(00 10 20 30 02 12 22 32) + punpckhwd mmC,mmE ; mmC=(04 14 24 34 06 16 26 36) + movq mmG,mmB + punpcklwd mmB,mmF ; mmB=(01 11 21 31 03 13 23 33) + punpckhwd mmG,mmF ; mmG=(05 15 25 35 07 17 27 37) + + movq mmD,mmA + punpckldq mmA,mmB ; mmA=(00 10 20 30 01 11 21 31) + punpckhdq mmD,mmB ; mmD=(02 12 22 32 03 13 23 33) + movq mmH,mmC + punpckldq mmC,mmG ; mmC=(04 14 24 34 05 15 25 35) + punpckhdq mmH,mmG ; mmH=(06 16 26 36 07 17 27 37) + + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st16 + + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmD + movq MMWORD [edi+2*SIZEOF_MMWORD], mmC + movq MMWORD [edi+3*SIZEOF_MMWORD], mmH + + sub ecx, byte SIZEOF_MMWORD + jz short .endcolumn + + add edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; outptr + add esi, byte SIZEOF_MMWORD ; inptr0 + dec al ; Yctr + jnz near .Yloop_2nd + + add ebx, byte SIZEOF_MMWORD ; inptr1 + add edx, byte SIZEOF_MMWORD ; inptr2 + jmp near .columnloop + alignx 16,7 + +.column_st16: + cmp ecx, byte SIZEOF_MMWORD/2 + jb short .column_st8 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq MMWORD [edi+1*SIZEOF_MMWORD], mmD + movq mmA,mmC + movq mmD,mmH + sub ecx, byte SIZEOF_MMWORD/2 + add edi, byte 2*SIZEOF_MMWORD +.column_st8: + cmp ecx, byte SIZEOF_MMWORD/4 + jb short .column_st4 + movq MMWORD [edi+0*SIZEOF_MMWORD], mmA + movq mmA,mmD + sub ecx, byte SIZEOF_MMWORD/4 + add edi, byte 1*SIZEOF_MMWORD +.column_st4: + cmp ecx, byte SIZEOF_MMWORD/8 + jb short .endcolumn + movd DWORD [edi+0*SIZEOF_DWORD], mmA + +%endif ; RGB_PIXELSIZE ; --------------- + +.endcolumn: + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. +; +; GLOBAL(void) +; jsimd_h2v2_merged_upsample_mmx (JDIMENSION output_width, +; JSAMPIMAGE input_buf, +; JDIMENSION in_row_group_ctr, +; JSAMPARRAY output_buf); +; + +%define output_width(b) (b)+8 ; JDIMENSION output_width +%define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf +%define in_row_group_ctr(b) (b)+16 ; JDIMENSION in_row_group_ctr +%define output_buf(b) (b)+20 ; JSAMPARRAY output_buf + + align 16 + global EXTN(jsimd_h2v2_merged_upsample_mmx) + +EXTN(jsimd_h2v2_merged_upsample_mmx): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov eax, JDIMENSION [output_width(ebp)] + + mov edi, JSAMPIMAGE [input_buf(ebp)] + mov ecx, JDIMENSION [in_row_group_ctr(ebp)] + mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] + mov edi, JSAMPARRAY [output_buf(ebp)] + lea esi, [esi+ecx*SIZEOF_JSAMPROW] + + push edx ; inptr2 + push ebx ; inptr1 + push esi ; inptr00 + mov ebx,esp + + push edi ; output_buf (outptr0) + push ecx ; in_row_group_ctr + push ebx ; input_buf + push eax ; output_width + + call near EXTN(jsimd_h2v1_merged_upsample_mmx) + + add esi, byte SIZEOF_JSAMPROW ; inptr01 + add edi, byte SIZEOF_JSAMPROW ; outptr1 + mov POINTER [ebx+0*SIZEOF_POINTER], esi + mov POINTER [ebx-1*SIZEOF_POINTER], edi + + call near EXTN(jsimd_h2v1_merged_upsample_mmx) + + add esp, byte 7*SIZEOF_DWORD + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmrgss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmrgss2.asm new file mode 100755 index 0000000..f190468 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdmrgss2.asm @@ -0,0 +1,518 @@ +; +; jdmrgss2.asm - merged upsampling/color conversion (SSE2) +; +; Copyright 2009, 2012 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. +; +; GLOBAL(void) +; jsimd_h2v1_merged_upsample_sse2 (JDIMENSION output_width, +; JSAMPIMAGE input_buf, +; JDIMENSION in_row_group_ctr, +; JSAMPARRAY output_buf); +; + +%define output_width(b) (b)+8 ; JDIMENSION output_width +%define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf +%define in_row_group_ctr(b) (b)+16 ; JDIMENSION in_row_group_ctr +%define output_buf(b) (b)+20 ; JSAMPARRAY output_buf + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 3 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_h2v1_merged_upsample_sse2) + +EXTN(jsimd_h2v1_merged_upsample_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov ecx, JDIMENSION [output_width(eax)] ; col + test ecx,ecx + jz near .return + + push ecx + + mov edi, JSAMPIMAGE [input_buf(eax)] + mov ecx, JDIMENSION [in_row_group_ctr(eax)] + mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] + mov edi, JSAMPARRAY [output_buf(eax)] + mov esi, JSAMPROW [esi+ecx*SIZEOF_JSAMPROW] ; inptr0 + mov ebx, JSAMPROW [ebx+ecx*SIZEOF_JSAMPROW] ; inptr1 + mov edx, JSAMPROW [edx+ecx*SIZEOF_JSAMPROW] ; inptr2 + mov edi, JSAMPROW [edi] ; outptr + + pop ecx ; col + + alignx 16,7 +.columnloop: + movpic eax, POINTER [gotptr] ; load GOT address (eax) + + movdqa xmm6, XMMWORD [ebx] ; xmm6=Cb(0123456789ABCDEF) + movdqa xmm7, XMMWORD [edx] ; xmm7=Cr(0123456789ABCDEF) + + pxor xmm1,xmm1 ; xmm1=(all 0's) + pcmpeqw xmm3,xmm3 + psllw xmm3,7 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..} + + movdqa xmm4,xmm6 + punpckhbw xmm6,xmm1 ; xmm6=Cb(89ABCDEF)=CbH + punpcklbw xmm4,xmm1 ; xmm4=Cb(01234567)=CbL + movdqa xmm0,xmm7 + punpckhbw xmm7,xmm1 ; xmm7=Cr(89ABCDEF)=CrH + punpcklbw xmm0,xmm1 ; xmm0=Cr(01234567)=CrL + + paddw xmm6,xmm3 + paddw xmm4,xmm3 + paddw xmm7,xmm3 + paddw xmm0,xmm3 + + ; (Original) + ; R = Y + 1.40200 * Cr + ; G = Y - 0.34414 * Cb - 0.71414 * Cr + ; B = Y + 1.77200 * Cb + ; + ; (This implementation) + ; R = Y + 0.40200 * Cr + Cr + ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr + ; B = Y - 0.22800 * Cb + Cb + Cb + + movdqa xmm5,xmm6 ; xmm5=CbH + movdqa xmm2,xmm4 ; xmm2=CbL + paddw xmm6,xmm6 ; xmm6=2*CbH + paddw xmm4,xmm4 ; xmm4=2*CbL + movdqa xmm1,xmm7 ; xmm1=CrH + movdqa xmm3,xmm0 ; xmm3=CrL + paddw xmm7,xmm7 ; xmm7=2*CrH + paddw xmm0,xmm0 ; xmm0=2*CrL + + pmulhw xmm6,[GOTOFF(eax,PW_MF0228)] ; xmm6=(2*CbH * -FIX(0.22800)) + pmulhw xmm4,[GOTOFF(eax,PW_MF0228)] ; xmm4=(2*CbL * -FIX(0.22800)) + pmulhw xmm7,[GOTOFF(eax,PW_F0402)] ; xmm7=(2*CrH * FIX(0.40200)) + pmulhw xmm0,[GOTOFF(eax,PW_F0402)] ; xmm0=(2*CrL * FIX(0.40200)) + + paddw xmm6,[GOTOFF(eax,PW_ONE)] + paddw xmm4,[GOTOFF(eax,PW_ONE)] + psraw xmm6,1 ; xmm6=(CbH * -FIX(0.22800)) + psraw xmm4,1 ; xmm4=(CbL * -FIX(0.22800)) + paddw xmm7,[GOTOFF(eax,PW_ONE)] + paddw xmm0,[GOTOFF(eax,PW_ONE)] + psraw xmm7,1 ; xmm7=(CrH * FIX(0.40200)) + psraw xmm0,1 ; xmm0=(CrL * FIX(0.40200)) + + paddw xmm6,xmm5 + paddw xmm4,xmm2 + paddw xmm6,xmm5 ; xmm6=(CbH * FIX(1.77200))=(B-Y)H + paddw xmm4,xmm2 ; xmm4=(CbL * FIX(1.77200))=(B-Y)L + paddw xmm7,xmm1 ; xmm7=(CrH * FIX(1.40200))=(R-Y)H + paddw xmm0,xmm3 ; xmm0=(CrL * FIX(1.40200))=(R-Y)L + + movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=(B-Y)H + movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(R-Y)H + + movdqa xmm6,xmm5 + movdqa xmm7,xmm2 + punpcklwd xmm5,xmm1 + punpckhwd xmm6,xmm1 + pmaddwd xmm5,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd xmm6,[GOTOFF(eax,PW_MF0344_F0285)] + punpcklwd xmm2,xmm3 + punpckhwd xmm7,xmm3 + pmaddwd xmm2,[GOTOFF(eax,PW_MF0344_F0285)] + pmaddwd xmm7,[GOTOFF(eax,PW_MF0344_F0285)] + + paddd xmm5,[GOTOFF(eax,PD_ONEHALF)] + paddd xmm6,[GOTOFF(eax,PD_ONEHALF)] + psrad xmm5,SCALEBITS + psrad xmm6,SCALEBITS + paddd xmm2,[GOTOFF(eax,PD_ONEHALF)] + paddd xmm7,[GOTOFF(eax,PD_ONEHALF)] + psrad xmm2,SCALEBITS + psrad xmm7,SCALEBITS + + packssdw xmm5,xmm6 ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285) + packssdw xmm2,xmm7 ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285) + psubw xmm5,xmm1 ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H + psubw xmm2,xmm3 ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L + + movdqa XMMWORD [wk(2)], xmm5 ; wk(2)=(G-Y)H + + mov al,2 ; Yctr + jmp short .Yloop_1st + alignx 16,7 + +.Yloop_2nd: + movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(R-Y)H + movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(G-Y)H + movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(B-Y)H + alignx 16,7 + +.Yloop_1st: + movdqa xmm7, XMMWORD [esi] ; xmm7=Y(0123456789ABCDEF) + + pcmpeqw xmm6,xmm6 + psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} + pand xmm6,xmm7 ; xmm6=Y(02468ACE)=YE + psrlw xmm7,BYTE_BIT ; xmm7=Y(13579BDF)=YO + + movdqa xmm1,xmm0 ; xmm1=xmm0=(R-Y)(L/H) + movdqa xmm3,xmm2 ; xmm3=xmm2=(G-Y)(L/H) + movdqa xmm5,xmm4 ; xmm5=xmm4=(B-Y)(L/H) + + paddw xmm0,xmm6 ; xmm0=((R-Y)+YE)=RE=R(02468ACE) + paddw xmm1,xmm7 ; xmm1=((R-Y)+YO)=RO=R(13579BDF) + packuswb xmm0,xmm0 ; xmm0=R(02468ACE********) + packuswb xmm1,xmm1 ; xmm1=R(13579BDF********) + + paddw xmm2,xmm6 ; xmm2=((G-Y)+YE)=GE=G(02468ACE) + paddw xmm3,xmm7 ; xmm3=((G-Y)+YO)=GO=G(13579BDF) + packuswb xmm2,xmm2 ; xmm2=G(02468ACE********) + packuswb xmm3,xmm3 ; xmm3=G(13579BDF********) + + paddw xmm4,xmm6 ; xmm4=((B-Y)+YE)=BE=B(02468ACE) + paddw xmm5,xmm7 ; xmm5=((B-Y)+YO)=BO=B(13579BDF) + packuswb xmm4,xmm4 ; xmm4=B(02468ACE********) + packuswb xmm5,xmm5 ; xmm5=B(13579BDF********) + +%if RGB_PIXELSIZE == 3 ; --------------- + + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F) + punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F) + + movdqa xmmG,xmmA + movdqa xmmH,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07) + punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F) + + psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --) + psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --) + + movdqa xmmC,xmmD + movdqa xmmB,xmmD + punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18) + punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --) + + psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --) + + movdqa xmmF,xmmE + punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29) + punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --) + + pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03) + movdqa xmmB,xmmE + punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14) + punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07) + punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29) + + pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B) + movdqa xmmB,xmmF + punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C) + punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F) + punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --) + + punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + cmp ecx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test edi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF +.out0: + add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub ecx, byte SIZEOF_XMMWORD + jz near .endcolumn + + add esi, byte SIZEOF_XMMWORD ; inptr0 + dec al ; Yctr + jnz near .Yloop_2nd + + add ebx, byte SIZEOF_XMMWORD ; inptr1 + add edx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + alignx 16,7 + +.column_st32: + lea ecx, [ecx+ecx*2] ; imul ecx, RGB_PIXELSIZE + cmp ecx, byte 2*SIZEOF_XMMWORD + jb short .column_st16 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + add edi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmF + sub ecx, byte 2*SIZEOF_XMMWORD + jmp short .column_st15 +.column_st16: + cmp ecx, byte SIZEOF_XMMWORD + jb short .column_st15 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + add edi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub ecx, byte SIZEOF_XMMWORD +.column_st15: + ; Store the lower 8 bytes of xmmA to the output when it has enough + ; space. + cmp ecx, byte SIZEOF_MMWORD + jb short .column_st7 + movq MMWORD [edi], xmmA + add edi, byte SIZEOF_MMWORD + sub ecx, byte SIZEOF_MMWORD + psrldq xmmA, SIZEOF_MMWORD +.column_st7: + ; Store the lower 4 bytes of xmmA to the output when it has enough + ; space. + cmp ecx, byte SIZEOF_DWORD + jb short .column_st3 + movd DWORD [edi], xmmA + add edi, byte SIZEOF_DWORD + sub ecx, byte SIZEOF_DWORD + psrldq xmmA, SIZEOF_DWORD +.column_st3: + ; Store the lower 2 bytes of eax to the output when it has enough + ; space. + movd eax, xmmA + cmp ecx, byte SIZEOF_WORD + jb short .column_st1 + mov WORD [edi], ax + add edi, byte SIZEOF_WORD + sub ecx, byte SIZEOF_WORD + shr eax, 16 +.column_st1: + ; Store the lower 1 byte of eax to the output when it has enough + ; space. + test ecx, ecx + jz short .endcolumn + mov BYTE [edi], al + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +%ifdef RGBX_FILLER_0XFF + pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%else + pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%endif + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E) + punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F) + punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F) + + movdqa xmmC,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36) + punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E) + movdqa xmmG,xmmB + punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37) + punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + movdqa xmmH,xmmC + punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + cmp ecx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test edi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC + movntdq XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC + movdqu XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH +.out0: + add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub ecx, byte SIZEOF_XMMWORD + jz near .endcolumn + + add esi, byte SIZEOF_XMMWORD ; inptr0 + dec al ; Yctr + jnz near .Yloop_2nd + + add ebx, byte SIZEOF_XMMWORD ; inptr1 + add edx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + alignx 16,7 + +.column_st32: + cmp ecx, byte SIZEOF_XMMWORD/2 + jb short .column_st16 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD + add edi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmC + movdqa xmmD,xmmH + sub ecx, byte SIZEOF_XMMWORD/2 +.column_st16: + cmp ecx, byte SIZEOF_XMMWORD/4 + jb short .column_st15 + movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA + add edi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub ecx, byte SIZEOF_XMMWORD/4 +.column_st15: + ; Store two pixels (8 bytes) of xmmA to the output when it has enough + ; space. + cmp ecx, byte SIZEOF_XMMWORD/8 + jb short .column_st7 + movq MMWORD [edi], xmmA + add edi, byte SIZEOF_XMMWORD/8*4 + sub ecx, byte SIZEOF_XMMWORD/8 + psrldq xmmA, SIZEOF_XMMWORD/8*4 +.column_st7: + ; Store one pixel (4 bytes) of xmmA to the output when it has enough + ; space. + test ecx, ecx + jz short .endcolumn + movd DWORD [edi], xmmA + +%endif ; RGB_PIXELSIZE ; --------------- + +.endcolumn: + sfence ; flush the write buffer + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. +; +; GLOBAL(void) +; jsimd_h2v2_merged_upsample_sse2 (JDIMENSION output_width, +; JSAMPIMAGE input_buf, +; JDIMENSION in_row_group_ctr, +; JSAMPARRAY output_buf); +; + +%define output_width(b) (b)+8 ; JDIMENSION output_width +%define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf +%define in_row_group_ctr(b) (b)+16 ; JDIMENSION in_row_group_ctr +%define output_buf(b) (b)+20 ; JSAMPARRAY output_buf + + align 16 + global EXTN(jsimd_h2v2_merged_upsample_sse2) + +EXTN(jsimd_h2v2_merged_upsample_sse2): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov eax, POINTER [output_width(ebp)] + + mov edi, JSAMPIMAGE [input_buf(ebp)] + mov ecx, JDIMENSION [in_row_group_ctr(ebp)] + mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] + mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] + mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] + mov edi, JSAMPARRAY [output_buf(ebp)] + lea esi, [esi+ecx*SIZEOF_JSAMPROW] + + push edx ; inptr2 + push ebx ; inptr1 + push esi ; inptr00 + mov ebx,esp + + push edi ; output_buf (outptr0) + push ecx ; in_row_group_ctr + push ebx ; input_buf + push eax ; output_width + + call near EXTN(jsimd_h2v1_merged_upsample_sse2) + + add esi, byte SIZEOF_JSAMPROW ; inptr01 + add edi, byte SIZEOF_JSAMPROW ; outptr1 + mov POINTER [ebx+0*SIZEOF_POINTER], esi + mov POINTER [ebx-1*SIZEOF_POINTER], edi + + call near EXTN(jsimd_h2v1_merged_upsample_sse2) + + add esp, byte 7*SIZEOF_DWORD + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdsammmx.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdsammmx.asm new file mode 100755 index 0000000..c09e5b9 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdsammmx.asm @@ -0,0 +1,737 @@ +; +; jdsammmx.asm - upsampling (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fancy_upsample_mmx) + +EXTN(jconst_fancy_upsample_mmx): + +PW_ONE times 4 dw 1 +PW_TWO times 4 dw 2 +PW_THREE times 4 dw 3 +PW_SEVEN times 4 dw 7 +PW_EIGHT times 4 dw 8 + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. +; +; The upsampling algorithm is linear interpolation between pixel centers, +; also known as a "triangle filter". This is a good compromise between +; speed and visual quality. The centers of the output pixels are 1/4 and 3/4 +; of the way between input pixel centers. +; +; GLOBAL(void) +; jsimd_h2v1_fancy_upsample_mmx (int max_v_samp_factor, +; JDIMENSION downsampled_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define downsamp_width(b) (b)+12 ; JDIMENSION downsampled_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v1_fancy_upsample_mmx) + +EXTN(jsimd_h2v1_fancy_upsample_mmx): + push ebp + mov ebp,esp + pushpic ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + mov eax, JDIMENSION [downsamp_width(ebp)] ; colctr + test eax,eax + jz near .return + + mov ecx, INT [max_v_samp(ebp)] ; rowctr + test ecx,ecx + jz near .return + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, POINTER [output_data_ptr(ebp)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push eax ; colctr + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr + + test eax, SIZEOF_MMWORD-1 + jz short .skip + mov dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl ; insert a dummy sample +.skip: + pxor mm0,mm0 ; mm0=(all 0's) + pcmpeqb mm7,mm7 + psrlq mm7,(SIZEOF_MMWORD-1)*BYTE_BIT + pand mm7, MMWORD [esi+0*SIZEOF_MMWORD] + + add eax, byte SIZEOF_MMWORD-1 + and eax, byte -SIZEOF_MMWORD + cmp eax, byte SIZEOF_MMWORD + ja short .columnloop + alignx 16,7 + +.columnloop_last: + pcmpeqb mm6,mm6 + psllq mm6,(SIZEOF_MMWORD-1)*BYTE_BIT + pand mm6, MMWORD [esi+0*SIZEOF_MMWORD] + jmp short .upsample + alignx 16,7 + +.columnloop: + movq mm6, MMWORD [esi+1*SIZEOF_MMWORD] + psllq mm6,(SIZEOF_MMWORD-1)*BYTE_BIT + +.upsample: + movq mm1, MMWORD [esi+0*SIZEOF_MMWORD] + movq mm2,mm1 + movq mm3,mm1 ; mm1=( 0 1 2 3 4 5 6 7) + psllq mm2,BYTE_BIT ; mm2=( - 0 1 2 3 4 5 6) + psrlq mm3,BYTE_BIT ; mm3=( 1 2 3 4 5 6 7 -) + + por mm2,mm7 ; mm2=(-1 0 1 2 3 4 5 6) + por mm3,mm6 ; mm3=( 1 2 3 4 5 6 7 8) + + movq mm7,mm1 + psrlq mm7,(SIZEOF_MMWORD-1)*BYTE_BIT ; mm7=( 7 - - - - - - -) + + movq mm4,mm1 + punpcklbw mm1,mm0 ; mm1=( 0 1 2 3) + punpckhbw mm4,mm0 ; mm4=( 4 5 6 7) + movq mm5,mm2 + punpcklbw mm2,mm0 ; mm2=(-1 0 1 2) + punpckhbw mm5,mm0 ; mm5=( 3 4 5 6) + movq mm6,mm3 + punpcklbw mm3,mm0 ; mm3=( 1 2 3 4) + punpckhbw mm6,mm0 ; mm6=( 5 6 7 8) + + pmullw mm1,[GOTOFF(ebx,PW_THREE)] + pmullw mm4,[GOTOFF(ebx,PW_THREE)] + paddw mm2,[GOTOFF(ebx,PW_ONE)] + paddw mm5,[GOTOFF(ebx,PW_ONE)] + paddw mm3,[GOTOFF(ebx,PW_TWO)] + paddw mm6,[GOTOFF(ebx,PW_TWO)] + + paddw mm2,mm1 + paddw mm5,mm4 + psrlw mm2,2 ; mm2=OutLE=( 0 2 4 6) + psrlw mm5,2 ; mm5=OutHE=( 8 10 12 14) + paddw mm3,mm1 + paddw mm6,mm4 + psrlw mm3,2 ; mm3=OutLO=( 1 3 5 7) + psrlw mm6,2 ; mm6=OutHO=( 9 11 13 15) + + psllw mm3,BYTE_BIT + psllw mm6,BYTE_BIT + por mm2,mm3 ; mm2=OutL=( 0 1 2 3 4 5 6 7) + por mm5,mm6 ; mm5=OutH=( 8 9 10 11 12 13 14 15) + + movq MMWORD [edi+0*SIZEOF_MMWORD], mm2 + movq MMWORD [edi+1*SIZEOF_MMWORD], mm5 + + sub eax, byte SIZEOF_MMWORD + add esi, byte 1*SIZEOF_MMWORD ; inptr + add edi, byte 2*SIZEOF_MMWORD ; outptr + cmp eax, byte SIZEOF_MMWORD + ja near .columnloop + test eax,eax + jnz near .columnloop_last + + pop esi + pop edi + pop eax + + add esi, byte SIZEOF_JSAMPROW ; input_data + add edi, byte SIZEOF_JSAMPROW ; output_data + dec ecx ; rowctr + jg near .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + poppic ebx + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. +; Again a triangle filter; see comments for h2v1 case, above. +; +; GLOBAL(void) +; jsimd_h2v2_fancy_upsample_mmx (int max_v_samp_factor, +; JDIMENSION downsampled_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define downsamp_width(b) (b)+12 ; JDIMENSION downsampled_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 4 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_h2v2_fancy_upsample_mmx) + +EXTN(jsimd_h2v2_fancy_upsample_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov edx,eax ; edx = original ebp + mov eax, JDIMENSION [downsamp_width(edx)] ; colctr + test eax,eax + jz near .return + + mov ecx, INT [max_v_samp(edx)] ; rowctr + test ecx,ecx + jz near .return + + mov esi, JSAMPARRAY [input_data(edx)] ; input_data + mov edi, POINTER [output_data_ptr(edx)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push eax ; colctr + push ecx + push edi + push esi + + mov ecx, JSAMPROW [esi-1*SIZEOF_JSAMPROW] ; inptr1(above) + mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; inptr0 + mov esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; inptr1(below) + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] ; outptr0 + mov edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] ; outptr1 + + test eax, SIZEOF_MMWORD-1 + jz short .skip + push edx + mov dl, JSAMPLE [ecx+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [ecx+eax*SIZEOF_JSAMPLE], dl + mov dl, JSAMPLE [ebx+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [ebx+eax*SIZEOF_JSAMPLE], dl + mov dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl ; insert a dummy sample + pop edx +.skip: + ; -- process the first column block + + movq mm0, MMWORD [ebx+0*SIZEOF_MMWORD] ; mm0=row[ 0][0] + movq mm1, MMWORD [ecx+0*SIZEOF_MMWORD] ; mm1=row[-1][0] + movq mm2, MMWORD [esi+0*SIZEOF_MMWORD] ; mm2=row[+1][0] + + pushpic ebx + movpic ebx, POINTER [gotptr] ; load GOT address + + pxor mm3,mm3 ; mm3=(all 0's) + movq mm4,mm0 + punpcklbw mm0,mm3 ; mm0=row[ 0][0]( 0 1 2 3) + punpckhbw mm4,mm3 ; mm4=row[ 0][0]( 4 5 6 7) + movq mm5,mm1 + punpcklbw mm1,mm3 ; mm1=row[-1][0]( 0 1 2 3) + punpckhbw mm5,mm3 ; mm5=row[-1][0]( 4 5 6 7) + movq mm6,mm2 + punpcklbw mm2,mm3 ; mm2=row[+1][0]( 0 1 2 3) + punpckhbw mm6,mm3 ; mm6=row[+1][0]( 4 5 6 7) + + pmullw mm0,[GOTOFF(ebx,PW_THREE)] + pmullw mm4,[GOTOFF(ebx,PW_THREE)] + + pcmpeqb mm7,mm7 + psrlq mm7,(SIZEOF_MMWORD-2)*BYTE_BIT + + paddw mm1,mm0 ; mm1=Int0L=( 0 1 2 3) + paddw mm5,mm4 ; mm5=Int0H=( 4 5 6 7) + paddw mm2,mm0 ; mm2=Int1L=( 0 1 2 3) + paddw mm6,mm4 ; mm6=Int1H=( 4 5 6 7) + + movq MMWORD [edx+0*SIZEOF_MMWORD], mm1 ; temporarily save + movq MMWORD [edx+1*SIZEOF_MMWORD], mm5 ; the intermediate data + movq MMWORD [edi+0*SIZEOF_MMWORD], mm2 + movq MMWORD [edi+1*SIZEOF_MMWORD], mm6 + + pand mm1,mm7 ; mm1=( 0 - - -) + pand mm2,mm7 ; mm2=( 0 - - -) + + movq MMWORD [wk(0)], mm1 + movq MMWORD [wk(1)], mm2 + + poppic ebx + + add eax, byte SIZEOF_MMWORD-1 + and eax, byte -SIZEOF_MMWORD + cmp eax, byte SIZEOF_MMWORD + ja short .columnloop + alignx 16,7 + +.columnloop_last: + ; -- process the last column block + + pushpic ebx + movpic ebx, POINTER [gotptr] ; load GOT address + + pcmpeqb mm1,mm1 + psllq mm1,(SIZEOF_MMWORD-2)*BYTE_BIT + movq mm2,mm1 + + pand mm1, MMWORD [edx+1*SIZEOF_MMWORD] ; mm1=( - - - 7) + pand mm2, MMWORD [edi+1*SIZEOF_MMWORD] ; mm2=( - - - 7) + + movq MMWORD [wk(2)], mm1 + movq MMWORD [wk(3)], mm2 + + jmp short .upsample + alignx 16,7 + +.columnloop: + ; -- process the next column block + + movq mm0, MMWORD [ebx+1*SIZEOF_MMWORD] ; mm0=row[ 0][1] + movq mm1, MMWORD [ecx+1*SIZEOF_MMWORD] ; mm1=row[-1][1] + movq mm2, MMWORD [esi+1*SIZEOF_MMWORD] ; mm2=row[+1][1] + + pushpic ebx + movpic ebx, POINTER [gotptr] ; load GOT address + + pxor mm3,mm3 ; mm3=(all 0's) + movq mm4,mm0 + punpcklbw mm0,mm3 ; mm0=row[ 0][1]( 0 1 2 3) + punpckhbw mm4,mm3 ; mm4=row[ 0][1]( 4 5 6 7) + movq mm5,mm1 + punpcklbw mm1,mm3 ; mm1=row[-1][1]( 0 1 2 3) + punpckhbw mm5,mm3 ; mm5=row[-1][1]( 4 5 6 7) + movq mm6,mm2 + punpcklbw mm2,mm3 ; mm2=row[+1][1]( 0 1 2 3) + punpckhbw mm6,mm3 ; mm6=row[+1][1]( 4 5 6 7) + + pmullw mm0,[GOTOFF(ebx,PW_THREE)] + pmullw mm4,[GOTOFF(ebx,PW_THREE)] + + paddw mm1,mm0 ; mm1=Int0L=( 0 1 2 3) + paddw mm5,mm4 ; mm5=Int0H=( 4 5 6 7) + paddw mm2,mm0 ; mm2=Int1L=( 0 1 2 3) + paddw mm6,mm4 ; mm6=Int1H=( 4 5 6 7) + + movq MMWORD [edx+2*SIZEOF_MMWORD], mm1 ; temporarily save + movq MMWORD [edx+3*SIZEOF_MMWORD], mm5 ; the intermediate data + movq MMWORD [edi+2*SIZEOF_MMWORD], mm2 + movq MMWORD [edi+3*SIZEOF_MMWORD], mm6 + + psllq mm1,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm1=( - - - 0) + psllq mm2,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm2=( - - - 0) + + movq MMWORD [wk(2)], mm1 + movq MMWORD [wk(3)], mm2 + +.upsample: + ; -- process the upper row + + movq mm7, MMWORD [edx+0*SIZEOF_MMWORD] ; mm7=Int0L=( 0 1 2 3) + movq mm3, MMWORD [edx+1*SIZEOF_MMWORD] ; mm3=Int0H=( 4 5 6 7) + + movq mm0,mm7 + movq mm4,mm3 + psrlq mm0,2*BYTE_BIT ; mm0=( 1 2 3 -) + psllq mm4,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm4=( - - - 4) + movq mm5,mm7 + movq mm6,mm3 + psrlq mm5,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm5=( 3 - - -) + psllq mm6,2*BYTE_BIT ; mm6=( - 4 5 6) + + por mm0,mm4 ; mm0=( 1 2 3 4) + por mm5,mm6 ; mm5=( 3 4 5 6) + + movq mm1,mm7 + movq mm2,mm3 + psllq mm1,2*BYTE_BIT ; mm1=( - 0 1 2) + psrlq mm2,2*BYTE_BIT ; mm2=( 5 6 7 -) + movq mm4,mm3 + psrlq mm4,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm4=( 7 - - -) + + por mm1, MMWORD [wk(0)] ; mm1=(-1 0 1 2) + por mm2, MMWORD [wk(2)] ; mm2=( 5 6 7 8) + + movq MMWORD [wk(0)], mm4 + + pmullw mm7,[GOTOFF(ebx,PW_THREE)] + pmullw mm3,[GOTOFF(ebx,PW_THREE)] + paddw mm1,[GOTOFF(ebx,PW_EIGHT)] + paddw mm5,[GOTOFF(ebx,PW_EIGHT)] + paddw mm0,[GOTOFF(ebx,PW_SEVEN)] + paddw mm2,[GOTOFF(ebx,PW_SEVEN)] + + paddw mm1,mm7 + paddw mm5,mm3 + psrlw mm1,4 ; mm1=Out0LE=( 0 2 4 6) + psrlw mm5,4 ; mm5=Out0HE=( 8 10 12 14) + paddw mm0,mm7 + paddw mm2,mm3 + psrlw mm0,4 ; mm0=Out0LO=( 1 3 5 7) + psrlw mm2,4 ; mm2=Out0HO=( 9 11 13 15) + + psllw mm0,BYTE_BIT + psllw mm2,BYTE_BIT + por mm1,mm0 ; mm1=Out0L=( 0 1 2 3 4 5 6 7) + por mm5,mm2 ; mm5=Out0H=( 8 9 10 11 12 13 14 15) + + movq MMWORD [edx+0*SIZEOF_MMWORD], mm1 + movq MMWORD [edx+1*SIZEOF_MMWORD], mm5 + + ; -- process the lower row + + movq mm6, MMWORD [edi+0*SIZEOF_MMWORD] ; mm6=Int1L=( 0 1 2 3) + movq mm4, MMWORD [edi+1*SIZEOF_MMWORD] ; mm4=Int1H=( 4 5 6 7) + + movq mm7,mm6 + movq mm3,mm4 + psrlq mm7,2*BYTE_BIT ; mm7=( 1 2 3 -) + psllq mm3,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm3=( - - - 4) + movq mm0,mm6 + movq mm2,mm4 + psrlq mm0,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm0=( 3 - - -) + psllq mm2,2*BYTE_BIT ; mm2=( - 4 5 6) + + por mm7,mm3 ; mm7=( 1 2 3 4) + por mm0,mm2 ; mm0=( 3 4 5 6) + + movq mm1,mm6 + movq mm5,mm4 + psllq mm1,2*BYTE_BIT ; mm1=( - 0 1 2) + psrlq mm5,2*BYTE_BIT ; mm5=( 5 6 7 -) + movq mm3,mm4 + psrlq mm3,(SIZEOF_MMWORD-2)*BYTE_BIT ; mm3=( 7 - - -) + + por mm1, MMWORD [wk(1)] ; mm1=(-1 0 1 2) + por mm5, MMWORD [wk(3)] ; mm5=( 5 6 7 8) + + movq MMWORD [wk(1)], mm3 + + pmullw mm6,[GOTOFF(ebx,PW_THREE)] + pmullw mm4,[GOTOFF(ebx,PW_THREE)] + paddw mm1,[GOTOFF(ebx,PW_EIGHT)] + paddw mm0,[GOTOFF(ebx,PW_EIGHT)] + paddw mm7,[GOTOFF(ebx,PW_SEVEN)] + paddw mm5,[GOTOFF(ebx,PW_SEVEN)] + + paddw mm1,mm6 + paddw mm0,mm4 + psrlw mm1,4 ; mm1=Out1LE=( 0 2 4 6) + psrlw mm0,4 ; mm0=Out1HE=( 8 10 12 14) + paddw mm7,mm6 + paddw mm5,mm4 + psrlw mm7,4 ; mm7=Out1LO=( 1 3 5 7) + psrlw mm5,4 ; mm5=Out1HO=( 9 11 13 15) + + psllw mm7,BYTE_BIT + psllw mm5,BYTE_BIT + por mm1,mm7 ; mm1=Out1L=( 0 1 2 3 4 5 6 7) + por mm0,mm5 ; mm0=Out1H=( 8 9 10 11 12 13 14 15) + + movq MMWORD [edi+0*SIZEOF_MMWORD], mm1 + movq MMWORD [edi+1*SIZEOF_MMWORD], mm0 + + poppic ebx + + sub eax, byte SIZEOF_MMWORD + add ecx, byte 1*SIZEOF_MMWORD ; inptr1(above) + add ebx, byte 1*SIZEOF_MMWORD ; inptr0 + add esi, byte 1*SIZEOF_MMWORD ; inptr1(below) + add edx, byte 2*SIZEOF_MMWORD ; outptr0 + add edi, byte 2*SIZEOF_MMWORD ; outptr1 + cmp eax, byte SIZEOF_MMWORD + ja near .columnloop + test eax,eax + jnz near .columnloop_last + + pop esi + pop edi + pop ecx + pop eax + + add esi, byte 1*SIZEOF_JSAMPROW ; input_data + add edi, byte 2*SIZEOF_JSAMPROW ; output_data + sub ecx, byte 2 ; rowctr + jg near .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Fast processing for the common case of 2:1 horizontal and 1:1 vertical. +; It's still a box filter. +; +; GLOBAL(void) +; jsimd_h2v1_upsample_mmx (int max_v_samp_factor, +; JDIMENSION output_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define output_width(b) (b)+12 ; JDIMENSION output_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v1_upsample_mmx) + +EXTN(jsimd_h2v1_upsample_mmx): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov edx, JDIMENSION [output_width(ebp)] + add edx, byte (2*SIZEOF_MMWORD)-1 + and edx, byte -(2*SIZEOF_MMWORD) + jz short .return + + mov ecx, INT [max_v_samp(ebp)] ; rowctr + test ecx,ecx + jz short .return + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, POINTER [output_data_ptr(ebp)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr + mov eax,edx ; colctr + alignx 16,7 +.columnloop: + + movq mm0, MMWORD [esi+0*SIZEOF_MMWORD] + + movq mm1,mm0 + punpcklbw mm0,mm0 + punpckhbw mm1,mm1 + + movq MMWORD [edi+0*SIZEOF_MMWORD], mm0 + movq MMWORD [edi+1*SIZEOF_MMWORD], mm1 + + sub eax, byte 2*SIZEOF_MMWORD + jz short .nextrow + + movq mm2, MMWORD [esi+1*SIZEOF_MMWORD] + + movq mm3,mm2 + punpcklbw mm2,mm2 + punpckhbw mm3,mm3 + + movq MMWORD [edi+2*SIZEOF_MMWORD], mm2 + movq MMWORD [edi+3*SIZEOF_MMWORD], mm3 + + sub eax, byte 2*SIZEOF_MMWORD + jz short .nextrow + + add esi, byte 2*SIZEOF_MMWORD ; inptr + add edi, byte 4*SIZEOF_MMWORD ; outptr + jmp short .columnloop + alignx 16,7 + +.nextrow: + pop esi + pop edi + + add esi, byte SIZEOF_JSAMPROW ; input_data + add edi, byte SIZEOF_JSAMPROW ; output_data + dec ecx ; rowctr + jg short .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved +; pop ebx ; unused + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Fast processing for the common case of 2:1 horizontal and 2:1 vertical. +; It's still a box filter. +; +; GLOBAL(void) +; jsimd_h2v2_upsample_mmx (int max_v_samp_factor, +; JDIMENSION output_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define output_width(b) (b)+12 ; JDIMENSION output_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v2_upsample_mmx) + +EXTN(jsimd_h2v2_upsample_mmx): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov edx, JDIMENSION [output_width(ebp)] + add edx, byte (2*SIZEOF_MMWORD)-1 + and edx, byte -(2*SIZEOF_MMWORD) + jz near .return + + mov ecx, INT [max_v_samp(ebp)] ; rowctr + test ecx,ecx + jz short .return + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, POINTER [output_data_ptr(ebp)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov ebx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] ; outptr0 + mov edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] ; outptr1 + mov eax,edx ; colctr + alignx 16,7 +.columnloop: + + movq mm0, MMWORD [esi+0*SIZEOF_MMWORD] + + movq mm1,mm0 + punpcklbw mm0,mm0 + punpckhbw mm1,mm1 + + movq MMWORD [ebx+0*SIZEOF_MMWORD], mm0 + movq MMWORD [ebx+1*SIZEOF_MMWORD], mm1 + movq MMWORD [edi+0*SIZEOF_MMWORD], mm0 + movq MMWORD [edi+1*SIZEOF_MMWORD], mm1 + + sub eax, byte 2*SIZEOF_MMWORD + jz short .nextrow + + movq mm2, MMWORD [esi+1*SIZEOF_MMWORD] + + movq mm3,mm2 + punpcklbw mm2,mm2 + punpckhbw mm3,mm3 + + movq MMWORD [ebx+2*SIZEOF_MMWORD], mm2 + movq MMWORD [ebx+3*SIZEOF_MMWORD], mm3 + movq MMWORD [edi+2*SIZEOF_MMWORD], mm2 + movq MMWORD [edi+3*SIZEOF_MMWORD], mm3 + + sub eax, byte 2*SIZEOF_MMWORD + jz short .nextrow + + add esi, byte 2*SIZEOF_MMWORD ; inptr + add ebx, byte 4*SIZEOF_MMWORD ; outptr0 + add edi, byte 4*SIZEOF_MMWORD ; outptr1 + jmp short .columnloop + alignx 16,7 + +.nextrow: + pop esi + pop edi + + add esi, byte 1*SIZEOF_JSAMPROW ; input_data + add edi, byte 2*SIZEOF_JSAMPROW ; output_data + sub ecx, byte 2 ; rowctr + jg short .rowloop + + emms ; empty MMX state + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdsamss2.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdsamss2.asm new file mode 100755 index 0000000..b5c863b --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jdsamss2.asm @@ -0,0 +1,729 @@ +; +; jdsamss2.asm - upsampling (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fancy_upsample_sse2) + +EXTN(jconst_fancy_upsample_sse2): + +PW_ONE times 8 dw 1 +PW_TWO times 8 dw 2 +PW_THREE times 8 dw 3 +PW_SEVEN times 8 dw 7 +PW_EIGHT times 8 dw 8 + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. +; +; The upsampling algorithm is linear interpolation between pixel centers, +; also known as a "triangle filter". This is a good compromise between +; speed and visual quality. The centers of the output pixels are 1/4 and 3/4 +; of the way between input pixel centers. +; +; GLOBAL(void) +; jsimd_h2v1_fancy_upsample_sse2 (int max_v_samp_factor, +; JDIMENSION downsampled_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define downsamp_width(b) (b)+12 ; JDIMENSION downsampled_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v1_fancy_upsample_sse2) + +EXTN(jsimd_h2v1_fancy_upsample_sse2): + push ebp + mov ebp,esp + pushpic ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + mov eax, JDIMENSION [downsamp_width(ebp)] ; colctr + test eax,eax + jz near .return + + mov ecx, INT [max_v_samp(ebp)] ; rowctr + test ecx,ecx + jz near .return + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, POINTER [output_data_ptr(ebp)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push eax ; colctr + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr + + test eax, SIZEOF_XMMWORD-1 + jz short .skip + mov dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl ; insert a dummy sample +.skip: + pxor xmm0,xmm0 ; xmm0=(all 0's) + pcmpeqb xmm7,xmm7 + psrldq xmm7,(SIZEOF_XMMWORD-1) + pand xmm7, XMMWORD [esi+0*SIZEOF_XMMWORD] + + add eax, byte SIZEOF_XMMWORD-1 + and eax, byte -SIZEOF_XMMWORD + cmp eax, byte SIZEOF_XMMWORD + ja short .columnloop + alignx 16,7 + +.columnloop_last: + pcmpeqb xmm6,xmm6 + pslldq xmm6,(SIZEOF_XMMWORD-1) + pand xmm6, XMMWORD [esi+0*SIZEOF_XMMWORD] + jmp short .upsample + alignx 16,7 + +.columnloop: + movdqa xmm6, XMMWORD [esi+1*SIZEOF_XMMWORD] + pslldq xmm6,(SIZEOF_XMMWORD-1) + +.upsample: + movdqa xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD] + movdqa xmm2,xmm1 + movdqa xmm3,xmm1 ; xmm1=( 0 1 2 ... 13 14 15) + pslldq xmm2,1 ; xmm2=(-- 0 1 ... 12 13 14) + psrldq xmm3,1 ; xmm3=( 1 2 3 ... 14 15 --) + + por xmm2,xmm7 ; xmm2=(-1 0 1 ... 12 13 14) + por xmm3,xmm6 ; xmm3=( 1 2 3 ... 14 15 16) + + movdqa xmm7,xmm1 + psrldq xmm7,(SIZEOF_XMMWORD-1) ; xmm7=(15 -- -- ... -- -- --) + + movdqa xmm4,xmm1 + punpcklbw xmm1,xmm0 ; xmm1=( 0 1 2 3 4 5 6 7) + punpckhbw xmm4,xmm0 ; xmm4=( 8 9 10 11 12 13 14 15) + movdqa xmm5,xmm2 + punpcklbw xmm2,xmm0 ; xmm2=(-1 0 1 2 3 4 5 6) + punpckhbw xmm5,xmm0 ; xmm5=( 7 8 9 10 11 12 13 14) + movdqa xmm6,xmm3 + punpcklbw xmm3,xmm0 ; xmm3=( 1 2 3 4 5 6 7 8) + punpckhbw xmm6,xmm0 ; xmm6=( 9 10 11 12 13 14 15 16) + + pmullw xmm1,[GOTOFF(ebx,PW_THREE)] + pmullw xmm4,[GOTOFF(ebx,PW_THREE)] + paddw xmm2,[GOTOFF(ebx,PW_ONE)] + paddw xmm5,[GOTOFF(ebx,PW_ONE)] + paddw xmm3,[GOTOFF(ebx,PW_TWO)] + paddw xmm6,[GOTOFF(ebx,PW_TWO)] + + paddw xmm2,xmm1 + paddw xmm5,xmm4 + psrlw xmm2,2 ; xmm2=OutLE=( 0 2 4 6 8 10 12 14) + psrlw xmm5,2 ; xmm5=OutHE=(16 18 20 22 24 26 28 30) + paddw xmm3,xmm1 + paddw xmm6,xmm4 + psrlw xmm3,2 ; xmm3=OutLO=( 1 3 5 7 9 11 13 15) + psrlw xmm6,2 ; xmm6=OutHO=(17 19 21 23 25 27 29 31) + + psllw xmm3,BYTE_BIT + psllw xmm6,BYTE_BIT + por xmm2,xmm3 ; xmm2=OutL=( 0 1 2 ... 13 14 15) + por xmm5,xmm6 ; xmm5=OutH=(16 17 18 ... 29 30 31) + + movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm5 + + sub eax, byte SIZEOF_XMMWORD + add esi, byte 1*SIZEOF_XMMWORD ; inptr + add edi, byte 2*SIZEOF_XMMWORD ; outptr + cmp eax, byte SIZEOF_XMMWORD + ja near .columnloop + test eax,eax + jnz near .columnloop_last + + pop esi + pop edi + pop eax + + add esi, byte SIZEOF_JSAMPROW ; input_data + add edi, byte SIZEOF_JSAMPROW ; output_data + dec ecx ; rowctr + jg near .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + poppic ebx + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. +; Again a triangle filter; see comments for h2v1 case, above. +; +; GLOBAL(void) +; jsimd_h2v2_fancy_upsample_sse2 (int max_v_samp_factor, +; JDIMENSION downsampled_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define downsamp_width(b) (b)+12 ; JDIMENSION downsampled_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 4 +%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr + + align 16 + global EXTN(jsimd_h2v2_fancy_upsample_sse2) + +EXTN(jsimd_h2v2_fancy_upsample_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic eax ; make a room for GOT address + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + movpic POINTER [gotptr], ebx ; save GOT address + + mov edx,eax ; edx = original ebp + mov eax, JDIMENSION [downsamp_width(edx)] ; colctr + test eax,eax + jz near .return + + mov ecx, INT [max_v_samp(edx)] ; rowctr + test ecx,ecx + jz near .return + + mov esi, JSAMPARRAY [input_data(edx)] ; input_data + mov edi, POINTER [output_data_ptr(edx)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push eax ; colctr + push ecx + push edi + push esi + + mov ecx, JSAMPROW [esi-1*SIZEOF_JSAMPROW] ; inptr1(above) + mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; inptr0 + mov esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; inptr1(below) + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] ; outptr0 + mov edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] ; outptr1 + + test eax, SIZEOF_XMMWORD-1 + jz short .skip + push edx + mov dl, JSAMPLE [ecx+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [ecx+eax*SIZEOF_JSAMPLE], dl + mov dl, JSAMPLE [ebx+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [ebx+eax*SIZEOF_JSAMPLE], dl + mov dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl ; insert a dummy sample + pop edx +.skip: + ; -- process the first column block + + movdqa xmm0, XMMWORD [ebx+0*SIZEOF_XMMWORD] ; xmm0=row[ 0][0] + movdqa xmm1, XMMWORD [ecx+0*SIZEOF_XMMWORD] ; xmm1=row[-1][0] + movdqa xmm2, XMMWORD [esi+0*SIZEOF_XMMWORD] ; xmm2=row[+1][0] + + pushpic ebx + movpic ebx, POINTER [gotptr] ; load GOT address + + pxor xmm3,xmm3 ; xmm3=(all 0's) + movdqa xmm4,xmm0 + punpcklbw xmm0,xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7) + punpckhbw xmm4,xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15) + movdqa xmm5,xmm1 + punpcklbw xmm1,xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm5,xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15) + movdqa xmm6,xmm2 + punpcklbw xmm2,xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm6,xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15) + + pmullw xmm0,[GOTOFF(ebx,PW_THREE)] + pmullw xmm4,[GOTOFF(ebx,PW_THREE)] + + pcmpeqb xmm7,xmm7 + psrldq xmm7,(SIZEOF_XMMWORD-2) + + paddw xmm1,xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7) + paddw xmm5,xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15) + paddw xmm2,xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7) + paddw xmm6,xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15) + + movdqa XMMWORD [edx+0*SIZEOF_XMMWORD], xmm1 ; temporarily save + movdqa XMMWORD [edx+1*SIZEOF_XMMWORD], xmm5 ; the intermediate data + movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm6 + + pand xmm1,xmm7 ; xmm1=( 0 -- -- -- -- -- -- --) + pand xmm2,xmm7 ; xmm2=( 0 -- -- -- -- -- -- --) + + movdqa XMMWORD [wk(0)], xmm1 + movdqa XMMWORD [wk(1)], xmm2 + + poppic ebx + + add eax, byte SIZEOF_XMMWORD-1 + and eax, byte -SIZEOF_XMMWORD + cmp eax, byte SIZEOF_XMMWORD + ja short .columnloop + alignx 16,7 + +.columnloop_last: + ; -- process the last column block + + pushpic ebx + movpic ebx, POINTER [gotptr] ; load GOT address + + pcmpeqb xmm1,xmm1 + pslldq xmm1,(SIZEOF_XMMWORD-2) + movdqa xmm2,xmm1 + + pand xmm1, XMMWORD [edx+1*SIZEOF_XMMWORD] + pand xmm2, XMMWORD [edi+1*SIZEOF_XMMWORD] + + movdqa XMMWORD [wk(2)], xmm1 ; xmm1=(-- -- -- -- -- -- -- 15) + movdqa XMMWORD [wk(3)], xmm2 ; xmm2=(-- -- -- -- -- -- -- 15) + + jmp near .upsample + alignx 16,7 + +.columnloop: + ; -- process the next column block + + movdqa xmm0, XMMWORD [ebx+1*SIZEOF_XMMWORD] ; xmm0=row[ 0][1] + movdqa xmm1, XMMWORD [ecx+1*SIZEOF_XMMWORD] ; xmm1=row[-1][1] + movdqa xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD] ; xmm2=row[+1][1] + + pushpic ebx + movpic ebx, POINTER [gotptr] ; load GOT address + + pxor xmm3,xmm3 ; xmm3=(all 0's) + movdqa xmm4,xmm0 + punpcklbw xmm0,xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7) + punpckhbw xmm4,xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15) + movdqa xmm5,xmm1 + punpcklbw xmm1,xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm5,xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15) + movdqa xmm6,xmm2 + punpcklbw xmm2,xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm6,xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15) + + pmullw xmm0,[GOTOFF(ebx,PW_THREE)] + pmullw xmm4,[GOTOFF(ebx,PW_THREE)] + + paddw xmm1,xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7) + paddw xmm5,xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15) + paddw xmm2,xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7) + paddw xmm6,xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15) + + movdqa XMMWORD [edx+2*SIZEOF_XMMWORD], xmm1 ; temporarily save + movdqa XMMWORD [edx+3*SIZEOF_XMMWORD], xmm5 ; the intermediate data + movdqa XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [edi+3*SIZEOF_XMMWORD], xmm6 + + pslldq xmm1,(SIZEOF_XMMWORD-2) ; xmm1=(-- -- -- -- -- -- -- 0) + pslldq xmm2,(SIZEOF_XMMWORD-2) ; xmm2=(-- -- -- -- -- -- -- 0) + + movdqa XMMWORD [wk(2)], xmm1 + movdqa XMMWORD [wk(3)], xmm2 + +.upsample: + ; -- process the upper row + + movdqa xmm7, XMMWORD [edx+0*SIZEOF_XMMWORD] + movdqa xmm3, XMMWORD [edx+1*SIZEOF_XMMWORD] + + movdqa xmm0,xmm7 ; xmm7=Int0L=( 0 1 2 3 4 5 6 7) + movdqa xmm4,xmm3 ; xmm3=Int0H=( 8 9 10 11 12 13 14 15) + psrldq xmm0,2 ; xmm0=( 1 2 3 4 5 6 7 --) + pslldq xmm4,(SIZEOF_XMMWORD-2) ; xmm4=(-- -- -- -- -- -- -- 8) + movdqa xmm5,xmm7 + movdqa xmm6,xmm3 + psrldq xmm5,(SIZEOF_XMMWORD-2) ; xmm5=( 7 -- -- -- -- -- -- --) + pslldq xmm6,2 ; xmm6=(-- 8 9 10 11 12 13 14) + + por xmm0,xmm4 ; xmm0=( 1 2 3 4 5 6 7 8) + por xmm5,xmm6 ; xmm5=( 7 8 9 10 11 12 13 14) + + movdqa xmm1,xmm7 + movdqa xmm2,xmm3 + pslldq xmm1,2 ; xmm1=(-- 0 1 2 3 4 5 6) + psrldq xmm2,2 ; xmm2=( 9 10 11 12 13 14 15 --) + movdqa xmm4,xmm3 + psrldq xmm4,(SIZEOF_XMMWORD-2) ; xmm4=(15 -- -- -- -- -- -- --) + + por xmm1, XMMWORD [wk(0)] ; xmm1=(-1 0 1 2 3 4 5 6) + por xmm2, XMMWORD [wk(2)] ; xmm2=( 9 10 11 12 13 14 15 16) + + movdqa XMMWORD [wk(0)], xmm4 + + pmullw xmm7,[GOTOFF(ebx,PW_THREE)] + pmullw xmm3,[GOTOFF(ebx,PW_THREE)] + paddw xmm1,[GOTOFF(ebx,PW_EIGHT)] + paddw xmm5,[GOTOFF(ebx,PW_EIGHT)] + paddw xmm0,[GOTOFF(ebx,PW_SEVEN)] + paddw xmm2,[GOTOFF(ebx,PW_SEVEN)] + + paddw xmm1,xmm7 + paddw xmm5,xmm3 + psrlw xmm1,4 ; xmm1=Out0LE=( 0 2 4 6 8 10 12 14) + psrlw xmm5,4 ; xmm5=Out0HE=(16 18 20 22 24 26 28 30) + paddw xmm0,xmm7 + paddw xmm2,xmm3 + psrlw xmm0,4 ; xmm0=Out0LO=( 1 3 5 7 9 11 13 15) + psrlw xmm2,4 ; xmm2=Out0HO=(17 19 21 23 25 27 29 31) + + psllw xmm0,BYTE_BIT + psllw xmm2,BYTE_BIT + por xmm1,xmm0 ; xmm1=Out0L=( 0 1 2 ... 13 14 15) + por xmm5,xmm2 ; xmm5=Out0H=(16 17 18 ... 29 30 31) + + movdqa XMMWORD [edx+0*SIZEOF_XMMWORD], xmm1 + movdqa XMMWORD [edx+1*SIZEOF_XMMWORD], xmm5 + + ; -- process the lower row + + movdqa xmm6, XMMWORD [edi+0*SIZEOF_XMMWORD] + movdqa xmm4, XMMWORD [edi+1*SIZEOF_XMMWORD] + + movdqa xmm7,xmm6 ; xmm6=Int1L=( 0 1 2 3 4 5 6 7) + movdqa xmm3,xmm4 ; xmm4=Int1H=( 8 9 10 11 12 13 14 15) + psrldq xmm7,2 ; xmm7=( 1 2 3 4 5 6 7 --) + pslldq xmm3,(SIZEOF_XMMWORD-2) ; xmm3=(-- -- -- -- -- -- -- 8) + movdqa xmm0,xmm6 + movdqa xmm2,xmm4 + psrldq xmm0,(SIZEOF_XMMWORD-2) ; xmm0=( 7 -- -- -- -- -- -- --) + pslldq xmm2,2 ; xmm2=(-- 8 9 10 11 12 13 14) + + por xmm7,xmm3 ; xmm7=( 1 2 3 4 5 6 7 8) + por xmm0,xmm2 ; xmm0=( 7 8 9 10 11 12 13 14) + + movdqa xmm1,xmm6 + movdqa xmm5,xmm4 + pslldq xmm1,2 ; xmm1=(-- 0 1 2 3 4 5 6) + psrldq xmm5,2 ; xmm5=( 9 10 11 12 13 14 15 --) + movdqa xmm3,xmm4 + psrldq xmm3,(SIZEOF_XMMWORD-2) ; xmm3=(15 -- -- -- -- -- -- --) + + por xmm1, XMMWORD [wk(1)] ; xmm1=(-1 0 1 2 3 4 5 6) + por xmm5, XMMWORD [wk(3)] ; xmm5=( 9 10 11 12 13 14 15 16) + + movdqa XMMWORD [wk(1)], xmm3 + + pmullw xmm6,[GOTOFF(ebx,PW_THREE)] + pmullw xmm4,[GOTOFF(ebx,PW_THREE)] + paddw xmm1,[GOTOFF(ebx,PW_EIGHT)] + paddw xmm0,[GOTOFF(ebx,PW_EIGHT)] + paddw xmm7,[GOTOFF(ebx,PW_SEVEN)] + paddw xmm5,[GOTOFF(ebx,PW_SEVEN)] + + paddw xmm1,xmm6 + paddw xmm0,xmm4 + psrlw xmm1,4 ; xmm1=Out1LE=( 0 2 4 6 8 10 12 14) + psrlw xmm0,4 ; xmm0=Out1HE=(16 18 20 22 24 26 28 30) + paddw xmm7,xmm6 + paddw xmm5,xmm4 + psrlw xmm7,4 ; xmm7=Out1LO=( 1 3 5 7 9 11 13 15) + psrlw xmm5,4 ; xmm5=Out1HO=(17 19 21 23 25 27 29 31) + + psllw xmm7,BYTE_BIT + psllw xmm5,BYTE_BIT + por xmm1,xmm7 ; xmm1=Out1L=( 0 1 2 ... 13 14 15) + por xmm0,xmm5 ; xmm0=Out1H=(16 17 18 ... 29 30 31) + + movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm1 + movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm0 + + poppic ebx + + sub eax, byte SIZEOF_XMMWORD + add ecx, byte 1*SIZEOF_XMMWORD ; inptr1(above) + add ebx, byte 1*SIZEOF_XMMWORD ; inptr0 + add esi, byte 1*SIZEOF_XMMWORD ; inptr1(below) + add edx, byte 2*SIZEOF_XMMWORD ; outptr0 + add edi, byte 2*SIZEOF_XMMWORD ; outptr1 + cmp eax, byte SIZEOF_XMMWORD + ja near .columnloop + test eax,eax + jnz near .columnloop_last + + pop esi + pop edi + pop ecx + pop eax + + add esi, byte 1*SIZEOF_JSAMPROW ; input_data + add edi, byte 2*SIZEOF_JSAMPROW ; output_data + sub ecx, byte 2 ; rowctr + jg near .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Fast processing for the common case of 2:1 horizontal and 1:1 vertical. +; It's still a box filter. +; +; GLOBAL(void) +; jsimd_h2v1_upsample_sse2 (int max_v_samp_factor, +; JDIMENSION output_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define output_width(b) (b)+12 ; JDIMENSION output_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v1_upsample_sse2) + +EXTN(jsimd_h2v1_upsample_sse2): + push ebp + mov ebp,esp +; push ebx ; unused +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov edx, JDIMENSION [output_width(ebp)] + add edx, byte (2*SIZEOF_XMMWORD)-1 + and edx, byte -(2*SIZEOF_XMMWORD) + jz short .return + + mov ecx, INT [max_v_samp(ebp)] ; rowctr + test ecx,ecx + jz short .return + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, POINTER [output_data_ptr(ebp)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov edi, JSAMPROW [edi] ; outptr + mov eax,edx ; colctr + alignx 16,7 +.columnloop: + + movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD] + + movdqa xmm1,xmm0 + punpcklbw xmm0,xmm0 + punpckhbw xmm1,xmm1 + + movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0 + movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm1 + + sub eax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + movdqa xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD] + + movdqa xmm3,xmm2 + punpcklbw xmm2,xmm2 + punpckhbw xmm3,xmm3 + + movdqa XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [edi+3*SIZEOF_XMMWORD], xmm3 + + sub eax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + add esi, byte 2*SIZEOF_XMMWORD ; inptr + add edi, byte 4*SIZEOF_XMMWORD ; outptr + jmp short .columnloop + alignx 16,7 + +.nextrow: + pop esi + pop edi + + add esi, byte SIZEOF_JSAMPROW ; input_data + add edi, byte SIZEOF_JSAMPROW ; output_data + dec ecx ; rowctr + jg short .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved +; pop ebx ; unused + pop ebp + ret + +; -------------------------------------------------------------------------- +; +; Fast processing for the common case of 2:1 horizontal and 2:1 vertical. +; It's still a box filter. +; +; GLOBAL(void) +; jsimd_h2v2_upsample_sse2 (nt max_v_samp_factor, +; JDIMENSION output_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +%define max_v_samp(b) (b)+8 ; int max_v_samp_factor +%define output_width(b) (b)+12 ; JDIMENSION output_width +%define input_data(b) (b)+16 ; JSAMPARRAY input_data +%define output_data_ptr(b) (b)+20 ; JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v2_upsample_sse2) + +EXTN(jsimd_h2v2_upsample_sse2): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + mov edx, JDIMENSION [output_width(ebp)] + add edx, byte (2*SIZEOF_XMMWORD)-1 + and edx, byte -(2*SIZEOF_XMMWORD) + jz near .return + + mov ecx, INT [max_v_samp(ebp)] ; rowctr + test ecx,ecx + jz near .return + + mov esi, JSAMPARRAY [input_data(ebp)] ; input_data + mov edi, POINTER [output_data_ptr(ebp)] + mov edi, JSAMPARRAY [edi] ; output_data + alignx 16,7 +.rowloop: + push edi + push esi + + mov esi, JSAMPROW [esi] ; inptr + mov ebx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] ; outptr0 + mov edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] ; outptr1 + mov eax,edx ; colctr + alignx 16,7 +.columnloop: + + movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD] + + movdqa xmm1,xmm0 + punpcklbw xmm0,xmm0 + punpckhbw xmm1,xmm1 + + movdqa XMMWORD [ebx+0*SIZEOF_XMMWORD], xmm0 + movdqa XMMWORD [ebx+1*SIZEOF_XMMWORD], xmm1 + movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0 + movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm1 + + sub eax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + movdqa xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD] + + movdqa xmm3,xmm2 + punpcklbw xmm2,xmm2 + punpckhbw xmm3,xmm3 + + movdqa XMMWORD [ebx+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [ebx+3*SIZEOF_XMMWORD], xmm3 + movdqa XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [edi+3*SIZEOF_XMMWORD], xmm3 + + sub eax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + add esi, byte 2*SIZEOF_XMMWORD ; inptr + add ebx, byte 4*SIZEOF_XMMWORD ; outptr0 + add edi, byte 4*SIZEOF_XMMWORD ; outptr1 + jmp short .columnloop + alignx 16,7 + +.nextrow: + pop esi + pop edi + + add esi, byte 1*SIZEOF_JSAMPROW ; input_data + add edi, byte 2*SIZEOF_JSAMPROW ; output_data + sub ecx, byte 2 ; rowctr + jg short .rowloop + +.return: + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jf3dnflt.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jf3dnflt.asm new file mode 100755 index 0000000..542672d --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jf3dnflt.asm @@ -0,0 +1,320 @@ +; +; jf3dnflt.asm - floating-point FDCT (3DNow!) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a floating-point implementation of the forward DCT +; (Discrete Cosine Transform). The following code is based directly on +; the IJG's original jfdctflt.c; see the jfdctflt.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fdct_float_3dnow) + +EXTN(jconst_fdct_float_3dnow): + +PD_0_382 times 2 dd 0.382683432365089771728460 +PD_0_707 times 2 dd 0.707106781186547524400844 +PD_0_541 times 2 dd 0.541196100146196984399723 +PD_1_306 times 2 dd 1.306562964876376527856643 + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_float_3dnow (FAST_FLOAT * data) +; + +%define data(b) (b)+8 ; FAST_FLOAT * data + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_fdct_float_3dnow) + +EXTN(jsimd_fdct_float_3dnow): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved +; push esi ; unused +; push edi ; unused + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process rows. + + mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) + mov ecx, DCTSIZE/2 + alignx 16,7 +.rowloop: + + movq mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] + movq mm1, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] + movq mm2, MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)] + + ; mm0=(00 01), mm1=(10 11), mm2=(06 07), mm3=(16 17) + + movq mm4,mm0 ; transpose coefficients + punpckldq mm0,mm1 ; mm0=(00 10)=data0 + punpckhdq mm4,mm1 ; mm4=(01 11)=data1 + movq mm5,mm2 ; transpose coefficients + punpckldq mm2,mm3 ; mm2=(06 16)=data6 + punpckhdq mm5,mm3 ; mm5=(07 17)=data7 + + movq mm6,mm4 + movq mm7,mm0 + pfsub mm4,mm2 ; mm4=data1-data6=tmp6 + pfsub mm0,mm5 ; mm0=data0-data7=tmp7 + pfadd mm6,mm2 ; mm6=data1+data6=tmp1 + pfadd mm7,mm5 ; mm7=data0+data7=tmp0 + + movq mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] + movq mm2, MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)] + movq mm5, MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)] + + ; mm1=(02 03), mm3=(12 13), mm2=(04 05), mm5=(14 15) + + movq MMWORD [wk(0)], mm4 ; wk(0)=tmp6 + movq MMWORD [wk(1)], mm0 ; wk(1)=tmp7 + + movq mm4,mm1 ; transpose coefficients + punpckldq mm1,mm3 ; mm1=(02 12)=data2 + punpckhdq mm4,mm3 ; mm4=(03 13)=data3 + movq mm0,mm2 ; transpose coefficients + punpckldq mm2,mm5 ; mm2=(04 14)=data4 + punpckhdq mm0,mm5 ; mm0=(05 15)=data5 + + movq mm3,mm4 + movq mm5,mm1 + pfadd mm4,mm2 ; mm4=data3+data4=tmp3 + pfadd mm1,mm0 ; mm1=data2+data5=tmp2 + pfsub mm3,mm2 ; mm3=data3-data4=tmp4 + pfsub mm5,mm0 ; mm5=data2-data5=tmp5 + + ; -- Even part + + movq mm2,mm7 + movq mm0,mm6 + pfsub mm7,mm4 ; mm7=tmp13 + pfsub mm6,mm1 ; mm6=tmp12 + pfadd mm2,mm4 ; mm2=tmp10 + pfadd mm0,mm1 ; mm0=tmp11 + + pfadd mm6,mm7 + pfmul mm6,[GOTOFF(ebx,PD_0_707)] ; mm6=z1 + + movq mm4,mm2 + movq mm1,mm7 + pfsub mm2,mm0 ; mm2=data4 + pfsub mm7,mm6 ; mm7=data6 + pfadd mm4,mm0 ; mm4=data0 + pfadd mm1,mm6 ; mm1=data2 + + movq MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)], mm2 + movq MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)], mm7 + movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], mm4 + movq MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], mm1 + + ; -- Odd part + + movq mm0, MMWORD [wk(0)] ; mm0=tmp6 + movq mm6, MMWORD [wk(1)] ; mm6=tmp7 + + pfadd mm3,mm5 ; mm3=tmp10 + pfadd mm5,mm0 ; mm5=tmp11 + pfadd mm0,mm6 ; mm0=tmp12, mm6=tmp7 + + pfmul mm5,[GOTOFF(ebx,PD_0_707)] ; mm5=z3 + + movq mm2,mm3 ; mm2=tmp10 + pfsub mm3,mm0 + pfmul mm3,[GOTOFF(ebx,PD_0_382)] ; mm3=z5 + pfmul mm2,[GOTOFF(ebx,PD_0_541)] ; mm2=MULTIPLY(tmp10,FIX_0_54119610) + pfmul mm0,[GOTOFF(ebx,PD_1_306)] ; mm0=MULTIPLY(tmp12,FIX_1_30656296) + pfadd mm2,mm3 ; mm2=z2 + pfadd mm0,mm3 ; mm0=z4 + + movq mm7,mm6 + pfsub mm6,mm5 ; mm6=z13 + pfadd mm7,mm5 ; mm7=z11 + + movq mm4,mm6 + movq mm1,mm7 + pfsub mm6,mm2 ; mm6=data3 + pfsub mm7,mm0 ; mm7=data7 + pfadd mm4,mm2 ; mm4=data5 + pfadd mm1,mm0 ; mm1=data1 + + movq MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], mm6 + movq MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)], mm7 + movq MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)], mm4 + movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], mm1 + + add edx, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT + dec ecx + jnz near .rowloop + + ; ---- Pass 2: process columns. + + mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) + mov ecx, DCTSIZE/2 + alignx 16,7 +.columnloop: + + movq mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] + movq mm1, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] + movq mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)] + + ; mm0=(00 10), mm1=(01 11), mm2=(60 70), mm3=(61 71) + + movq mm4,mm0 ; transpose coefficients + punpckldq mm0,mm1 ; mm0=(00 01)=data0 + punpckhdq mm4,mm1 ; mm4=(10 11)=data1 + movq mm5,mm2 ; transpose coefficients + punpckldq mm2,mm3 ; mm2=(60 61)=data6 + punpckhdq mm5,mm3 ; mm5=(70 71)=data7 + + movq mm6,mm4 + movq mm7,mm0 + pfsub mm4,mm2 ; mm4=data1-data6=tmp6 + pfsub mm0,mm5 ; mm0=data0-data7=tmp7 + pfadd mm6,mm2 ; mm6=data1+data6=tmp1 + pfadd mm7,mm5 ; mm7=data0+data7=tmp0 + + movq mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)] + movq mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)] + movq mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)] + + ; mm1=(20 30), mm3=(21 31), mm2=(40 50), mm5=(41 51) + + movq MMWORD [wk(0)], mm4 ; wk(0)=tmp6 + movq MMWORD [wk(1)], mm0 ; wk(1)=tmp7 + + movq mm4,mm1 ; transpose coefficients + punpckldq mm1,mm3 ; mm1=(20 21)=data2 + punpckhdq mm4,mm3 ; mm4=(30 31)=data3 + movq mm0,mm2 ; transpose coefficients + punpckldq mm2,mm5 ; mm2=(40 41)=data4 + punpckhdq mm0,mm5 ; mm0=(50 51)=data5 + + movq mm3,mm4 + movq mm5,mm1 + pfadd mm4,mm2 ; mm4=data3+data4=tmp3 + pfadd mm1,mm0 ; mm1=data2+data5=tmp2 + pfsub mm3,mm2 ; mm3=data3-data4=tmp4 + pfsub mm5,mm0 ; mm5=data2-data5=tmp5 + + ; -- Even part + + movq mm2,mm7 + movq mm0,mm6 + pfsub mm7,mm4 ; mm7=tmp13 + pfsub mm6,mm1 ; mm6=tmp12 + pfadd mm2,mm4 ; mm2=tmp10 + pfadd mm0,mm1 ; mm0=tmp11 + + pfadd mm6,mm7 + pfmul mm6,[GOTOFF(ebx,PD_0_707)] ; mm6=z1 + + movq mm4,mm2 + movq mm1,mm7 + pfsub mm2,mm0 ; mm2=data4 + pfsub mm7,mm6 ; mm7=data6 + pfadd mm4,mm0 ; mm4=data0 + pfadd mm1,mm6 ; mm1=data2 + + movq MMWORD [MMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], mm2 + movq MMWORD [MMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], mm7 + movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], mm4 + movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], mm1 + + ; -- Odd part + + movq mm0, MMWORD [wk(0)] ; mm0=tmp6 + movq mm6, MMWORD [wk(1)] ; mm6=tmp7 + + pfadd mm3,mm5 ; mm3=tmp10 + pfadd mm5,mm0 ; mm5=tmp11 + pfadd mm0,mm6 ; mm0=tmp12, mm6=tmp7 + + pfmul mm5,[GOTOFF(ebx,PD_0_707)] ; mm5=z3 + + movq mm2,mm3 ; mm2=tmp10 + pfsub mm3,mm0 + pfmul mm3,[GOTOFF(ebx,PD_0_382)] ; mm3=z5 + pfmul mm2,[GOTOFF(ebx,PD_0_541)] ; mm2=MULTIPLY(tmp10,FIX_0_54119610) + pfmul mm0,[GOTOFF(ebx,PD_1_306)] ; mm0=MULTIPLY(tmp12,FIX_1_30656296) + pfadd mm2,mm3 ; mm2=z2 + pfadd mm0,mm3 ; mm0=z4 + + movq mm7,mm6 + pfsub mm6,mm5 ; mm6=z13 + pfadd mm7,mm5 ; mm7=z11 + + movq mm4,mm6 + movq mm1,mm7 + pfsub mm6,mm2 ; mm6=data3 + pfsub mm7,mm0 ; mm7=data7 + pfadd mm4,mm2 ; mm4=data5 + pfadd mm1,mm0 ; mm1=data1 + + movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], mm6 + movq MMWORD [MMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], mm7 + movq MMWORD [MMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], mm4 + movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], mm1 + + add edx, byte 2*SIZEOF_FAST_FLOAT + dec ecx + jnz near .columnloop + + femms ; empty MMX/3DNow! state + +; pop edi ; unused +; pop esi ; unused +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfmmxfst.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfmmxfst.asm new file mode 100755 index 0000000..0647242 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfmmxfst.asm @@ -0,0 +1,397 @@ +; +; jfmmxfst.asm - fast integer FDCT (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a fast, not so accurate integer implementation of +; the forward DCT (Discrete Cosine Transform). The following code is +; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c +; for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 8 ; 14 is also OK. + +%if CONST_BITS == 8 +F_0_382 equ 98 ; FIX(0.382683433) +F_0_541 equ 139 ; FIX(0.541196100) +F_0_707 equ 181 ; FIX(0.707106781) +F_1_306 equ 334 ; FIX(1.306562965) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_382 equ DESCALE( 410903207,30-CONST_BITS) ; FIX(0.382683433) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_707 equ DESCALE( 759250124,30-CONST_BITS) ; FIX(0.707106781) +F_1_306 equ DESCALE(1402911301,30-CONST_BITS) ; FIX(1.306562965) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + +; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow) +; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw) + +%define PRE_MULTIPLY_SCALE_BITS 2 +%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS) + + alignz 16 + global EXTN(jconst_fdct_ifast_mmx) + +EXTN(jconst_fdct_ifast_mmx): + +PW_F0707 times 4 dw F_0_707 << CONST_SHIFT +PW_F0382 times 4 dw F_0_382 << CONST_SHIFT +PW_F0541 times 4 dw F_0_541 << CONST_SHIFT +PW_F1306 times 4 dw F_1_306 << CONST_SHIFT + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_ifast_mmx (DCTELEM * data) +; + +%define data(b) (b)+8 ; DCTELEM * data + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_fdct_ifast_mmx) + +EXTN(jsimd_fdct_ifast_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved +; push esi ; unused +; push edi ; unused + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process rows. + + mov edx, POINTER [data(eax)] ; (DCTELEM *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.rowloop: + + movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)] + movq mm2, MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)] + + ; mm0=(20 21 22 23), mm2=(24 25 26 27) + ; mm1=(30 31 32 33), mm3=(34 35 36 37) + + movq mm4,mm0 ; transpose coefficients(phase 1) + punpcklwd mm0,mm1 ; mm0=(20 30 21 31) + punpckhwd mm4,mm1 ; mm4=(22 32 23 33) + movq mm5,mm2 ; transpose coefficients(phase 1) + punpcklwd mm2,mm3 ; mm2=(24 34 25 35) + punpckhwd mm5,mm3 ; mm5=(26 36 27 37) + + movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)] + movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)] + + ; mm6=(00 01 02 03), mm1=(04 05 06 07) + ; mm7=(10 11 12 13), mm3=(14 15 16 17) + + movq MMWORD [wk(0)], mm4 ; wk(0)=(22 32 23 33) + movq MMWORD [wk(1)], mm2 ; wk(1)=(24 34 25 35) + + movq mm4,mm6 ; transpose coefficients(phase 1) + punpcklwd mm6,mm7 ; mm6=(00 10 01 11) + punpckhwd mm4,mm7 ; mm4=(02 12 03 13) + movq mm2,mm1 ; transpose coefficients(phase 1) + punpcklwd mm1,mm3 ; mm1=(04 14 05 15) + punpckhwd mm2,mm3 ; mm2=(06 16 07 17) + + movq mm7,mm6 ; transpose coefficients(phase 2) + punpckldq mm6,mm0 ; mm6=(00 10 20 30)=data0 + punpckhdq mm7,mm0 ; mm7=(01 11 21 31)=data1 + movq mm3,mm2 ; transpose coefficients(phase 2) + punpckldq mm2,mm5 ; mm2=(06 16 26 36)=data6 + punpckhdq mm3,mm5 ; mm3=(07 17 27 37)=data7 + + movq mm0,mm7 + movq mm5,mm6 + psubw mm7,mm2 ; mm7=data1-data6=tmp6 + psubw mm6,mm3 ; mm6=data0-data7=tmp7 + paddw mm0,mm2 ; mm0=data1+data6=tmp1 + paddw mm5,mm3 ; mm5=data0+data7=tmp0 + + movq mm2, MMWORD [wk(0)] ; mm2=(22 32 23 33) + movq mm3, MMWORD [wk(1)] ; mm3=(24 34 25 35) + movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6 + movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7 + + movq mm7,mm4 ; transpose coefficients(phase 2) + punpckldq mm4,mm2 ; mm4=(02 12 22 32)=data2 + punpckhdq mm7,mm2 ; mm7=(03 13 23 33)=data3 + movq mm6,mm1 ; transpose coefficients(phase 2) + punpckldq mm1,mm3 ; mm1=(04 14 24 34)=data4 + punpckhdq mm6,mm3 ; mm6=(05 15 25 35)=data5 + + movq mm2,mm7 + movq mm3,mm4 + paddw mm7,mm1 ; mm7=data3+data4=tmp3 + paddw mm4,mm6 ; mm4=data2+data5=tmp2 + psubw mm2,mm1 ; mm2=data3-data4=tmp4 + psubw mm3,mm6 ; mm3=data2-data5=tmp5 + + ; -- Even part + + movq mm1,mm5 + movq mm6,mm0 + psubw mm5,mm7 ; mm5=tmp13 + psubw mm0,mm4 ; mm0=tmp12 + paddw mm1,mm7 ; mm1=tmp10 + paddw mm6,mm4 ; mm6=tmp11 + + paddw mm0,mm5 + psllw mm0,PRE_MULTIPLY_SCALE_BITS + pmulhw mm0,[GOTOFF(ebx,PW_F0707)] ; mm0=z1 + + movq mm7,mm1 + movq mm4,mm5 + psubw mm1,mm6 ; mm1=data4 + psubw mm5,mm0 ; mm5=data6 + paddw mm7,mm6 ; mm7=data0 + paddw mm4,mm0 ; mm4=data2 + + movq MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)], mm1 + movq MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)], mm5 + movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm7 + movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4 + + ; -- Odd part + + movq mm6, MMWORD [wk(0)] ; mm6=tmp6 + movq mm0, MMWORD [wk(1)] ; mm0=tmp7 + + paddw mm2,mm3 ; mm2=tmp10 + paddw mm3,mm6 ; mm3=tmp11 + paddw mm6,mm0 ; mm6=tmp12, mm0=tmp7 + + psllw mm2,PRE_MULTIPLY_SCALE_BITS + psllw mm6,PRE_MULTIPLY_SCALE_BITS + + psllw mm3,PRE_MULTIPLY_SCALE_BITS + pmulhw mm3,[GOTOFF(ebx,PW_F0707)] ; mm3=z3 + + movq mm1,mm2 ; mm1=tmp10 + psubw mm2,mm6 + pmulhw mm2,[GOTOFF(ebx,PW_F0382)] ; mm2=z5 + pmulhw mm1,[GOTOFF(ebx,PW_F0541)] ; mm1=MULTIPLY(tmp10,FIX_0_54119610) + pmulhw mm6,[GOTOFF(ebx,PW_F1306)] ; mm6=MULTIPLY(tmp12,FIX_1_30656296) + paddw mm1,mm2 ; mm1=z2 + paddw mm6,mm2 ; mm6=z4 + + movq mm5,mm0 + psubw mm0,mm3 ; mm0=z13 + paddw mm5,mm3 ; mm5=z11 + + movq mm7,mm0 + movq mm4,mm5 + psubw mm0,mm1 ; mm0=data3 + psubw mm5,mm6 ; mm5=data7 + paddw mm7,mm1 ; mm7=data5 + paddw mm4,mm6 ; mm4=data1 + + movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm0 + movq MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)], mm5 + movq MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)], mm7 + movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm4 + + add edx, byte 4*DCTSIZE*SIZEOF_DCTELEM + dec ecx + jnz near .rowloop + + ; ---- Pass 2: process columns. + + mov edx, POINTER [data(eax)] ; (DCTELEM *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.columnloop: + + movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)] + movq mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)] + + ; mm0=(02 12 22 32), mm2=(42 52 62 72) + ; mm1=(03 13 23 33), mm3=(43 53 63 73) + + movq mm4,mm0 ; transpose coefficients(phase 1) + punpcklwd mm0,mm1 ; mm0=(02 03 12 13) + punpckhwd mm4,mm1 ; mm4=(22 23 32 33) + movq mm5,mm2 ; transpose coefficients(phase 1) + punpcklwd mm2,mm3 ; mm2=(42 43 52 53) + punpckhwd mm5,mm3 ; mm5=(62 63 72 73) + + movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)] + movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)] + + ; mm6=(00 10 20 30), mm1=(40 50 60 70) + ; mm7=(01 11 21 31), mm3=(41 51 61 71) + + movq MMWORD [wk(0)], mm4 ; wk(0)=(22 23 32 33) + movq MMWORD [wk(1)], mm2 ; wk(1)=(42 43 52 53) + + movq mm4,mm6 ; transpose coefficients(phase 1) + punpcklwd mm6,mm7 ; mm6=(00 01 10 11) + punpckhwd mm4,mm7 ; mm4=(20 21 30 31) + movq mm2,mm1 ; transpose coefficients(phase 1) + punpcklwd mm1,mm3 ; mm1=(40 41 50 51) + punpckhwd mm2,mm3 ; mm2=(60 61 70 71) + + movq mm7,mm6 ; transpose coefficients(phase 2) + punpckldq mm6,mm0 ; mm6=(00 01 02 03)=data0 + punpckhdq mm7,mm0 ; mm7=(10 11 12 13)=data1 + movq mm3,mm2 ; transpose coefficients(phase 2) + punpckldq mm2,mm5 ; mm2=(60 61 62 63)=data6 + punpckhdq mm3,mm5 ; mm3=(70 71 72 73)=data7 + + movq mm0,mm7 + movq mm5,mm6 + psubw mm7,mm2 ; mm7=data1-data6=tmp6 + psubw mm6,mm3 ; mm6=data0-data7=tmp7 + paddw mm0,mm2 ; mm0=data1+data6=tmp1 + paddw mm5,mm3 ; mm5=data0+data7=tmp0 + + movq mm2, MMWORD [wk(0)] ; mm2=(22 23 32 33) + movq mm3, MMWORD [wk(1)] ; mm3=(42 43 52 53) + movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6 + movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7 + + movq mm7,mm4 ; transpose coefficients(phase 2) + punpckldq mm4,mm2 ; mm4=(20 21 22 23)=data2 + punpckhdq mm7,mm2 ; mm7=(30 31 32 33)=data3 + movq mm6,mm1 ; transpose coefficients(phase 2) + punpckldq mm1,mm3 ; mm1=(40 41 42 43)=data4 + punpckhdq mm6,mm3 ; mm6=(50 51 52 53)=data5 + + movq mm2,mm7 + movq mm3,mm4 + paddw mm7,mm1 ; mm7=data3+data4=tmp3 + paddw mm4,mm6 ; mm4=data2+data5=tmp2 + psubw mm2,mm1 ; mm2=data3-data4=tmp4 + psubw mm3,mm6 ; mm3=data2-data5=tmp5 + + ; -- Even part + + movq mm1,mm5 + movq mm6,mm0 + psubw mm5,mm7 ; mm5=tmp13 + psubw mm0,mm4 ; mm0=tmp12 + paddw mm1,mm7 ; mm1=tmp10 + paddw mm6,mm4 ; mm6=tmp11 + + paddw mm0,mm5 + psllw mm0,PRE_MULTIPLY_SCALE_BITS + pmulhw mm0,[GOTOFF(ebx,PW_F0707)] ; mm0=z1 + + movq mm7,mm1 + movq mm4,mm5 + psubw mm1,mm6 ; mm1=data4 + psubw mm5,mm0 ; mm5=data6 + paddw mm7,mm6 ; mm7=data0 + paddw mm4,mm0 ; mm4=data2 + + movq MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)], mm1 + movq MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)], mm5 + movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm7 + movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4 + + ; -- Odd part + + movq mm6, MMWORD [wk(0)] ; mm6=tmp6 + movq mm0, MMWORD [wk(1)] ; mm0=tmp7 + + paddw mm2,mm3 ; mm2=tmp10 + paddw mm3,mm6 ; mm3=tmp11 + paddw mm6,mm0 ; mm6=tmp12, mm0=tmp7 + + psllw mm2,PRE_MULTIPLY_SCALE_BITS + psllw mm6,PRE_MULTIPLY_SCALE_BITS + + psllw mm3,PRE_MULTIPLY_SCALE_BITS + pmulhw mm3,[GOTOFF(ebx,PW_F0707)] ; mm3=z3 + + movq mm1,mm2 ; mm1=tmp10 + psubw mm2,mm6 + pmulhw mm2,[GOTOFF(ebx,PW_F0382)] ; mm2=z5 + pmulhw mm1,[GOTOFF(ebx,PW_F0541)] ; mm1=MULTIPLY(tmp10,FIX_0_54119610) + pmulhw mm6,[GOTOFF(ebx,PW_F1306)] ; mm6=MULTIPLY(tmp12,FIX_1_30656296) + paddw mm1,mm2 ; mm1=z2 + paddw mm6,mm2 ; mm6=z4 + + movq mm5,mm0 + psubw mm0,mm3 ; mm0=z13 + paddw mm5,mm3 ; mm5=z11 + + movq mm7,mm0 + movq mm4,mm5 + psubw mm0,mm1 ; mm0=data3 + psubw mm5,mm6 ; mm5=data7 + paddw mm7,mm1 ; mm7=data5 + paddw mm4,mm6 ; mm4=data1 + + movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm0 + movq MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)], mm5 + movq MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)], mm7 + movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm4 + + add edx, byte 4*SIZEOF_DCTELEM + dec ecx + jnz near .columnloop + + emms ; empty MMX state + +; pop edi ; unused +; pop esi ; unused +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfmmxint.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfmmxint.asm new file mode 100755 index 0000000..a7e73f7 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfmmxint.asm @@ -0,0 +1,622 @@ +; +; jfmmxint.asm - accurate integer FDCT (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a slow-but-accurate integer implementation of the +; forward DCT (Discrete Cosine Transform). The following code is based +; directly on the IJG's original jfdctint.c; see the jfdctint.c for +; more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1 (CONST_BITS-PASS1_BITS) +%define DESCALE_P2 (CONST_BITS+PASS1_BITS) + +%if CONST_BITS == 13 +F_0_298 equ 2446 ; FIX(0.298631336) +F_0_390 equ 3196 ; FIX(0.390180644) +F_0_541 equ 4433 ; FIX(0.541196100) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_175 equ 9633 ; FIX(1.175875602) +F_1_501 equ 12299 ; FIX(1.501321110) +F_1_847 equ 15137 ; FIX(1.847759065) +F_1_961 equ 16069 ; FIX(1.961570560) +F_2_053 equ 16819 ; FIX(2.053119869) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_072 equ 25172 ; FIX(3.072711026) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) +F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) +F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) +F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fdct_islow_mmx) + +EXTN(jconst_fdct_islow_mmx): + +PW_F130_F054 times 2 dw (F_0_541+F_0_765), F_0_541 +PW_F054_MF130 times 2 dw F_0_541, (F_0_541-F_1_847) +PW_MF078_F117 times 2 dw (F_1_175-F_1_961), F_1_175 +PW_F117_F078 times 2 dw F_1_175, (F_1_175-F_0_390) +PW_MF060_MF089 times 2 dw (F_0_298-F_0_899),-F_0_899 +PW_MF089_F060 times 2 dw -F_0_899, (F_1_501-F_0_899) +PW_MF050_MF256 times 2 dw (F_2_053-F_2_562),-F_2_562 +PW_MF256_F050 times 2 dw -F_2_562, (F_3_072-F_2_562) +PD_DESCALE_P1 times 2 dd 1 << (DESCALE_P1-1) +PD_DESCALE_P2 times 2 dd 1 << (DESCALE_P2-1) +PW_DESCALE_P2X times 4 dw 1 << (PASS1_BITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_islow_mmx (DCTELEM * data) +; + +%define data(b) (b)+8 ; DCTELEM * data + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_fdct_islow_mmx) + +EXTN(jsimd_fdct_islow_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved +; push esi ; unused +; push edi ; unused + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process rows. + + mov edx, POINTER [data(eax)] ; (DCTELEM *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.rowloop: + + movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)] + movq mm2, MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)] + + ; mm0=(20 21 22 23), mm2=(24 25 26 27) + ; mm1=(30 31 32 33), mm3=(34 35 36 37) + + movq mm4,mm0 ; transpose coefficients(phase 1) + punpcklwd mm0,mm1 ; mm0=(20 30 21 31) + punpckhwd mm4,mm1 ; mm4=(22 32 23 33) + movq mm5,mm2 ; transpose coefficients(phase 1) + punpcklwd mm2,mm3 ; mm2=(24 34 25 35) + punpckhwd mm5,mm3 ; mm5=(26 36 27 37) + + movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)] + movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)] + + ; mm6=(00 01 02 03), mm1=(04 05 06 07) + ; mm7=(10 11 12 13), mm3=(14 15 16 17) + + movq MMWORD [wk(0)], mm4 ; wk(0)=(22 32 23 33) + movq MMWORD [wk(1)], mm2 ; wk(1)=(24 34 25 35) + + movq mm4,mm6 ; transpose coefficients(phase 1) + punpcklwd mm6,mm7 ; mm6=(00 10 01 11) + punpckhwd mm4,mm7 ; mm4=(02 12 03 13) + movq mm2,mm1 ; transpose coefficients(phase 1) + punpcklwd mm1,mm3 ; mm1=(04 14 05 15) + punpckhwd mm2,mm3 ; mm2=(06 16 07 17) + + movq mm7,mm6 ; transpose coefficients(phase 2) + punpckldq mm6,mm0 ; mm6=(00 10 20 30)=data0 + punpckhdq mm7,mm0 ; mm7=(01 11 21 31)=data1 + movq mm3,mm2 ; transpose coefficients(phase 2) + punpckldq mm2,mm5 ; mm2=(06 16 26 36)=data6 + punpckhdq mm3,mm5 ; mm3=(07 17 27 37)=data7 + + movq mm0,mm7 + movq mm5,mm6 + psubw mm7,mm2 ; mm7=data1-data6=tmp6 + psubw mm6,mm3 ; mm6=data0-data7=tmp7 + paddw mm0,mm2 ; mm0=data1+data6=tmp1 + paddw mm5,mm3 ; mm5=data0+data7=tmp0 + + movq mm2, MMWORD [wk(0)] ; mm2=(22 32 23 33) + movq mm3, MMWORD [wk(1)] ; mm3=(24 34 25 35) + movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6 + movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7 + + movq mm7,mm4 ; transpose coefficients(phase 2) + punpckldq mm4,mm2 ; mm4=(02 12 22 32)=data2 + punpckhdq mm7,mm2 ; mm7=(03 13 23 33)=data3 + movq mm6,mm1 ; transpose coefficients(phase 2) + punpckldq mm1,mm3 ; mm1=(04 14 24 34)=data4 + punpckhdq mm6,mm3 ; mm6=(05 15 25 35)=data5 + + movq mm2,mm7 + movq mm3,mm4 + paddw mm7,mm1 ; mm7=data3+data4=tmp3 + paddw mm4,mm6 ; mm4=data2+data5=tmp2 + psubw mm2,mm1 ; mm2=data3-data4=tmp4 + psubw mm3,mm6 ; mm3=data2-data5=tmp5 + + ; -- Even part + + movq mm1,mm5 + movq mm6,mm0 + paddw mm5,mm7 ; mm5=tmp10 + paddw mm0,mm4 ; mm0=tmp11 + psubw mm1,mm7 ; mm1=tmp13 + psubw mm6,mm4 ; mm6=tmp12 + + movq mm7,mm5 + paddw mm5,mm0 ; mm5=tmp10+tmp11 + psubw mm7,mm0 ; mm7=tmp10-tmp11 + + psllw mm5,PASS1_BITS ; mm5=data0 + psllw mm7,PASS1_BITS ; mm7=data4 + + movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5 + movq MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)], mm7 + + ; (Original) + ; z1 = (tmp12 + tmp13) * 0.541196100; + ; data2 = z1 + tmp13 * 0.765366865; + ; data6 = z1 + tmp12 * -1.847759065; + ; + ; (This implementation) + ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100; + ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065); + + movq mm4,mm1 ; mm1=tmp13 + movq mm0,mm1 + punpcklwd mm4,mm6 ; mm6=tmp12 + punpckhwd mm0,mm6 + movq mm1,mm4 + movq mm6,mm0 + pmaddwd mm4,[GOTOFF(ebx,PW_F130_F054)] ; mm4=data2L + pmaddwd mm0,[GOTOFF(ebx,PW_F130_F054)] ; mm0=data2H + pmaddwd mm1,[GOTOFF(ebx,PW_F054_MF130)] ; mm1=data6L + pmaddwd mm6,[GOTOFF(ebx,PW_F054_MF130)] ; mm6=data6H + + paddd mm4,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd mm0,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad mm4,DESCALE_P1 + psrad mm0,DESCALE_P1 + paddd mm1,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd mm6,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad mm1,DESCALE_P1 + psrad mm6,DESCALE_P1 + + packssdw mm4,mm0 ; mm4=data2 + packssdw mm1,mm6 ; mm1=data6 + + movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4 + movq MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)], mm1 + + ; -- Odd part + + movq mm5, MMWORD [wk(0)] ; mm5=tmp6 + movq mm7, MMWORD [wk(1)] ; mm7=tmp7 + + movq mm0,mm2 ; mm2=tmp4 + movq mm6,mm3 ; mm3=tmp5 + paddw mm0,mm5 ; mm0=z3 + paddw mm6,mm7 ; mm6=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movq mm4,mm0 + movq mm1,mm0 + punpcklwd mm4,mm6 + punpckhwd mm1,mm6 + movq mm0,mm4 + movq mm6,mm1 + pmaddwd mm4,[GOTOFF(ebx,PW_MF078_F117)] ; mm4=z3L + pmaddwd mm1,[GOTOFF(ebx,PW_MF078_F117)] ; mm1=z3H + pmaddwd mm0,[GOTOFF(ebx,PW_F117_F078)] ; mm0=z4L + pmaddwd mm6,[GOTOFF(ebx,PW_F117_F078)] ; mm6=z4H + + movq MMWORD [wk(0)], mm4 ; wk(0)=z3L + movq MMWORD [wk(1)], mm1 ; wk(1)=z3H + + ; (Original) + ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; + ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869; + ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4; + ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4; + ; + ; (This implementation) + ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223; + ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447; + ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447); + ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223); + ; data7 = tmp4 + z3; data5 = tmp5 + z4; + ; data3 = tmp6 + z3; data1 = tmp7 + z4; + + movq mm4,mm2 + movq mm1,mm2 + punpcklwd mm4,mm7 + punpckhwd mm1,mm7 + movq mm2,mm4 + movq mm7,mm1 + pmaddwd mm4,[GOTOFF(ebx,PW_MF060_MF089)] ; mm4=tmp4L + pmaddwd mm1,[GOTOFF(ebx,PW_MF060_MF089)] ; mm1=tmp4H + pmaddwd mm2,[GOTOFF(ebx,PW_MF089_F060)] ; mm2=tmp7L + pmaddwd mm7,[GOTOFF(ebx,PW_MF089_F060)] ; mm7=tmp7H + + paddd mm4, MMWORD [wk(0)] ; mm4=data7L + paddd mm1, MMWORD [wk(1)] ; mm1=data7H + paddd mm2,mm0 ; mm2=data1L + paddd mm7,mm6 ; mm7=data1H + + paddd mm4,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd mm1,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad mm4,DESCALE_P1 + psrad mm1,DESCALE_P1 + paddd mm2,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd mm7,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad mm2,DESCALE_P1 + psrad mm7,DESCALE_P1 + + packssdw mm4,mm1 ; mm4=data7 + packssdw mm2,mm7 ; mm2=data1 + + movq MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)], mm4 + movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2 + + movq mm1,mm3 + movq mm7,mm3 + punpcklwd mm1,mm5 + punpckhwd mm7,mm5 + movq mm3,mm1 + movq mm5,mm7 + pmaddwd mm1,[GOTOFF(ebx,PW_MF050_MF256)] ; mm1=tmp5L + pmaddwd mm7,[GOTOFF(ebx,PW_MF050_MF256)] ; mm7=tmp5H + pmaddwd mm3,[GOTOFF(ebx,PW_MF256_F050)] ; mm3=tmp6L + pmaddwd mm5,[GOTOFF(ebx,PW_MF256_F050)] ; mm5=tmp6H + + paddd mm1,mm0 ; mm1=data5L + paddd mm7,mm6 ; mm7=data5H + paddd mm3, MMWORD [wk(0)] ; mm3=data3L + paddd mm5, MMWORD [wk(1)] ; mm5=data3H + + paddd mm1,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd mm7,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad mm1,DESCALE_P1 + psrad mm7,DESCALE_P1 + paddd mm3,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd mm5,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad mm3,DESCALE_P1 + psrad mm5,DESCALE_P1 + + packssdw mm1,mm7 ; mm1=data5 + packssdw mm3,mm5 ; mm3=data3 + + movq MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)], mm1 + movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3 + + add edx, byte 4*DCTSIZE*SIZEOF_DCTELEM + dec ecx + jnz near .rowloop + + ; ---- Pass 2: process columns. + + mov edx, POINTER [data(eax)] ; (DCTELEM *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.columnloop: + + movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)] + movq mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)] + + ; mm0=(02 12 22 32), mm2=(42 52 62 72) + ; mm1=(03 13 23 33), mm3=(43 53 63 73) + + movq mm4,mm0 ; transpose coefficients(phase 1) + punpcklwd mm0,mm1 ; mm0=(02 03 12 13) + punpckhwd mm4,mm1 ; mm4=(22 23 32 33) + movq mm5,mm2 ; transpose coefficients(phase 1) + punpcklwd mm2,mm3 ; mm2=(42 43 52 53) + punpckhwd mm5,mm3 ; mm5=(62 63 72 73) + + movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)] + movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)] + movq mm1, MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)] + movq mm3, MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)] + + ; mm6=(00 10 20 30), mm1=(40 50 60 70) + ; mm7=(01 11 21 31), mm3=(41 51 61 71) + + movq MMWORD [wk(0)], mm4 ; wk(0)=(22 23 32 33) + movq MMWORD [wk(1)], mm2 ; wk(1)=(42 43 52 53) + + movq mm4,mm6 ; transpose coefficients(phase 1) + punpcklwd mm6,mm7 ; mm6=(00 01 10 11) + punpckhwd mm4,mm7 ; mm4=(20 21 30 31) + movq mm2,mm1 ; transpose coefficients(phase 1) + punpcklwd mm1,mm3 ; mm1=(40 41 50 51) + punpckhwd mm2,mm3 ; mm2=(60 61 70 71) + + movq mm7,mm6 ; transpose coefficients(phase 2) + punpckldq mm6,mm0 ; mm6=(00 01 02 03)=data0 + punpckhdq mm7,mm0 ; mm7=(10 11 12 13)=data1 + movq mm3,mm2 ; transpose coefficients(phase 2) + punpckldq mm2,mm5 ; mm2=(60 61 62 63)=data6 + punpckhdq mm3,mm5 ; mm3=(70 71 72 73)=data7 + + movq mm0,mm7 + movq mm5,mm6 + psubw mm7,mm2 ; mm7=data1-data6=tmp6 + psubw mm6,mm3 ; mm6=data0-data7=tmp7 + paddw mm0,mm2 ; mm0=data1+data6=tmp1 + paddw mm5,mm3 ; mm5=data0+data7=tmp0 + + movq mm2, MMWORD [wk(0)] ; mm2=(22 23 32 33) + movq mm3, MMWORD [wk(1)] ; mm3=(42 43 52 53) + movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6 + movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7 + + movq mm7,mm4 ; transpose coefficients(phase 2) + punpckldq mm4,mm2 ; mm4=(20 21 22 23)=data2 + punpckhdq mm7,mm2 ; mm7=(30 31 32 33)=data3 + movq mm6,mm1 ; transpose coefficients(phase 2) + punpckldq mm1,mm3 ; mm1=(40 41 42 43)=data4 + punpckhdq mm6,mm3 ; mm6=(50 51 52 53)=data5 + + movq mm2,mm7 + movq mm3,mm4 + paddw mm7,mm1 ; mm7=data3+data4=tmp3 + paddw mm4,mm6 ; mm4=data2+data5=tmp2 + psubw mm2,mm1 ; mm2=data3-data4=tmp4 + psubw mm3,mm6 ; mm3=data2-data5=tmp5 + + ; -- Even part + + movq mm1,mm5 + movq mm6,mm0 + paddw mm5,mm7 ; mm5=tmp10 + paddw mm0,mm4 ; mm0=tmp11 + psubw mm1,mm7 ; mm1=tmp13 + psubw mm6,mm4 ; mm6=tmp12 + + movq mm7,mm5 + paddw mm5,mm0 ; mm5=tmp10+tmp11 + psubw mm7,mm0 ; mm7=tmp10-tmp11 + + paddw mm5,[GOTOFF(ebx,PW_DESCALE_P2X)] + paddw mm7,[GOTOFF(ebx,PW_DESCALE_P2X)] + psraw mm5,PASS1_BITS ; mm5=data0 + psraw mm7,PASS1_BITS ; mm7=data4 + + movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5 + movq MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)], mm7 + + ; (Original) + ; z1 = (tmp12 + tmp13) * 0.541196100; + ; data2 = z1 + tmp13 * 0.765366865; + ; data6 = z1 + tmp12 * -1.847759065; + ; + ; (This implementation) + ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100; + ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065); + + movq mm4,mm1 ; mm1=tmp13 + movq mm0,mm1 + punpcklwd mm4,mm6 ; mm6=tmp12 + punpckhwd mm0,mm6 + movq mm1,mm4 + movq mm6,mm0 + pmaddwd mm4,[GOTOFF(ebx,PW_F130_F054)] ; mm4=data2L + pmaddwd mm0,[GOTOFF(ebx,PW_F130_F054)] ; mm0=data2H + pmaddwd mm1,[GOTOFF(ebx,PW_F054_MF130)] ; mm1=data6L + pmaddwd mm6,[GOTOFF(ebx,PW_F054_MF130)] ; mm6=data6H + + paddd mm4,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd mm0,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad mm4,DESCALE_P2 + psrad mm0,DESCALE_P2 + paddd mm1,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd mm6,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad mm1,DESCALE_P2 + psrad mm6,DESCALE_P2 + + packssdw mm4,mm0 ; mm4=data2 + packssdw mm1,mm6 ; mm1=data6 + + movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4 + movq MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)], mm1 + + ; -- Odd part + + movq mm5, MMWORD [wk(0)] ; mm5=tmp6 + movq mm7, MMWORD [wk(1)] ; mm7=tmp7 + + movq mm0,mm2 ; mm2=tmp4 + movq mm6,mm3 ; mm3=tmp5 + paddw mm0,mm5 ; mm0=z3 + paddw mm6,mm7 ; mm6=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movq mm4,mm0 + movq mm1,mm0 + punpcklwd mm4,mm6 + punpckhwd mm1,mm6 + movq mm0,mm4 + movq mm6,mm1 + pmaddwd mm4,[GOTOFF(ebx,PW_MF078_F117)] ; mm4=z3L + pmaddwd mm1,[GOTOFF(ebx,PW_MF078_F117)] ; mm1=z3H + pmaddwd mm0,[GOTOFF(ebx,PW_F117_F078)] ; mm0=z4L + pmaddwd mm6,[GOTOFF(ebx,PW_F117_F078)] ; mm6=z4H + + movq MMWORD [wk(0)], mm4 ; wk(0)=z3L + movq MMWORD [wk(1)], mm1 ; wk(1)=z3H + + ; (Original) + ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; + ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869; + ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4; + ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4; + ; + ; (This implementation) + ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223; + ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447; + ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447); + ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223); + ; data7 = tmp4 + z3; data5 = tmp5 + z4; + ; data3 = tmp6 + z3; data1 = tmp7 + z4; + + movq mm4,mm2 + movq mm1,mm2 + punpcklwd mm4,mm7 + punpckhwd mm1,mm7 + movq mm2,mm4 + movq mm7,mm1 + pmaddwd mm4,[GOTOFF(ebx,PW_MF060_MF089)] ; mm4=tmp4L + pmaddwd mm1,[GOTOFF(ebx,PW_MF060_MF089)] ; mm1=tmp4H + pmaddwd mm2,[GOTOFF(ebx,PW_MF089_F060)] ; mm2=tmp7L + pmaddwd mm7,[GOTOFF(ebx,PW_MF089_F060)] ; mm7=tmp7H + + paddd mm4, MMWORD [wk(0)] ; mm4=data7L + paddd mm1, MMWORD [wk(1)] ; mm1=data7H + paddd mm2,mm0 ; mm2=data1L + paddd mm7,mm6 ; mm7=data1H + + paddd mm4,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd mm1,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad mm4,DESCALE_P2 + psrad mm1,DESCALE_P2 + paddd mm2,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd mm7,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad mm2,DESCALE_P2 + psrad mm7,DESCALE_P2 + + packssdw mm4,mm1 ; mm4=data7 + packssdw mm2,mm7 ; mm2=data1 + + movq MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)], mm4 + movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2 + + movq mm1,mm3 + movq mm7,mm3 + punpcklwd mm1,mm5 + punpckhwd mm7,mm5 + movq mm3,mm1 + movq mm5,mm7 + pmaddwd mm1,[GOTOFF(ebx,PW_MF050_MF256)] ; mm1=tmp5L + pmaddwd mm7,[GOTOFF(ebx,PW_MF050_MF256)] ; mm7=tmp5H + pmaddwd mm3,[GOTOFF(ebx,PW_MF256_F050)] ; mm3=tmp6L + pmaddwd mm5,[GOTOFF(ebx,PW_MF256_F050)] ; mm5=tmp6H + + paddd mm1,mm0 ; mm1=data5L + paddd mm7,mm6 ; mm7=data5H + paddd mm3, MMWORD [wk(0)] ; mm3=data3L + paddd mm5, MMWORD [wk(1)] ; mm5=data3H + + paddd mm1,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd mm7,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad mm1,DESCALE_P2 + psrad mm7,DESCALE_P2 + paddd mm3,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd mm5,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad mm3,DESCALE_P2 + psrad mm5,DESCALE_P2 + + packssdw mm1,mm7 ; mm1=data5 + packssdw mm3,mm5 ; mm3=data3 + + movq MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)], mm1 + movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3 + + add edx, byte 4*SIZEOF_DCTELEM + dec ecx + jnz near .columnloop + + emms ; empty MMX state + +; pop edi ; unused +; pop esi ; unused +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfss2fst.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfss2fst.asm new file mode 100755 index 0000000..73fc9e5 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfss2fst.asm @@ -0,0 +1,404 @@ +; +; jfss2fst.asm - fast integer FDCT (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a fast, not so accurate integer implementation of +; the forward DCT (Discrete Cosine Transform). The following code is +; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c +; for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 8 ; 14 is also OK. + +%if CONST_BITS == 8 +F_0_382 equ 98 ; FIX(0.382683433) +F_0_541 equ 139 ; FIX(0.541196100) +F_0_707 equ 181 ; FIX(0.707106781) +F_1_306 equ 334 ; FIX(1.306562965) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_382 equ DESCALE( 410903207,30-CONST_BITS) ; FIX(0.382683433) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_707 equ DESCALE( 759250124,30-CONST_BITS) ; FIX(0.707106781) +F_1_306 equ DESCALE(1402911301,30-CONST_BITS) ; FIX(1.306562965) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + +; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow) +; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw) + +%define PRE_MULTIPLY_SCALE_BITS 2 +%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS) + + alignz 16 + global EXTN(jconst_fdct_ifast_sse2) + +EXTN(jconst_fdct_ifast_sse2): + +PW_F0707 times 8 dw F_0_707 << CONST_SHIFT +PW_F0382 times 8 dw F_0_382 << CONST_SHIFT +PW_F0541 times 8 dw F_0_541 << CONST_SHIFT +PW_F1306 times 8 dw F_1_306 << CONST_SHIFT + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_ifast_sse2 (DCTELEM * data) +; + +%define data(b) (b)+8 ; DCTELEM * data + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_fdct_ifast_sse2) + +EXTN(jsimd_fdct_ifast_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; unused +; push edx ; need not be preserved +; push esi ; unused +; push edi ; unused + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process rows. + + mov edx, POINTER [data(eax)] ; (DCTELEM *) + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)] + movdqa xmm2, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)] + + ; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27) + ; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37) + + movdqa xmm4,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm1 ; xmm0=(00 10 01 11 02 12 03 13) + punpckhwd xmm4,xmm1 ; xmm4=(04 14 05 15 06 16 07 17) + movdqa xmm5,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm3 ; xmm2=(20 30 21 31 22 32 23 33) + punpckhwd xmm5,xmm3 ; xmm5=(24 34 25 35 26 36 27 37) + + movdqa xmm6, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)] + movdqa xmm7, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)] + + ; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62) + ; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63) + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(20 30 21 31 22 32 23 33) + movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(24 34 25 35 26 36 27 37) + + movdqa xmm2,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm7 ; xmm6=(40 50 41 51 42 52 43 53) + punpckhwd xmm2,xmm7 ; xmm2=(44 54 45 55 46 56 47 57) + movdqa xmm5,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm3 ; xmm1=(60 70 61 71 62 72 63 73) + punpckhwd xmm5,xmm3 ; xmm5=(64 74 65 75 66 76 67 77) + + movdqa xmm7,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm1 ; xmm6=(40 50 60 70 41 51 61 71) + punpckhdq xmm7,xmm1 ; xmm7=(42 52 62 72 43 53 63 73) + movdqa xmm3,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm5 ; xmm2=(44 54 64 74 45 55 65 75) + punpckhdq xmm3,xmm5 ; xmm3=(46 56 66 76 47 57 67 77) + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(20 30 21 31 22 32 23 33) + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(24 34 25 35 26 36 27 37) + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=(42 52 62 72 43 53 63 73) + movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=(44 54 64 74 45 55 65 75) + + movdqa xmm7,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm1 ; xmm0=(00 10 20 30 01 11 21 31) + punpckhdq xmm7,xmm1 ; xmm7=(02 12 22 32 03 13 23 33) + movdqa xmm2,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm5 ; xmm4=(04 14 24 34 05 15 25 35) + punpckhdq xmm2,xmm5 ; xmm2=(06 16 26 36 07 17 27 37) + + movdqa xmm1,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm6 ; xmm0=(00 10 20 30 40 50 60 70)=data0 + punpckhqdq xmm1,xmm6 ; xmm1=(01 11 21 31 41 51 61 71)=data1 + movdqa xmm5,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm3 ; xmm2=(06 16 26 36 46 56 66 76)=data6 + punpckhqdq xmm5,xmm3 ; xmm5=(07 17 27 37 47 57 67 77)=data7 + + movdqa xmm6,xmm1 + movdqa xmm3,xmm0 + psubw xmm1,xmm2 ; xmm1=data1-data6=tmp6 + psubw xmm0,xmm5 ; xmm0=data0-data7=tmp7 + paddw xmm6,xmm2 ; xmm6=data1+data6=tmp1 + paddw xmm3,xmm5 ; xmm3=data0+data7=tmp0 + + movdqa xmm2, XMMWORD [wk(0)] ; xmm2=(42 52 62 72 43 53 63 73) + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(44 54 64 74 45 55 65 75) + movdqa XMMWORD [wk(0)], xmm1 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp7 + + movdqa xmm1,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm2 ; xmm7=(02 12 22 32 42 52 62 72)=data2 + punpckhqdq xmm1,xmm2 ; xmm1=(03 13 23 33 43 53 63 73)=data3 + movdqa xmm0,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm5 ; xmm4=(04 14 24 34 44 54 64 74)=data4 + punpckhqdq xmm0,xmm5 ; xmm0=(05 15 25 35 45 55 65 75)=data5 + + movdqa xmm2,xmm1 + movdqa xmm5,xmm7 + paddw xmm1,xmm4 ; xmm1=data3+data4=tmp3 + paddw xmm7,xmm0 ; xmm7=data2+data5=tmp2 + psubw xmm2,xmm4 ; xmm2=data3-data4=tmp4 + psubw xmm5,xmm0 ; xmm5=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm4,xmm3 + movdqa xmm0,xmm6 + psubw xmm3,xmm1 ; xmm3=tmp13 + psubw xmm6,xmm7 ; xmm6=tmp12 + paddw xmm4,xmm1 ; xmm4=tmp10 + paddw xmm0,xmm7 ; xmm0=tmp11 + + paddw xmm6,xmm3 + psllw xmm6,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm6,[GOTOFF(ebx,PW_F0707)] ; xmm6=z1 + + movdqa xmm1,xmm4 + movdqa xmm7,xmm3 + psubw xmm4,xmm0 ; xmm4=data4 + psubw xmm3,xmm6 ; xmm3=data6 + paddw xmm1,xmm0 ; xmm1=data0 + paddw xmm7,xmm6 ; xmm7=data2 + + movdqa xmm0, XMMWORD [wk(0)] ; xmm0=tmp6 + movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp7 + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=data4 + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=data6 + + ; -- Odd part + + paddw xmm2,xmm5 ; xmm2=tmp10 + paddw xmm5,xmm0 ; xmm5=tmp11 + paddw xmm0,xmm6 ; xmm0=tmp12, xmm6=tmp7 + + psllw xmm2,PRE_MULTIPLY_SCALE_BITS + psllw xmm0,PRE_MULTIPLY_SCALE_BITS + + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm5,[GOTOFF(ebx,PW_F0707)] ; xmm5=z3 + + movdqa xmm4,xmm2 ; xmm4=tmp10 + psubw xmm2,xmm0 + pmulhw xmm2,[GOTOFF(ebx,PW_F0382)] ; xmm2=z5 + pmulhw xmm4,[GOTOFF(ebx,PW_F0541)] ; xmm4=MULTIPLY(tmp10,FIX_0_541196) + pmulhw xmm0,[GOTOFF(ebx,PW_F1306)] ; xmm0=MULTIPLY(tmp12,FIX_1_306562) + paddw xmm4,xmm2 ; xmm4=z2 + paddw xmm0,xmm2 ; xmm0=z4 + + movdqa xmm3,xmm6 + psubw xmm6,xmm5 ; xmm6=z13 + paddw xmm3,xmm5 ; xmm3=z11 + + movdqa xmm2,xmm6 + movdqa xmm5,xmm3 + psubw xmm6,xmm4 ; xmm6=data3 + psubw xmm3,xmm0 ; xmm3=data7 + paddw xmm2,xmm4 ; xmm2=data5 + paddw xmm5,xmm0 ; xmm5=data1 + + ; ---- Pass 2: process columns. + +; mov edx, POINTER [data(eax)] ; (DCTELEM *) + + ; xmm1=(00 10 20 30 40 50 60 70), xmm7=(02 12 22 32 42 52 62 72) + ; xmm5=(01 11 21 31 41 51 61 71), xmm6=(03 13 23 33 43 53 63 73) + + movdqa xmm4,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm5 ; xmm1=(00 01 10 11 20 21 30 31) + punpckhwd xmm4,xmm5 ; xmm4=(40 41 50 51 60 61 70 71) + movdqa xmm0,xmm7 ; transpose coefficients(phase 1) + punpcklwd xmm7,xmm6 ; xmm7=(02 03 12 13 22 23 32 33) + punpckhwd xmm0,xmm6 ; xmm0=(42 43 52 53 62 63 72 73) + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=col4 + movdqa xmm6, XMMWORD [wk(1)] ; xmm6=col6 + + ; xmm5=(04 14 24 34 44 54 64 74), xmm6=(06 16 26 36 46 56 66 76) + ; xmm2=(05 15 25 35 45 55 65 75), xmm3=(07 17 27 37 47 57 67 77) + + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=(02 03 12 13 22 23 32 33) + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(42 43 52 53 62 63 72 73) + + movdqa xmm7,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm2 ; xmm5=(04 05 14 15 24 25 34 35) + punpckhwd xmm7,xmm2 ; xmm7=(44 45 54 55 64 65 74 75) + movdqa xmm0,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm3 ; xmm6=(06 07 16 17 26 27 36 37) + punpckhwd xmm0,xmm3 ; xmm0=(46 47 56 57 66 67 76 77) + + movdqa xmm2,xmm5 ; transpose coefficients(phase 2) + punpckldq xmm5,xmm6 ; xmm5=(04 05 06 07 14 15 16 17) + punpckhdq xmm2,xmm6 ; xmm2=(24 25 26 27 34 35 36 37) + movdqa xmm3,xmm7 ; transpose coefficients(phase 2) + punpckldq xmm7,xmm0 ; xmm7=(44 45 46 47 54 55 56 57) + punpckhdq xmm3,xmm0 ; xmm3=(64 65 66 67 74 75 76 77) + + movdqa xmm6, XMMWORD [wk(0)] ; xmm6=(02 03 12 13 22 23 32 33) + movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(42 43 52 53 62 63 72 73) + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(24 25 26 27 34 35 36 37) + movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(44 45 46 47 54 55 56 57) + + movdqa xmm2,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm6 ; xmm1=(00 01 02 03 10 11 12 13) + punpckhdq xmm2,xmm6 ; xmm2=(20 21 22 23 30 31 32 33) + movdqa xmm7,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm0 ; xmm4=(40 41 42 43 50 51 52 53) + punpckhdq xmm7,xmm0 ; xmm7=(60 61 62 63 70 71 72 73) + + movdqa xmm6,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm5 ; xmm1=(00 01 02 03 04 05 06 07)=data0 + punpckhqdq xmm6,xmm5 ; xmm6=(10 11 12 13 14 15 16 17)=data1 + movdqa xmm0,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm3 ; xmm7=(60 61 62 63 64 65 66 67)=data6 + punpckhqdq xmm0,xmm3 ; xmm0=(70 71 72 73 74 75 76 77)=data7 + + movdqa xmm5,xmm6 + movdqa xmm3,xmm1 + psubw xmm6,xmm7 ; xmm6=data1-data6=tmp6 + psubw xmm1,xmm0 ; xmm1=data0-data7=tmp7 + paddw xmm5,xmm7 ; xmm5=data1+data6=tmp1 + paddw xmm3,xmm0 ; xmm3=data0+data7=tmp0 + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(24 25 26 27 34 35 36 37) + movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(44 45 46 47 54 55 56 57) + movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=tmp7 + + movdqa xmm6,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm7 ; xmm2=(20 21 22 23 24 25 26 27)=data2 + punpckhqdq xmm6,xmm7 ; xmm6=(30 31 32 33 34 35 36 37)=data3 + movdqa xmm1,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm0 ; xmm4=(40 41 42 43 44 45 46 47)=data4 + punpckhqdq xmm1,xmm0 ; xmm1=(50 51 52 53 54 55 56 57)=data5 + + movdqa xmm7,xmm6 + movdqa xmm0,xmm2 + paddw xmm6,xmm4 ; xmm6=data3+data4=tmp3 + paddw xmm2,xmm1 ; xmm2=data2+data5=tmp2 + psubw xmm7,xmm4 ; xmm7=data3-data4=tmp4 + psubw xmm0,xmm1 ; xmm0=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm4,xmm3 + movdqa xmm1,xmm5 + psubw xmm3,xmm6 ; xmm3=tmp13 + psubw xmm5,xmm2 ; xmm5=tmp12 + paddw xmm4,xmm6 ; xmm4=tmp10 + paddw xmm1,xmm2 ; xmm1=tmp11 + + paddw xmm5,xmm3 + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm5,[GOTOFF(ebx,PW_F0707)] ; xmm5=z1 + + movdqa xmm6,xmm4 + movdqa xmm2,xmm3 + psubw xmm4,xmm1 ; xmm4=data4 + psubw xmm3,xmm5 ; xmm3=data6 + paddw xmm6,xmm1 ; xmm6=data0 + paddw xmm2,xmm5 ; xmm2=data2 + + movdqa XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)], xmm4 + movdqa XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)], xmm3 + movdqa XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)], xmm6 + movdqa XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)], xmm2 + + ; -- Odd part + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=tmp6 + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp7 + + paddw xmm7,xmm0 ; xmm7=tmp10 + paddw xmm0,xmm1 ; xmm0=tmp11 + paddw xmm1,xmm5 ; xmm1=tmp12, xmm5=tmp7 + + psllw xmm7,PRE_MULTIPLY_SCALE_BITS + psllw xmm1,PRE_MULTIPLY_SCALE_BITS + + psllw xmm0,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm0,[GOTOFF(ebx,PW_F0707)] ; xmm0=z3 + + movdqa xmm4,xmm7 ; xmm4=tmp10 + psubw xmm7,xmm1 + pmulhw xmm7,[GOTOFF(ebx,PW_F0382)] ; xmm7=z5 + pmulhw xmm4,[GOTOFF(ebx,PW_F0541)] ; xmm4=MULTIPLY(tmp10,FIX_0_541196) + pmulhw xmm1,[GOTOFF(ebx,PW_F1306)] ; xmm1=MULTIPLY(tmp12,FIX_1_306562) + paddw xmm4,xmm7 ; xmm4=z2 + paddw xmm1,xmm7 ; xmm1=z4 + + movdqa xmm3,xmm5 + psubw xmm5,xmm0 ; xmm5=z13 + paddw xmm3,xmm0 ; xmm3=z11 + + movdqa xmm6,xmm5 + movdqa xmm2,xmm3 + psubw xmm5,xmm4 ; xmm5=data3 + psubw xmm3,xmm1 ; xmm3=data7 + paddw xmm6,xmm4 ; xmm6=data5 + paddw xmm2,xmm1 ; xmm2=data1 + + movdqa XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)], xmm5 + movdqa XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)], xmm3 + movdqa XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)], xmm6 + movdqa XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)], xmm2 + +; pop edi ; unused +; pop esi ; unused +; pop edx ; need not be preserved +; pop ecx ; unused + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfss2int.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfss2int.asm new file mode 100755 index 0000000..5e3f2aa --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfss2int.asm @@ -0,0 +1,634 @@ +; +; jfss2int.asm - accurate integer FDCT (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a slow-but-accurate integer implementation of the +; forward DCT (Discrete Cosine Transform). The following code is based +; directly on the IJG's original jfdctint.c; see the jfdctint.c for +; more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1 (CONST_BITS-PASS1_BITS) +%define DESCALE_P2 (CONST_BITS+PASS1_BITS) + +%if CONST_BITS == 13 +F_0_298 equ 2446 ; FIX(0.298631336) +F_0_390 equ 3196 ; FIX(0.390180644) +F_0_541 equ 4433 ; FIX(0.541196100) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_175 equ 9633 ; FIX(1.175875602) +F_1_501 equ 12299 ; FIX(1.501321110) +F_1_847 equ 15137 ; FIX(1.847759065) +F_1_961 equ 16069 ; FIX(1.961570560) +F_2_053 equ 16819 ; FIX(2.053119869) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_072 equ 25172 ; FIX(3.072711026) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) +F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) +F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) +F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fdct_islow_sse2) + +EXTN(jconst_fdct_islow_sse2): + +PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541 +PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847) +PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175 +PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390) +PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899 +PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899) +PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562 +PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562) +PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1) +PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1) +PW_DESCALE_P2X times 8 dw 1 << (PASS1_BITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_islow_sse2 (DCTELEM * data) +; + +%define data(b) (b)+8 ; DCTELEM * data + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 6 + + align 16 + global EXTN(jsimd_fdct_islow_sse2) + +EXTN(jsimd_fdct_islow_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; unused +; push edx ; need not be preserved +; push esi ; unused +; push edi ; unused + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process rows. + + mov edx, POINTER [data(eax)] ; (DCTELEM *) + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)] + movdqa xmm2, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)] + + ; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27) + ; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37) + + movdqa xmm4,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm1 ; xmm0=(00 10 01 11 02 12 03 13) + punpckhwd xmm4,xmm1 ; xmm4=(04 14 05 15 06 16 07 17) + movdqa xmm5,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm3 ; xmm2=(20 30 21 31 22 32 23 33) + punpckhwd xmm5,xmm3 ; xmm5=(24 34 25 35 26 36 27 37) + + movdqa xmm6, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)] + movdqa xmm7, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)] + + ; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62) + ; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63) + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(20 30 21 31 22 32 23 33) + movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(24 34 25 35 26 36 27 37) + + movdqa xmm2,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm7 ; xmm6=(40 50 41 51 42 52 43 53) + punpckhwd xmm2,xmm7 ; xmm2=(44 54 45 55 46 56 47 57) + movdqa xmm5,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm3 ; xmm1=(60 70 61 71 62 72 63 73) + punpckhwd xmm5,xmm3 ; xmm5=(64 74 65 75 66 76 67 77) + + movdqa xmm7,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm1 ; xmm6=(40 50 60 70 41 51 61 71) + punpckhdq xmm7,xmm1 ; xmm7=(42 52 62 72 43 53 63 73) + movdqa xmm3,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm5 ; xmm2=(44 54 64 74 45 55 65 75) + punpckhdq xmm3,xmm5 ; xmm3=(46 56 66 76 47 57 67 77) + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(20 30 21 31 22 32 23 33) + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(24 34 25 35 26 36 27 37) + movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=(42 52 62 72 43 53 63 73) + movdqa XMMWORD [wk(3)], xmm2 ; wk(3)=(44 54 64 74 45 55 65 75) + + movdqa xmm7,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm1 ; xmm0=(00 10 20 30 01 11 21 31) + punpckhdq xmm7,xmm1 ; xmm7=(02 12 22 32 03 13 23 33) + movdqa xmm2,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm5 ; xmm4=(04 14 24 34 05 15 25 35) + punpckhdq xmm2,xmm5 ; xmm2=(06 16 26 36 07 17 27 37) + + movdqa xmm1,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm6 ; xmm0=(00 10 20 30 40 50 60 70)=data0 + punpckhqdq xmm1,xmm6 ; xmm1=(01 11 21 31 41 51 61 71)=data1 + movdqa xmm5,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm3 ; xmm2=(06 16 26 36 46 56 66 76)=data6 + punpckhqdq xmm5,xmm3 ; xmm5=(07 17 27 37 47 57 67 77)=data7 + + movdqa xmm6,xmm1 + movdqa xmm3,xmm0 + psubw xmm1,xmm2 ; xmm1=data1-data6=tmp6 + psubw xmm0,xmm5 ; xmm0=data0-data7=tmp7 + paddw xmm6,xmm2 ; xmm6=data1+data6=tmp1 + paddw xmm3,xmm5 ; xmm3=data0+data7=tmp0 + + movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(42 52 62 72 43 53 63 73) + movdqa xmm5, XMMWORD [wk(3)] ; xmm5=(44 54 64 74 45 55 65 75) + movdqa XMMWORD [wk(0)], xmm1 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp7 + + movdqa xmm1,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm2 ; xmm7=(02 12 22 32 42 52 62 72)=data2 + punpckhqdq xmm1,xmm2 ; xmm1=(03 13 23 33 43 53 63 73)=data3 + movdqa xmm0,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm5 ; xmm4=(04 14 24 34 44 54 64 74)=data4 + punpckhqdq xmm0,xmm5 ; xmm0=(05 15 25 35 45 55 65 75)=data5 + + movdqa xmm2,xmm1 + movdqa xmm5,xmm7 + paddw xmm1,xmm4 ; xmm1=data3+data4=tmp3 + paddw xmm7,xmm0 ; xmm7=data2+data5=tmp2 + psubw xmm2,xmm4 ; xmm2=data3-data4=tmp4 + psubw xmm5,xmm0 ; xmm5=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm4,xmm3 + movdqa xmm0,xmm6 + paddw xmm3,xmm1 ; xmm3=tmp10 + paddw xmm6,xmm7 ; xmm6=tmp11 + psubw xmm4,xmm1 ; xmm4=tmp13 + psubw xmm0,xmm7 ; xmm0=tmp12 + + movdqa xmm1,xmm3 + paddw xmm3,xmm6 ; xmm3=tmp10+tmp11 + psubw xmm1,xmm6 ; xmm1=tmp10-tmp11 + + psllw xmm3,PASS1_BITS ; xmm3=data0 + psllw xmm1,PASS1_BITS ; xmm1=data4 + + movdqa XMMWORD [wk(2)], xmm3 ; wk(2)=data0 + movdqa XMMWORD [wk(3)], xmm1 ; wk(3)=data4 + + ; (Original) + ; z1 = (tmp12 + tmp13) * 0.541196100; + ; data2 = z1 + tmp13 * 0.765366865; + ; data6 = z1 + tmp12 * -1.847759065; + ; + ; (This implementation) + ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100; + ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065); + + movdqa xmm7,xmm4 ; xmm4=tmp13 + movdqa xmm6,xmm4 + punpcklwd xmm7,xmm0 ; xmm0=tmp12 + punpckhwd xmm6,xmm0 + movdqa xmm4,xmm7 + movdqa xmm0,xmm6 + pmaddwd xmm7,[GOTOFF(ebx,PW_F130_F054)] ; xmm7=data2L + pmaddwd xmm6,[GOTOFF(ebx,PW_F130_F054)] ; xmm6=data2H + pmaddwd xmm4,[GOTOFF(ebx,PW_F054_MF130)] ; xmm4=data6L + pmaddwd xmm0,[GOTOFF(ebx,PW_F054_MF130)] ; xmm0=data6H + + paddd xmm7,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd xmm6,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad xmm7,DESCALE_P1 + psrad xmm6,DESCALE_P1 + paddd xmm4,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd xmm0,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad xmm4,DESCALE_P1 + psrad xmm0,DESCALE_P1 + + packssdw xmm7,xmm6 ; xmm7=data2 + packssdw xmm4,xmm0 ; xmm4=data6 + + movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=data2 + movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=data6 + + ; -- Odd part + + movdqa xmm3, XMMWORD [wk(0)] ; xmm3=tmp6 + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=tmp7 + + movdqa xmm6,xmm2 ; xmm2=tmp4 + movdqa xmm0,xmm5 ; xmm5=tmp5 + paddw xmm6,xmm3 ; xmm6=z3 + paddw xmm0,xmm1 ; xmm0=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm7,xmm6 + movdqa xmm4,xmm6 + punpcklwd xmm7,xmm0 + punpckhwd xmm4,xmm0 + movdqa xmm6,xmm7 + movdqa xmm0,xmm4 + pmaddwd xmm7,[GOTOFF(ebx,PW_MF078_F117)] ; xmm7=z3L + pmaddwd xmm4,[GOTOFF(ebx,PW_MF078_F117)] ; xmm4=z3H + pmaddwd xmm6,[GOTOFF(ebx,PW_F117_F078)] ; xmm6=z4L + pmaddwd xmm0,[GOTOFF(ebx,PW_F117_F078)] ; xmm0=z4H + + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=z3L + movdqa XMMWORD [wk(1)], xmm4 ; wk(1)=z3H + + ; (Original) + ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; + ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869; + ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4; + ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4; + ; + ; (This implementation) + ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223; + ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447; + ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447); + ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223); + ; data7 = tmp4 + z3; data5 = tmp5 + z4; + ; data3 = tmp6 + z3; data1 = tmp7 + z4; + + movdqa xmm7,xmm2 + movdqa xmm4,xmm2 + punpcklwd xmm7,xmm1 + punpckhwd xmm4,xmm1 + movdqa xmm2,xmm7 + movdqa xmm1,xmm4 + pmaddwd xmm7,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm7=tmp4L + pmaddwd xmm4,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm4=tmp4H + pmaddwd xmm2,[GOTOFF(ebx,PW_MF089_F060)] ; xmm2=tmp7L + pmaddwd xmm1,[GOTOFF(ebx,PW_MF089_F060)] ; xmm1=tmp7H + + paddd xmm7, XMMWORD [wk(0)] ; xmm7=data7L + paddd xmm4, XMMWORD [wk(1)] ; xmm4=data7H + paddd xmm2,xmm6 ; xmm2=data1L + paddd xmm1,xmm0 ; xmm1=data1H + + paddd xmm7,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd xmm4,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad xmm7,DESCALE_P1 + psrad xmm4,DESCALE_P1 + paddd xmm2,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd xmm1,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad xmm2,DESCALE_P1 + psrad xmm1,DESCALE_P1 + + packssdw xmm7,xmm4 ; xmm7=data7 + packssdw xmm2,xmm1 ; xmm2=data1 + + movdqa xmm4,xmm5 + movdqa xmm1,xmm5 + punpcklwd xmm4,xmm3 + punpckhwd xmm1,xmm3 + movdqa xmm5,xmm4 + movdqa xmm3,xmm1 + pmaddwd xmm4,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm4=tmp5L + pmaddwd xmm1,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm1=tmp5H + pmaddwd xmm5,[GOTOFF(ebx,PW_MF256_F050)] ; xmm5=tmp6L + pmaddwd xmm3,[GOTOFF(ebx,PW_MF256_F050)] ; xmm3=tmp6H + + paddd xmm4,xmm6 ; xmm4=data5L + paddd xmm1,xmm0 ; xmm1=data5H + paddd xmm5, XMMWORD [wk(0)] ; xmm5=data3L + paddd xmm3, XMMWORD [wk(1)] ; xmm3=data3H + + paddd xmm4,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd xmm1,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad xmm4,DESCALE_P1 + psrad xmm1,DESCALE_P1 + paddd xmm5,[GOTOFF(ebx,PD_DESCALE_P1)] + paddd xmm3,[GOTOFF(ebx,PD_DESCALE_P1)] + psrad xmm5,DESCALE_P1 + psrad xmm3,DESCALE_P1 + + packssdw xmm4,xmm1 ; xmm4=data5 + packssdw xmm5,xmm3 ; xmm5=data3 + + ; ---- Pass 2: process columns. + +; mov edx, POINTER [data(eax)] ; (DCTELEM *) + + movdqa xmm6, XMMWORD [wk(2)] ; xmm6=col0 + movdqa xmm0, XMMWORD [wk(4)] ; xmm0=col2 + + ; xmm6=(00 10 20 30 40 50 60 70), xmm0=(02 12 22 32 42 52 62 72) + ; xmm2=(01 11 21 31 41 51 61 71), xmm5=(03 13 23 33 43 53 63 73) + + movdqa xmm1,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm2 ; xmm6=(00 01 10 11 20 21 30 31) + punpckhwd xmm1,xmm2 ; xmm1=(40 41 50 51 60 61 70 71) + movdqa xmm3,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm5 ; xmm0=(02 03 12 13 22 23 32 33) + punpckhwd xmm3,xmm5 ; xmm3=(42 43 52 53 62 63 72 73) + + movdqa xmm2, XMMWORD [wk(3)] ; xmm2=col4 + movdqa xmm5, XMMWORD [wk(5)] ; xmm5=col6 + + ; xmm2=(04 14 24 34 44 54 64 74), xmm5=(06 16 26 36 46 56 66 76) + ; xmm4=(05 15 25 35 45 55 65 75), xmm7=(07 17 27 37 47 57 67 77) + + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=(02 03 12 13 22 23 32 33) + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(42 43 52 53 62 63 72 73) + + movdqa xmm0,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm4 ; xmm2=(04 05 14 15 24 25 34 35) + punpckhwd xmm0,xmm4 ; xmm0=(44 45 54 55 64 65 74 75) + movdqa xmm3,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm7 ; xmm5=(06 07 16 17 26 27 36 37) + punpckhwd xmm3,xmm7 ; xmm3=(46 47 56 57 66 67 76 77) + + movdqa xmm4,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm5 ; xmm2=(04 05 06 07 14 15 16 17) + punpckhdq xmm4,xmm5 ; xmm4=(24 25 26 27 34 35 36 37) + movdqa xmm7,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm3 ; xmm0=(44 45 46 47 54 55 56 57) + punpckhdq xmm7,xmm3 ; xmm7=(64 65 66 67 74 75 76 77) + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=(02 03 12 13 22 23 32 33) + movdqa xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53 62 63 72 73) + movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=(24 25 26 27 34 35 36 37) + movdqa XMMWORD [wk(3)], xmm0 ; wk(3)=(44 45 46 47 54 55 56 57) + + movdqa xmm4,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm5 ; xmm6=(00 01 02 03 10 11 12 13) + punpckhdq xmm4,xmm5 ; xmm4=(20 21 22 23 30 31 32 33) + movdqa xmm0,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm3 ; xmm1=(40 41 42 43 50 51 52 53) + punpckhdq xmm0,xmm3 ; xmm0=(60 61 62 63 70 71 72 73) + + movdqa xmm5,xmm6 ; transpose coefficients(phase 3) + punpcklqdq xmm6,xmm2 ; xmm6=(00 01 02 03 04 05 06 07)=data0 + punpckhqdq xmm5,xmm2 ; xmm5=(10 11 12 13 14 15 16 17)=data1 + movdqa xmm3,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm7 ; xmm0=(60 61 62 63 64 65 66 67)=data6 + punpckhqdq xmm3,xmm7 ; xmm3=(70 71 72 73 74 75 76 77)=data7 + + movdqa xmm2,xmm5 + movdqa xmm7,xmm6 + psubw xmm5,xmm0 ; xmm5=data1-data6=tmp6 + psubw xmm6,xmm3 ; xmm6=data0-data7=tmp7 + paddw xmm2,xmm0 ; xmm2=data1+data6=tmp1 + paddw xmm7,xmm3 ; xmm7=data0+data7=tmp0 + + movdqa xmm0, XMMWORD [wk(2)] ; xmm0=(24 25 26 27 34 35 36 37) + movdqa xmm3, XMMWORD [wk(3)] ; xmm3=(44 45 46 47 54 55 56 57) + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 + + movdqa xmm5,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm0 ; xmm4=(20 21 22 23 24 25 26 27)=data2 + punpckhqdq xmm5,xmm0 ; xmm5=(30 31 32 33 34 35 36 37)=data3 + movdqa xmm6,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm3 ; xmm1=(40 41 42 43 44 45 46 47)=data4 + punpckhqdq xmm6,xmm3 ; xmm6=(50 51 52 53 54 55 56 57)=data5 + + movdqa xmm0,xmm5 + movdqa xmm3,xmm4 + paddw xmm5,xmm1 ; xmm5=data3+data4=tmp3 + paddw xmm4,xmm6 ; xmm4=data2+data5=tmp2 + psubw xmm0,xmm1 ; xmm0=data3-data4=tmp4 + psubw xmm3,xmm6 ; xmm3=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm1,xmm7 + movdqa xmm6,xmm2 + paddw xmm7,xmm5 ; xmm7=tmp10 + paddw xmm2,xmm4 ; xmm2=tmp11 + psubw xmm1,xmm5 ; xmm1=tmp13 + psubw xmm6,xmm4 ; xmm6=tmp12 + + movdqa xmm5,xmm7 + paddw xmm7,xmm2 ; xmm7=tmp10+tmp11 + psubw xmm5,xmm2 ; xmm5=tmp10-tmp11 + + paddw xmm7,[GOTOFF(ebx,PW_DESCALE_P2X)] + paddw xmm5,[GOTOFF(ebx,PW_DESCALE_P2X)] + psraw xmm7,PASS1_BITS ; xmm7=data0 + psraw xmm5,PASS1_BITS ; xmm5=data4 + + movdqa XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)], xmm7 + movdqa XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)], xmm5 + + ; (Original) + ; z1 = (tmp12 + tmp13) * 0.541196100; + ; data2 = z1 + tmp13 * 0.765366865; + ; data6 = z1 + tmp12 * -1.847759065; + ; + ; (This implementation) + ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100; + ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065); + + movdqa xmm4,xmm1 ; xmm1=tmp13 + movdqa xmm2,xmm1 + punpcklwd xmm4,xmm6 ; xmm6=tmp12 + punpckhwd xmm2,xmm6 + movdqa xmm1,xmm4 + movdqa xmm6,xmm2 + pmaddwd xmm4,[GOTOFF(ebx,PW_F130_F054)] ; xmm4=data2L + pmaddwd xmm2,[GOTOFF(ebx,PW_F130_F054)] ; xmm2=data2H + pmaddwd xmm1,[GOTOFF(ebx,PW_F054_MF130)] ; xmm1=data6L + pmaddwd xmm6,[GOTOFF(ebx,PW_F054_MF130)] ; xmm6=data6H + + paddd xmm4,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd xmm2,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad xmm4,DESCALE_P2 + psrad xmm2,DESCALE_P2 + paddd xmm1,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd xmm6,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad xmm1,DESCALE_P2 + psrad xmm6,DESCALE_P2 + + packssdw xmm4,xmm2 ; xmm4=data2 + packssdw xmm1,xmm6 ; xmm1=data6 + + movdqa XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)], xmm4 + movdqa XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)], xmm1 + + ; -- Odd part + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp6 + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp7 + + movdqa xmm2,xmm0 ; xmm0=tmp4 + movdqa xmm6,xmm3 ; xmm3=tmp5 + paddw xmm2,xmm7 ; xmm2=z3 + paddw xmm6,xmm5 ; xmm6=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm4,xmm2 + movdqa xmm1,xmm2 + punpcklwd xmm4,xmm6 + punpckhwd xmm1,xmm6 + movdqa xmm2,xmm4 + movdqa xmm6,xmm1 + pmaddwd xmm4,[GOTOFF(ebx,PW_MF078_F117)] ; xmm4=z3L + pmaddwd xmm1,[GOTOFF(ebx,PW_MF078_F117)] ; xmm1=z3H + pmaddwd xmm2,[GOTOFF(ebx,PW_F117_F078)] ; xmm2=z4L + pmaddwd xmm6,[GOTOFF(ebx,PW_F117_F078)] ; xmm6=z4H + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=z3L + movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=z3H + + ; (Original) + ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; + ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869; + ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4; + ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4; + ; + ; (This implementation) + ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223; + ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447; + ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447); + ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223); + ; data7 = tmp4 + z3; data5 = tmp5 + z4; + ; data3 = tmp6 + z3; data1 = tmp7 + z4; + + movdqa xmm4,xmm0 + movdqa xmm1,xmm0 + punpcklwd xmm4,xmm5 + punpckhwd xmm1,xmm5 + movdqa xmm0,xmm4 + movdqa xmm5,xmm1 + pmaddwd xmm4,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm4=tmp4L + pmaddwd xmm1,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm1=tmp4H + pmaddwd xmm0,[GOTOFF(ebx,PW_MF089_F060)] ; xmm0=tmp7L + pmaddwd xmm5,[GOTOFF(ebx,PW_MF089_F060)] ; xmm5=tmp7H + + paddd xmm4, XMMWORD [wk(0)] ; xmm4=data7L + paddd xmm1, XMMWORD [wk(1)] ; xmm1=data7H + paddd xmm0,xmm2 ; xmm0=data1L + paddd xmm5,xmm6 ; xmm5=data1H + + paddd xmm4,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd xmm1,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad xmm4,DESCALE_P2 + psrad xmm1,DESCALE_P2 + paddd xmm0,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd xmm5,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad xmm0,DESCALE_P2 + psrad xmm5,DESCALE_P2 + + packssdw xmm4,xmm1 ; xmm4=data7 + packssdw xmm0,xmm5 ; xmm0=data1 + + movdqa XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)], xmm4 + movdqa XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)], xmm0 + + movdqa xmm1,xmm3 + movdqa xmm5,xmm3 + punpcklwd xmm1,xmm7 + punpckhwd xmm5,xmm7 + movdqa xmm3,xmm1 + movdqa xmm7,xmm5 + pmaddwd xmm1,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm1=tmp5L + pmaddwd xmm5,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm5=tmp5H + pmaddwd xmm3,[GOTOFF(ebx,PW_MF256_F050)] ; xmm3=tmp6L + pmaddwd xmm7,[GOTOFF(ebx,PW_MF256_F050)] ; xmm7=tmp6H + + paddd xmm1,xmm2 ; xmm1=data5L + paddd xmm5,xmm6 ; xmm5=data5H + paddd xmm3, XMMWORD [wk(0)] ; xmm3=data3L + paddd xmm7, XMMWORD [wk(1)] ; xmm7=data3H + + paddd xmm1,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd xmm5,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad xmm1,DESCALE_P2 + psrad xmm5,DESCALE_P2 + paddd xmm3,[GOTOFF(ebx,PD_DESCALE_P2)] + paddd xmm7,[GOTOFF(ebx,PD_DESCALE_P2)] + psrad xmm3,DESCALE_P2 + psrad xmm7,DESCALE_P2 + + packssdw xmm1,xmm5 ; xmm1=data5 + packssdw xmm3,xmm7 ; xmm3=data3 + + movdqa XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)], xmm1 + movdqa XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)], xmm3 + +; pop edi ; unused +; pop esi ; unused +; pop edx ; need not be preserved +; pop ecx ; unused + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfsseflt.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfsseflt.asm new file mode 100755 index 0000000..bc54ccc --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jfsseflt.asm @@ -0,0 +1,370 @@ +; +; jfsseflt.asm - floating-point FDCT (SSE) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a floating-point implementation of the forward DCT +; (Discrete Cosine Transform). The following code is based directly on +; the IJG's original jfdctflt.c; see the jfdctflt.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5) + shufps %1,%2,0x44 +%endmacro + +%macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7) + shufps %1,%2,0xEE +%endmacro + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fdct_float_sse) + +EXTN(jconst_fdct_float_sse): + +PD_0_382 times 4 dd 0.382683432365089771728460 +PD_0_707 times 4 dd 0.707106781186547524400844 +PD_0_541 times 4 dd 0.541196100146196984399723 +PD_1_306 times 4 dd 1.306562964876376527856643 + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_float_sse (FAST_FLOAT * data) +; + +%define data(b) (b)+8 ; FAST_FLOAT * data + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_fdct_float_sse) + +EXTN(jsimd_fdct_float_sse): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved +; push esi ; unused +; push edi ; unused + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process rows. + + mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.rowloop: + + movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)] + + ; xmm0=(20 21 22 23), xmm2=(24 25 26 27) + ; xmm1=(30 31 32 33), xmm3=(34 35 36 37) + + movaps xmm4,xmm0 ; transpose coefficients(phase 1) + unpcklps xmm0,xmm1 ; xmm0=(20 30 21 31) + unpckhps xmm4,xmm1 ; xmm4=(22 32 23 33) + movaps xmm5,xmm2 ; transpose coefficients(phase 1) + unpcklps xmm2,xmm3 ; xmm2=(24 34 25 35) + unpckhps xmm5,xmm3 ; xmm5=(26 36 27 37) + + movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] + + ; xmm6=(00 01 02 03), xmm1=(04 05 06 07) + ; xmm7=(10 11 12 13), xmm3=(14 15 16 17) + + movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 32 23 33) + movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(24 34 25 35) + + movaps xmm4,xmm6 ; transpose coefficients(phase 1) + unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11) + unpckhps xmm4,xmm7 ; xmm4=(02 12 03 13) + movaps xmm2,xmm1 ; transpose coefficients(phase 1) + unpcklps xmm1,xmm3 ; xmm1=(04 14 05 15) + unpckhps xmm2,xmm3 ; xmm2=(06 16 07 17) + + movaps xmm7,xmm6 ; transpose coefficients(phase 2) + unpcklps2 xmm6,xmm0 ; xmm6=(00 10 20 30)=data0 + unpckhps2 xmm7,xmm0 ; xmm7=(01 11 21 31)=data1 + movaps xmm3,xmm2 ; transpose coefficients(phase 2) + unpcklps2 xmm2,xmm5 ; xmm2=(06 16 26 36)=data6 + unpckhps2 xmm3,xmm5 ; xmm3=(07 17 27 37)=data7 + + movaps xmm0,xmm7 + movaps xmm5,xmm6 + subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 + subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 + addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 + addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 + + movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 32 23 33) + movaps xmm3, XMMWORD [wk(1)] ; xmm3=(24 34 25 35) + movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 + movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 + + movaps xmm7,xmm4 ; transpose coefficients(phase 2) + unpcklps2 xmm4,xmm2 ; xmm4=(02 12 22 32)=data2 + unpckhps2 xmm7,xmm2 ; xmm7=(03 13 23 33)=data3 + movaps xmm6,xmm1 ; transpose coefficients(phase 2) + unpcklps2 xmm1,xmm3 ; xmm1=(04 14 24 34)=data4 + unpckhps2 xmm6,xmm3 ; xmm6=(05 15 25 35)=data5 + + movaps xmm2,xmm7 + movaps xmm3,xmm4 + addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 + addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 + subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 + subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 + + ; -- Even part + + movaps xmm1,xmm5 + movaps xmm6,xmm0 + subps xmm5,xmm7 ; xmm5=tmp13 + subps xmm0,xmm4 ; xmm0=tmp12 + addps xmm1,xmm7 ; xmm1=tmp10 + addps xmm6,xmm4 ; xmm6=tmp11 + + addps xmm0,xmm5 + mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1 + + movaps xmm7,xmm1 + movaps xmm4,xmm5 + subps xmm1,xmm6 ; xmm1=data4 + subps xmm5,xmm0 ; xmm5=data6 + addps xmm7,xmm6 ; xmm7=data0 + addps xmm4,xmm0 ; xmm4=data2 + + movaps XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4 + + ; -- Odd part + + movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 + movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 + + addps xmm2,xmm3 ; xmm2=tmp10 + addps xmm3,xmm6 ; xmm3=tmp11 + addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 + + mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3 + + movaps xmm1,xmm2 ; xmm1=tmp10 + subps xmm2,xmm6 + mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5 + mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) + mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) + addps xmm1,xmm2 ; xmm1=z2 + addps xmm6,xmm2 ; xmm6=z4 + + movaps xmm5,xmm0 + subps xmm0,xmm3 ; xmm0=z13 + addps xmm5,xmm3 ; xmm5=z11 + + movaps xmm7,xmm0 + movaps xmm4,xmm5 + subps xmm0,xmm1 ; xmm0=data3 + subps xmm5,xmm6 ; xmm5=data7 + addps xmm7,xmm1 ; xmm7=data5 + addps xmm4,xmm6 ; xmm4=data1 + + movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4 + + add edx, 4*DCTSIZE*SIZEOF_FAST_FLOAT + dec ecx + jnz near .rowloop + + ; ---- Pass 2: process columns. + + mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) + mov ecx, DCTSIZE/4 + alignx 16,7 +.columnloop: + + movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)] + + ; xmm0=(02 12 22 32), xmm2=(42 52 62 72) + ; xmm1=(03 13 23 33), xmm3=(43 53 63 73) + + movaps xmm4,xmm0 ; transpose coefficients(phase 1) + unpcklps xmm0,xmm1 ; xmm0=(02 03 12 13) + unpckhps xmm4,xmm1 ; xmm4=(22 23 32 33) + movaps xmm5,xmm2 ; transpose coefficients(phase 1) + unpcklps xmm2,xmm3 ; xmm2=(42 43 52 53) + unpckhps xmm5,xmm3 ; xmm5=(62 63 72 73) + + movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)] + + ; xmm6=(00 10 20 30), xmm1=(40 50 60 70) + ; xmm7=(01 11 21 31), xmm3=(41 51 61 71) + + movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 23 32 33) + movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(42 43 52 53) + + movaps xmm4,xmm6 ; transpose coefficients(phase 1) + unpcklps xmm6,xmm7 ; xmm6=(00 01 10 11) + unpckhps xmm4,xmm7 ; xmm4=(20 21 30 31) + movaps xmm2,xmm1 ; transpose coefficients(phase 1) + unpcklps xmm1,xmm3 ; xmm1=(40 41 50 51) + unpckhps xmm2,xmm3 ; xmm2=(60 61 70 71) + + movaps xmm7,xmm6 ; transpose coefficients(phase 2) + unpcklps2 xmm6,xmm0 ; xmm6=(00 01 02 03)=data0 + unpckhps2 xmm7,xmm0 ; xmm7=(10 11 12 13)=data1 + movaps xmm3,xmm2 ; transpose coefficients(phase 2) + unpcklps2 xmm2,xmm5 ; xmm2=(60 61 62 63)=data6 + unpckhps2 xmm3,xmm5 ; xmm3=(70 71 72 73)=data7 + + movaps xmm0,xmm7 + movaps xmm5,xmm6 + subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 + subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 + addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 + addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 + + movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 23 32 33) + movaps xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53) + movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 + movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 + + movaps xmm7,xmm4 ; transpose coefficients(phase 2) + unpcklps2 xmm4,xmm2 ; xmm4=(20 21 22 23)=data2 + unpckhps2 xmm7,xmm2 ; xmm7=(30 31 32 33)=data3 + movaps xmm6,xmm1 ; transpose coefficients(phase 2) + unpcklps2 xmm1,xmm3 ; xmm1=(40 41 42 43)=data4 + unpckhps2 xmm6,xmm3 ; xmm6=(50 51 52 53)=data5 + + movaps xmm2,xmm7 + movaps xmm3,xmm4 + addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 + addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 + subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 + subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 + + ; -- Even part + + movaps xmm1,xmm5 + movaps xmm6,xmm0 + subps xmm5,xmm7 ; xmm5=tmp13 + subps xmm0,xmm4 ; xmm0=tmp12 + addps xmm1,xmm7 ; xmm1=tmp10 + addps xmm6,xmm4 ; xmm6=tmp11 + + addps xmm0,xmm5 + mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1 + + movaps xmm7,xmm1 + movaps xmm4,xmm5 + subps xmm1,xmm6 ; xmm1=data4 + subps xmm5,xmm0 ; xmm5=data6 + addps xmm7,xmm6 ; xmm7=data0 + addps xmm4,xmm0 ; xmm4=data2 + + movaps XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4 + + ; -- Odd part + + movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 + movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 + + addps xmm2,xmm3 ; xmm2=tmp10 + addps xmm3,xmm6 ; xmm3=tmp11 + addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 + + mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3 + + movaps xmm1,xmm2 ; xmm1=tmp10 + subps xmm2,xmm6 + mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5 + mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) + mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) + addps xmm1,xmm2 ; xmm1=z2 + addps xmm6,xmm2 ; xmm6=z4 + + movaps xmm5,xmm0 + subps xmm0,xmm3 ; xmm0=z13 + addps xmm5,xmm3 ; xmm5=z11 + + movaps xmm7,xmm0 + movaps xmm4,xmm5 + subps xmm0,xmm1 ; xmm0=data3 + subps xmm5,xmm6 ; xmm5=data7 + addps xmm7,xmm1 ; xmm7=data5 + addps xmm4,xmm6 ; xmm4=data1 + + movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4 + + add edx, byte 4*SIZEOF_FAST_FLOAT + dec ecx + jnz near .columnloop + +; pop edi ; unused +; pop esi ; unused +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/ji3dnflt.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/ji3dnflt.asm new file mode 100755 index 0000000..dc2076f --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/ji3dnflt.asm @@ -0,0 +1,452 @@ +; +; ji3dnflt.asm - floating-point IDCT (3DNow! & MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a floating-point implementation of the inverse DCT +; (Discrete Cosine Transform). The following code is based directly on +; the IJG's original jidctflt.c; see the jidctflt.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_float_3dnow) + +EXTN(jconst_idct_float_3dnow): + +PD_1_414 times 2 dd 1.414213562373095048801689 +PD_1_847 times 2 dd 1.847759065022573512256366 +PD_1_082 times 2 dd 1.082392200292393968799446 +PD_2_613 times 2 dd 2.613125929752753055713286 +PD_RNDINT_MAGIC times 2 dd 100663296.0 ; (float)(0x00C00000 << 3) +PB_CENTERJSAMP times 8 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_float_3dnow (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; void * dct_table +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 +%define workspace wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT + ; FAST_FLOAT workspace[DCTSIZE2] + + align 16 + global EXTN(jsimd_idct_float_3dnow) + +EXTN(jsimd_idct_float_3dnow): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [workspace] + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input, store into work array. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + lea edi, [workspace] ; FAST_FLOAT * wsptr + mov ecx, DCTSIZE/2 ; ctr + alignx 16,7 +.columnloop: +%ifndef NO_ZERO_COLUMN_TEST_FLOAT_3DNOW + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz short .columnDCT + + pushpic ebx ; save GOT address + mov ebx, DWORD [DWBLOCK(3,0,esi,SIZEOF_JCOEF)] + mov eax, DWORD [DWBLOCK(4,0,esi,SIZEOF_JCOEF)] + or ebx, DWORD [DWBLOCK(5,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(6,0,esi,SIZEOF_JCOEF)] + or ebx, DWORD [DWBLOCK(7,0,esi,SIZEOF_JCOEF)] + or eax,ebx + poppic ebx ; restore GOT address + jnz short .columnDCT + + ; -- AC terms all zero + + movd mm0, DWORD [DWBLOCK(0,0,esi,SIZEOF_JCOEF)] + + punpcklwd mm0,mm0 + psrad mm0,(DWORD_BIT-WORD_BIT) + pi2fd mm0,mm0 + + pfmul mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movq mm1,mm0 + punpckldq mm0,mm0 + punpckhdq mm1,mm1 + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm0 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm0 + movq MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm0 + movq MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm1 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm1 + movq MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm1 + movq MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm1 + jmp near .nextcolumn + alignx 16,7 +%endif +.columnDCT: + + ; -- Even part + + movd mm0, DWORD [DWBLOCK(0,0,esi,SIZEOF_JCOEF)] + movd mm1, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + movd mm2, DWORD [DWBLOCK(4,0,esi,SIZEOF_JCOEF)] + movd mm3, DWORD [DWBLOCK(6,0,esi,SIZEOF_JCOEF)] + + punpcklwd mm0,mm0 + punpcklwd mm1,mm1 + psrad mm0,(DWORD_BIT-WORD_BIT) + psrad mm1,(DWORD_BIT-WORD_BIT) + pi2fd mm0,mm0 + pi2fd mm1,mm1 + + pfmul mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + pfmul mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + punpcklwd mm2,mm2 + punpcklwd mm3,mm3 + psrad mm2,(DWORD_BIT-WORD_BIT) + psrad mm3,(DWORD_BIT-WORD_BIT) + pi2fd mm2,mm2 + pi2fd mm3,mm3 + + pfmul mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + pfmul mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movq mm4,mm0 + movq mm5,mm1 + pfsub mm0,mm2 ; mm0=tmp11 + pfsub mm1,mm3 + pfadd mm4,mm2 ; mm4=tmp10 + pfadd mm5,mm3 ; mm5=tmp13 + + pfmul mm1,[GOTOFF(ebx,PD_1_414)] + pfsub mm1,mm5 ; mm1=tmp12 + + movq mm6,mm4 + movq mm7,mm0 + pfsub mm4,mm5 ; mm4=tmp3 + pfsub mm0,mm1 ; mm0=tmp2 + pfadd mm6,mm5 ; mm6=tmp0 + pfadd mm7,mm1 ; mm7=tmp1 + + movq MMWORD [wk(1)], mm4 ; tmp3 + movq MMWORD [wk(0)], mm0 ; tmp2 + + ; -- Odd part + + movd mm2, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + movd mm3, DWORD [DWBLOCK(3,0,esi,SIZEOF_JCOEF)] + movd mm5, DWORD [DWBLOCK(5,0,esi,SIZEOF_JCOEF)] + movd mm1, DWORD [DWBLOCK(7,0,esi,SIZEOF_JCOEF)] + + punpcklwd mm2,mm2 + punpcklwd mm3,mm3 + psrad mm2,(DWORD_BIT-WORD_BIT) + psrad mm3,(DWORD_BIT-WORD_BIT) + pi2fd mm2,mm2 + pi2fd mm3,mm3 + + pfmul mm2, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + pfmul mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + punpcklwd mm5,mm5 + punpcklwd mm1,mm1 + psrad mm5,(DWORD_BIT-WORD_BIT) + psrad mm1,(DWORD_BIT-WORD_BIT) + pi2fd mm5,mm5 + pi2fd mm1,mm1 + + pfmul mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + pfmul mm1, MMWORD [MMBLOCK(7,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movq mm4,mm2 + movq mm0,mm5 + pfadd mm2,mm1 ; mm2=z11 + pfadd mm5,mm3 ; mm5=z13 + pfsub mm4,mm1 ; mm4=z12 + pfsub mm0,mm3 ; mm0=z10 + + movq mm1,mm2 + pfsub mm2,mm5 + pfadd mm1,mm5 ; mm1=tmp7 + + pfmul mm2,[GOTOFF(ebx,PD_1_414)] ; mm2=tmp11 + + movq mm3,mm0 + pfadd mm0,mm4 + pfmul mm0,[GOTOFF(ebx,PD_1_847)] ; mm0=z5 + pfmul mm3,[GOTOFF(ebx,PD_2_613)] ; mm3=(z10 * 2.613125930) + pfmul mm4,[GOTOFF(ebx,PD_1_082)] ; mm4=(z12 * 1.082392200) + pfsubr mm3,mm0 ; mm3=tmp12 + pfsub mm4,mm0 ; mm4=tmp10 + + ; -- Final output stage + + pfsub mm3,mm1 ; mm3=tmp6 + movq mm5,mm6 + movq mm0,mm7 + pfadd mm6,mm1 ; mm6=data0=(00 01) + pfadd mm7,mm3 ; mm7=data1=(10 11) + pfsub mm5,mm1 ; mm5=data7=(70 71) + pfsub mm0,mm3 ; mm0=data6=(60 61) + pfsub mm2,mm3 ; mm2=tmp5 + + movq mm1,mm6 ; transpose coefficients + punpckldq mm6,mm7 ; mm6=(00 10) + punpckhdq mm1,mm7 ; mm1=(01 11) + movq mm3,mm0 ; transpose coefficients + punpckldq mm0,mm5 ; mm0=(60 70) + punpckhdq mm3,mm5 ; mm3=(61 71) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm6 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm1 + movq MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0 + movq MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm3 + + movq mm7, MMWORD [wk(0)] ; mm7=tmp2 + movq mm5, MMWORD [wk(1)] ; mm5=tmp3 + + pfadd mm4,mm2 ; mm4=tmp4 + movq mm6,mm7 + movq mm1,mm5 + pfadd mm7,mm2 ; mm7=data2=(20 21) + pfadd mm5,mm4 ; mm5=data4=(40 41) + pfsub mm6,mm2 ; mm6=data5=(50 51) + pfsub mm1,mm4 ; mm1=data3=(30 31) + + movq mm0,mm7 ; transpose coefficients + punpckldq mm7,mm1 ; mm7=(20 30) + punpckhdq mm0,mm1 ; mm0=(21 31) + movq mm3,mm5 ; transpose coefficients + punpckldq mm5,mm6 ; mm5=(40 50) + punpckhdq mm3,mm6 ; mm3=(41 51) + + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm7 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm0 + movq MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm5 + movq MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm3 + +.nextcolumn: + add esi, byte 2*SIZEOF_JCOEF ; coef_block + add edx, byte 2*SIZEOF_FLOAT_MULT_TYPE ; quantptr + add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT ; wsptr + dec ecx ; ctr + jnz near .columnloop + + ; -- Prefetch the next coefficient block + + prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32] + prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32] + prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32] + prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + lea esi, [workspace] ; FAST_FLOAT * wsptr + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + mov ecx, DCTSIZE/2 ; ctr + alignx 16,7 +.rowloop: + + ; -- Even part + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_FAST_FLOAT)] + movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_FAST_FLOAT)] + + movq mm4,mm0 + movq mm5,mm1 + pfsub mm0,mm2 ; mm0=tmp11 + pfsub mm1,mm3 + pfadd mm4,mm2 ; mm4=tmp10 + pfadd mm5,mm3 ; mm5=tmp13 + + pfmul mm1,[GOTOFF(ebx,PD_1_414)] + pfsub mm1,mm5 ; mm1=tmp12 + + movq mm6,mm4 + movq mm7,mm0 + pfsub mm4,mm5 ; mm4=tmp3 + pfsub mm0,mm1 ; mm0=tmp2 + pfadd mm6,mm5 ; mm6=tmp0 + pfadd mm7,mm1 ; mm7=tmp1 + + movq MMWORD [wk(1)], mm4 ; tmp3 + movq MMWORD [wk(0)], mm0 ; tmp2 + + ; -- Odd part + + movq mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] + movq mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_FAST_FLOAT)] + movq mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_FAST_FLOAT)] + movq mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_FAST_FLOAT)] + + movq mm4,mm2 + movq mm0,mm5 + pfadd mm2,mm1 ; mm2=z11 + pfadd mm5,mm3 ; mm5=z13 + pfsub mm4,mm1 ; mm4=z12 + pfsub mm0,mm3 ; mm0=z10 + + movq mm1,mm2 + pfsub mm2,mm5 + pfadd mm1,mm5 ; mm1=tmp7 + + pfmul mm2,[GOTOFF(ebx,PD_1_414)] ; mm2=tmp11 + + movq mm3,mm0 + pfadd mm0,mm4 + pfmul mm0,[GOTOFF(ebx,PD_1_847)] ; mm0=z5 + pfmul mm3,[GOTOFF(ebx,PD_2_613)] ; mm3=(z10 * 2.613125930) + pfmul mm4,[GOTOFF(ebx,PD_1_082)] ; mm4=(z12 * 1.082392200) + pfsubr mm3,mm0 ; mm3=tmp12 + pfsub mm4,mm0 ; mm4=tmp10 + + ; -- Final output stage + + pfsub mm3,mm1 ; mm3=tmp6 + movq mm5,mm6 + movq mm0,mm7 + pfadd mm6,mm1 ; mm6=data0=(00 10) + pfadd mm7,mm3 ; mm7=data1=(01 11) + pfsub mm5,mm1 ; mm5=data7=(07 17) + pfsub mm0,mm3 ; mm0=data6=(06 16) + pfsub mm2,mm3 ; mm2=tmp5 + + movq mm1,[GOTOFF(ebx,PD_RNDINT_MAGIC)] ; mm1=[PD_RNDINT_MAGIC] + pcmpeqd mm3,mm3 + psrld mm3,WORD_BIT ; mm3={0xFFFF 0x0000 0xFFFF 0x0000} + + pfadd mm6,mm1 ; mm6=roundint(data0/8)=(00 ** 10 **) + pfadd mm7,mm1 ; mm7=roundint(data1/8)=(01 ** 11 **) + pfadd mm0,mm1 ; mm0=roundint(data6/8)=(06 ** 16 **) + pfadd mm5,mm1 ; mm5=roundint(data7/8)=(07 ** 17 **) + + pand mm6,mm3 ; mm6=(00 -- 10 --) + pslld mm7,WORD_BIT ; mm7=(-- 01 -- 11) + pand mm0,mm3 ; mm0=(06 -- 16 --) + pslld mm5,WORD_BIT ; mm5=(-- 07 -- 17) + por mm6,mm7 ; mm6=(00 01 10 11) + por mm0,mm5 ; mm0=(06 07 16 17) + + movq mm1, MMWORD [wk(0)] ; mm1=tmp2 + movq mm3, MMWORD [wk(1)] ; mm3=tmp3 + + pfadd mm4,mm2 ; mm4=tmp4 + movq mm7,mm1 + movq mm5,mm3 + pfadd mm1,mm2 ; mm1=data2=(02 12) + pfadd mm3,mm4 ; mm3=data4=(04 14) + pfsub mm7,mm2 ; mm7=data5=(05 15) + pfsub mm5,mm4 ; mm5=data3=(03 13) + + movq mm2,[GOTOFF(ebx,PD_RNDINT_MAGIC)] ; mm2=[PD_RNDINT_MAGIC] + pcmpeqd mm4,mm4 + psrld mm4,WORD_BIT ; mm4={0xFFFF 0x0000 0xFFFF 0x0000} + + pfadd mm3,mm2 ; mm3=roundint(data4/8)=(04 ** 14 **) + pfadd mm7,mm2 ; mm7=roundint(data5/8)=(05 ** 15 **) + pfadd mm1,mm2 ; mm1=roundint(data2/8)=(02 ** 12 **) + pfadd mm5,mm2 ; mm5=roundint(data3/8)=(03 ** 13 **) + + pand mm3,mm4 ; mm3=(04 -- 14 --) + pslld mm7,WORD_BIT ; mm7=(-- 05 -- 15) + pand mm1,mm4 ; mm1=(02 -- 12 --) + pslld mm5,WORD_BIT ; mm5=(-- 03 -- 13) + por mm3,mm7 ; mm3=(04 05 14 15) + por mm1,mm5 ; mm1=(02 03 12 13) + + movq mm2,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm2=[PB_CENTERJSAMP] + + packsswb mm6,mm3 ; mm6=(00 01 10 11 04 05 14 15) + packsswb mm1,mm0 ; mm1=(02 03 12 13 06 07 16 17) + paddb mm6,mm2 + paddb mm1,mm2 + + movq mm4,mm6 ; transpose coefficients(phase 2) + punpcklwd mm6,mm1 ; mm6=(00 01 02 03 10 11 12 13) + punpckhwd mm4,mm1 ; mm4=(04 05 06 07 14 15 16 17) + + movq mm7,mm6 ; transpose coefficients(phase 3) + punpckldq mm6,mm4 ; mm6=(00 01 02 03 04 05 06 07) + punpckhdq mm7,mm4 ; mm7=(10 11 12 13 14 15 16 17) + + pushpic ebx ; save GOT address + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm6 + movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm7 + + poppic ebx ; restore GOT address + + add esi, byte 2*SIZEOF_FAST_FLOAT ; wsptr + add edi, byte 2*SIZEOF_JSAMPROW + dec ecx ; ctr + jnz near .rowloop + + femms ; empty MMX/3DNow! state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxfst.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxfst.asm new file mode 100755 index 0000000..3b05572 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxfst.asm @@ -0,0 +1,500 @@ +; +; jimmxfst.asm - fast integer IDCT (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a fast, not so accurate integer implementation of +; the inverse DCT (Discrete Cosine Transform). The following code is +; based directly on the IJG's original jidctfst.c; see the jidctfst.c +; for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 8 ; 14 is also OK. +%define PASS1_BITS 2 + +%if IFAST_SCALE_BITS != PASS1_BITS +%error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'." +%endif + +%if CONST_BITS == 8 +F_1_082 equ 277 ; FIX(1.082392200) +F_1_414 equ 362 ; FIX(1.414213562) +F_1_847 equ 473 ; FIX(1.847759065) +F_2_613 equ 669 ; FIX(2.613125930) +F_1_613 equ (F_2_613 - 256) ; FIX(2.613125930) - FIX(1) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_1_082 equ DESCALE(1162209775,30-CONST_BITS) ; FIX(1.082392200) +F_1_414 equ DESCALE(1518500249,30-CONST_BITS) ; FIX(1.414213562) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_2_613 equ DESCALE(2805822602,30-CONST_BITS) ; FIX(2.613125930) +F_1_613 equ (F_2_613 - (1 << CONST_BITS)) ; FIX(2.613125930) - FIX(1) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + +; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow) +; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw) + +%define PRE_MULTIPLY_SCALE_BITS 2 +%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS) + + alignz 16 + global EXTN(jconst_idct_ifast_mmx) + +EXTN(jconst_idct_ifast_mmx): + +PW_F1414 times 4 dw F_1_414 << CONST_SHIFT +PW_F1847 times 4 dw F_1_847 << CONST_SHIFT +PW_MF1613 times 4 dw -F_1_613 << CONST_SHIFT +PW_F1082 times 4 dw F_1_082 << CONST_SHIFT +PB_CENTERJSAMP times 8 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_ifast_mmx (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; jpeg_component_info * compptr +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 +%define workspace wk(0)-DCTSIZE2*SIZEOF_JCOEF + ; JCOEF workspace[DCTSIZE2] + + align 16 + global EXTN(jsimd_idct_ifast_mmx) + +EXTN(jsimd_idct_ifast_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [workspace] + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input, store into work array. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + lea edi, [workspace] ; JCOEF * wsptr + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.columnloop: +%ifndef NO_ZERO_COLUMN_TEST_IFAST_MMX + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz short .columnDCT + + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por mm1,mm0 + packsswb mm1,mm1 + movd eax,mm1 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)] + + movq mm2,mm0 ; mm0=in0=(00 01 02 03) + punpcklwd mm0,mm0 ; mm0=(00 00 01 01) + punpckhwd mm2,mm2 ; mm2=(02 02 03 03) + + movq mm1,mm0 + punpckldq mm0,mm0 ; mm0=(00 00 00 00) + punpckhdq mm1,mm1 ; mm1=(01 01 01 01) + movq mm3,mm2 + punpckldq mm2,mm2 ; mm2=(02 02 02 02) + punpckhdq mm3,mm3 ; mm3=(03 03 03 03) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 + movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm3 + jmp near .nextcolumn + alignx 16,7 +%endif +.columnDCT: + + ; -- Even part + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_IFAST_MULT_TYPE)] + movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + pmullw mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_IFAST_MULT_TYPE)] + + movq mm4,mm0 + movq mm5,mm1 + psubw mm0,mm2 ; mm0=tmp11 + psubw mm1,mm3 + paddw mm4,mm2 ; mm4=tmp10 + paddw mm5,mm3 ; mm5=tmp13 + + psllw mm1,PRE_MULTIPLY_SCALE_BITS + pmulhw mm1,[GOTOFF(ebx,PW_F1414)] + psubw mm1,mm5 ; mm1=tmp12 + + movq mm6,mm4 + movq mm7,mm0 + psubw mm4,mm5 ; mm4=tmp3 + psubw mm0,mm1 ; mm0=tmp2 + paddw mm6,mm5 ; mm6=tmp0 + paddw mm7,mm1 ; mm7=tmp1 + + movq MMWORD [wk(1)], mm4 ; wk(1)=tmp3 + movq MMWORD [wk(0)], mm0 ; wk(0)=tmp2 + + ; -- Odd part + + movq mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw mm2, MMWORD [MMBLOCK(1,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_IFAST_MULT_TYPE)] + movq mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw mm1, MMWORD [MMBLOCK(7,0,edx,SIZEOF_IFAST_MULT_TYPE)] + + movq mm4,mm2 + movq mm0,mm5 + psubw mm2,mm1 ; mm2=z12 + psubw mm5,mm3 ; mm5=z10 + paddw mm4,mm1 ; mm4=z11 + paddw mm0,mm3 ; mm0=z13 + + movq mm1,mm5 ; mm1=z10(unscaled) + psllw mm2,PRE_MULTIPLY_SCALE_BITS + psllw mm5,PRE_MULTIPLY_SCALE_BITS + + movq mm3,mm4 + psubw mm4,mm0 + paddw mm3,mm0 ; mm3=tmp7 + + psllw mm4,PRE_MULTIPLY_SCALE_BITS + pmulhw mm4,[GOTOFF(ebx,PW_F1414)] ; mm4=tmp11 + + ; To avoid overflow... + ; + ; (Original) + ; tmp12 = -2.613125930 * z10 + z5; + ; + ; (This implementation) + ; tmp12 = (-1.613125930 - 1) * z10 + z5; + ; = -1.613125930 * z10 - z10 + z5; + + movq mm0,mm5 + paddw mm5,mm2 + pmulhw mm5,[GOTOFF(ebx,PW_F1847)] ; mm5=z5 + pmulhw mm0,[GOTOFF(ebx,PW_MF1613)] + pmulhw mm2,[GOTOFF(ebx,PW_F1082)] + psubw mm0,mm1 + psubw mm2,mm5 ; mm2=tmp10 + paddw mm0,mm5 ; mm0=tmp12 + + ; -- Final output stage + + psubw mm0,mm3 ; mm0=tmp6 + movq mm1,mm6 + movq mm5,mm7 + paddw mm6,mm3 ; mm6=data0=(00 01 02 03) + paddw mm7,mm0 ; mm7=data1=(10 11 12 13) + psubw mm1,mm3 ; mm1=data7=(70 71 72 73) + psubw mm5,mm0 ; mm5=data6=(60 61 62 63) + psubw mm4,mm0 ; mm4=tmp5 + + movq mm3,mm6 ; transpose coefficients(phase 1) + punpcklwd mm6,mm7 ; mm6=(00 10 01 11) + punpckhwd mm3,mm7 ; mm3=(02 12 03 13) + movq mm0,mm5 ; transpose coefficients(phase 1) + punpcklwd mm5,mm1 ; mm5=(60 70 61 71) + punpckhwd mm0,mm1 ; mm0=(62 72 63 73) + + movq mm7, MMWORD [wk(0)] ; mm7=tmp2 + movq mm1, MMWORD [wk(1)] ; mm1=tmp3 + + movq MMWORD [wk(0)], mm5 ; wk(0)=(60 70 61 71) + movq MMWORD [wk(1)], mm0 ; wk(1)=(62 72 63 73) + + paddw mm2,mm4 ; mm2=tmp4 + movq mm5,mm7 + movq mm0,mm1 + paddw mm7,mm4 ; mm7=data2=(20 21 22 23) + paddw mm1,mm2 ; mm1=data4=(40 41 42 43) + psubw mm5,mm4 ; mm5=data5=(50 51 52 53) + psubw mm0,mm2 ; mm0=data3=(30 31 32 33) + + movq mm4,mm7 ; transpose coefficients(phase 1) + punpcklwd mm7,mm0 ; mm7=(20 30 21 31) + punpckhwd mm4,mm0 ; mm4=(22 32 23 33) + movq mm2,mm1 ; transpose coefficients(phase 1) + punpcklwd mm1,mm5 ; mm1=(40 50 41 51) + punpckhwd mm2,mm5 ; mm2=(42 52 43 53) + + movq mm0,mm6 ; transpose coefficients(phase 2) + punpckldq mm6,mm7 ; mm6=(00 10 20 30) + punpckhdq mm0,mm7 ; mm0=(01 11 21 31) + movq mm5,mm3 ; transpose coefficients(phase 2) + punpckldq mm3,mm4 ; mm3=(02 12 22 32) + punpckhdq mm5,mm4 ; mm5=(03 13 23 33) + + movq mm7, MMWORD [wk(0)] ; mm7=(60 70 61 71) + movq mm4, MMWORD [wk(1)] ; mm4=(62 72 63 73) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm6 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm3 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm5 + + movq mm6,mm1 ; transpose coefficients(phase 2) + punpckldq mm1,mm7 ; mm1=(40 50 60 70) + punpckhdq mm6,mm7 ; mm6=(41 51 61 71) + movq mm0,mm2 ; transpose coefficients(phase 2) + punpckldq mm2,mm4 ; mm2=(42 52 62 72) + punpckhdq mm0,mm4 ; mm0=(43 53 63 73) + + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm6 + movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm0 + +.nextcolumn: + add esi, byte 4*SIZEOF_JCOEF ; coef_block + add edx, byte 4*SIZEOF_IFAST_MULT_TYPE ; quantptr + add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr + dec ecx ; ctr + jnz near .columnloop + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + lea esi, [workspace] ; JCOEF * wsptr + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.rowloop: + + ; -- Even part + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + + movq mm4,mm0 + movq mm5,mm1 + psubw mm0,mm2 ; mm0=tmp11 + psubw mm1,mm3 + paddw mm4,mm2 ; mm4=tmp10 + paddw mm5,mm3 ; mm5=tmp13 + + psllw mm1,PRE_MULTIPLY_SCALE_BITS + pmulhw mm1,[GOTOFF(ebx,PW_F1414)] + psubw mm1,mm5 ; mm1=tmp12 + + movq mm6,mm4 + movq mm7,mm0 + psubw mm4,mm5 ; mm4=tmp3 + psubw mm0,mm1 ; mm0=tmp2 + paddw mm6,mm5 ; mm6=tmp0 + paddw mm7,mm1 ; mm7=tmp1 + + movq MMWORD [wk(1)], mm4 ; wk(1)=tmp3 + movq MMWORD [wk(0)], mm0 ; wk(0)=tmp2 + + ; -- Odd part + + movq mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + movq mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + + movq mm4,mm2 + movq mm0,mm5 + psubw mm2,mm1 ; mm2=z12 + psubw mm5,mm3 ; mm5=z10 + paddw mm4,mm1 ; mm4=z11 + paddw mm0,mm3 ; mm0=z13 + + movq mm1,mm5 ; mm1=z10(unscaled) + psllw mm2,PRE_MULTIPLY_SCALE_BITS + psllw mm5,PRE_MULTIPLY_SCALE_BITS + + movq mm3,mm4 + psubw mm4,mm0 + paddw mm3,mm0 ; mm3=tmp7 + + psllw mm4,PRE_MULTIPLY_SCALE_BITS + pmulhw mm4,[GOTOFF(ebx,PW_F1414)] ; mm4=tmp11 + + ; To avoid overflow... + ; + ; (Original) + ; tmp12 = -2.613125930 * z10 + z5; + ; + ; (This implementation) + ; tmp12 = (-1.613125930 - 1) * z10 + z5; + ; = -1.613125930 * z10 - z10 + z5; + + movq mm0,mm5 + paddw mm5,mm2 + pmulhw mm5,[GOTOFF(ebx,PW_F1847)] ; mm5=z5 + pmulhw mm0,[GOTOFF(ebx,PW_MF1613)] + pmulhw mm2,[GOTOFF(ebx,PW_F1082)] + psubw mm0,mm1 + psubw mm2,mm5 ; mm2=tmp10 + paddw mm0,mm5 ; mm0=tmp12 + + ; -- Final output stage + + psubw mm0,mm3 ; mm0=tmp6 + movq mm1,mm6 + movq mm5,mm7 + paddw mm6,mm3 ; mm6=data0=(00 10 20 30) + paddw mm7,mm0 ; mm7=data1=(01 11 21 31) + psraw mm6,(PASS1_BITS+3) ; descale + psraw mm7,(PASS1_BITS+3) ; descale + psubw mm1,mm3 ; mm1=data7=(07 17 27 37) + psubw mm5,mm0 ; mm5=data6=(06 16 26 36) + psraw mm1,(PASS1_BITS+3) ; descale + psraw mm5,(PASS1_BITS+3) ; descale + psubw mm4,mm0 ; mm4=tmp5 + + packsswb mm6,mm5 ; mm6=(00 10 20 30 06 16 26 36) + packsswb mm7,mm1 ; mm7=(01 11 21 31 07 17 27 37) + + movq mm3, MMWORD [wk(0)] ; mm3=tmp2 + movq mm0, MMWORD [wk(1)] ; mm0=tmp3 + + paddw mm2,mm4 ; mm2=tmp4 + movq mm5,mm3 + movq mm1,mm0 + paddw mm3,mm4 ; mm3=data2=(02 12 22 32) + paddw mm0,mm2 ; mm0=data4=(04 14 24 34) + psraw mm3,(PASS1_BITS+3) ; descale + psraw mm0,(PASS1_BITS+3) ; descale + psubw mm5,mm4 ; mm5=data5=(05 15 25 35) + psubw mm1,mm2 ; mm1=data3=(03 13 23 33) + psraw mm5,(PASS1_BITS+3) ; descale + psraw mm1,(PASS1_BITS+3) ; descale + + movq mm4,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm4=[PB_CENTERJSAMP] + + packsswb mm3,mm0 ; mm3=(02 12 22 32 04 14 24 34) + packsswb mm1,mm5 ; mm1=(03 13 23 33 05 15 25 35) + + paddb mm6,mm4 + paddb mm7,mm4 + paddb mm3,mm4 + paddb mm1,mm4 + + movq mm2,mm6 ; transpose coefficients(phase 1) + punpcklbw mm6,mm7 ; mm6=(00 01 10 11 20 21 30 31) + punpckhbw mm2,mm7 ; mm2=(06 07 16 17 26 27 36 37) + movq mm0,mm3 ; transpose coefficients(phase 1) + punpcklbw mm3,mm1 ; mm3=(02 03 12 13 22 23 32 33) + punpckhbw mm0,mm1 ; mm0=(04 05 14 15 24 25 34 35) + + movq mm5,mm6 ; transpose coefficients(phase 2) + punpcklwd mm6,mm3 ; mm6=(00 01 02 03 10 11 12 13) + punpckhwd mm5,mm3 ; mm5=(20 21 22 23 30 31 32 33) + movq mm4,mm0 ; transpose coefficients(phase 2) + punpcklwd mm0,mm2 ; mm0=(04 05 06 07 14 15 16 17) + punpckhwd mm4,mm2 ; mm4=(24 25 26 27 34 35 36 37) + + movq mm7,mm6 ; transpose coefficients(phase 3) + punpckldq mm6,mm0 ; mm6=(00 01 02 03 04 05 06 07) + punpckhdq mm7,mm0 ; mm7=(10 11 12 13 14 15 16 17) + movq mm1,mm5 ; transpose coefficients(phase 3) + punpckldq mm5,mm4 ; mm5=(20 21 22 23 24 25 26 27) + punpckhdq mm1,mm4 ; mm1=(30 31 32 33 34 35 36 37) + + pushpic ebx ; save GOT address + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm6 + movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm7 + mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm5 + movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm1 + + poppic ebx ; restore GOT address + + add esi, byte 4*SIZEOF_JCOEF ; wsptr + add edi, byte 4*SIZEOF_JSAMPROW + dec ecx ; ctr + jnz near .rowloop + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxint.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxint.asm new file mode 100755 index 0000000..7b52fae --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxint.asm @@ -0,0 +1,852 @@ +; +; jimmxint.asm - accurate integer IDCT (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a slow-but-accurate integer implementation of the +; inverse DCT (Discrete Cosine Transform). The following code is based +; directly on the IJG's original jidctint.c; see the jidctint.c for +; more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1 (CONST_BITS-PASS1_BITS) +%define DESCALE_P2 (CONST_BITS+PASS1_BITS+3) + +%if CONST_BITS == 13 +F_0_298 equ 2446 ; FIX(0.298631336) +F_0_390 equ 3196 ; FIX(0.390180644) +F_0_541 equ 4433 ; FIX(0.541196100) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_175 equ 9633 ; FIX(1.175875602) +F_1_501 equ 12299 ; FIX(1.501321110) +F_1_847 equ 15137 ; FIX(1.847759065) +F_1_961 equ 16069 ; FIX(1.961570560) +F_2_053 equ 16819 ; FIX(2.053119869) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_072 equ 25172 ; FIX(3.072711026) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) +F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) +F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) +F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_islow_mmx) + +EXTN(jconst_idct_islow_mmx): + +PW_F130_F054 times 2 dw (F_0_541+F_0_765), F_0_541 +PW_F054_MF130 times 2 dw F_0_541, (F_0_541-F_1_847) +PW_MF078_F117 times 2 dw (F_1_175-F_1_961), F_1_175 +PW_F117_F078 times 2 dw F_1_175, (F_1_175-F_0_390) +PW_MF060_MF089 times 2 dw (F_0_298-F_0_899),-F_0_899 +PW_MF089_F060 times 2 dw -F_0_899, (F_1_501-F_0_899) +PW_MF050_MF256 times 2 dw (F_2_053-F_2_562),-F_2_562 +PW_MF256_F050 times 2 dw -F_2_562, (F_3_072-F_2_562) +PD_DESCALE_P1 times 2 dd 1 << (DESCALE_P1-1) +PD_DESCALE_P2 times 2 dd 1 << (DESCALE_P2-1) +PB_CENTERJSAMP times 8 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_islow_mmx (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; jpeg_component_info * compptr +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 12 +%define workspace wk(0)-DCTSIZE2*SIZEOF_JCOEF + ; JCOEF workspace[DCTSIZE2] + + align 16 + global EXTN(jsimd_idct_islow_mmx) + +EXTN(jsimd_idct_islow_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [workspace] + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input, store into work array. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + lea edi, [workspace] ; JCOEF * wsptr + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.columnloop: +%ifndef NO_ZERO_COLUMN_TEST_ISLOW_MMX + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz short .columnDCT + + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por mm1,mm0 + packsswb mm1,mm1 + movd eax,mm1 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + psllw mm0,PASS1_BITS + + movq mm2,mm0 ; mm0=in0=(00 01 02 03) + punpcklwd mm0,mm0 ; mm0=(00 00 01 01) + punpckhwd mm2,mm2 ; mm2=(02 02 03 03) + + movq mm1,mm0 + punpckldq mm0,mm0 ; mm0=(00 00 00 00) + punpckhdq mm1,mm1 ; mm1=(01 01 01 01) + movq mm3,mm2 + punpckldq mm2,mm2 ; mm2=(02 02 02 02) + punpckhdq mm3,mm3 ; mm3=(03 03 03 03) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 + movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm3 + jmp near .nextcolumn + alignx 16,7 +%endif +.columnDCT: + + ; -- Even part + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + pmullw mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + ; (Original) + ; z1 = (z2 + z3) * 0.541196100; + ; tmp2 = z1 + z3 * -1.847759065; + ; tmp3 = z1 + z2 * 0.765366865; + ; + ; (This implementation) + ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); + ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; + + movq mm4,mm1 ; mm1=in2=z2 + movq mm5,mm1 + punpcklwd mm4,mm3 ; mm3=in6=z3 + punpckhwd mm5,mm3 + movq mm1,mm4 + movq mm3,mm5 + pmaddwd mm4,[GOTOFF(ebx,PW_F130_F054)] ; mm4=tmp3L + pmaddwd mm5,[GOTOFF(ebx,PW_F130_F054)] ; mm5=tmp3H + pmaddwd mm1,[GOTOFF(ebx,PW_F054_MF130)] ; mm1=tmp2L + pmaddwd mm3,[GOTOFF(ebx,PW_F054_MF130)] ; mm3=tmp2H + + movq mm6,mm0 + paddw mm0,mm2 ; mm0=in0+in4 + psubw mm6,mm2 ; mm6=in0-in4 + + pxor mm7,mm7 + pxor mm2,mm2 + punpcklwd mm7,mm0 ; mm7=tmp0L + punpckhwd mm2,mm0 ; mm2=tmp0H + psrad mm7,(16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS + psrad mm2,(16-CONST_BITS) ; psrad mm2,16 & pslld mm2,CONST_BITS + + movq mm0,mm7 + paddd mm7,mm4 ; mm7=tmp10L + psubd mm0,mm4 ; mm0=tmp13L + movq mm4,mm2 + paddd mm2,mm5 ; mm2=tmp10H + psubd mm4,mm5 ; mm4=tmp13H + + movq MMWORD [wk(0)], mm7 ; wk(0)=tmp10L + movq MMWORD [wk(1)], mm2 ; wk(1)=tmp10H + movq MMWORD [wk(2)], mm0 ; wk(2)=tmp13L + movq MMWORD [wk(3)], mm4 ; wk(3)=tmp13H + + pxor mm5,mm5 + pxor mm7,mm7 + punpcklwd mm5,mm6 ; mm5=tmp1L + punpckhwd mm7,mm6 ; mm7=tmp1H + psrad mm5,(16-CONST_BITS) ; psrad mm5,16 & pslld mm5,CONST_BITS + psrad mm7,(16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS + + movq mm2,mm5 + paddd mm5,mm1 ; mm5=tmp11L + psubd mm2,mm1 ; mm2=tmp12L + movq mm0,mm7 + paddd mm7,mm3 ; mm7=tmp11H + psubd mm0,mm3 ; mm0=tmp12H + + movq MMWORD [wk(4)], mm5 ; wk(4)=tmp11L + movq MMWORD [wk(5)], mm7 ; wk(5)=tmp11H + movq MMWORD [wk(6)], mm2 ; wk(6)=tmp12L + movq MMWORD [wk(7)], mm0 ; wk(7)=tmp12H + + ; -- Odd part + + movq mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm6, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw mm4, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm6, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movq mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw mm1, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + movq mm5,mm6 + movq mm7,mm4 + paddw mm5,mm3 ; mm5=z3 + paddw mm7,mm1 ; mm7=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movq mm2,mm5 + movq mm0,mm5 + punpcklwd mm2,mm7 + punpckhwd mm0,mm7 + movq mm5,mm2 + movq mm7,mm0 + pmaddwd mm2,[GOTOFF(ebx,PW_MF078_F117)] ; mm2=z3L + pmaddwd mm0,[GOTOFF(ebx,PW_MF078_F117)] ; mm0=z3H + pmaddwd mm5,[GOTOFF(ebx,PW_F117_F078)] ; mm5=z4L + pmaddwd mm7,[GOTOFF(ebx,PW_F117_F078)] ; mm7=z4H + + movq MMWORD [wk(10)], mm2 ; wk(10)=z3L + movq MMWORD [wk(11)], mm0 ; wk(11)=z3H + + ; (Original) + ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; + ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; + ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; tmp0 += z1 + z3; tmp1 += z2 + z4; + ; tmp2 += z2 + z3; tmp3 += z1 + z4; + ; + ; (This implementation) + ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; + ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; + ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); + ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); + ; tmp0 += z3; tmp1 += z4; + ; tmp2 += z3; tmp3 += z4; + + movq mm2,mm3 + movq mm0,mm3 + punpcklwd mm2,mm4 + punpckhwd mm0,mm4 + movq mm3,mm2 + movq mm4,mm0 + pmaddwd mm2,[GOTOFF(ebx,PW_MF060_MF089)] ; mm2=tmp0L + pmaddwd mm0,[GOTOFF(ebx,PW_MF060_MF089)] ; mm0=tmp0H + pmaddwd mm3,[GOTOFF(ebx,PW_MF089_F060)] ; mm3=tmp3L + pmaddwd mm4,[GOTOFF(ebx,PW_MF089_F060)] ; mm4=tmp3H + + paddd mm2, MMWORD [wk(10)] ; mm2=tmp0L + paddd mm0, MMWORD [wk(11)] ; mm0=tmp0H + paddd mm3,mm5 ; mm3=tmp3L + paddd mm4,mm7 ; mm4=tmp3H + + movq MMWORD [wk(8)], mm2 ; wk(8)=tmp0L + movq MMWORD [wk(9)], mm0 ; wk(9)=tmp0H + + movq mm2,mm1 + movq mm0,mm1 + punpcklwd mm2,mm6 + punpckhwd mm0,mm6 + movq mm1,mm2 + movq mm6,mm0 + pmaddwd mm2,[GOTOFF(ebx,PW_MF050_MF256)] ; mm2=tmp1L + pmaddwd mm0,[GOTOFF(ebx,PW_MF050_MF256)] ; mm0=tmp1H + pmaddwd mm1,[GOTOFF(ebx,PW_MF256_F050)] ; mm1=tmp2L + pmaddwd mm6,[GOTOFF(ebx,PW_MF256_F050)] ; mm6=tmp2H + + paddd mm2,mm5 ; mm2=tmp1L + paddd mm0,mm7 ; mm0=tmp1H + paddd mm1, MMWORD [wk(10)] ; mm1=tmp2L + paddd mm6, MMWORD [wk(11)] ; mm6=tmp2H + + movq MMWORD [wk(10)], mm2 ; wk(10)=tmp1L + movq MMWORD [wk(11)], mm0 ; wk(11)=tmp1H + + ; -- Final output stage + + movq mm5, MMWORD [wk(0)] ; mm5=tmp10L + movq mm7, MMWORD [wk(1)] ; mm7=tmp10H + + movq mm2,mm5 + movq mm0,mm7 + paddd mm5,mm3 ; mm5=data0L + paddd mm7,mm4 ; mm7=data0H + psubd mm2,mm3 ; mm2=data7L + psubd mm0,mm4 ; mm0=data7H + + movq mm3,[GOTOFF(ebx,PD_DESCALE_P1)] ; mm3=[PD_DESCALE_P1] + + paddd mm5,mm3 + paddd mm7,mm3 + psrad mm5,DESCALE_P1 + psrad mm7,DESCALE_P1 + paddd mm2,mm3 + paddd mm0,mm3 + psrad mm2,DESCALE_P1 + psrad mm0,DESCALE_P1 + + packssdw mm5,mm7 ; mm5=data0=(00 01 02 03) + packssdw mm2,mm0 ; mm2=data7=(70 71 72 73) + + movq mm4, MMWORD [wk(4)] ; mm4=tmp11L + movq mm3, MMWORD [wk(5)] ; mm3=tmp11H + + movq mm7,mm4 + movq mm0,mm3 + paddd mm4,mm1 ; mm4=data1L + paddd mm3,mm6 ; mm3=data1H + psubd mm7,mm1 ; mm7=data6L + psubd mm0,mm6 ; mm0=data6H + + movq mm1,[GOTOFF(ebx,PD_DESCALE_P1)] ; mm1=[PD_DESCALE_P1] + + paddd mm4,mm1 + paddd mm3,mm1 + psrad mm4,DESCALE_P1 + psrad mm3,DESCALE_P1 + paddd mm7,mm1 + paddd mm0,mm1 + psrad mm7,DESCALE_P1 + psrad mm0,DESCALE_P1 + + packssdw mm4,mm3 ; mm4=data1=(10 11 12 13) + packssdw mm7,mm0 ; mm7=data6=(60 61 62 63) + + movq mm6,mm5 ; transpose coefficients(phase 1) + punpcklwd mm5,mm4 ; mm5=(00 10 01 11) + punpckhwd mm6,mm4 ; mm6=(02 12 03 13) + movq mm1,mm7 ; transpose coefficients(phase 1) + punpcklwd mm7,mm2 ; mm7=(60 70 61 71) + punpckhwd mm1,mm2 ; mm1=(62 72 63 73) + + movq mm3, MMWORD [wk(6)] ; mm3=tmp12L + movq mm0, MMWORD [wk(7)] ; mm0=tmp12H + movq mm4, MMWORD [wk(10)] ; mm4=tmp1L + movq mm2, MMWORD [wk(11)] ; mm2=tmp1H + + movq MMWORD [wk(0)], mm5 ; wk(0)=(00 10 01 11) + movq MMWORD [wk(1)], mm6 ; wk(1)=(02 12 03 13) + movq MMWORD [wk(4)], mm7 ; wk(4)=(60 70 61 71) + movq MMWORD [wk(5)], mm1 ; wk(5)=(62 72 63 73) + + movq mm5,mm3 + movq mm6,mm0 + paddd mm3,mm4 ; mm3=data2L + paddd mm0,mm2 ; mm0=data2H + psubd mm5,mm4 ; mm5=data5L + psubd mm6,mm2 ; mm6=data5H + + movq mm7,[GOTOFF(ebx,PD_DESCALE_P1)] ; mm7=[PD_DESCALE_P1] + + paddd mm3,mm7 + paddd mm0,mm7 + psrad mm3,DESCALE_P1 + psrad mm0,DESCALE_P1 + paddd mm5,mm7 + paddd mm6,mm7 + psrad mm5,DESCALE_P1 + psrad mm6,DESCALE_P1 + + packssdw mm3,mm0 ; mm3=data2=(20 21 22 23) + packssdw mm5,mm6 ; mm5=data5=(50 51 52 53) + + movq mm1, MMWORD [wk(2)] ; mm1=tmp13L + movq mm4, MMWORD [wk(3)] ; mm4=tmp13H + movq mm2, MMWORD [wk(8)] ; mm2=tmp0L + movq mm7, MMWORD [wk(9)] ; mm7=tmp0H + + movq mm0,mm1 + movq mm6,mm4 + paddd mm1,mm2 ; mm1=data3L + paddd mm4,mm7 ; mm4=data3H + psubd mm0,mm2 ; mm0=data4L + psubd mm6,mm7 ; mm6=data4H + + movq mm2,[GOTOFF(ebx,PD_DESCALE_P1)] ; mm2=[PD_DESCALE_P1] + + paddd mm1,mm2 + paddd mm4,mm2 + psrad mm1,DESCALE_P1 + psrad mm4,DESCALE_P1 + paddd mm0,mm2 + paddd mm6,mm2 + psrad mm0,DESCALE_P1 + psrad mm6,DESCALE_P1 + + packssdw mm1,mm4 ; mm1=data3=(30 31 32 33) + packssdw mm0,mm6 ; mm0=data4=(40 41 42 43) + + movq mm7, MMWORD [wk(0)] ; mm7=(00 10 01 11) + movq mm2, MMWORD [wk(1)] ; mm2=(02 12 03 13) + + movq mm4,mm3 ; transpose coefficients(phase 1) + punpcklwd mm3,mm1 ; mm3=(20 30 21 31) + punpckhwd mm4,mm1 ; mm4=(22 32 23 33) + movq mm6,mm0 ; transpose coefficients(phase 1) + punpcklwd mm0,mm5 ; mm0=(40 50 41 51) + punpckhwd mm6,mm5 ; mm6=(42 52 43 53) + + movq mm1,mm7 ; transpose coefficients(phase 2) + punpckldq mm7,mm3 ; mm7=(00 10 20 30) + punpckhdq mm1,mm3 ; mm1=(01 11 21 31) + movq mm5,mm2 ; transpose coefficients(phase 2) + punpckldq mm2,mm4 ; mm2=(02 12 22 32) + punpckhdq mm5,mm4 ; mm5=(03 13 23 33) + + movq mm3, MMWORD [wk(4)] ; mm3=(60 70 61 71) + movq mm4, MMWORD [wk(5)] ; mm4=(62 72 63 73) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm7 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm5 + + movq mm7,mm0 ; transpose coefficients(phase 2) + punpckldq mm0,mm3 ; mm0=(40 50 60 70) + punpckhdq mm7,mm3 ; mm7=(41 51 61 71) + movq mm1,mm6 ; transpose coefficients(phase 2) + punpckldq mm6,mm4 ; mm6=(42 52 62 72) + punpckhdq mm1,mm4 ; mm1=(43 53 63 73) + + movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm7 + movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm6 + movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm1 + +.nextcolumn: + add esi, byte 4*SIZEOF_JCOEF ; coef_block + add edx, byte 4*SIZEOF_ISLOW_MULT_TYPE ; quantptr + add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr + dec ecx ; ctr + jnz near .columnloop + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + lea esi, [workspace] ; JCOEF * wsptr + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.rowloop: + + ; -- Even part + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + + ; (Original) + ; z1 = (z2 + z3) * 0.541196100; + ; tmp2 = z1 + z3 * -1.847759065; + ; tmp3 = z1 + z2 * 0.765366865; + ; + ; (This implementation) + ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); + ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; + + movq mm4,mm1 ; mm1=in2=z2 + movq mm5,mm1 + punpcklwd mm4,mm3 ; mm3=in6=z3 + punpckhwd mm5,mm3 + movq mm1,mm4 + movq mm3,mm5 + pmaddwd mm4,[GOTOFF(ebx,PW_F130_F054)] ; mm4=tmp3L + pmaddwd mm5,[GOTOFF(ebx,PW_F130_F054)] ; mm5=tmp3H + pmaddwd mm1,[GOTOFF(ebx,PW_F054_MF130)] ; mm1=tmp2L + pmaddwd mm3,[GOTOFF(ebx,PW_F054_MF130)] ; mm3=tmp2H + + movq mm6,mm0 + paddw mm0,mm2 ; mm0=in0+in4 + psubw mm6,mm2 ; mm6=in0-in4 + + pxor mm7,mm7 + pxor mm2,mm2 + punpcklwd mm7,mm0 ; mm7=tmp0L + punpckhwd mm2,mm0 ; mm2=tmp0H + psrad mm7,(16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS + psrad mm2,(16-CONST_BITS) ; psrad mm2,16 & pslld mm2,CONST_BITS + + movq mm0,mm7 + paddd mm7,mm4 ; mm7=tmp10L + psubd mm0,mm4 ; mm0=tmp13L + movq mm4,mm2 + paddd mm2,mm5 ; mm2=tmp10H + psubd mm4,mm5 ; mm4=tmp13H + + movq MMWORD [wk(0)], mm7 ; wk(0)=tmp10L + movq MMWORD [wk(1)], mm2 ; wk(1)=tmp10H + movq MMWORD [wk(2)], mm0 ; wk(2)=tmp13L + movq MMWORD [wk(3)], mm4 ; wk(3)=tmp13H + + pxor mm5,mm5 + pxor mm7,mm7 + punpcklwd mm5,mm6 ; mm5=tmp1L + punpckhwd mm7,mm6 ; mm7=tmp1H + psrad mm5,(16-CONST_BITS) ; psrad mm5,16 & pslld mm5,CONST_BITS + psrad mm7,(16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS + + movq mm2,mm5 + paddd mm5,mm1 ; mm5=tmp11L + psubd mm2,mm1 ; mm2=tmp12L + movq mm0,mm7 + paddd mm7,mm3 ; mm7=tmp11H + psubd mm0,mm3 ; mm0=tmp12H + + movq MMWORD [wk(4)], mm5 ; wk(4)=tmp11L + movq MMWORD [wk(5)], mm7 ; wk(5)=tmp11H + movq MMWORD [wk(6)], mm2 ; wk(6)=tmp12L + movq MMWORD [wk(7)], mm0 ; wk(7)=tmp12H + + ; -- Odd part + + movq mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm6, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + + movq mm5,mm6 + movq mm7,mm4 + paddw mm5,mm3 ; mm5=z3 + paddw mm7,mm1 ; mm7=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movq mm2,mm5 + movq mm0,mm5 + punpcklwd mm2,mm7 + punpckhwd mm0,mm7 + movq mm5,mm2 + movq mm7,mm0 + pmaddwd mm2,[GOTOFF(ebx,PW_MF078_F117)] ; mm2=z3L + pmaddwd mm0,[GOTOFF(ebx,PW_MF078_F117)] ; mm0=z3H + pmaddwd mm5,[GOTOFF(ebx,PW_F117_F078)] ; mm5=z4L + pmaddwd mm7,[GOTOFF(ebx,PW_F117_F078)] ; mm7=z4H + + movq MMWORD [wk(10)], mm2 ; wk(10)=z3L + movq MMWORD [wk(11)], mm0 ; wk(11)=z3H + + ; (Original) + ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; + ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; + ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; tmp0 += z1 + z3; tmp1 += z2 + z4; + ; tmp2 += z2 + z3; tmp3 += z1 + z4; + ; + ; (This implementation) + ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; + ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; + ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); + ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); + ; tmp0 += z3; tmp1 += z4; + ; tmp2 += z3; tmp3 += z4; + + movq mm2,mm3 + movq mm0,mm3 + punpcklwd mm2,mm4 + punpckhwd mm0,mm4 + movq mm3,mm2 + movq mm4,mm0 + pmaddwd mm2,[GOTOFF(ebx,PW_MF060_MF089)] ; mm2=tmp0L + pmaddwd mm0,[GOTOFF(ebx,PW_MF060_MF089)] ; mm0=tmp0H + pmaddwd mm3,[GOTOFF(ebx,PW_MF089_F060)] ; mm3=tmp3L + pmaddwd mm4,[GOTOFF(ebx,PW_MF089_F060)] ; mm4=tmp3H + + paddd mm2, MMWORD [wk(10)] ; mm2=tmp0L + paddd mm0, MMWORD [wk(11)] ; mm0=tmp0H + paddd mm3,mm5 ; mm3=tmp3L + paddd mm4,mm7 ; mm4=tmp3H + + movq MMWORD [wk(8)], mm2 ; wk(8)=tmp0L + movq MMWORD [wk(9)], mm0 ; wk(9)=tmp0H + + movq mm2,mm1 + movq mm0,mm1 + punpcklwd mm2,mm6 + punpckhwd mm0,mm6 + movq mm1,mm2 + movq mm6,mm0 + pmaddwd mm2,[GOTOFF(ebx,PW_MF050_MF256)] ; mm2=tmp1L + pmaddwd mm0,[GOTOFF(ebx,PW_MF050_MF256)] ; mm0=tmp1H + pmaddwd mm1,[GOTOFF(ebx,PW_MF256_F050)] ; mm1=tmp2L + pmaddwd mm6,[GOTOFF(ebx,PW_MF256_F050)] ; mm6=tmp2H + + paddd mm2,mm5 ; mm2=tmp1L + paddd mm0,mm7 ; mm0=tmp1H + paddd mm1, MMWORD [wk(10)] ; mm1=tmp2L + paddd mm6, MMWORD [wk(11)] ; mm6=tmp2H + + movq MMWORD [wk(10)], mm2 ; wk(10)=tmp1L + movq MMWORD [wk(11)], mm0 ; wk(11)=tmp1H + + ; -- Final output stage + + movq mm5, MMWORD [wk(0)] ; mm5=tmp10L + movq mm7, MMWORD [wk(1)] ; mm7=tmp10H + + movq mm2,mm5 + movq mm0,mm7 + paddd mm5,mm3 ; mm5=data0L + paddd mm7,mm4 ; mm7=data0H + psubd mm2,mm3 ; mm2=data7L + psubd mm0,mm4 ; mm0=data7H + + movq mm3,[GOTOFF(ebx,PD_DESCALE_P2)] ; mm3=[PD_DESCALE_P2] + + paddd mm5,mm3 + paddd mm7,mm3 + psrad mm5,DESCALE_P2 + psrad mm7,DESCALE_P2 + paddd mm2,mm3 + paddd mm0,mm3 + psrad mm2,DESCALE_P2 + psrad mm0,DESCALE_P2 + + packssdw mm5,mm7 ; mm5=data0=(00 10 20 30) + packssdw mm2,mm0 ; mm2=data7=(07 17 27 37) + + movq mm4, MMWORD [wk(4)] ; mm4=tmp11L + movq mm3, MMWORD [wk(5)] ; mm3=tmp11H + + movq mm7,mm4 + movq mm0,mm3 + paddd mm4,mm1 ; mm4=data1L + paddd mm3,mm6 ; mm3=data1H + psubd mm7,mm1 ; mm7=data6L + psubd mm0,mm6 ; mm0=data6H + + movq mm1,[GOTOFF(ebx,PD_DESCALE_P2)] ; mm1=[PD_DESCALE_P2] + + paddd mm4,mm1 + paddd mm3,mm1 + psrad mm4,DESCALE_P2 + psrad mm3,DESCALE_P2 + paddd mm7,mm1 + paddd mm0,mm1 + psrad mm7,DESCALE_P2 + psrad mm0,DESCALE_P2 + + packssdw mm4,mm3 ; mm4=data1=(01 11 21 31) + packssdw mm7,mm0 ; mm7=data6=(06 16 26 36) + + packsswb mm5,mm7 ; mm5=(00 10 20 30 06 16 26 36) + packsswb mm4,mm2 ; mm4=(01 11 21 31 07 17 27 37) + + movq mm6, MMWORD [wk(6)] ; mm6=tmp12L + movq mm1, MMWORD [wk(7)] ; mm1=tmp12H + movq mm3, MMWORD [wk(10)] ; mm3=tmp1L + movq mm0, MMWORD [wk(11)] ; mm0=tmp1H + + movq MMWORD [wk(0)], mm5 ; wk(0)=(00 10 20 30 06 16 26 36) + movq MMWORD [wk(1)], mm4 ; wk(1)=(01 11 21 31 07 17 27 37) + + movq mm7,mm6 + movq mm2,mm1 + paddd mm6,mm3 ; mm6=data2L + paddd mm1,mm0 ; mm1=data2H + psubd mm7,mm3 ; mm7=data5L + psubd mm2,mm0 ; mm2=data5H + + movq mm5,[GOTOFF(ebx,PD_DESCALE_P2)] ; mm5=[PD_DESCALE_P2] + + paddd mm6,mm5 + paddd mm1,mm5 + psrad mm6,DESCALE_P2 + psrad mm1,DESCALE_P2 + paddd mm7,mm5 + paddd mm2,mm5 + psrad mm7,DESCALE_P2 + psrad mm2,DESCALE_P2 + + packssdw mm6,mm1 ; mm6=data2=(02 12 22 32) + packssdw mm7,mm2 ; mm7=data5=(05 15 25 35) + + movq mm4, MMWORD [wk(2)] ; mm4=tmp13L + movq mm3, MMWORD [wk(3)] ; mm3=tmp13H + movq mm0, MMWORD [wk(8)] ; mm0=tmp0L + movq mm5, MMWORD [wk(9)] ; mm5=tmp0H + + movq mm1,mm4 + movq mm2,mm3 + paddd mm4,mm0 ; mm4=data3L + paddd mm3,mm5 ; mm3=data3H + psubd mm1,mm0 ; mm1=data4L + psubd mm2,mm5 ; mm2=data4H + + movq mm0,[GOTOFF(ebx,PD_DESCALE_P2)] ; mm0=[PD_DESCALE_P2] + + paddd mm4,mm0 + paddd mm3,mm0 + psrad mm4,DESCALE_P2 + psrad mm3,DESCALE_P2 + paddd mm1,mm0 + paddd mm2,mm0 + psrad mm1,DESCALE_P2 + psrad mm2,DESCALE_P2 + + movq mm5,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm5=[PB_CENTERJSAMP] + + packssdw mm4,mm3 ; mm4=data3=(03 13 23 33) + packssdw mm1,mm2 ; mm1=data4=(04 14 24 34) + + movq mm0, MMWORD [wk(0)] ; mm0=(00 10 20 30 06 16 26 36) + movq mm3, MMWORD [wk(1)] ; mm3=(01 11 21 31 07 17 27 37) + + packsswb mm6,mm1 ; mm6=(02 12 22 32 04 14 24 34) + packsswb mm4,mm7 ; mm4=(03 13 23 33 05 15 25 35) + + paddb mm0,mm5 + paddb mm3,mm5 + paddb mm6,mm5 + paddb mm4,mm5 + + movq mm2,mm0 ; transpose coefficients(phase 1) + punpcklbw mm0,mm3 ; mm0=(00 01 10 11 20 21 30 31) + punpckhbw mm2,mm3 ; mm2=(06 07 16 17 26 27 36 37) + movq mm1,mm6 ; transpose coefficients(phase 1) + punpcklbw mm6,mm4 ; mm6=(02 03 12 13 22 23 32 33) + punpckhbw mm1,mm4 ; mm1=(04 05 14 15 24 25 34 35) + + movq mm7,mm0 ; transpose coefficients(phase 2) + punpcklwd mm0,mm6 ; mm0=(00 01 02 03 10 11 12 13) + punpckhwd mm7,mm6 ; mm7=(20 21 22 23 30 31 32 33) + movq mm5,mm1 ; transpose coefficients(phase 2) + punpcklwd mm1,mm2 ; mm1=(04 05 06 07 14 15 16 17) + punpckhwd mm5,mm2 ; mm5=(24 25 26 27 34 35 36 37) + + movq mm3,mm0 ; transpose coefficients(phase 3) + punpckldq mm0,mm1 ; mm0=(00 01 02 03 04 05 06 07) + punpckhdq mm3,mm1 ; mm3=(10 11 12 13 14 15 16 17) + movq mm4,mm7 ; transpose coefficients(phase 3) + punpckldq mm7,mm5 ; mm7=(20 21 22 23 24 25 26 27) + punpckhdq mm4,mm5 ; mm4=(30 31 32 33 34 35 36 37) + + pushpic ebx ; save GOT address + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm0 + movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm3 + mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm7 + movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm4 + + poppic ebx ; restore GOT address + + add esi, byte 4*SIZEOF_JCOEF ; wsptr + add edi, byte 4*SIZEOF_JSAMPROW + dec ecx ; ctr + jnz near .rowloop + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxred.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxred.asm new file mode 100755 index 0000000..a2b7103 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jimmxred.asm @@ -0,0 +1,706 @@ +; +; jimmxred.asm - reduced-size IDCT (MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains inverse-DCT routines that produce reduced-size +; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. +; The following code is based directly on the IJG's original jidctred.c; +; see the jidctred.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1_4 (CONST_BITS-PASS1_BITS+1) +%define DESCALE_P2_4 (CONST_BITS+PASS1_BITS+3+1) +%define DESCALE_P1_2 (CONST_BITS-PASS1_BITS+2) +%define DESCALE_P2_2 (CONST_BITS+PASS1_BITS+3+2) + +%if CONST_BITS == 13 +F_0_211 equ 1730 ; FIX(0.211164243) +F_0_509 equ 4176 ; FIX(0.509795579) +F_0_601 equ 4926 ; FIX(0.601344887) +F_0_720 equ 5906 ; FIX(0.720959822) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_850 equ 6967 ; FIX(0.850430095) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_061 equ 8697 ; FIX(1.061594337) +F_1_272 equ 10426 ; FIX(1.272758580) +F_1_451 equ 11893 ; FIX(1.451774981) +F_1_847 equ 15137 ; FIX(1.847759065) +F_2_172 equ 17799 ; FIX(2.172734803) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_624 equ 29692 ; FIX(3.624509785) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_211 equ DESCALE( 226735879,30-CONST_BITS) ; FIX(0.211164243) +F_0_509 equ DESCALE( 547388834,30-CONST_BITS) ; FIX(0.509795579) +F_0_601 equ DESCALE( 645689155,30-CONST_BITS) ; FIX(0.601344887) +F_0_720 equ DESCALE( 774124714,30-CONST_BITS) ; FIX(0.720959822) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_850 equ DESCALE( 913142361,30-CONST_BITS) ; FIX(0.850430095) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_061 equ DESCALE(1139878239,30-CONST_BITS) ; FIX(1.061594337) +F_1_272 equ DESCALE(1366614119,30-CONST_BITS) ; FIX(1.272758580) +F_1_451 equ DESCALE(1558831516,30-CONST_BITS) ; FIX(1.451774981) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_2_172 equ DESCALE(2332956230,30-CONST_BITS) ; FIX(2.172734803) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_624 equ DESCALE(3891787747,30-CONST_BITS) ; FIX(3.624509785) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_red_mmx) + +EXTN(jconst_idct_red_mmx): + +PW_F184_MF076 times 2 dw F_1_847,-F_0_765 +PW_F256_F089 times 2 dw F_2_562, F_0_899 +PW_F106_MF217 times 2 dw F_1_061,-F_2_172 +PW_MF060_MF050 times 2 dw -F_0_601,-F_0_509 +PW_F145_MF021 times 2 dw F_1_451,-F_0_211 +PW_F362_MF127 times 2 dw F_3_624,-F_1_272 +PW_F085_MF072 times 2 dw F_0_850,-F_0_720 +PD_DESCALE_P1_4 times 2 dd 1 << (DESCALE_P1_4-1) +PD_DESCALE_P2_4 times 2 dd 1 << (DESCALE_P2_4-1) +PD_DESCALE_P1_2 times 2 dd 1 << (DESCALE_P1_2-1) +PD_DESCALE_P2_2 times 2 dd 1 << (DESCALE_P2_2-1) +PB_CENTERJSAMP times 8 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients, +; producing a reduced-size 4x4 output block. +; +; GLOBAL(void) +; jsimd_idct_4x4_mmx (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; void * dct_table +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] +%define WK_NUM 2 +%define workspace wk(0)-DCTSIZE2*SIZEOF_JCOEF + ; JCOEF workspace[DCTSIZE2] + + align 16 + global EXTN(jsimd_idct_4x4_mmx) + +EXTN(jsimd_idct_4x4_mmx): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [workspace] + pushpic ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input, store into work array. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + lea edi, [workspace] ; JCOEF * wsptr + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.columnloop: +%ifndef NO_ZERO_COLUMN_TEST_4X4_MMX + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz short .columnDCT + + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por mm0,mm1 + packsswb mm0,mm0 + movd eax,mm0 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + psllw mm0,PASS1_BITS + + movq mm2,mm0 ; mm0=in0=(00 01 02 03) + punpcklwd mm0,mm0 ; mm0=(00 00 01 01) + punpckhwd mm2,mm2 ; mm2=(02 02 03 03) + + movq mm1,mm0 + punpckldq mm0,mm0 ; mm0=(00 00 00 00) + punpckhdq mm1,mm1 ; mm1=(01 01 01 01) + movq mm3,mm2 + punpckldq mm2,mm2 ; mm2=(02 02 02 02) + punpckhdq mm3,mm3 ; mm3=(03 03 03 03) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 + jmp near .nextcolumn + alignx 16,7 +%endif +.columnDCT: + + ; -- Odd part + + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + movq mm4,mm0 + movq mm5,mm0 + punpcklwd mm4,mm1 + punpckhwd mm5,mm1 + movq mm0,mm4 + movq mm1,mm5 + pmaddwd mm4,[GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L) + pmaddwd mm5,[GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H) + pmaddwd mm0,[GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L) + pmaddwd mm1,[GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H) + + movq mm6,mm2 + movq mm7,mm2 + punpcklwd mm6,mm3 + punpckhwd mm7,mm3 + movq mm2,mm6 + movq mm3,mm7 + pmaddwd mm6,[GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L) + pmaddwd mm7,[GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H) + pmaddwd mm2,[GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L) + pmaddwd mm3,[GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H) + + paddd mm6,mm4 ; mm6=tmp2L + paddd mm7,mm5 ; mm7=tmp2H + paddd mm2,mm0 ; mm2=tmp0L + paddd mm3,mm1 ; mm3=tmp0H + + movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L + movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H + + ; -- Even part + + movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + pmullw mm4, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm5, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm0, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + pxor mm1,mm1 + pxor mm2,mm2 + punpcklwd mm1,mm4 ; mm1=tmp0L + punpckhwd mm2,mm4 ; mm2=tmp0H + psrad mm1,(16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1 + psrad mm2,(16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1 + + movq mm3,mm5 ; mm5=in2=z2 + punpcklwd mm5,mm0 ; mm0=in6=z3 + punpckhwd mm3,mm0 + pmaddwd mm5,[GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L + pmaddwd mm3,[GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H + + movq mm4,mm1 + movq mm0,mm2 + paddd mm1,mm5 ; mm1=tmp10L + paddd mm2,mm3 ; mm2=tmp10H + psubd mm4,mm5 ; mm4=tmp12L + psubd mm0,mm3 ; mm0=tmp12H + + ; -- Final output stage + + movq mm5,mm1 + movq mm3,mm2 + paddd mm1,mm6 ; mm1=data0L + paddd mm2,mm7 ; mm2=data0H + psubd mm5,mm6 ; mm5=data3L + psubd mm3,mm7 ; mm3=data3H + + movq mm6,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm6=[PD_DESCALE_P1_4] + + paddd mm1,mm6 + paddd mm2,mm6 + psrad mm1,DESCALE_P1_4 + psrad mm2,DESCALE_P1_4 + paddd mm5,mm6 + paddd mm3,mm6 + psrad mm5,DESCALE_P1_4 + psrad mm3,DESCALE_P1_4 + + packssdw mm1,mm2 ; mm1=data0=(00 01 02 03) + packssdw mm5,mm3 ; mm5=data3=(30 31 32 33) + + movq mm7, MMWORD [wk(0)] ; mm7=tmp0L + movq mm6, MMWORD [wk(1)] ; mm6=tmp0H + + movq mm2,mm4 + movq mm3,mm0 + paddd mm4,mm7 ; mm4=data1L + paddd mm0,mm6 ; mm0=data1H + psubd mm2,mm7 ; mm2=data2L + psubd mm3,mm6 ; mm3=data2H + + movq mm7,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm7=[PD_DESCALE_P1_4] + + paddd mm4,mm7 + paddd mm0,mm7 + psrad mm4,DESCALE_P1_4 + psrad mm0,DESCALE_P1_4 + paddd mm2,mm7 + paddd mm3,mm7 + psrad mm2,DESCALE_P1_4 + psrad mm3,DESCALE_P1_4 + + packssdw mm4,mm0 ; mm4=data1=(10 11 12 13) + packssdw mm2,mm3 ; mm2=data2=(20 21 22 23) + + movq mm6,mm1 ; transpose coefficients(phase 1) + punpcklwd mm1,mm4 ; mm1=(00 10 01 11) + punpckhwd mm6,mm4 ; mm6=(02 12 03 13) + movq mm7,mm2 ; transpose coefficients(phase 1) + punpcklwd mm2,mm5 ; mm2=(20 30 21 31) + punpckhwd mm7,mm5 ; mm7=(22 32 23 33) + + movq mm0,mm1 ; transpose coefficients(phase 2) + punpckldq mm1,mm2 ; mm1=(00 10 20 30) + punpckhdq mm0,mm2 ; mm0=(01 11 21 31) + movq mm3,mm6 ; transpose coefficients(phase 2) + punpckldq mm6,mm7 ; mm6=(02 12 22 32) + punpckhdq mm3,mm7 ; mm3=(03 13 23 33) + + movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm1 + movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0 + movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm6 + movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3 + +.nextcolumn: + add esi, byte 4*SIZEOF_JCOEF ; coef_block + add edx, byte 4*SIZEOF_ISLOW_MULT_TYPE ; quantptr + add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr + dec ecx ; ctr + jnz near .columnloop + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + lea esi, [workspace] ; JCOEF * wsptr + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + + ; -- Odd part + + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + + movq mm4,mm0 + movq mm5,mm0 + punpcklwd mm4,mm1 + punpckhwd mm5,mm1 + movq mm0,mm4 + movq mm1,mm5 + pmaddwd mm4,[GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L) + pmaddwd mm5,[GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H) + pmaddwd mm0,[GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L) + pmaddwd mm1,[GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H) + + movq mm6,mm2 + movq mm7,mm2 + punpcklwd mm6,mm3 + punpckhwd mm7,mm3 + movq mm2,mm6 + movq mm3,mm7 + pmaddwd mm6,[GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L) + pmaddwd mm7,[GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H) + pmaddwd mm2,[GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L) + pmaddwd mm3,[GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H) + + paddd mm6,mm4 ; mm6=tmp2L + paddd mm7,mm5 ; mm7=tmp2H + paddd mm2,mm0 ; mm2=tmp0L + paddd mm3,mm1 ; mm3=tmp0H + + movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L + movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H + + ; -- Even part + + movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + + pxor mm1,mm1 + pxor mm2,mm2 + punpcklwd mm1,mm4 ; mm1=tmp0L + punpckhwd mm2,mm4 ; mm2=tmp0H + psrad mm1,(16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1 + psrad mm2,(16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1 + + movq mm3,mm5 ; mm5=in2=z2 + punpcklwd mm5,mm0 ; mm0=in6=z3 + punpckhwd mm3,mm0 + pmaddwd mm5,[GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L + pmaddwd mm3,[GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H + + movq mm4,mm1 + movq mm0,mm2 + paddd mm1,mm5 ; mm1=tmp10L + paddd mm2,mm3 ; mm2=tmp10H + psubd mm4,mm5 ; mm4=tmp12L + psubd mm0,mm3 ; mm0=tmp12H + + ; -- Final output stage + + movq mm5,mm1 + movq mm3,mm2 + paddd mm1,mm6 ; mm1=data0L + paddd mm2,mm7 ; mm2=data0H + psubd mm5,mm6 ; mm5=data3L + psubd mm3,mm7 ; mm3=data3H + + movq mm6,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm6=[PD_DESCALE_P2_4] + + paddd mm1,mm6 + paddd mm2,mm6 + psrad mm1,DESCALE_P2_4 + psrad mm2,DESCALE_P2_4 + paddd mm5,mm6 + paddd mm3,mm6 + psrad mm5,DESCALE_P2_4 + psrad mm3,DESCALE_P2_4 + + packssdw mm1,mm2 ; mm1=data0=(00 10 20 30) + packssdw mm5,mm3 ; mm5=data3=(03 13 23 33) + + movq mm7, MMWORD [wk(0)] ; mm7=tmp0L + movq mm6, MMWORD [wk(1)] ; mm6=tmp0H + + movq mm2,mm4 + movq mm3,mm0 + paddd mm4,mm7 ; mm4=data1L + paddd mm0,mm6 ; mm0=data1H + psubd mm2,mm7 ; mm2=data2L + psubd mm3,mm6 ; mm3=data2H + + movq mm7,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm7=[PD_DESCALE_P2_4] + + paddd mm4,mm7 + paddd mm0,mm7 + psrad mm4,DESCALE_P2_4 + psrad mm0,DESCALE_P2_4 + paddd mm2,mm7 + paddd mm3,mm7 + psrad mm2,DESCALE_P2_4 + psrad mm3,DESCALE_P2_4 + + packssdw mm4,mm0 ; mm4=data1=(01 11 21 31) + packssdw mm2,mm3 ; mm2=data2=(02 12 22 32) + + movq mm6,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm6=[PB_CENTERJSAMP] + + packsswb mm1,mm2 ; mm1=(00 10 20 30 02 12 22 32) + packsswb mm4,mm5 ; mm4=(01 11 21 31 03 13 23 33) + paddb mm1,mm6 + paddb mm4,mm6 + + movq mm7,mm1 ; transpose coefficients(phase 1) + punpcklbw mm1,mm4 ; mm1=(00 01 10 11 20 21 30 31) + punpckhbw mm7,mm4 ; mm7=(02 03 12 13 22 23 32 33) + + movq mm0,mm1 ; transpose coefficients(phase 2) + punpcklwd mm1,mm7 ; mm1=(00 01 02 03 10 11 12 13) + punpckhwd mm0,mm7 ; mm0=(20 21 22 23 30 31 32 33) + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1 + movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0 + + psrlq mm1,4*BYTE_BIT + psrlq mm0,4*BYTE_BIT + + mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1 + movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0 + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + + +; -------------------------------------------------------------------------- +; +; Perform dequantization and inverse DCT on one block of coefficients, +; producing a reduced-size 2x2 output block. +; +; GLOBAL(void) +; jsimd_idct_2x2_mmx (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; void * dct_table +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + + align 16 + global EXTN(jsimd_idct_2x2_mmx) + +EXTN(jsimd_idct_2x2_mmx): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input. + + mov edx, POINTER [dct_table(ebp)] ; quantptr + mov esi, JCOEFPTR [coef_block(ebp)] ; inptr + + ; | input: | result: | + ; | 00 01 ** 03 ** 05 ** 07 | | + ; | 10 11 ** 13 ** 15 ** 17 | | + ; | ** ** ** ** ** ** ** ** | | + ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 | + ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 | + ; | 50 51 ** 53 ** 55 ** 57 | | + ; | ** ** ** ** ** ** ** ** | | + ; | 70 71 ** 73 ** 75 ** 77 | | + + ; -- Odd part + + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + ; mm0=(10 11 ** 13), mm1=(30 31 ** 33) + ; mm2=(50 51 ** 53), mm3=(70 71 ** 73) + + pcmpeqd mm7,mm7 + pslld mm7,WORD_BIT ; mm7={0x0000 0xFFFF 0x0000 0xFFFF} + + movq mm4,mm0 ; mm4=(10 11 ** 13) + movq mm5,mm2 ; mm5=(50 51 ** 53) + punpcklwd mm4,mm1 ; mm4=(10 30 11 31) + punpcklwd mm5,mm3 ; mm5=(50 70 51 71) + pmaddwd mm4,[GOTOFF(ebx,PW_F362_MF127)] + pmaddwd mm5,[GOTOFF(ebx,PW_F085_MF072)] + + psrld mm0,WORD_BIT ; mm0=(11 -- 13 --) + pand mm1,mm7 ; mm1=(-- 31 -- 33) + psrld mm2,WORD_BIT ; mm2=(51 -- 53 --) + pand mm3,mm7 ; mm3=(-- 71 -- 73) + por mm0,mm1 ; mm0=(11 31 13 33) + por mm2,mm3 ; mm2=(51 71 53 73) + pmaddwd mm0,[GOTOFF(ebx,PW_F362_MF127)] + pmaddwd mm2,[GOTOFF(ebx,PW_F085_MF072)] + + paddd mm4,mm5 ; mm4=tmp0[col0 col1] + + movq mm6, MMWORD [MMBLOCK(1,1,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(3,1,esi,SIZEOF_JCOEF)] + pmullw mm6, MMWORD [MMBLOCK(1,1,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm1, MMWORD [MMBLOCK(3,1,edx,SIZEOF_ISLOW_MULT_TYPE)] + movq mm3, MMWORD [MMBLOCK(5,1,esi,SIZEOF_JCOEF)] + movq mm5, MMWORD [MMBLOCK(7,1,esi,SIZEOF_JCOEF)] + pmullw mm3, MMWORD [MMBLOCK(5,1,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm5, MMWORD [MMBLOCK(7,1,edx,SIZEOF_ISLOW_MULT_TYPE)] + + ; mm6=(** 15 ** 17), mm1=(** 35 ** 37) + ; mm3=(** 55 ** 57), mm5=(** 75 ** 77) + + psrld mm6,WORD_BIT ; mm6=(15 -- 17 --) + pand mm1,mm7 ; mm1=(-- 35 -- 37) + psrld mm3,WORD_BIT ; mm3=(55 -- 57 --) + pand mm5,mm7 ; mm5=(-- 75 -- 77) + por mm6,mm1 ; mm6=(15 35 17 37) + por mm3,mm5 ; mm3=(55 75 57 77) + pmaddwd mm6,[GOTOFF(ebx,PW_F362_MF127)] + pmaddwd mm3,[GOTOFF(ebx,PW_F085_MF072)] + + paddd mm0,mm2 ; mm0=tmp0[col1 col3] + paddd mm6,mm3 ; mm6=tmp0[col5 col7] + + ; -- Even part + + movq mm1, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm5, MMWORD [MMBLOCK(0,1,esi,SIZEOF_JCOEF)] + pmullw mm1, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw mm5, MMWORD [MMBLOCK(0,1,edx,SIZEOF_ISLOW_MULT_TYPE)] + + ; mm1=(00 01 ** 03), mm5=(** 05 ** 07) + + movq mm2,mm1 ; mm2=(00 01 ** 03) + pslld mm1,WORD_BIT ; mm1=(-- 00 -- **) + psrad mm1,(WORD_BIT-CONST_BITS-2) ; mm1=tmp10[col0 ****] + + pand mm2,mm7 ; mm2=(-- 01 -- 03) + pand mm5,mm7 ; mm5=(-- 05 -- 07) + psrad mm2,(WORD_BIT-CONST_BITS-2) ; mm2=tmp10[col1 col3] + psrad mm5,(WORD_BIT-CONST_BITS-2) ; mm5=tmp10[col5 col7] + + ; -- Final output stage + + movq mm3,mm1 + paddd mm1,mm4 ; mm1=data0[col0 ****]=(A0 **) + psubd mm3,mm4 ; mm3=data1[col0 ****]=(B0 **) + punpckldq mm1,mm3 ; mm1=(A0 B0) + + movq mm7,[GOTOFF(ebx,PD_DESCALE_P1_2)] ; mm7=[PD_DESCALE_P1_2] + + movq mm4,mm2 + movq mm3,mm5 + paddd mm2,mm0 ; mm2=data0[col1 col3]=(A1 A3) + paddd mm5,mm6 ; mm5=data0[col5 col7]=(A5 A7) + psubd mm4,mm0 ; mm4=data1[col1 col3]=(B1 B3) + psubd mm3,mm6 ; mm3=data1[col5 col7]=(B5 B7) + + paddd mm1,mm7 + psrad mm1,DESCALE_P1_2 + + paddd mm2,mm7 + paddd mm5,mm7 + psrad mm2,DESCALE_P1_2 + psrad mm5,DESCALE_P1_2 + paddd mm4,mm7 + paddd mm3,mm7 + psrad mm4,DESCALE_P1_2 + psrad mm3,DESCALE_P1_2 + + ; ---- Pass 2: process rows, store into output array. + + mov edi, JSAMPARRAY [output_buf(ebp)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(ebp)] + + ; | input:| result:| + ; | A0 B0 | | + ; | A1 B1 | C0 C1 | + ; | A3 B3 | D0 D1 | + ; | A5 B5 | | + ; | A7 B7 | | + + ; -- Odd part + + packssdw mm2,mm4 ; mm2=(A1 A3 B1 B3) + packssdw mm5,mm3 ; mm5=(A5 A7 B5 B7) + pmaddwd mm2,[GOTOFF(ebx,PW_F362_MF127)] + pmaddwd mm5,[GOTOFF(ebx,PW_F085_MF072)] + + paddd mm2,mm5 ; mm2=tmp0[row0 row1] + + ; -- Even part + + pslld mm1,(CONST_BITS+2) ; mm1=tmp10[row0 row1] + + ; -- Final output stage + + movq mm0,[GOTOFF(ebx,PD_DESCALE_P2_2)] ; mm0=[PD_DESCALE_P2_2] + + movq mm6,mm1 + paddd mm1,mm2 ; mm1=data0[row0 row1]=(C0 C1) + psubd mm6,mm2 ; mm6=data1[row0 row1]=(D0 D1) + + paddd mm1,mm0 + paddd mm6,mm0 + psrad mm1,DESCALE_P2_2 + psrad mm6,DESCALE_P2_2 + + movq mm7,mm1 ; transpose coefficients + punpckldq mm1,mm6 ; mm1=(C0 D0) + punpckhdq mm7,mm6 ; mm7=(C1 D1) + + packssdw mm1,mm7 ; mm1=(C0 D0 C1 D1) + packsswb mm1,mm1 ; mm1=(C0 D0 C1 D1 C0 D0 C1 D1) + paddb mm1,[GOTOFF(ebx,PB_CENTERJSAMP)] + + movd ecx,mm1 + movd ebx,mm1 ; ebx=(C0 D0 C1 D1) + shr ecx,2*BYTE_BIT ; ecx=(C1 D1 -- --) + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + mov WORD [edx+eax*SIZEOF_JSAMPLE], bx + mov WORD [esi+eax*SIZEOF_JSAMPLE], cx + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2flt.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2flt.asm new file mode 100755 index 0000000..17bc363 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2flt.asm @@ -0,0 +1,498 @@ +; +; jiss2flt.asm - floating-point IDCT (SSE & SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a floating-point implementation of the inverse DCT +; (Discrete Cosine Transform). The following code is based directly on +; the IJG's original jidctflt.c; see the jidctflt.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5) + shufps %1,%2,0x44 +%endmacro + +%macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7) + shufps %1,%2,0xEE +%endmacro + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_float_sse2) + +EXTN(jconst_idct_float_sse2): + +PD_1_414 times 4 dd 1.414213562373095048801689 +PD_1_847 times 4 dd 1.847759065022573512256366 +PD_1_082 times 4 dd 1.082392200292393968799446 +PD_M2_613 times 4 dd -2.613125929752753055713286 +PD_RNDINT_MAGIC times 4 dd 100663296.0 ; (float)(0x00C00000 << 3) +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_float_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; void * dct_table +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 +%define workspace wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT + ; FAST_FLOAT workspace[DCTSIZE2] + + align 16 + global EXTN(jsimd_idct_float_sse2) + +EXTN(jsimd_idct_float_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [workspace] + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input, store into work array. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + lea edi, [workspace] ; FAST_FLOAT * wsptr + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.columnloop: +%ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz near .columnDCT + + movq xmm1, XMM_MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq xmm2, XMM_MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movq xmm3, XMM_MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + movq xmm4, XMM_MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movq xmm5, XMM_MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq xmm6, XMM_MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + movq xmm7, XMM_MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por xmm1,xmm2 + por xmm3,xmm4 + por xmm5,xmm6 + por xmm1,xmm3 + por xmm5,xmm7 + por xmm1,xmm5 + packsswb xmm1,xmm1 + movd eax,xmm1 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movq xmm0, XMM_MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + psrad xmm0,(DWORD_BIT-WORD_BIT) ; xmm0=in0=(00 01 02 03) + cvtdq2ps xmm0,xmm0 ; xmm0=in0=(00 01 02 03) + + mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm1,xmm0 + movaps xmm2,xmm0 + movaps xmm3,xmm0 + + shufps xmm0,xmm0,0x00 ; xmm0=(00 00 00 00) + shufps xmm1,xmm1,0x55 ; xmm1=(01 01 01 01) + shufps xmm2,xmm2,0xAA ; xmm2=(02 02 02 02) + shufps xmm3,xmm3,0xFF ; xmm3=(03 03 03 03) + + movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3 + jmp near .nextcolumn + alignx 16,7 +%endif +.columnDCT: + + ; -- Even part + + movq xmm0, XMM_MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq xmm1, XMM_MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movq xmm2, XMM_MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movq xmm3, XMM_MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + punpcklwd xmm1,xmm1 ; xmm1=(20 20 21 21 22 22 23 23) + psrad xmm0,(DWORD_BIT-WORD_BIT) ; xmm0=in0=(00 01 02 03) + psrad xmm1,(DWORD_BIT-WORD_BIT) ; xmm1=in2=(20 21 22 23) + cvtdq2ps xmm0,xmm0 ; xmm0=in0=(00 01 02 03) + cvtdq2ps xmm1,xmm1 ; xmm1=in2=(20 21 22 23) + + punpcklwd xmm2,xmm2 ; xmm2=(40 40 41 41 42 42 43 43) + punpcklwd xmm3,xmm3 ; xmm3=(60 60 61 61 62 62 63 63) + psrad xmm2,(DWORD_BIT-WORD_BIT) ; xmm2=in4=(40 41 42 43) + psrad xmm3,(DWORD_BIT-WORD_BIT) ; xmm3=in6=(60 61 62 63) + cvtdq2ps xmm2,xmm2 ; xmm2=in4=(40 41 42 43) + cvtdq2ps xmm3,xmm3 ; xmm3=in6=(60 61 62 63) + + mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm4,xmm0 + movaps xmm5,xmm1 + subps xmm0,xmm2 ; xmm0=tmp11 + subps xmm1,xmm3 + addps xmm4,xmm2 ; xmm4=tmp10 + addps xmm5,xmm3 ; xmm5=tmp13 + + mulps xmm1,[GOTOFF(ebx,PD_1_414)] + subps xmm1,xmm5 ; xmm1=tmp12 + + movaps xmm6,xmm4 + movaps xmm7,xmm0 + subps xmm4,xmm5 ; xmm4=tmp3 + subps xmm0,xmm1 ; xmm0=tmp2 + addps xmm6,xmm5 ; xmm6=tmp0 + addps xmm7,xmm1 ; xmm7=tmp1 + + movaps XMMWORD [wk(1)], xmm4 ; tmp3 + movaps XMMWORD [wk(0)], xmm0 ; tmp2 + + ; -- Odd part + + movq xmm2, XMM_MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq xmm3, XMM_MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + movq xmm5, XMM_MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq xmm1, XMM_MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + + punpcklwd xmm2,xmm2 ; xmm2=(10 10 11 11 12 12 13 13) + punpcklwd xmm3,xmm3 ; xmm3=(30 30 31 31 32 32 33 33) + psrad xmm2,(DWORD_BIT-WORD_BIT) ; xmm2=in1=(10 11 12 13) + psrad xmm3,(DWORD_BIT-WORD_BIT) ; xmm3=in3=(30 31 32 33) + cvtdq2ps xmm2,xmm2 ; xmm2=in1=(10 11 12 13) + cvtdq2ps xmm3,xmm3 ; xmm3=in3=(30 31 32 33) + + punpcklwd xmm5,xmm5 ; xmm5=(50 50 51 51 52 52 53 53) + punpcklwd xmm1,xmm1 ; xmm1=(70 70 71 71 72 72 73 73) + psrad xmm5,(DWORD_BIT-WORD_BIT) ; xmm5=in5=(50 51 52 53) + psrad xmm1,(DWORD_BIT-WORD_BIT) ; xmm1=in7=(70 71 72 73) + cvtdq2ps xmm5,xmm5 ; xmm5=in5=(50 51 52 53) + cvtdq2ps xmm1,xmm1 ; xmm1=in7=(70 71 72 73) + + mulps xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm5, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm1, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm4,xmm2 + movaps xmm0,xmm5 + addps xmm2,xmm1 ; xmm2=z11 + addps xmm5,xmm3 ; xmm5=z13 + subps xmm4,xmm1 ; xmm4=z12 + subps xmm0,xmm3 ; xmm0=z10 + + movaps xmm1,xmm2 + subps xmm2,xmm5 + addps xmm1,xmm5 ; xmm1=tmp7 + + mulps xmm2,[GOTOFF(ebx,PD_1_414)] ; xmm2=tmp11 + + movaps xmm3,xmm0 + addps xmm0,xmm4 + mulps xmm0,[GOTOFF(ebx,PD_1_847)] ; xmm0=z5 + mulps xmm3,[GOTOFF(ebx,PD_M2_613)] ; xmm3=(z10 * -2.613125930) + mulps xmm4,[GOTOFF(ebx,PD_1_082)] ; xmm4=(z12 * 1.082392200) + addps xmm3,xmm0 ; xmm3=tmp12 + subps xmm4,xmm0 ; xmm4=tmp10 + + ; -- Final output stage + + subps xmm3,xmm1 ; xmm3=tmp6 + movaps xmm5,xmm6 + movaps xmm0,xmm7 + addps xmm6,xmm1 ; xmm6=data0=(00 01 02 03) + addps xmm7,xmm3 ; xmm7=data1=(10 11 12 13) + subps xmm5,xmm1 ; xmm5=data7=(70 71 72 73) + subps xmm0,xmm3 ; xmm0=data6=(60 61 62 63) + subps xmm2,xmm3 ; xmm2=tmp5 + + movaps xmm1,xmm6 ; transpose coefficients(phase 1) + unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11) + unpckhps xmm1,xmm7 ; xmm1=(02 12 03 13) + movaps xmm3,xmm0 ; transpose coefficients(phase 1) + unpcklps xmm0,xmm5 ; xmm0=(60 70 61 71) + unpckhps xmm3,xmm5 ; xmm3=(62 72 63 73) + + movaps xmm7, XMMWORD [wk(0)] ; xmm7=tmp2 + movaps xmm5, XMMWORD [wk(1)] ; xmm5=tmp3 + + movaps XMMWORD [wk(0)], xmm0 ; wk(0)=(60 70 61 71) + movaps XMMWORD [wk(1)], xmm3 ; wk(1)=(62 72 63 73) + + addps xmm4,xmm2 ; xmm4=tmp4 + movaps xmm0,xmm7 + movaps xmm3,xmm5 + addps xmm7,xmm2 ; xmm7=data2=(20 21 22 23) + addps xmm5,xmm4 ; xmm5=data4=(40 41 42 43) + subps xmm0,xmm2 ; xmm0=data5=(50 51 52 53) + subps xmm3,xmm4 ; xmm3=data3=(30 31 32 33) + + movaps xmm2,xmm7 ; transpose coefficients(phase 1) + unpcklps xmm7,xmm3 ; xmm7=(20 30 21 31) + unpckhps xmm2,xmm3 ; xmm2=(22 32 23 33) + movaps xmm4,xmm5 ; transpose coefficients(phase 1) + unpcklps xmm5,xmm0 ; xmm5=(40 50 41 51) + unpckhps xmm4,xmm0 ; xmm4=(42 52 43 53) + + movaps xmm3,xmm6 ; transpose coefficients(phase 2) + unpcklps2 xmm6,xmm7 ; xmm6=(00 10 20 30) + unpckhps2 xmm3,xmm7 ; xmm3=(01 11 21 31) + movaps xmm0,xmm1 ; transpose coefficients(phase 2) + unpcklps2 xmm1,xmm2 ; xmm1=(02 12 22 32) + unpckhps2 xmm0,xmm2 ; xmm0=(03 13 23 33) + + movaps xmm7, XMMWORD [wk(0)] ; xmm7=(60 70 61 71) + movaps xmm2, XMMWORD [wk(1)] ; xmm2=(62 72 63 73) + + movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm6 + movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm0 + + movaps xmm6,xmm5 ; transpose coefficients(phase 2) + unpcklps2 xmm5,xmm7 ; xmm5=(40 50 60 70) + unpckhps2 xmm6,xmm7 ; xmm6=(41 51 61 71) + movaps xmm3,xmm4 ; transpose coefficients(phase 2) + unpcklps2 xmm4,xmm2 ; xmm4=(42 52 62 72) + unpckhps2 xmm3,xmm2 ; xmm3=(43 53 63 73) + + movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6 + movaps XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm4 + movaps XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3 + +.nextcolumn: + add esi, byte 4*SIZEOF_JCOEF ; coef_block + add edx, byte 4*SIZEOF_FLOAT_MULT_TYPE ; quantptr + add edi, 4*DCTSIZE*SIZEOF_FAST_FLOAT ; wsptr + dec ecx ; ctr + jnz near .columnloop + + ; -- Prefetch the next coefficient block + + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32] + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32] + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32] + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + lea esi, [workspace] ; FAST_FLOAT * wsptr + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.rowloop: + + ; -- Even part + + movaps xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_FAST_FLOAT)] + + movaps xmm4,xmm0 + movaps xmm5,xmm1 + subps xmm0,xmm2 ; xmm0=tmp11 + subps xmm1,xmm3 + addps xmm4,xmm2 ; xmm4=tmp10 + addps xmm5,xmm3 ; xmm5=tmp13 + + mulps xmm1,[GOTOFF(ebx,PD_1_414)] + subps xmm1,xmm5 ; xmm1=tmp12 + + movaps xmm6,xmm4 + movaps xmm7,xmm0 + subps xmm4,xmm5 ; xmm4=tmp3 + subps xmm0,xmm1 ; xmm0=tmp2 + addps xmm6,xmm5 ; xmm6=tmp0 + addps xmm7,xmm1 ; xmm7=tmp1 + + movaps XMMWORD [wk(1)], xmm4 ; tmp3 + movaps XMMWORD [wk(0)], xmm0 ; tmp2 + + ; -- Odd part + + movaps xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm5, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_FAST_FLOAT)] + + movaps xmm4,xmm2 + movaps xmm0,xmm5 + addps xmm2,xmm1 ; xmm2=z11 + addps xmm5,xmm3 ; xmm5=z13 + subps xmm4,xmm1 ; xmm4=z12 + subps xmm0,xmm3 ; xmm0=z10 + + movaps xmm1,xmm2 + subps xmm2,xmm5 + addps xmm1,xmm5 ; xmm1=tmp7 + + mulps xmm2,[GOTOFF(ebx,PD_1_414)] ; xmm2=tmp11 + + movaps xmm3,xmm0 + addps xmm0,xmm4 + mulps xmm0,[GOTOFF(ebx,PD_1_847)] ; xmm0=z5 + mulps xmm3,[GOTOFF(ebx,PD_M2_613)] ; xmm3=(z10 * -2.613125930) + mulps xmm4,[GOTOFF(ebx,PD_1_082)] ; xmm4=(z12 * 1.082392200) + addps xmm3,xmm0 ; xmm3=tmp12 + subps xmm4,xmm0 ; xmm4=tmp10 + + ; -- Final output stage + + subps xmm3,xmm1 ; xmm3=tmp6 + movaps xmm5,xmm6 + movaps xmm0,xmm7 + addps xmm6,xmm1 ; xmm6=data0=(00 10 20 30) + addps xmm7,xmm3 ; xmm7=data1=(01 11 21 31) + subps xmm5,xmm1 ; xmm5=data7=(07 17 27 37) + subps xmm0,xmm3 ; xmm0=data6=(06 16 26 36) + subps xmm2,xmm3 ; xmm2=tmp5 + + movaps xmm1,[GOTOFF(ebx,PD_RNDINT_MAGIC)] ; xmm1=[PD_RNDINT_MAGIC] + pcmpeqd xmm3,xmm3 + psrld xmm3,WORD_BIT ; xmm3={0xFFFF 0x0000 0xFFFF 0x0000 ..} + + addps xmm6,xmm1 ; xmm6=roundint(data0/8)=(00 ** 10 ** 20 ** 30 **) + addps xmm7,xmm1 ; xmm7=roundint(data1/8)=(01 ** 11 ** 21 ** 31 **) + addps xmm0,xmm1 ; xmm0=roundint(data6/8)=(06 ** 16 ** 26 ** 36 **) + addps xmm5,xmm1 ; xmm5=roundint(data7/8)=(07 ** 17 ** 27 ** 37 **) + + pand xmm6,xmm3 ; xmm6=(00 -- 10 -- 20 -- 30 --) + pslld xmm7,WORD_BIT ; xmm7=(-- 01 -- 11 -- 21 -- 31) + pand xmm0,xmm3 ; xmm0=(06 -- 16 -- 26 -- 36 --) + pslld xmm5,WORD_BIT ; xmm5=(-- 07 -- 17 -- 27 -- 37) + por xmm6,xmm7 ; xmm6=(00 01 10 11 20 21 30 31) + por xmm0,xmm5 ; xmm0=(06 07 16 17 26 27 36 37) + + movaps xmm1, XMMWORD [wk(0)] ; xmm1=tmp2 + movaps xmm3, XMMWORD [wk(1)] ; xmm3=tmp3 + + addps xmm4,xmm2 ; xmm4=tmp4 + movaps xmm7,xmm1 + movaps xmm5,xmm3 + addps xmm1,xmm2 ; xmm1=data2=(02 12 22 32) + addps xmm3,xmm4 ; xmm3=data4=(04 14 24 34) + subps xmm7,xmm2 ; xmm7=data5=(05 15 25 35) + subps xmm5,xmm4 ; xmm5=data3=(03 13 23 33) + + movaps xmm2,[GOTOFF(ebx,PD_RNDINT_MAGIC)] ; xmm2=[PD_RNDINT_MAGIC] + pcmpeqd xmm4,xmm4 + psrld xmm4,WORD_BIT ; xmm4={0xFFFF 0x0000 0xFFFF 0x0000 ..} + + addps xmm3,xmm2 ; xmm3=roundint(data4/8)=(04 ** 14 ** 24 ** 34 **) + addps xmm7,xmm2 ; xmm7=roundint(data5/8)=(05 ** 15 ** 25 ** 35 **) + addps xmm1,xmm2 ; xmm1=roundint(data2/8)=(02 ** 12 ** 22 ** 32 **) + addps xmm5,xmm2 ; xmm5=roundint(data3/8)=(03 ** 13 ** 23 ** 33 **) + + pand xmm3,xmm4 ; xmm3=(04 -- 14 -- 24 -- 34 --) + pslld xmm7,WORD_BIT ; xmm7=(-- 05 -- 15 -- 25 -- 35) + pand xmm1,xmm4 ; xmm1=(02 -- 12 -- 22 -- 32 --) + pslld xmm5,WORD_BIT ; xmm5=(-- 03 -- 13 -- 23 -- 33) + por xmm3,xmm7 ; xmm3=(04 05 14 15 24 25 34 35) + por xmm1,xmm5 ; xmm1=(02 03 12 13 22 23 32 33) + + movdqa xmm2,[GOTOFF(ebx,PB_CENTERJSAMP)] ; xmm2=[PB_CENTERJSAMP] + + packsswb xmm6,xmm3 ; xmm6=(00 01 10 11 20 21 30 31 04 05 14 15 24 25 34 35) + packsswb xmm1,xmm0 ; xmm1=(02 03 12 13 22 23 32 33 06 07 16 17 26 27 36 37) + paddb xmm6,xmm2 + paddb xmm1,xmm2 + + movdqa xmm4,xmm6 ; transpose coefficients(phase 2) + punpcklwd xmm6,xmm1 ; xmm6=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) + punpckhwd xmm4,xmm1 ; xmm4=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) + + movdqa xmm7,xmm6 ; transpose coefficients(phase 3) + punpckldq xmm6,xmm4 ; xmm6=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) + punpckhdq xmm7,xmm4 ; xmm7=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) + + pshufd xmm5,xmm6,0x4E ; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) + pshufd xmm3,xmm7,0x4E ; xmm3=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) + + pushpic ebx ; save GOT address + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm6 + movq XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE], xmm7 + mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm5 + movq XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE], xmm3 + + poppic ebx ; restore GOT address + + add esi, byte 4*SIZEOF_FAST_FLOAT ; wsptr + add edi, byte 4*SIZEOF_JSAMPROW + dec ecx ; ctr + jnz near .rowloop + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2fst.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2fst.asm new file mode 100755 index 0000000..b53664d --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2fst.asm @@ -0,0 +1,502 @@ +; +; jiss2fst.asm - fast integer IDCT (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a fast, not so accurate integer implementation of +; the inverse DCT (Discrete Cosine Transform). The following code is +; based directly on the IJG's original jidctfst.c; see the jidctfst.c +; for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 8 ; 14 is also OK. +%define PASS1_BITS 2 + +%if IFAST_SCALE_BITS != PASS1_BITS +%error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'." +%endif + +%if CONST_BITS == 8 +F_1_082 equ 277 ; FIX(1.082392200) +F_1_414 equ 362 ; FIX(1.414213562) +F_1_847 equ 473 ; FIX(1.847759065) +F_2_613 equ 669 ; FIX(2.613125930) +F_1_613 equ (F_2_613 - 256) ; FIX(2.613125930) - FIX(1) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_1_082 equ DESCALE(1162209775,30-CONST_BITS) ; FIX(1.082392200) +F_1_414 equ DESCALE(1518500249,30-CONST_BITS) ; FIX(1.414213562) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_2_613 equ DESCALE(2805822602,30-CONST_BITS) ; FIX(2.613125930) +F_1_613 equ (F_2_613 - (1 << CONST_BITS)) ; FIX(2.613125930) - FIX(1) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + +; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow) +; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw) + +%define PRE_MULTIPLY_SCALE_BITS 2 +%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS) + + alignz 16 + global EXTN(jconst_idct_ifast_sse2) + +EXTN(jconst_idct_ifast_sse2): + +PW_F1414 times 8 dw F_1_414 << CONST_SHIFT +PW_F1847 times 8 dw F_1_847 << CONST_SHIFT +PW_MF1613 times 8 dw -F_1_613 << CONST_SHIFT +PW_F1082 times 8 dw F_1_082 << CONST_SHIFT +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_ifast_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; jpeg_component_info * compptr +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_idct_ifast_sse2) + +EXTN(jsimd_idct_ifast_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + +%ifndef NO_ZERO_COLUMN_TEST_IFAST_SSE2 + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz near .columnDCT + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por xmm1,xmm0 + packsswb xmm1,xmm1 + packsswb xmm1,xmm1 + movd eax,xmm1 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + movdqa xmm7,xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07) + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + punpckhwd xmm7,xmm7 ; xmm7=(04 04 05 05 06 06 07 07) + + pshufd xmm6,xmm0,0x00 ; xmm6=col0=(00 00 00 00 00 00 00 00) + pshufd xmm2,xmm0,0x55 ; xmm2=col1=(01 01 01 01 01 01 01 01) + pshufd xmm5,xmm0,0xAA ; xmm5=col2=(02 02 02 02 02 02 02 02) + pshufd xmm0,xmm0,0xFF ; xmm0=col3=(03 03 03 03 03 03 03 03) + pshufd xmm1,xmm7,0x00 ; xmm1=col4=(04 04 04 04 04 04 04 04) + pshufd xmm4,xmm7,0x55 ; xmm4=col5=(05 05 05 05 05 05 05 05) + pshufd xmm3,xmm7,0xAA ; xmm3=col6=(06 06 06 06 06 06 06 06) + pshufd xmm7,xmm7,0xFF ; xmm7=col7=(07 07 07 07 07 07 07 07) + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=col1 + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=col3 + jmp near .column_end + alignx 16,7 +%endif +.columnDCT: + + ; -- Even part + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_IFAST_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_IFAST_MULT_TYPE)] + + movdqa xmm4,xmm0 + movdqa xmm5,xmm1 + psubw xmm0,xmm2 ; xmm0=tmp11 + psubw xmm1,xmm3 + paddw xmm4,xmm2 ; xmm4=tmp10 + paddw xmm5,xmm3 ; xmm5=tmp13 + + psllw xmm1,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm1,[GOTOFF(ebx,PW_F1414)] + psubw xmm1,xmm5 ; xmm1=tmp12 + + movdqa xmm6,xmm4 + movdqa xmm7,xmm0 + psubw xmm4,xmm5 ; xmm4=tmp3 + psubw xmm0,xmm1 ; xmm0=tmp2 + paddw xmm6,xmm5 ; xmm6=tmp0 + paddw xmm7,xmm1 ; xmm7=tmp1 + + movdqa XMMWORD [wk(1)], xmm4 ; wk(1)=tmp3 + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=tmp2 + + ; -- Odd part + + movdqa xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_IFAST_MULT_TYPE)] + movdqa xmm5, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw xmm5, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_IFAST_MULT_TYPE)] + + movdqa xmm4,xmm2 + movdqa xmm0,xmm5 + psubw xmm2,xmm1 ; xmm2=z12 + psubw xmm5,xmm3 ; xmm5=z10 + paddw xmm4,xmm1 ; xmm4=z11 + paddw xmm0,xmm3 ; xmm0=z13 + + movdqa xmm1,xmm5 ; xmm1=z10(unscaled) + psllw xmm2,PRE_MULTIPLY_SCALE_BITS + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + + movdqa xmm3,xmm4 + psubw xmm4,xmm0 + paddw xmm3,xmm0 ; xmm3=tmp7 + + psllw xmm4,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm4,[GOTOFF(ebx,PW_F1414)] ; xmm4=tmp11 + + ; To avoid overflow... + ; + ; (Original) + ; tmp12 = -2.613125930 * z10 + z5; + ; + ; (This implementation) + ; tmp12 = (-1.613125930 - 1) * z10 + z5; + ; = -1.613125930 * z10 - z10 + z5; + + movdqa xmm0,xmm5 + paddw xmm5,xmm2 + pmulhw xmm5,[GOTOFF(ebx,PW_F1847)] ; xmm5=z5 + pmulhw xmm0,[GOTOFF(ebx,PW_MF1613)] + pmulhw xmm2,[GOTOFF(ebx,PW_F1082)] + psubw xmm0,xmm1 + psubw xmm2,xmm5 ; xmm2=tmp10 + paddw xmm0,xmm5 ; xmm0=tmp12 + + ; -- Final output stage + + psubw xmm0,xmm3 ; xmm0=tmp6 + movdqa xmm1,xmm6 + movdqa xmm5,xmm7 + paddw xmm6,xmm3 ; xmm6=data0=(00 01 02 03 04 05 06 07) + paddw xmm7,xmm0 ; xmm7=data1=(10 11 12 13 14 15 16 17) + psubw xmm1,xmm3 ; xmm1=data7=(70 71 72 73 74 75 76 77) + psubw xmm5,xmm0 ; xmm5=data6=(60 61 62 63 64 65 66 67) + psubw xmm4,xmm0 ; xmm4=tmp5 + + movdqa xmm3,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm7 ; xmm6=(00 10 01 11 02 12 03 13) + punpckhwd xmm3,xmm7 ; xmm3=(04 14 05 15 06 16 07 17) + movdqa xmm0,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm1 ; xmm5=(60 70 61 71 62 72 63 73) + punpckhwd xmm0,xmm1 ; xmm0=(64 74 65 75 66 76 67 77) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp2 + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=tmp3 + + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(60 70 61 71 62 72 63 73) + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(64 74 65 75 66 76 67 77) + + paddw xmm2,xmm4 ; xmm2=tmp4 + movdqa xmm5,xmm7 + movdqa xmm0,xmm1 + paddw xmm7,xmm4 ; xmm7=data2=(20 21 22 23 24 25 26 27) + paddw xmm1,xmm2 ; xmm1=data4=(40 41 42 43 44 45 46 47) + psubw xmm5,xmm4 ; xmm5=data5=(50 51 52 53 54 55 56 57) + psubw xmm0,xmm2 ; xmm0=data3=(30 31 32 33 34 35 36 37) + + movdqa xmm4,xmm7 ; transpose coefficients(phase 1) + punpcklwd xmm7,xmm0 ; xmm7=(20 30 21 31 22 32 23 33) + punpckhwd xmm4,xmm0 ; xmm4=(24 34 25 35 26 36 27 37) + movdqa xmm2,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm5 ; xmm1=(40 50 41 51 42 52 43 53) + punpckhwd xmm2,xmm5 ; xmm2=(44 54 45 55 46 56 47 57) + + movdqa xmm0,xmm3 ; transpose coefficients(phase 2) + punpckldq xmm3,xmm4 ; xmm3=(04 14 24 34 05 15 25 35) + punpckhdq xmm0,xmm4 ; xmm0=(06 16 26 36 07 17 27 37) + movdqa xmm5,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm7 ; xmm6=(00 10 20 30 01 11 21 31) + punpckhdq xmm5,xmm7 ; xmm5=(02 12 22 32 03 13 23 33) + + movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(60 70 61 71 62 72 63 73) + movdqa xmm7, XMMWORD [wk(1)] ; xmm7=(64 74 65 75 66 76 67 77) + + movdqa XMMWORD [wk(0)], xmm3 ; wk(0)=(04 14 24 34 05 15 25 35) + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(06 16 26 36 07 17 27 37) + + movdqa xmm3,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm4 ; xmm1=(40 50 60 70 41 51 61 71) + punpckhdq xmm3,xmm4 ; xmm3=(42 52 62 72 43 53 63 73) + movdqa xmm0,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm7 ; xmm2=(44 54 64 74 45 55 65 75) + punpckhdq xmm0,xmm7 ; xmm0=(46 56 66 76 47 57 67 77) + + movdqa xmm4,xmm6 ; transpose coefficients(phase 3) + punpcklqdq xmm6,xmm1 ; xmm6=col0=(00 10 20 30 40 50 60 70) + punpckhqdq xmm4,xmm1 ; xmm4=col1=(01 11 21 31 41 51 61 71) + movdqa xmm7,xmm5 ; transpose coefficients(phase 3) + punpcklqdq xmm5,xmm3 ; xmm5=col2=(02 12 22 32 42 52 62 72) + punpckhqdq xmm7,xmm3 ; xmm7=col3=(03 13 23 33 43 53 63 73) + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(04 14 24 34 05 15 25 35) + movdqa xmm3, XMMWORD [wk(1)] ; xmm3=(06 16 26 36 07 17 27 37) + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=col1 + movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=col3 + + movdqa xmm4,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm2 ; xmm1=col4=(04 14 24 34 44 54 64 74) + punpckhqdq xmm4,xmm2 ; xmm4=col5=(05 15 25 35 45 55 65 75) + movdqa xmm7,xmm3 ; transpose coefficients(phase 3) + punpcklqdq xmm3,xmm0 ; xmm3=col6=(06 16 26 36 46 56 66 76) + punpckhqdq xmm7,xmm0 ; xmm7=col7=(07 17 27 37 47 57 67 77) +.column_end: + + ; -- Prefetch the next coefficient block + + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + + ; -- Even part + + ; xmm6=col0, xmm5=col2, xmm1=col4, xmm3=col6 + + movdqa xmm2,xmm6 + movdqa xmm0,xmm5 + psubw xmm6,xmm1 ; xmm6=tmp11 + psubw xmm5,xmm3 + paddw xmm2,xmm1 ; xmm2=tmp10 + paddw xmm0,xmm3 ; xmm0=tmp13 + + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm5,[GOTOFF(ebx,PW_F1414)] + psubw xmm5,xmm0 ; xmm5=tmp12 + + movdqa xmm1,xmm2 + movdqa xmm3,xmm6 + psubw xmm2,xmm0 ; xmm2=tmp3 + psubw xmm6,xmm5 ; xmm6=tmp2 + paddw xmm1,xmm0 ; xmm1=tmp0 + paddw xmm3,xmm5 ; xmm3=tmp1 + + movdqa xmm0, XMMWORD [wk(0)] ; xmm0=col1 + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=col3 + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp3 + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=tmp2 + + ; -- Odd part + + ; xmm0=col1, xmm5=col3, xmm4=col5, xmm7=col7 + + movdqa xmm2,xmm0 + movdqa xmm6,xmm4 + psubw xmm0,xmm7 ; xmm0=z12 + psubw xmm4,xmm5 ; xmm4=z10 + paddw xmm2,xmm7 ; xmm2=z11 + paddw xmm6,xmm5 ; xmm6=z13 + + movdqa xmm7,xmm4 ; xmm7=z10(unscaled) + psllw xmm0,PRE_MULTIPLY_SCALE_BITS + psllw xmm4,PRE_MULTIPLY_SCALE_BITS + + movdqa xmm5,xmm2 + psubw xmm2,xmm6 + paddw xmm5,xmm6 ; xmm5=tmp7 + + psllw xmm2,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm2,[GOTOFF(ebx,PW_F1414)] ; xmm2=tmp11 + + ; To avoid overflow... + ; + ; (Original) + ; tmp12 = -2.613125930 * z10 + z5; + ; + ; (This implementation) + ; tmp12 = (-1.613125930 - 1) * z10 + z5; + ; = -1.613125930 * z10 - z10 + z5; + + movdqa xmm6,xmm4 + paddw xmm4,xmm0 + pmulhw xmm4,[GOTOFF(ebx,PW_F1847)] ; xmm4=z5 + pmulhw xmm6,[GOTOFF(ebx,PW_MF1613)] + pmulhw xmm0,[GOTOFF(ebx,PW_F1082)] + psubw xmm6,xmm7 + psubw xmm0,xmm4 ; xmm0=tmp10 + paddw xmm6,xmm4 ; xmm6=tmp12 + + ; -- Final output stage + + psubw xmm6,xmm5 ; xmm6=tmp6 + movdqa xmm7,xmm1 + movdqa xmm4,xmm3 + paddw xmm1,xmm5 ; xmm1=data0=(00 10 20 30 40 50 60 70) + paddw xmm3,xmm6 ; xmm3=data1=(01 11 21 31 41 51 61 71) + psraw xmm1,(PASS1_BITS+3) ; descale + psraw xmm3,(PASS1_BITS+3) ; descale + psubw xmm7,xmm5 ; xmm7=data7=(07 17 27 37 47 57 67 77) + psubw xmm4,xmm6 ; xmm4=data6=(06 16 26 36 46 56 66 76) + psraw xmm7,(PASS1_BITS+3) ; descale + psraw xmm4,(PASS1_BITS+3) ; descale + psubw xmm2,xmm6 ; xmm2=tmp5 + + packsswb xmm1,xmm4 ; xmm1=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + packsswb xmm3,xmm7 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp2 + movdqa xmm6, XMMWORD [wk(0)] ; xmm6=tmp3 + + paddw xmm0,xmm2 ; xmm0=tmp4 + movdqa xmm4,xmm5 + movdqa xmm7,xmm6 + paddw xmm5,xmm2 ; xmm5=data2=(02 12 22 32 42 52 62 72) + paddw xmm6,xmm0 ; xmm6=data4=(04 14 24 34 44 54 64 74) + psraw xmm5,(PASS1_BITS+3) ; descale + psraw xmm6,(PASS1_BITS+3) ; descale + psubw xmm4,xmm2 ; xmm4=data5=(05 15 25 35 45 55 65 75) + psubw xmm7,xmm0 ; xmm7=data3=(03 13 23 33 43 53 63 73) + psraw xmm4,(PASS1_BITS+3) ; descale + psraw xmm7,(PASS1_BITS+3) ; descale + + movdqa xmm2,[GOTOFF(ebx,PB_CENTERJSAMP)] ; xmm2=[PB_CENTERJSAMP] + + packsswb xmm5,xmm6 ; xmm5=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74) + packsswb xmm7,xmm4 ; xmm7=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75) + + paddb xmm1,xmm2 + paddb xmm3,xmm2 + paddb xmm5,xmm2 + paddb xmm7,xmm2 + + movdqa xmm0,xmm1 ; transpose coefficients(phase 1) + punpcklbw xmm1,xmm3 ; xmm1=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71) + punpckhbw xmm0,xmm3 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77) + movdqa xmm6,xmm5 ; transpose coefficients(phase 1) + punpcklbw xmm5,xmm7 ; xmm5=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73) + punpckhbw xmm6,xmm7 ; xmm6=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75) + + movdqa xmm4,xmm1 ; transpose coefficients(phase 2) + punpcklwd xmm1,xmm5 ; xmm1=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) + punpckhwd xmm4,xmm5 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73) + movdqa xmm2,xmm6 ; transpose coefficients(phase 2) + punpcklwd xmm6,xmm0 ; xmm6=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) + punpckhwd xmm2,xmm0 ; xmm2=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77) + + movdqa xmm3,xmm1 ; transpose coefficients(phase 3) + punpckldq xmm1,xmm6 ; xmm1=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) + punpckhdq xmm3,xmm6 ; xmm3=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) + movdqa xmm7,xmm4 ; transpose coefficients(phase 3) + punpckldq xmm4,xmm2 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57) + punpckhdq xmm7,xmm2 ; xmm7=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77) + + pshufd xmm5,xmm1,0x4E ; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) + pshufd xmm0,xmm3,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) + pshufd xmm6,xmm4,0x4E ; xmm6=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47) + pshufd xmm2,xmm7,0x4E ; xmm2=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67) + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm1 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm3 + mov edx, JSAMPROW [edi+4*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+6*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm4 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm7 + + mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm5 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm0 + mov edx, JSAMPROW [edi+5*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+7*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm6 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm2 + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2int.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2int.asm new file mode 100755 index 0000000..adf39fb --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2int.asm @@ -0,0 +1,859 @@ +; +; jiss2int.asm - accurate integer IDCT (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a slow-but-accurate integer implementation of the +; inverse DCT (Discrete Cosine Transform). The following code is based +; directly on the IJG's original jidctint.c; see the jidctint.c for +; more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1 (CONST_BITS-PASS1_BITS) +%define DESCALE_P2 (CONST_BITS+PASS1_BITS+3) + +%if CONST_BITS == 13 +F_0_298 equ 2446 ; FIX(0.298631336) +F_0_390 equ 3196 ; FIX(0.390180644) +F_0_541 equ 4433 ; FIX(0.541196100) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_175 equ 9633 ; FIX(1.175875602) +F_1_501 equ 12299 ; FIX(1.501321110) +F_1_847 equ 15137 ; FIX(1.847759065) +F_1_961 equ 16069 ; FIX(1.961570560) +F_2_053 equ 16819 ; FIX(2.053119869) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_072 equ 25172 ; FIX(3.072711026) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) +F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) +F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) +F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_islow_sse2) + +EXTN(jconst_idct_islow_sse2): + +PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541 +PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847) +PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175 +PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390) +PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899 +PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899) +PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562 +PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562) +PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1) +PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1) +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_islow_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; jpeg_component_info * compptr +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 12 + + align 16 + global EXTN(jsimd_idct_islow_sse2) + +EXTN(jsimd_idct_islow_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + +%ifndef NO_ZERO_COLUMN_TEST_ISLOW_SSE2 + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz near .columnDCT + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por xmm1,xmm0 + packsswb xmm1,xmm1 + packsswb xmm1,xmm1 + movd eax,xmm1 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movdqa xmm5, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] + pmullw xmm5, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + psllw xmm5,PASS1_BITS + + movdqa xmm4,xmm5 ; xmm5=in0=(00 01 02 03 04 05 06 07) + punpcklwd xmm5,xmm5 ; xmm5=(00 00 01 01 02 02 03 03) + punpckhwd xmm4,xmm4 ; xmm4=(04 04 05 05 06 06 07 07) + + pshufd xmm7,xmm5,0x00 ; xmm7=col0=(00 00 00 00 00 00 00 00) + pshufd xmm6,xmm5,0x55 ; xmm6=col1=(01 01 01 01 01 01 01 01) + pshufd xmm1,xmm5,0xAA ; xmm1=col2=(02 02 02 02 02 02 02 02) + pshufd xmm5,xmm5,0xFF ; xmm5=col3=(03 03 03 03 03 03 03 03) + pshufd xmm0,xmm4,0x00 ; xmm0=col4=(04 04 04 04 04 04 04 04) + pshufd xmm3,xmm4,0x55 ; xmm3=col5=(05 05 05 05 05 05 05 05) + pshufd xmm2,xmm4,0xAA ; xmm2=col6=(06 06 06 06 06 06 06 06) + pshufd xmm4,xmm4,0xFF ; xmm4=col7=(07 07 07 07 07 07 07 07) + + movdqa XMMWORD [wk(8)], xmm6 ; wk(8)=col1 + movdqa XMMWORD [wk(9)], xmm5 ; wk(9)=col3 + movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 + movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 + jmp near .column_end + alignx 16,7 +%endif +.columnDCT: + + ; -- Even part + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + ; (Original) + ; z1 = (z2 + z3) * 0.541196100; + ; tmp2 = z1 + z3 * -1.847759065; + ; tmp3 = z1 + z2 * 0.765366865; + ; + ; (This implementation) + ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); + ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; + + movdqa xmm4,xmm1 ; xmm1=in2=z2 + movdqa xmm5,xmm1 + punpcklwd xmm4,xmm3 ; xmm3=in6=z3 + punpckhwd xmm5,xmm3 + movdqa xmm1,xmm4 + movdqa xmm3,xmm5 + pmaddwd xmm4,[GOTOFF(ebx,PW_F130_F054)] ; xmm4=tmp3L + pmaddwd xmm5,[GOTOFF(ebx,PW_F130_F054)] ; xmm5=tmp3H + pmaddwd xmm1,[GOTOFF(ebx,PW_F054_MF130)] ; xmm1=tmp2L + pmaddwd xmm3,[GOTOFF(ebx,PW_F054_MF130)] ; xmm3=tmp2H + + movdqa xmm6,xmm0 + paddw xmm0,xmm2 ; xmm0=in0+in4 + psubw xmm6,xmm2 ; xmm6=in0-in4 + + pxor xmm7,xmm7 + pxor xmm2,xmm2 + punpcklwd xmm7,xmm0 ; xmm7=tmp0L + punpckhwd xmm2,xmm0 ; xmm2=tmp0H + psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS + psrad xmm2,(16-CONST_BITS) ; psrad xmm2,16 & pslld xmm2,CONST_BITS + + movdqa xmm0,xmm7 + paddd xmm7,xmm4 ; xmm7=tmp10L + psubd xmm0,xmm4 ; xmm0=tmp13L + movdqa xmm4,xmm2 + paddd xmm2,xmm5 ; xmm2=tmp10H + psubd xmm4,xmm5 ; xmm4=tmp13H + + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=tmp10L + movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=tmp10H + movdqa XMMWORD [wk(2)], xmm0 ; wk(2)=tmp13L + movdqa XMMWORD [wk(3)], xmm4 ; wk(3)=tmp13H + + pxor xmm5,xmm5 + pxor xmm7,xmm7 + punpcklwd xmm5,xmm6 ; xmm5=tmp1L + punpckhwd xmm7,xmm6 ; xmm7=tmp1H + psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS + psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS + + movdqa xmm2,xmm5 + paddd xmm5,xmm1 ; xmm5=tmp11L + psubd xmm2,xmm1 ; xmm2=tmp12L + movdqa xmm0,xmm7 + paddd xmm7,xmm3 ; xmm7=tmp11H + psubd xmm0,xmm3 ; xmm0=tmp12H + + movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L + movdqa XMMWORD [wk(5)], xmm7 ; wk(5)=tmp11H + movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=tmp12L + movdqa XMMWORD [wk(7)], xmm0 ; wk(7)=tmp12H + + ; -- Odd part + + movdqa xmm4, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movdqa xmm6, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw xmm4, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm6, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm1, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw xmm1, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + movdqa xmm5,xmm6 + movdqa xmm7,xmm4 + paddw xmm5,xmm3 ; xmm5=z3 + paddw xmm7,xmm1 ; xmm7=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm2,xmm5 + movdqa xmm0,xmm5 + punpcklwd xmm2,xmm7 + punpckhwd xmm0,xmm7 + movdqa xmm5,xmm2 + movdqa xmm7,xmm0 + pmaddwd xmm2,[GOTOFF(ebx,PW_MF078_F117)] ; xmm2=z3L + pmaddwd xmm0,[GOTOFF(ebx,PW_MF078_F117)] ; xmm0=z3H + pmaddwd xmm5,[GOTOFF(ebx,PW_F117_F078)] ; xmm5=z4L + pmaddwd xmm7,[GOTOFF(ebx,PW_F117_F078)] ; xmm7=z4H + + movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=z3L + movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=z3H + + ; (Original) + ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; + ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; + ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; tmp0 += z1 + z3; tmp1 += z2 + z4; + ; tmp2 += z2 + z3; tmp3 += z1 + z4; + ; + ; (This implementation) + ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; + ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; + ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); + ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); + ; tmp0 += z3; tmp1 += z4; + ; tmp2 += z3; tmp3 += z4; + + movdqa xmm2,xmm3 + movdqa xmm0,xmm3 + punpcklwd xmm2,xmm4 + punpckhwd xmm0,xmm4 + movdqa xmm3,xmm2 + movdqa xmm4,xmm0 + pmaddwd xmm2,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm2=tmp0L + pmaddwd xmm0,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm0=tmp0H + pmaddwd xmm3,[GOTOFF(ebx,PW_MF089_F060)] ; xmm3=tmp3L + pmaddwd xmm4,[GOTOFF(ebx,PW_MF089_F060)] ; xmm4=tmp3H + + paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp0L + paddd xmm0, XMMWORD [wk(11)] ; xmm0=tmp0H + paddd xmm3,xmm5 ; xmm3=tmp3L + paddd xmm4,xmm7 ; xmm4=tmp3H + + movdqa XMMWORD [wk(8)], xmm2 ; wk(8)=tmp0L + movdqa XMMWORD [wk(9)], xmm0 ; wk(9)=tmp0H + + movdqa xmm2,xmm1 + movdqa xmm0,xmm1 + punpcklwd xmm2,xmm6 + punpckhwd xmm0,xmm6 + movdqa xmm1,xmm2 + movdqa xmm6,xmm0 + pmaddwd xmm2,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm2=tmp1L + pmaddwd xmm0,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm0=tmp1H + pmaddwd xmm1,[GOTOFF(ebx,PW_MF256_F050)] ; xmm1=tmp2L + pmaddwd xmm6,[GOTOFF(ebx,PW_MF256_F050)] ; xmm6=tmp2H + + paddd xmm2,xmm5 ; xmm2=tmp1L + paddd xmm0,xmm7 ; xmm0=tmp1H + paddd xmm1, XMMWORD [wk(10)] ; xmm1=tmp2L + paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H + + movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=tmp1L + movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=tmp1H + + ; -- Final output stage + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L + movdqa xmm7, XMMWORD [wk(1)] ; xmm7=tmp10H + + movdqa xmm2,xmm5 + movdqa xmm0,xmm7 + paddd xmm5,xmm3 ; xmm5=data0L + paddd xmm7,xmm4 ; xmm7=data0H + psubd xmm2,xmm3 ; xmm2=data7L + psubd xmm0,xmm4 ; xmm0=data7H + + movdqa xmm3,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm3=[PD_DESCALE_P1] + + paddd xmm5,xmm3 + paddd xmm7,xmm3 + psrad xmm5,DESCALE_P1 + psrad xmm7,DESCALE_P1 + paddd xmm2,xmm3 + paddd xmm0,xmm3 + psrad xmm2,DESCALE_P1 + psrad xmm0,DESCALE_P1 + + packssdw xmm5,xmm7 ; xmm5=data0=(00 01 02 03 04 05 06 07) + packssdw xmm2,xmm0 ; xmm2=data7=(70 71 72 73 74 75 76 77) + + movdqa xmm4, XMMWORD [wk(4)] ; xmm4=tmp11L + movdqa xmm3, XMMWORD [wk(5)] ; xmm3=tmp11H + + movdqa xmm7,xmm4 + movdqa xmm0,xmm3 + paddd xmm4,xmm1 ; xmm4=data1L + paddd xmm3,xmm6 ; xmm3=data1H + psubd xmm7,xmm1 ; xmm7=data6L + psubd xmm0,xmm6 ; xmm0=data6H + + movdqa xmm1,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm1=[PD_DESCALE_P1] + + paddd xmm4,xmm1 + paddd xmm3,xmm1 + psrad xmm4,DESCALE_P1 + psrad xmm3,DESCALE_P1 + paddd xmm7,xmm1 + paddd xmm0,xmm1 + psrad xmm7,DESCALE_P1 + psrad xmm0,DESCALE_P1 + + packssdw xmm4,xmm3 ; xmm4=data1=(10 11 12 13 14 15 16 17) + packssdw xmm7,xmm0 ; xmm7=data6=(60 61 62 63 64 65 66 67) + + movdqa xmm6,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm4 ; xmm5=(00 10 01 11 02 12 03 13) + punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17) + movdqa xmm1,xmm7 ; transpose coefficients(phase 1) + punpcklwd xmm7,xmm2 ; xmm7=(60 70 61 71 62 72 63 73) + punpckhwd xmm1,xmm2 ; xmm1=(64 74 65 75 66 76 67 77) + + movdqa xmm3, XMMWORD [wk(6)] ; xmm3=tmp12L + movdqa xmm0, XMMWORD [wk(7)] ; xmm0=tmp12H + movdqa xmm4, XMMWORD [wk(10)] ; xmm4=tmp1L + movdqa xmm2, XMMWORD [wk(11)] ; xmm2=tmp1H + + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 01 11 02 12 03 13) + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=(04 14 05 15 06 16 07 17) + movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=(60 70 61 71 62 72 63 73) + movdqa XMMWORD [wk(5)], xmm1 ; wk(5)=(64 74 65 75 66 76 67 77) + + movdqa xmm5,xmm3 + movdqa xmm6,xmm0 + paddd xmm3,xmm4 ; xmm3=data2L + paddd xmm0,xmm2 ; xmm0=data2H + psubd xmm5,xmm4 ; xmm5=data5L + psubd xmm6,xmm2 ; xmm6=data5H + + movdqa xmm7,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm7=[PD_DESCALE_P1] + + paddd xmm3,xmm7 + paddd xmm0,xmm7 + psrad xmm3,DESCALE_P1 + psrad xmm0,DESCALE_P1 + paddd xmm5,xmm7 + paddd xmm6,xmm7 + psrad xmm5,DESCALE_P1 + psrad xmm6,DESCALE_P1 + + packssdw xmm3,xmm0 ; xmm3=data2=(20 21 22 23 24 25 26 27) + packssdw xmm5,xmm6 ; xmm5=data5=(50 51 52 53 54 55 56 57) + + movdqa xmm1, XMMWORD [wk(2)] ; xmm1=tmp13L + movdqa xmm4, XMMWORD [wk(3)] ; xmm4=tmp13H + movdqa xmm2, XMMWORD [wk(8)] ; xmm2=tmp0L + movdqa xmm7, XMMWORD [wk(9)] ; xmm7=tmp0H + + movdqa xmm0,xmm1 + movdqa xmm6,xmm4 + paddd xmm1,xmm2 ; xmm1=data3L + paddd xmm4,xmm7 ; xmm4=data3H + psubd xmm0,xmm2 ; xmm0=data4L + psubd xmm6,xmm7 ; xmm6=data4H + + movdqa xmm2,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm2=[PD_DESCALE_P1] + + paddd xmm1,xmm2 + paddd xmm4,xmm2 + psrad xmm1,DESCALE_P1 + psrad xmm4,DESCALE_P1 + paddd xmm0,xmm2 + paddd xmm6,xmm2 + psrad xmm0,DESCALE_P1 + psrad xmm6,DESCALE_P1 + + packssdw xmm1,xmm4 ; xmm1=data3=(30 31 32 33 34 35 36 37) + packssdw xmm0,xmm6 ; xmm0=data4=(40 41 42 43 44 45 46 47) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 01 11 02 12 03 13) + movdqa xmm2, XMMWORD [wk(1)] ; xmm2=(04 14 05 15 06 16 07 17) + + movdqa xmm4,xmm3 ; transpose coefficients(phase 1) + punpcklwd xmm3,xmm1 ; xmm3=(20 30 21 31 22 32 23 33) + punpckhwd xmm4,xmm1 ; xmm4=(24 34 25 35 26 36 27 37) + movdqa xmm6,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm5 ; xmm0=(40 50 41 51 42 52 43 53) + punpckhwd xmm6,xmm5 ; xmm6=(44 54 45 55 46 56 47 57) + + movdqa xmm1,xmm7 ; transpose coefficients(phase 2) + punpckldq xmm7,xmm3 ; xmm7=(00 10 20 30 01 11 21 31) + punpckhdq xmm1,xmm3 ; xmm1=(02 12 22 32 03 13 23 33) + movdqa xmm5,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm4 ; xmm2=(04 14 24 34 05 15 25 35) + punpckhdq xmm5,xmm4 ; xmm5=(06 16 26 36 07 17 27 37) + + movdqa xmm3, XMMWORD [wk(4)] ; xmm3=(60 70 61 71 62 72 63 73) + movdqa xmm4, XMMWORD [wk(5)] ; xmm4=(64 74 65 75 66 76 67 77) + + movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=(04 14 24 34 05 15 25 35) + movdqa XMMWORD [wk(7)], xmm5 ; wk(7)=(06 16 26 36 07 17 27 37) + + movdqa xmm2,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm3 ; xmm0=(40 50 60 70 41 51 61 71) + punpckhdq xmm2,xmm3 ; xmm2=(42 52 62 72 43 53 63 73) + movdqa xmm5,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm4 ; xmm6=(44 54 64 74 45 55 65 75) + punpckhdq xmm5,xmm4 ; xmm5=(46 56 66 76 47 57 67 77) + + movdqa xmm3,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm0 ; xmm7=col0=(00 10 20 30 40 50 60 70) + punpckhqdq xmm3,xmm0 ; xmm3=col1=(01 11 21 31 41 51 61 71) + movdqa xmm4,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm2 ; xmm1=col2=(02 12 22 32 42 52 62 72) + punpckhqdq xmm4,xmm2 ; xmm4=col3=(03 13 23 33 43 53 63 73) + + movdqa xmm0, XMMWORD [wk(6)] ; xmm0=(04 14 24 34 05 15 25 35) + movdqa xmm2, XMMWORD [wk(7)] ; xmm2=(06 16 26 36 07 17 27 37) + + movdqa XMMWORD [wk(8)], xmm3 ; wk(8)=col1 + movdqa XMMWORD [wk(9)], xmm4 ; wk(9)=col3 + + movdqa xmm3,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm6 ; xmm0=col4=(04 14 24 34 44 54 64 74) + punpckhqdq xmm3,xmm6 ; xmm3=col5=(05 15 25 35 45 55 65 75) + movdqa xmm4,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm5 ; xmm2=col6=(06 16 26 36 46 56 66 76) + punpckhqdq xmm4,xmm5 ; xmm4=col7=(07 17 27 37 47 57 67 77) + + movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 + movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 +.column_end: + + ; -- Prefetch the next coefficient block + + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + + ; -- Even part + + ; xmm7=col0, xmm1=col2, xmm0=col4, xmm2=col6 + + ; (Original) + ; z1 = (z2 + z3) * 0.541196100; + ; tmp2 = z1 + z3 * -1.847759065; + ; tmp3 = z1 + z2 * 0.765366865; + ; + ; (This implementation) + ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); + ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; + + movdqa xmm6,xmm1 ; xmm1=in2=z2 + movdqa xmm5,xmm1 + punpcklwd xmm6,xmm2 ; xmm2=in6=z3 + punpckhwd xmm5,xmm2 + movdqa xmm1,xmm6 + movdqa xmm2,xmm5 + pmaddwd xmm6,[GOTOFF(ebx,PW_F130_F054)] ; xmm6=tmp3L + pmaddwd xmm5,[GOTOFF(ebx,PW_F130_F054)] ; xmm5=tmp3H + pmaddwd xmm1,[GOTOFF(ebx,PW_F054_MF130)] ; xmm1=tmp2L + pmaddwd xmm2,[GOTOFF(ebx,PW_F054_MF130)] ; xmm2=tmp2H + + movdqa xmm3,xmm7 + paddw xmm7,xmm0 ; xmm7=in0+in4 + psubw xmm3,xmm0 ; xmm3=in0-in4 + + pxor xmm4,xmm4 + pxor xmm0,xmm0 + punpcklwd xmm4,xmm7 ; xmm4=tmp0L + punpckhwd xmm0,xmm7 ; xmm0=tmp0H + psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS + psrad xmm0,(16-CONST_BITS) ; psrad xmm0,16 & pslld xmm0,CONST_BITS + + movdqa xmm7,xmm4 + paddd xmm4,xmm6 ; xmm4=tmp10L + psubd xmm7,xmm6 ; xmm7=tmp13L + movdqa xmm6,xmm0 + paddd xmm0,xmm5 ; xmm0=tmp10H + psubd xmm6,xmm5 ; xmm6=tmp13H + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=tmp10L + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp10H + movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=tmp13L + movdqa XMMWORD [wk(3)], xmm6 ; wk(3)=tmp13H + + pxor xmm5,xmm5 + pxor xmm4,xmm4 + punpcklwd xmm5,xmm3 ; xmm5=tmp1L + punpckhwd xmm4,xmm3 ; xmm4=tmp1H + psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS + psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS + + movdqa xmm0,xmm5 + paddd xmm5,xmm1 ; xmm5=tmp11L + psubd xmm0,xmm1 ; xmm0=tmp12L + movdqa xmm7,xmm4 + paddd xmm4,xmm2 ; xmm4=tmp11H + psubd xmm7,xmm2 ; xmm7=tmp12H + + movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L + movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=tmp11H + movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=tmp12L + movdqa XMMWORD [wk(7)], xmm7 ; wk(7)=tmp12H + + ; -- Odd part + + movdqa xmm6, XMMWORD [wk(9)] ; xmm6=col3 + movdqa xmm3, XMMWORD [wk(8)] ; xmm3=col1 + movdqa xmm1, XMMWORD [wk(11)] ; xmm1=col7 + movdqa xmm2, XMMWORD [wk(10)] ; xmm2=col5 + + movdqa xmm5,xmm6 + movdqa xmm4,xmm3 + paddw xmm5,xmm1 ; xmm5=z3 + paddw xmm4,xmm2 ; xmm4=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm0,xmm5 + movdqa xmm7,xmm5 + punpcklwd xmm0,xmm4 + punpckhwd xmm7,xmm4 + movdqa xmm5,xmm0 + movdqa xmm4,xmm7 + pmaddwd xmm0,[GOTOFF(ebx,PW_MF078_F117)] ; xmm0=z3L + pmaddwd xmm7,[GOTOFF(ebx,PW_MF078_F117)] ; xmm7=z3H + pmaddwd xmm5,[GOTOFF(ebx,PW_F117_F078)] ; xmm5=z4L + pmaddwd xmm4,[GOTOFF(ebx,PW_F117_F078)] ; xmm4=z4H + + movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=z3L + movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=z3H + + ; (Original) + ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; + ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; + ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; tmp0 += z1 + z3; tmp1 += z2 + z4; + ; tmp2 += z2 + z3; tmp3 += z1 + z4; + ; + ; (This implementation) + ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; + ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; + ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); + ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); + ; tmp0 += z3; tmp1 += z4; + ; tmp2 += z3; tmp3 += z4; + + movdqa xmm0,xmm1 + movdqa xmm7,xmm1 + punpcklwd xmm0,xmm3 + punpckhwd xmm7,xmm3 + movdqa xmm1,xmm0 + movdqa xmm3,xmm7 + pmaddwd xmm0,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm0=tmp0L + pmaddwd xmm7,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm7=tmp0H + pmaddwd xmm1,[GOTOFF(ebx,PW_MF089_F060)] ; xmm1=tmp3L + pmaddwd xmm3,[GOTOFF(ebx,PW_MF089_F060)] ; xmm3=tmp3H + + paddd xmm0, XMMWORD [wk(10)] ; xmm0=tmp0L + paddd xmm7, XMMWORD [wk(11)] ; xmm7=tmp0H + paddd xmm1,xmm5 ; xmm1=tmp3L + paddd xmm3,xmm4 ; xmm3=tmp3H + + movdqa XMMWORD [wk(8)], xmm0 ; wk(8)=tmp0L + movdqa XMMWORD [wk(9)], xmm7 ; wk(9)=tmp0H + + movdqa xmm0,xmm2 + movdqa xmm7,xmm2 + punpcklwd xmm0,xmm6 + punpckhwd xmm7,xmm6 + movdqa xmm2,xmm0 + movdqa xmm6,xmm7 + pmaddwd xmm0,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm0=tmp1L + pmaddwd xmm7,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm7=tmp1H + pmaddwd xmm2,[GOTOFF(ebx,PW_MF256_F050)] ; xmm2=tmp2L + pmaddwd xmm6,[GOTOFF(ebx,PW_MF256_F050)] ; xmm6=tmp2H + + paddd xmm0,xmm5 ; xmm0=tmp1L + paddd xmm7,xmm4 ; xmm7=tmp1H + paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp2L + paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H + + movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=tmp1L + movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=tmp1H + + ; -- Final output stage + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L + movdqa xmm4, XMMWORD [wk(1)] ; xmm4=tmp10H + + movdqa xmm0,xmm5 + movdqa xmm7,xmm4 + paddd xmm5,xmm1 ; xmm5=data0L + paddd xmm4,xmm3 ; xmm4=data0H + psubd xmm0,xmm1 ; xmm0=data7L + psubd xmm7,xmm3 ; xmm7=data7H + + movdqa xmm1,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm1=[PD_DESCALE_P2] + + paddd xmm5,xmm1 + paddd xmm4,xmm1 + psrad xmm5,DESCALE_P2 + psrad xmm4,DESCALE_P2 + paddd xmm0,xmm1 + paddd xmm7,xmm1 + psrad xmm0,DESCALE_P2 + psrad xmm7,DESCALE_P2 + + packssdw xmm5,xmm4 ; xmm5=data0=(00 10 20 30 40 50 60 70) + packssdw xmm0,xmm7 ; xmm0=data7=(07 17 27 37 47 57 67 77) + + movdqa xmm3, XMMWORD [wk(4)] ; xmm3=tmp11L + movdqa xmm1, XMMWORD [wk(5)] ; xmm1=tmp11H + + movdqa xmm4,xmm3 + movdqa xmm7,xmm1 + paddd xmm3,xmm2 ; xmm3=data1L + paddd xmm1,xmm6 ; xmm1=data1H + psubd xmm4,xmm2 ; xmm4=data6L + psubd xmm7,xmm6 ; xmm7=data6H + + movdqa xmm2,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm2=[PD_DESCALE_P2] + + paddd xmm3,xmm2 + paddd xmm1,xmm2 + psrad xmm3,DESCALE_P2 + psrad xmm1,DESCALE_P2 + paddd xmm4,xmm2 + paddd xmm7,xmm2 + psrad xmm4,DESCALE_P2 + psrad xmm7,DESCALE_P2 + + packssdw xmm3,xmm1 ; xmm3=data1=(01 11 21 31 41 51 61 71) + packssdw xmm4,xmm7 ; xmm4=data6=(06 16 26 36 46 56 66 76) + + packsswb xmm5,xmm4 ; xmm5=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + packsswb xmm3,xmm0 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + movdqa xmm6, XMMWORD [wk(6)] ; xmm6=tmp12L + movdqa xmm2, XMMWORD [wk(7)] ; xmm2=tmp12H + movdqa xmm1, XMMWORD [wk(10)] ; xmm1=tmp1L + movdqa xmm7, XMMWORD [wk(11)] ; xmm7=tmp1H + + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + movdqa xmm4,xmm6 + movdqa xmm0,xmm2 + paddd xmm6,xmm1 ; xmm6=data2L + paddd xmm2,xmm7 ; xmm2=data2H + psubd xmm4,xmm1 ; xmm4=data5L + psubd xmm0,xmm7 ; xmm0=data5H + + movdqa xmm5,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm5=[PD_DESCALE_P2] + + paddd xmm6,xmm5 + paddd xmm2,xmm5 + psrad xmm6,DESCALE_P2 + psrad xmm2,DESCALE_P2 + paddd xmm4,xmm5 + paddd xmm0,xmm5 + psrad xmm4,DESCALE_P2 + psrad xmm0,DESCALE_P2 + + packssdw xmm6,xmm2 ; xmm6=data2=(02 12 22 32 42 52 62 72) + packssdw xmm4,xmm0 ; xmm4=data5=(05 15 25 35 45 55 65 75) + + movdqa xmm3, XMMWORD [wk(2)] ; xmm3=tmp13L + movdqa xmm1, XMMWORD [wk(3)] ; xmm1=tmp13H + movdqa xmm7, XMMWORD [wk(8)] ; xmm7=tmp0L + movdqa xmm5, XMMWORD [wk(9)] ; xmm5=tmp0H + + movdqa xmm2,xmm3 + movdqa xmm0,xmm1 + paddd xmm3,xmm7 ; xmm3=data3L + paddd xmm1,xmm5 ; xmm1=data3H + psubd xmm2,xmm7 ; xmm2=data4L + psubd xmm0,xmm5 ; xmm0=data4H + + movdqa xmm7,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm7=[PD_DESCALE_P2] + + paddd xmm3,xmm7 + paddd xmm1,xmm7 + psrad xmm3,DESCALE_P2 + psrad xmm1,DESCALE_P2 + paddd xmm2,xmm7 + paddd xmm0,xmm7 + psrad xmm2,DESCALE_P2 + psrad xmm0,DESCALE_P2 + + movdqa xmm5,[GOTOFF(ebx,PB_CENTERJSAMP)] ; xmm5=[PB_CENTERJSAMP] + + packssdw xmm3,xmm1 ; xmm3=data3=(03 13 23 33 43 53 63 73) + packssdw xmm2,xmm0 ; xmm2=data4=(04 14 24 34 44 54 64 74) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + packsswb xmm6,xmm2 ; xmm6=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74) + packsswb xmm3,xmm4 ; xmm3=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75) + + paddb xmm7,xmm5 + paddb xmm1,xmm5 + paddb xmm6,xmm5 + paddb xmm3,xmm5 + + movdqa xmm0,xmm7 ; transpose coefficients(phase 1) + punpcklbw xmm7,xmm1 ; xmm7=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71) + punpckhbw xmm0,xmm1 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77) + movdqa xmm2,xmm6 ; transpose coefficients(phase 1) + punpcklbw xmm6,xmm3 ; xmm6=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73) + punpckhbw xmm2,xmm3 ; xmm2=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75) + + movdqa xmm4,xmm7 ; transpose coefficients(phase 2) + punpcklwd xmm7,xmm6 ; xmm7=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) + punpckhwd xmm4,xmm6 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73) + movdqa xmm5,xmm2 ; transpose coefficients(phase 2) + punpcklwd xmm2,xmm0 ; xmm2=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) + punpckhwd xmm5,xmm0 ; xmm5=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77) + + movdqa xmm1,xmm7 ; transpose coefficients(phase 3) + punpckldq xmm7,xmm2 ; xmm7=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) + punpckhdq xmm1,xmm2 ; xmm1=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) + movdqa xmm3,xmm4 ; transpose coefficients(phase 3) + punpckldq xmm4,xmm5 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57) + punpckhdq xmm3,xmm5 ; xmm3=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77) + + pshufd xmm6,xmm7,0x4E ; xmm6=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) + pshufd xmm0,xmm1,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) + pshufd xmm2,xmm4,0x4E ; xmm2=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47) + pshufd xmm5,xmm3,0x4E ; xmm5=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67) + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm7 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm1 + mov edx, JSAMPROW [edi+4*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+6*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm4 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm3 + + mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm6 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm0 + mov edx, JSAMPROW [edi+5*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+7*SIZEOF_JSAMPROW] + movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm2 + movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm5 + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2red.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2red.asm new file mode 100755 index 0000000..238c61d --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jiss2red.asm @@ -0,0 +1,594 @@ +; +; jiss2red.asm - reduced-size IDCT (SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains inverse-DCT routines that produce reduced-size +; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. +; The following code is based directly on the IJG's original jidctred.c; +; see the jidctred.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1_4 (CONST_BITS-PASS1_BITS+1) +%define DESCALE_P2_4 (CONST_BITS+PASS1_BITS+3+1) +%define DESCALE_P1_2 (CONST_BITS-PASS1_BITS+2) +%define DESCALE_P2_2 (CONST_BITS+PASS1_BITS+3+2) + +%if CONST_BITS == 13 +F_0_211 equ 1730 ; FIX(0.211164243) +F_0_509 equ 4176 ; FIX(0.509795579) +F_0_601 equ 4926 ; FIX(0.601344887) +F_0_720 equ 5906 ; FIX(0.720959822) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_850 equ 6967 ; FIX(0.850430095) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_061 equ 8697 ; FIX(1.061594337) +F_1_272 equ 10426 ; FIX(1.272758580) +F_1_451 equ 11893 ; FIX(1.451774981) +F_1_847 equ 15137 ; FIX(1.847759065) +F_2_172 equ 17799 ; FIX(2.172734803) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_624 equ 29692 ; FIX(3.624509785) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_211 equ DESCALE( 226735879,30-CONST_BITS) ; FIX(0.211164243) +F_0_509 equ DESCALE( 547388834,30-CONST_BITS) ; FIX(0.509795579) +F_0_601 equ DESCALE( 645689155,30-CONST_BITS) ; FIX(0.601344887) +F_0_720 equ DESCALE( 774124714,30-CONST_BITS) ; FIX(0.720959822) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_850 equ DESCALE( 913142361,30-CONST_BITS) ; FIX(0.850430095) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_061 equ DESCALE(1139878239,30-CONST_BITS) ; FIX(1.061594337) +F_1_272 equ DESCALE(1366614119,30-CONST_BITS) ; FIX(1.272758580) +F_1_451 equ DESCALE(1558831516,30-CONST_BITS) ; FIX(1.451774981) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_2_172 equ DESCALE(2332956230,30-CONST_BITS) ; FIX(2.172734803) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_624 equ DESCALE(3891787747,30-CONST_BITS) ; FIX(3.624509785) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_red_sse2) + +EXTN(jconst_idct_red_sse2): + +PW_F184_MF076 times 4 dw F_1_847,-F_0_765 +PW_F256_F089 times 4 dw F_2_562, F_0_899 +PW_F106_MF217 times 4 dw F_1_061,-F_2_172 +PW_MF060_MF050 times 4 dw -F_0_601,-F_0_509 +PW_F145_MF021 times 4 dw F_1_451,-F_0_211 +PW_F362_MF127 times 4 dw F_3_624,-F_1_272 +PW_F085_MF072 times 4 dw F_0_850,-F_0_720 +PD_DESCALE_P1_4 times 4 dd 1 << (DESCALE_P1_4-1) +PD_DESCALE_P2_4 times 4 dd 1 << (DESCALE_P2_4-1) +PD_DESCALE_P1_2 times 4 dd 1 << (DESCALE_P1_2-1) +PD_DESCALE_P2_2 times 4 dd 1 << (DESCALE_P2_2-1) +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients, +; producing a reduced-size 4x4 output block. +; +; GLOBAL(void) +; jsimd_idct_4x4_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; void * dct_table +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_idct_4x4_sse2) + +EXTN(jsimd_idct_4x4_sse2): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [wk(0)] + pushpic ebx +; push ecx ; unused +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + +%ifndef NO_ZERO_COLUMN_TEST_4X4_SSE2 + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz short .columnDCT + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por xmm0,xmm1 + packsswb xmm0,xmm0 + packsswb xmm0,xmm0 + movd eax,xmm0 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + psllw xmm0,PASS1_BITS + + movdqa xmm3,xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07) + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + punpckhwd xmm3,xmm3 ; xmm3=(04 04 05 05 06 06 07 07) + + pshufd xmm1,xmm0,0x50 ; xmm1=[col0 col1]=(00 00 00 00 01 01 01 01) + pshufd xmm0,xmm0,0xFA ; xmm0=[col2 col3]=(02 02 02 02 03 03 03 03) + pshufd xmm6,xmm3,0x50 ; xmm6=[col4 col5]=(04 04 04 04 05 05 05 05) + pshufd xmm3,xmm3,0xFA ; xmm3=[col6 col7]=(06 06 06 06 07 07 07 07) + + jmp near .column_end + alignx 16,7 +%endif +.columnDCT: + + ; -- Odd part + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + movdqa xmm4,xmm0 + movdqa xmm5,xmm0 + punpcklwd xmm4,xmm1 + punpckhwd xmm5,xmm1 + movdqa xmm0,xmm4 + movdqa xmm1,xmm5 + pmaddwd xmm4,[GOTOFF(ebx,PW_F256_F089)] ; xmm4=(tmp2L) + pmaddwd xmm5,[GOTOFF(ebx,PW_F256_F089)] ; xmm5=(tmp2H) + pmaddwd xmm0,[GOTOFF(ebx,PW_F106_MF217)] ; xmm0=(tmp0L) + pmaddwd xmm1,[GOTOFF(ebx,PW_F106_MF217)] ; xmm1=(tmp0H) + + movdqa xmm6,xmm2 + movdqa xmm7,xmm2 + punpcklwd xmm6,xmm3 + punpckhwd xmm7,xmm3 + movdqa xmm2,xmm6 + movdqa xmm3,xmm7 + pmaddwd xmm6,[GOTOFF(ebx,PW_MF060_MF050)] ; xmm6=(tmp2L) + pmaddwd xmm7,[GOTOFF(ebx,PW_MF060_MF050)] ; xmm7=(tmp2H) + pmaddwd xmm2,[GOTOFF(ebx,PW_F145_MF021)] ; xmm2=(tmp0L) + pmaddwd xmm3,[GOTOFF(ebx,PW_F145_MF021)] ; xmm3=(tmp0H) + + paddd xmm6,xmm4 ; xmm6=tmp2L + paddd xmm7,xmm5 ; xmm7=tmp2H + paddd xmm2,xmm0 ; xmm2=tmp0L + paddd xmm3,xmm1 ; xmm3=tmp0H + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp0L + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=tmp0H + + ; -- Even part + + movdqa xmm4, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movdqa xmm5, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movdqa xmm0, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] + pmullw xmm4, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm5, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm0, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + pxor xmm1,xmm1 + pxor xmm2,xmm2 + punpcklwd xmm1,xmm4 ; xmm1=tmp0L + punpckhwd xmm2,xmm4 ; xmm2=tmp0H + psrad xmm1,(16-CONST_BITS-1) ; psrad xmm1,16 & pslld xmm1,CONST_BITS+1 + psrad xmm2,(16-CONST_BITS-1) ; psrad xmm2,16 & pslld xmm2,CONST_BITS+1 + + movdqa xmm3,xmm5 ; xmm5=in2=z2 + punpcklwd xmm5,xmm0 ; xmm0=in6=z3 + punpckhwd xmm3,xmm0 + pmaddwd xmm5,[GOTOFF(ebx,PW_F184_MF076)] ; xmm5=tmp2L + pmaddwd xmm3,[GOTOFF(ebx,PW_F184_MF076)] ; xmm3=tmp2H + + movdqa xmm4,xmm1 + movdqa xmm0,xmm2 + paddd xmm1,xmm5 ; xmm1=tmp10L + paddd xmm2,xmm3 ; xmm2=tmp10H + psubd xmm4,xmm5 ; xmm4=tmp12L + psubd xmm0,xmm3 ; xmm0=tmp12H + + ; -- Final output stage + + movdqa xmm5,xmm1 + movdqa xmm3,xmm2 + paddd xmm1,xmm6 ; xmm1=data0L + paddd xmm2,xmm7 ; xmm2=data0H + psubd xmm5,xmm6 ; xmm5=data3L + psubd xmm3,xmm7 ; xmm3=data3H + + movdqa xmm6,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; xmm6=[PD_DESCALE_P1_4] + + paddd xmm1,xmm6 + paddd xmm2,xmm6 + psrad xmm1,DESCALE_P1_4 + psrad xmm2,DESCALE_P1_4 + paddd xmm5,xmm6 + paddd xmm3,xmm6 + psrad xmm5,DESCALE_P1_4 + psrad xmm3,DESCALE_P1_4 + + packssdw xmm1,xmm2 ; xmm1=data0=(00 01 02 03 04 05 06 07) + packssdw xmm5,xmm3 ; xmm5=data3=(30 31 32 33 34 35 36 37) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp0L + movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp0H + + movdqa xmm2,xmm4 + movdqa xmm3,xmm0 + paddd xmm4,xmm7 ; xmm4=data1L + paddd xmm0,xmm6 ; xmm0=data1H + psubd xmm2,xmm7 ; xmm2=data2L + psubd xmm3,xmm6 ; xmm3=data2H + + movdqa xmm7,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; xmm7=[PD_DESCALE_P1_4] + + paddd xmm4,xmm7 + paddd xmm0,xmm7 + psrad xmm4,DESCALE_P1_4 + psrad xmm0,DESCALE_P1_4 + paddd xmm2,xmm7 + paddd xmm3,xmm7 + psrad xmm2,DESCALE_P1_4 + psrad xmm3,DESCALE_P1_4 + + packssdw xmm4,xmm0 ; xmm4=data1=(10 11 12 13 14 15 16 17) + packssdw xmm2,xmm3 ; xmm2=data2=(20 21 22 23 24 25 26 27) + + movdqa xmm6,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm4 ; xmm1=(00 10 01 11 02 12 03 13) + punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17) + movdqa xmm7,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm5 ; xmm2=(20 30 21 31 22 32 23 33) + punpckhwd xmm7,xmm5 ; xmm7=(24 34 25 35 26 36 27 37) + + movdqa xmm0,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm2 ; xmm1=[col0 col1]=(00 10 20 30 01 11 21 31) + punpckhdq xmm0,xmm2 ; xmm0=[col2 col3]=(02 12 22 32 03 13 23 33) + movdqa xmm3,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm7 ; xmm6=[col4 col5]=(04 14 24 34 05 15 25 35) + punpckhdq xmm3,xmm7 ; xmm3=[col6 col7]=(06 16 26 36 07 17 27 37) +.column_end: + + ; -- Prefetch the next coefficient block + + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows, store into output array. + + mov eax, [original_ebp] + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + + ; -- Even part + + pxor xmm4,xmm4 + punpcklwd xmm4,xmm1 ; xmm4=tmp0 + psrad xmm4,(16-CONST_BITS-1) ; psrad xmm4,16 & pslld xmm4,CONST_BITS+1 + + ; -- Odd part + + punpckhwd xmm1,xmm0 + punpckhwd xmm6,xmm3 + movdqa xmm5,xmm1 + movdqa xmm2,xmm6 + pmaddwd xmm1,[GOTOFF(ebx,PW_F256_F089)] ; xmm1=(tmp2) + pmaddwd xmm6,[GOTOFF(ebx,PW_MF060_MF050)] ; xmm6=(tmp2) + pmaddwd xmm5,[GOTOFF(ebx,PW_F106_MF217)] ; xmm5=(tmp0) + pmaddwd xmm2,[GOTOFF(ebx,PW_F145_MF021)] ; xmm2=(tmp0) + + paddd xmm6,xmm1 ; xmm6=tmp2 + paddd xmm2,xmm5 ; xmm2=tmp0 + + ; -- Even part + + punpcklwd xmm0,xmm3 + pmaddwd xmm0,[GOTOFF(ebx,PW_F184_MF076)] ; xmm0=tmp2 + + movdqa xmm7,xmm4 + paddd xmm4,xmm0 ; xmm4=tmp10 + psubd xmm7,xmm0 ; xmm7=tmp12 + + ; -- Final output stage + + movdqa xmm1,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; xmm1=[PD_DESCALE_P2_4] + + movdqa xmm5,xmm4 + movdqa xmm3,xmm7 + paddd xmm4,xmm6 ; xmm4=data0=(00 10 20 30) + paddd xmm7,xmm2 ; xmm7=data1=(01 11 21 31) + psubd xmm5,xmm6 ; xmm5=data3=(03 13 23 33) + psubd xmm3,xmm2 ; xmm3=data2=(02 12 22 32) + + paddd xmm4,xmm1 + paddd xmm7,xmm1 + psrad xmm4,DESCALE_P2_4 + psrad xmm7,DESCALE_P2_4 + paddd xmm5,xmm1 + paddd xmm3,xmm1 + psrad xmm5,DESCALE_P2_4 + psrad xmm3,DESCALE_P2_4 + + packssdw xmm4,xmm3 ; xmm4=(00 10 20 30 02 12 22 32) + packssdw xmm7,xmm5 ; xmm7=(01 11 21 31 03 13 23 33) + + movdqa xmm0,xmm4 ; transpose coefficients(phase 1) + punpcklwd xmm4,xmm7 ; xmm4=(00 01 10 11 20 21 30 31) + punpckhwd xmm0,xmm7 ; xmm0=(02 03 12 13 22 23 32 33) + + movdqa xmm6,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm0 ; xmm4=(00 01 02 03 10 11 12 13) + punpckhdq xmm6,xmm0 ; xmm6=(20 21 22 23 30 31 32 33) + + packsswb xmm4,xmm6 ; xmm4=(00 01 02 03 10 11 12 13 20 ..) + paddb xmm4,[GOTOFF(ebx,PB_CENTERJSAMP)] + + pshufd xmm2,xmm4,0x39 ; xmm2=(10 11 12 13 20 21 22 23 30 ..) + pshufd xmm1,xmm4,0x4E ; xmm1=(20 21 22 23 30 31 32 33 00 ..) + pshufd xmm3,xmm4,0x93 ; xmm3=(30 31 32 33 00 01 02 03 10 ..) + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + movd XMM_DWORD [edx+eax*SIZEOF_JSAMPLE], xmm4 + movd XMM_DWORD [esi+eax*SIZEOF_JSAMPLE], xmm2 + mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movd XMM_DWORD [edx+eax*SIZEOF_JSAMPLE], xmm1 + movd XMM_DWORD [esi+eax*SIZEOF_JSAMPLE], xmm3 + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; unused + poppic ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + + +; -------------------------------------------------------------------------- +; +; Perform dequantization and inverse DCT on one block of coefficients, +; producing a reduced-size 2x2 output block. +; +; GLOBAL(void) +; jsimd_idct_2x2_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; void * dct_table +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + + align 16 + global EXTN(jsimd_idct_2x2_sse2) + +EXTN(jsimd_idct_2x2_sse2): + push ebp + mov ebp,esp + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input. + + mov edx, POINTER [dct_table(ebp)] ; quantptr + mov esi, JCOEFPTR [coef_block(ebp)] ; inptr + + ; | input: | result: | + ; | 00 01 ** 03 ** 05 ** 07 | | + ; | 10 11 ** 13 ** 15 ** 17 | | + ; | ** ** ** ** ** ** ** ** | | + ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 | + ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 | + ; | 50 51 ** 53 ** 55 ** 57 | | + ; | ** ** ** ** ** ** ** ** | | + ; | 70 71 ** 73 ** 75 ** 77 | | + + ; -- Odd part + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + ; xmm0=(10 11 ** 13 ** 15 ** 17), xmm1=(30 31 ** 33 ** 35 ** 37) + ; xmm2=(50 51 ** 53 ** 55 ** 57), xmm3=(70 71 ** 73 ** 75 ** 77) + + pcmpeqd xmm7,xmm7 + pslld xmm7,WORD_BIT ; xmm7={0x0000 0xFFFF 0x0000 0xFFFF ..} + + movdqa xmm4,xmm0 ; xmm4=(10 11 ** 13 ** 15 ** 17) + movdqa xmm5,xmm2 ; xmm5=(50 51 ** 53 ** 55 ** 57) + punpcklwd xmm4,xmm1 ; xmm4=(10 30 11 31 ** ** 13 33) + punpcklwd xmm5,xmm3 ; xmm5=(50 70 51 71 ** ** 53 73) + pmaddwd xmm4,[GOTOFF(ebx,PW_F362_MF127)] + pmaddwd xmm5,[GOTOFF(ebx,PW_F085_MF072)] + + psrld xmm0,WORD_BIT ; xmm0=(11 -- 13 -- 15 -- 17 --) + pand xmm1,xmm7 ; xmm1=(-- 31 -- 33 -- 35 -- 37) + psrld xmm2,WORD_BIT ; xmm2=(51 -- 53 -- 55 -- 57 --) + pand xmm3,xmm7 ; xmm3=(-- 71 -- 73 -- 75 -- 77) + por xmm0,xmm1 ; xmm0=(11 31 13 33 15 35 17 37) + por xmm2,xmm3 ; xmm2=(51 71 53 73 55 75 57 77) + pmaddwd xmm0,[GOTOFF(ebx,PW_F362_MF127)] + pmaddwd xmm2,[GOTOFF(ebx,PW_F085_MF072)] + + paddd xmm4,xmm5 ; xmm4=tmp0[col0 col1 **** col3] + paddd xmm0,xmm2 ; xmm0=tmp0[col1 col3 col5 col7] + + ; -- Even part + + movdqa xmm6, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] + pmullw xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] + + ; xmm6=(00 01 ** 03 ** 05 ** 07) + + movdqa xmm1,xmm6 ; xmm1=(00 01 ** 03 ** 05 ** 07) + pslld xmm6,WORD_BIT ; xmm6=(-- 00 -- ** -- ** -- **) + pand xmm1,xmm7 ; xmm1=(-- 01 -- 03 -- 05 -- 07) + psrad xmm6,(WORD_BIT-CONST_BITS-2) ; xmm6=tmp10[col0 **** **** ****] + psrad xmm1,(WORD_BIT-CONST_BITS-2) ; xmm1=tmp10[col1 col3 col5 col7] + + ; -- Final output stage + + movdqa xmm3,xmm6 + movdqa xmm5,xmm1 + paddd xmm6,xmm4 ; xmm6=data0[col0 **** **** ****]=(A0 ** ** **) + paddd xmm1,xmm0 ; xmm1=data0[col1 col3 col5 col7]=(A1 A3 A5 A7) + psubd xmm3,xmm4 ; xmm3=data1[col0 **** **** ****]=(B0 ** ** **) + psubd xmm5,xmm0 ; xmm5=data1[col1 col3 col5 col7]=(B1 B3 B5 B7) + + movdqa xmm2,[GOTOFF(ebx,PD_DESCALE_P1_2)] ; xmm2=[PD_DESCALE_P1_2] + + punpckldq xmm6,xmm3 ; xmm6=(A0 B0 ** **) + + movdqa xmm7,xmm1 + punpcklqdq xmm1,xmm5 ; xmm1=(A1 A3 B1 B3) + punpckhqdq xmm7,xmm5 ; xmm7=(A5 A7 B5 B7) + + paddd xmm6,xmm2 + psrad xmm6,DESCALE_P1_2 + + paddd xmm1,xmm2 + paddd xmm7,xmm2 + psrad xmm1,DESCALE_P1_2 + psrad xmm7,DESCALE_P1_2 + + ; -- Prefetch the next coefficient block + + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows, store into output array. + + mov edi, JSAMPARRAY [output_buf(ebp)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(ebp)] + + ; | input:| result:| + ; | A0 B0 | | + ; | A1 B1 | C0 C1 | + ; | A3 B3 | D0 D1 | + ; | A5 B5 | | + ; | A7 B7 | | + + ; -- Odd part + + packssdw xmm1,xmm1 ; xmm1=(A1 A3 B1 B3 A1 A3 B1 B3) + packssdw xmm7,xmm7 ; xmm7=(A5 A7 B5 B7 A5 A7 B5 B7) + pmaddwd xmm1,[GOTOFF(ebx,PW_F362_MF127)] + pmaddwd xmm7,[GOTOFF(ebx,PW_F085_MF072)] + + paddd xmm1,xmm7 ; xmm1=tmp0[row0 row1 row0 row1] + + ; -- Even part + + pslld xmm6,(CONST_BITS+2) ; xmm6=tmp10[row0 row1 **** ****] + + ; -- Final output stage + + movdqa xmm4,xmm6 + paddd xmm6,xmm1 ; xmm6=data0[row0 row1 **** ****]=(C0 C1 ** **) + psubd xmm4,xmm1 ; xmm4=data1[row0 row1 **** ****]=(D0 D1 ** **) + + punpckldq xmm6,xmm4 ; xmm6=(C0 D0 C1 D1) + + paddd xmm6,[GOTOFF(ebx,PD_DESCALE_P2_2)] + psrad xmm6,DESCALE_P2_2 + + packssdw xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1) + packsswb xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1 ..) + paddb xmm6,[GOTOFF(ebx,PB_CENTERJSAMP)] + + pextrw ebx,xmm6,0x00 ; ebx=(C0 D0 -- --) + pextrw ecx,xmm6,0x01 ; ecx=(C1 D1 -- --) + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + mov WORD [edx+eax*SIZEOF_JSAMPLE], bx + mov WORD [esi+eax*SIZEOF_JSAMPLE], cx + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jisseflt.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jisseflt.asm new file mode 100755 index 0000000..d6147c1 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jisseflt.asm @@ -0,0 +1,572 @@ +; +; jisseflt.asm - floating-point IDCT (SSE & MMX) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a floating-point implementation of the inverse DCT +; (Discrete Cosine Transform). The following code is based directly on +; the IJG's original jidctflt.c; see the jidctflt.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5) + shufps %1,%2,0x44 +%endmacro + +%macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7) + shufps %1,%2,0xEE +%endmacro + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_float_sse) + +EXTN(jconst_idct_float_sse): + +PD_1_414 times 4 dd 1.414213562373095048801689 +PD_1_847 times 4 dd 1.847759065022573512256366 +PD_1_082 times 4 dd 1.082392200292393968799446 +PD_M2_613 times 4 dd -2.613125929752753055713286 +PD_0_125 times 4 dd 0.125 ; 1/8 +PB_CENTERJSAMP times 8 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_float_sse (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +%define dct_table(b) (b)+8 ; void * dct_table +%define coef_block(b) (b)+12 ; JCOEFPTR coef_block +%define output_buf(b) (b)+16 ; JSAMPARRAY output_buf +%define output_col(b) (b)+20 ; JDIMENSION output_col + +%define original_ebp ebp+0 +%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 +%define workspace wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT + ; FAST_FLOAT workspace[DCTSIZE2] + + align 16 + global EXTN(jsimd_idct_float_sse) + +EXTN(jsimd_idct_float_sse): + push ebp + mov eax,esp ; eax = original ebp + sub esp, byte 4 + and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [esp],eax + mov ebp,esp ; ebp = aligned ebp + lea esp, [workspace] + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved + push esi + push edi + + get_GOT ebx ; get GOT address + + ; ---- Pass 1: process columns from input, store into work array. + +; mov eax, [original_ebp] + mov edx, POINTER [dct_table(eax)] ; quantptr + mov esi, JCOEFPTR [coef_block(eax)] ; inptr + lea edi, [workspace] ; FAST_FLOAT * wsptr + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.columnloop: +%ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE + mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] + jnz near .columnDCT + + movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + por mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + por mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + por mm1,mm0 + packsswb mm1,mm1 + movd eax,mm1 + test eax,eax + jnz short .columnDCT + + ; -- AC terms all zero + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + + punpckhwd mm1,mm0 ; mm1=(** 02 ** 03) + punpcklwd mm0,mm0 ; mm0=(00 00 01 01) + psrad mm1,(DWORD_BIT-WORD_BIT) ; mm1=in0H=(02 03) + psrad mm0,(DWORD_BIT-WORD_BIT) ; mm0=in0L=(00 01) + cvtpi2ps xmm3,mm1 ; xmm3=(02 03 ** **) + cvtpi2ps xmm0,mm0 ; xmm0=(00 01 ** **) + movlhps xmm0,xmm3 ; xmm0=in0=(00 01 02 03) + + mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm1,xmm0 + movaps xmm2,xmm0 + movaps xmm3,xmm0 + + shufps xmm0,xmm0,0x00 ; xmm0=(00 00 00 00) + shufps xmm1,xmm1,0x55 ; xmm1=(01 01 01 01) + shufps xmm2,xmm2,0xAA ; xmm2=(02 02 02 02) + shufps xmm3,xmm3,0xFF ; xmm3=(03 03 03 03) + + movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3 + jmp near .nextcolumn + alignx 16,7 +%endif +.columnDCT: + + ; -- Even part + + movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)] + movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)] + movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)] + + punpckhwd mm4,mm0 ; mm4=(** 02 ** 03) + punpcklwd mm0,mm0 ; mm0=(00 00 01 01) + punpckhwd mm5,mm1 ; mm5=(** 22 ** 23) + punpcklwd mm1,mm1 ; mm1=(20 20 21 21) + + psrad mm4,(DWORD_BIT-WORD_BIT) ; mm4=in0H=(02 03) + psrad mm0,(DWORD_BIT-WORD_BIT) ; mm0=in0L=(00 01) + cvtpi2ps xmm4,mm4 ; xmm4=(02 03 ** **) + cvtpi2ps xmm0,mm0 ; xmm0=(00 01 ** **) + psrad mm5,(DWORD_BIT-WORD_BIT) ; mm5=in2H=(22 23) + psrad mm1,(DWORD_BIT-WORD_BIT) ; mm1=in2L=(20 21) + cvtpi2ps xmm5,mm5 ; xmm5=(22 23 ** **) + cvtpi2ps xmm1,mm1 ; xmm1=(20 21 ** **) + + punpckhwd mm6,mm2 ; mm6=(** 42 ** 43) + punpcklwd mm2,mm2 ; mm2=(40 40 41 41) + punpckhwd mm7,mm3 ; mm7=(** 62 ** 63) + punpcklwd mm3,mm3 ; mm3=(60 60 61 61) + + psrad mm6,(DWORD_BIT-WORD_BIT) ; mm6=in4H=(42 43) + psrad mm2,(DWORD_BIT-WORD_BIT) ; mm2=in4L=(40 41) + cvtpi2ps xmm6,mm6 ; xmm6=(42 43 ** **) + cvtpi2ps xmm2,mm2 ; xmm2=(40 41 ** **) + psrad mm7,(DWORD_BIT-WORD_BIT) ; mm7=in6H=(62 63) + psrad mm3,(DWORD_BIT-WORD_BIT) ; mm3=in6L=(60 61) + cvtpi2ps xmm7,mm7 ; xmm7=(62 63 ** **) + cvtpi2ps xmm3,mm3 ; xmm3=(60 61 ** **) + + movlhps xmm0,xmm4 ; xmm0=in0=(00 01 02 03) + movlhps xmm1,xmm5 ; xmm1=in2=(20 21 22 23) + mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movlhps xmm2,xmm6 ; xmm2=in4=(40 41 42 43) + movlhps xmm3,xmm7 ; xmm3=in6=(60 61 62 63) + mulps xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm4,xmm0 + movaps xmm5,xmm1 + subps xmm0,xmm2 ; xmm0=tmp11 + subps xmm1,xmm3 + addps xmm4,xmm2 ; xmm4=tmp10 + addps xmm5,xmm3 ; xmm5=tmp13 + + mulps xmm1,[GOTOFF(ebx,PD_1_414)] + subps xmm1,xmm5 ; xmm1=tmp12 + + movaps xmm6,xmm4 + movaps xmm7,xmm0 + subps xmm4,xmm5 ; xmm4=tmp3 + subps xmm0,xmm1 ; xmm0=tmp2 + addps xmm6,xmm5 ; xmm6=tmp0 + addps xmm7,xmm1 ; xmm7=tmp1 + + movaps XMMWORD [wk(1)], xmm4 ; tmp3 + movaps XMMWORD [wk(0)], xmm0 ; tmp2 + + ; -- Odd part + + movq mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)] + movq mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)] + movq mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)] + movq mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)] + + punpckhwd mm6,mm4 ; mm6=(** 12 ** 13) + punpcklwd mm4,mm4 ; mm4=(10 10 11 11) + punpckhwd mm2,mm0 ; mm2=(** 32 ** 33) + punpcklwd mm0,mm0 ; mm0=(30 30 31 31) + + psrad mm6,(DWORD_BIT-WORD_BIT) ; mm6=in1H=(12 13) + psrad mm4,(DWORD_BIT-WORD_BIT) ; mm4=in1L=(10 11) + cvtpi2ps xmm4,mm6 ; xmm4=(12 13 ** **) + cvtpi2ps xmm2,mm4 ; xmm2=(10 11 ** **) + psrad mm2,(DWORD_BIT-WORD_BIT) ; mm2=in3H=(32 33) + psrad mm0,(DWORD_BIT-WORD_BIT) ; mm0=in3L=(30 31) + cvtpi2ps xmm0,mm2 ; xmm0=(32 33 ** **) + cvtpi2ps xmm3,mm0 ; xmm3=(30 31 ** **) + + punpckhwd mm7,mm5 ; mm7=(** 52 ** 53) + punpcklwd mm5,mm5 ; mm5=(50 50 51 51) + punpckhwd mm3,mm1 ; mm3=(** 72 ** 73) + punpcklwd mm1,mm1 ; mm1=(70 70 71 71) + + movlhps xmm2,xmm4 ; xmm2=in1=(10 11 12 13) + movlhps xmm3,xmm0 ; xmm3=in3=(30 31 32 33) + + psrad mm7,(DWORD_BIT-WORD_BIT) ; mm7=in5H=(52 53) + psrad mm5,(DWORD_BIT-WORD_BIT) ; mm5=in5L=(50 51) + cvtpi2ps xmm4,mm7 ; xmm4=(52 53 ** **) + cvtpi2ps xmm5,mm5 ; xmm5=(50 51 ** **) + psrad mm3,(DWORD_BIT-WORD_BIT) ; mm3=in7H=(72 73) + psrad mm1,(DWORD_BIT-WORD_BIT) ; mm1=in7L=(70 71) + cvtpi2ps xmm0,mm3 ; xmm0=(72 73 ** **) + cvtpi2ps xmm1,mm1 ; xmm1=(70 71 ** **) + + mulps xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movlhps xmm5,xmm4 ; xmm5=in5=(50 51 52 53) + movlhps xmm1,xmm0 ; xmm1=in7=(70 71 72 73) + mulps xmm5, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm1, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm4,xmm2 + movaps xmm0,xmm5 + addps xmm2,xmm1 ; xmm2=z11 + addps xmm5,xmm3 ; xmm5=z13 + subps xmm4,xmm1 ; xmm4=z12 + subps xmm0,xmm3 ; xmm0=z10 + + movaps xmm1,xmm2 + subps xmm2,xmm5 + addps xmm1,xmm5 ; xmm1=tmp7 + + mulps xmm2,[GOTOFF(ebx,PD_1_414)] ; xmm2=tmp11 + + movaps xmm3,xmm0 + addps xmm0,xmm4 + mulps xmm0,[GOTOFF(ebx,PD_1_847)] ; xmm0=z5 + mulps xmm3,[GOTOFF(ebx,PD_M2_613)] ; xmm3=(z10 * -2.613125930) + mulps xmm4,[GOTOFF(ebx,PD_1_082)] ; xmm4=(z12 * 1.082392200) + addps xmm3,xmm0 ; xmm3=tmp12 + subps xmm4,xmm0 ; xmm4=tmp10 + + ; -- Final output stage + + subps xmm3,xmm1 ; xmm3=tmp6 + movaps xmm5,xmm6 + movaps xmm0,xmm7 + addps xmm6,xmm1 ; xmm6=data0=(00 01 02 03) + addps xmm7,xmm3 ; xmm7=data1=(10 11 12 13) + subps xmm5,xmm1 ; xmm5=data7=(70 71 72 73) + subps xmm0,xmm3 ; xmm0=data6=(60 61 62 63) + subps xmm2,xmm3 ; xmm2=tmp5 + + movaps xmm1,xmm6 ; transpose coefficients(phase 1) + unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11) + unpckhps xmm1,xmm7 ; xmm1=(02 12 03 13) + movaps xmm3,xmm0 ; transpose coefficients(phase 1) + unpcklps xmm0,xmm5 ; xmm0=(60 70 61 71) + unpckhps xmm3,xmm5 ; xmm3=(62 72 63 73) + + movaps xmm7, XMMWORD [wk(0)] ; xmm7=tmp2 + movaps xmm5, XMMWORD [wk(1)] ; xmm5=tmp3 + + movaps XMMWORD [wk(0)], xmm0 ; wk(0)=(60 70 61 71) + movaps XMMWORD [wk(1)], xmm3 ; wk(1)=(62 72 63 73) + + addps xmm4,xmm2 ; xmm4=tmp4 + movaps xmm0,xmm7 + movaps xmm3,xmm5 + addps xmm7,xmm2 ; xmm7=data2=(20 21 22 23) + addps xmm5,xmm4 ; xmm5=data4=(40 41 42 43) + subps xmm0,xmm2 ; xmm0=data5=(50 51 52 53) + subps xmm3,xmm4 ; xmm3=data3=(30 31 32 33) + + movaps xmm2,xmm7 ; transpose coefficients(phase 1) + unpcklps xmm7,xmm3 ; xmm7=(20 30 21 31) + unpckhps xmm2,xmm3 ; xmm2=(22 32 23 33) + movaps xmm4,xmm5 ; transpose coefficients(phase 1) + unpcklps xmm5,xmm0 ; xmm5=(40 50 41 51) + unpckhps xmm4,xmm0 ; xmm4=(42 52 43 53) + + movaps xmm3,xmm6 ; transpose coefficients(phase 2) + unpcklps2 xmm6,xmm7 ; xmm6=(00 10 20 30) + unpckhps2 xmm3,xmm7 ; xmm3=(01 11 21 31) + movaps xmm0,xmm1 ; transpose coefficients(phase 2) + unpcklps2 xmm1,xmm2 ; xmm1=(02 12 22 32) + unpckhps2 xmm0,xmm2 ; xmm0=(03 13 23 33) + + movaps xmm7, XMMWORD [wk(0)] ; xmm7=(60 70 61 71) + movaps xmm2, XMMWORD [wk(1)] ; xmm2=(62 72 63 73) + + movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm6 + movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm0 + + movaps xmm6,xmm5 ; transpose coefficients(phase 2) + unpcklps2 xmm5,xmm7 ; xmm5=(40 50 60 70) + unpckhps2 xmm6,xmm7 ; xmm6=(41 51 61 71) + movaps xmm3,xmm4 ; transpose coefficients(phase 2) + unpcklps2 xmm4,xmm2 ; xmm4=(42 52 62 72) + unpckhps2 xmm3,xmm2 ; xmm3=(43 53 63 73) + + movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6 + movaps XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm4 + movaps XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3 + +.nextcolumn: + add esi, byte 4*SIZEOF_JCOEF ; coef_block + add edx, byte 4*SIZEOF_FLOAT_MULT_TYPE ; quantptr + add edi, 4*DCTSIZE*SIZEOF_FAST_FLOAT ; wsptr + dec ecx ; ctr + jnz near .columnloop + + ; -- Prefetch the next coefficient block + + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32] + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32] + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32] + prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov eax, [original_ebp] + lea esi, [workspace] ; FAST_FLOAT * wsptr + mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) + mov eax, JDIMENSION [output_col(eax)] + mov ecx, DCTSIZE/4 ; ctr + alignx 16,7 +.rowloop: + + ; -- Even part + + movaps xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_FAST_FLOAT)] + + movaps xmm4,xmm0 + movaps xmm5,xmm1 + subps xmm0,xmm2 ; xmm0=tmp11 + subps xmm1,xmm3 + addps xmm4,xmm2 ; xmm4=tmp10 + addps xmm5,xmm3 ; xmm5=tmp13 + + mulps xmm1,[GOTOFF(ebx,PD_1_414)] + subps xmm1,xmm5 ; xmm1=tmp12 + + movaps xmm6,xmm4 + movaps xmm7,xmm0 + subps xmm4,xmm5 ; xmm4=tmp3 + subps xmm0,xmm1 ; xmm0=tmp2 + addps xmm6,xmm5 ; xmm6=tmp0 + addps xmm7,xmm1 ; xmm7=tmp1 + + movaps XMMWORD [wk(1)], xmm4 ; tmp3 + movaps XMMWORD [wk(0)], xmm0 ; tmp2 + + ; -- Odd part + + movaps xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm5, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_FAST_FLOAT)] + + movaps xmm4,xmm2 + movaps xmm0,xmm5 + addps xmm2,xmm1 ; xmm2=z11 + addps xmm5,xmm3 ; xmm5=z13 + subps xmm4,xmm1 ; xmm4=z12 + subps xmm0,xmm3 ; xmm0=z10 + + movaps xmm1,xmm2 + subps xmm2,xmm5 + addps xmm1,xmm5 ; xmm1=tmp7 + + mulps xmm2,[GOTOFF(ebx,PD_1_414)] ; xmm2=tmp11 + + movaps xmm3,xmm0 + addps xmm0,xmm4 + mulps xmm0,[GOTOFF(ebx,PD_1_847)] ; xmm0=z5 + mulps xmm3,[GOTOFF(ebx,PD_M2_613)] ; xmm3=(z10 * -2.613125930) + mulps xmm4,[GOTOFF(ebx,PD_1_082)] ; xmm4=(z12 * 1.082392200) + addps xmm3,xmm0 ; xmm3=tmp12 + subps xmm4,xmm0 ; xmm4=tmp10 + + ; -- Final output stage + + subps xmm3,xmm1 ; xmm3=tmp6 + movaps xmm5,xmm6 + movaps xmm0,xmm7 + addps xmm6,xmm1 ; xmm6=data0=(00 10 20 30) + addps xmm7,xmm3 ; xmm7=data1=(01 11 21 31) + subps xmm5,xmm1 ; xmm5=data7=(07 17 27 37) + subps xmm0,xmm3 ; xmm0=data6=(06 16 26 36) + subps xmm2,xmm3 ; xmm2=tmp5 + + movaps xmm1,[GOTOFF(ebx,PD_0_125)] ; xmm1=[PD_0_125] + + mulps xmm6,xmm1 ; descale(1/8) + mulps xmm7,xmm1 ; descale(1/8) + mulps xmm5,xmm1 ; descale(1/8) + mulps xmm0,xmm1 ; descale(1/8) + + movhlps xmm3,xmm6 + movhlps xmm1,xmm7 + cvtps2pi mm0,xmm6 ; round to int32, mm0=data0L=(00 10) + cvtps2pi mm1,xmm7 ; round to int32, mm1=data1L=(01 11) + cvtps2pi mm2,xmm3 ; round to int32, mm2=data0H=(20 30) + cvtps2pi mm3,xmm1 ; round to int32, mm3=data1H=(21 31) + packssdw mm0,mm2 ; mm0=data0=(00 10 20 30) + packssdw mm1,mm3 ; mm1=data1=(01 11 21 31) + + movhlps xmm6,xmm5 + movhlps xmm7,xmm0 + cvtps2pi mm4,xmm5 ; round to int32, mm4=data7L=(07 17) + cvtps2pi mm5,xmm0 ; round to int32, mm5=data6L=(06 16) + cvtps2pi mm6,xmm6 ; round to int32, mm6=data7H=(27 37) + cvtps2pi mm7,xmm7 ; round to int32, mm7=data6H=(26 36) + packssdw mm4,mm6 ; mm4=data7=(07 17 27 37) + packssdw mm5,mm7 ; mm5=data6=(06 16 26 36) + + packsswb mm0,mm5 ; mm0=(00 10 20 30 06 16 26 36) + packsswb mm1,mm4 ; mm1=(01 11 21 31 07 17 27 37) + + movaps xmm3, XMMWORD [wk(0)] ; xmm3=tmp2 + movaps xmm1, XMMWORD [wk(1)] ; xmm1=tmp3 + + movaps xmm6,[GOTOFF(ebx,PD_0_125)] ; xmm6=[PD_0_125] + + addps xmm4,xmm2 ; xmm4=tmp4 + movaps xmm5,xmm3 + movaps xmm0,xmm1 + addps xmm3,xmm2 ; xmm3=data2=(02 12 22 32) + addps xmm1,xmm4 ; xmm1=data4=(04 14 24 34) + subps xmm5,xmm2 ; xmm5=data5=(05 15 25 35) + subps xmm0,xmm4 ; xmm0=data3=(03 13 23 33) + + mulps xmm3,xmm6 ; descale(1/8) + mulps xmm1,xmm6 ; descale(1/8) + mulps xmm5,xmm6 ; descale(1/8) + mulps xmm0,xmm6 ; descale(1/8) + + movhlps xmm7,xmm3 + movhlps xmm2,xmm1 + cvtps2pi mm2,xmm3 ; round to int32, mm2=data2L=(02 12) + cvtps2pi mm3,xmm1 ; round to int32, mm3=data4L=(04 14) + cvtps2pi mm6,xmm7 ; round to int32, mm6=data2H=(22 32) + cvtps2pi mm7,xmm2 ; round to int32, mm7=data4H=(24 34) + packssdw mm2,mm6 ; mm2=data2=(02 12 22 32) + packssdw mm3,mm7 ; mm3=data4=(04 14 24 34) + + movhlps xmm4,xmm5 + movhlps xmm6,xmm0 + cvtps2pi mm5,xmm5 ; round to int32, mm5=data5L=(05 15) + cvtps2pi mm4,xmm0 ; round to int32, mm4=data3L=(03 13) + cvtps2pi mm6,xmm4 ; round to int32, mm6=data5H=(25 35) + cvtps2pi mm7,xmm6 ; round to int32, mm7=data3H=(23 33) + packssdw mm5,mm6 ; mm5=data5=(05 15 25 35) + packssdw mm4,mm7 ; mm4=data3=(03 13 23 33) + + movq mm6,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm6=[PB_CENTERJSAMP] + + packsswb mm2,mm3 ; mm2=(02 12 22 32 04 14 24 34) + packsswb mm4,mm5 ; mm4=(03 13 23 33 05 15 25 35) + + paddb mm0,mm6 + paddb mm1,mm6 + paddb mm2,mm6 + paddb mm4,mm6 + + movq mm7,mm0 ; transpose coefficients(phase 1) + punpcklbw mm0,mm1 ; mm0=(00 01 10 11 20 21 30 31) + punpckhbw mm7,mm1 ; mm7=(06 07 16 17 26 27 36 37) + movq mm3,mm2 ; transpose coefficients(phase 1) + punpcklbw mm2,mm4 ; mm2=(02 03 12 13 22 23 32 33) + punpckhbw mm3,mm4 ; mm3=(04 05 14 15 24 25 34 35) + + movq mm5,mm0 ; transpose coefficients(phase 2) + punpcklwd mm0,mm2 ; mm0=(00 01 02 03 10 11 12 13) + punpckhwd mm5,mm2 ; mm5=(20 21 22 23 30 31 32 33) + movq mm6,mm3 ; transpose coefficients(phase 2) + punpcklwd mm3,mm7 ; mm3=(04 05 06 07 14 15 16 17) + punpckhwd mm6,mm7 ; mm6=(24 25 26 27 34 35 36 37) + + movq mm1,mm0 ; transpose coefficients(phase 3) + punpckldq mm0,mm3 ; mm0=(00 01 02 03 04 05 06 07) + punpckhdq mm1,mm3 ; mm1=(10 11 12 13 14 15 16 17) + movq mm4,mm5 ; transpose coefficients(phase 3) + punpckldq mm5,mm6 ; mm5=(20 21 22 23 24 25 26 27) + punpckhdq mm4,mm6 ; mm4=(30 31 32 33 34 35 36 37) + + pushpic ebx ; save GOT address + + mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] + movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm0 + movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm1 + mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW] + mov ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW] + movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm5 + movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm4 + + poppic ebx ; restore GOT address + + add esi, byte 4*SIZEOF_FAST_FLOAT ; wsptr + add edi, byte 4*SIZEOF_JSAMPROW + dec ecx ; ctr + jnz near .rowloop + + emms ; empty MMX state + + pop edi + pop esi +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + mov esp,ebp ; esp <- aligned ebp + pop esp ; esp <- original ebp + pop ebp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimd.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimd.h new file mode 100755 index 0000000..3d4751f --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimd.h @@ -0,0 +1,670 @@ +/* + * simd/jsimd.h + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + */ + +/* Bitmask for supported acceleration methods */ + +#define JSIMD_NONE 0x00 +#define JSIMD_MMX 0x01 +#define JSIMD_3DNOW 0x02 +#define JSIMD_SSE 0x04 +#define JSIMD_SSE2 0x08 +#define JSIMD_ARM_NEON 0x10 + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_simd_cpu_support jSiCpuSupport +#define jsimd_rgb_ycc_convert_mmx jSRGBYCCM +#define jsimd_extrgb_ycc_convert_mmx jSEXTRGBYCCM +#define jsimd_extrgbx_ycc_convert_mmx jSEXTRGBXYCCM +#define jsimd_extbgr_ycc_convert_mmx jSEXTBGRYCCM +#define jsimd_extbgrx_ycc_convert_mmx jSEXTBGRXYCCM +#define jsimd_extxbgr_ycc_convert_mmx jSEXTXBGRYCCM +#define jsimd_extxrgb_ycc_convert_mmx jSEXTXRGBYCCM +#define jsimd_rgb_gray_convert_mmx jSRGBGRYM +#define jsimd_extrgb_gray_convert_mmx jSEXTRGBGRYM +#define jsimd_extrgbx_gray_convert_mmx jSEXTRGBXGRYM +#define jsimd_extbgr_gray_convert_mmx jSEXTBGRGRYM +#define jsimd_extbgrx_gray_convert_mmx jSEXTBGRXGRYM +#define jsimd_extxbgr_gray_convert_mmx jSEXTXBGRGRYM +#define jsimd_extxrgb_gray_convert_mmx jSEXTXRGBGRYM +#define jsimd_ycc_rgb_convert_mmx jSYCCRGBM +#define jsimd_ycc_extrgb_convert_mmx jSYCCEXTRGBM +#define jsimd_ycc_extrgbx_convert_mmx jSYCCEXTRGBXM +#define jsimd_ycc_extbgr_convert_mmx jSYCCEXTBGRM +#define jsimd_ycc_extbgrx_convert_mmx jSYCCEXTBGRXM +#define jsimd_ycc_extxbgr_convert_mmx jSYCCEXTXBGRM +#define jsimd_ycc_extxrgb_convert_mmx jSYCCEXTXRGBM +#define jconst_rgb_ycc_convert_sse2 jSCRGBYCCS2 +#define jsimd_rgb_ycc_convert_sse2 jSRGBYCCS2 +#define jsimd_extrgb_ycc_convert_sse2 jSEXTRGBYCCS2 +#define jsimd_extrgbx_ycc_convert_sse2 jSEXTRGBXYCCS2 +#define jsimd_extbgr_ycc_convert_sse2 jSEXTBGRYCCS2 +#define jsimd_extbgrx_ycc_convert_sse2 jSEXTBGRXYCCS2 +#define jsimd_extxbgr_ycc_convert_sse2 jSEXTXBGRYCCS2 +#define jsimd_extxrgb_ycc_convert_sse2 jSEXTXRGBYCCS2 +#define jconst_rgb_gray_convert_sse2 jSCRGBGRYS2 +#define jsimd_rgb_gray_convert_sse2 jSRGBGRYS2 +#define jsimd_extrgb_gray_convert_sse2 jSEXTRGBGRYS2 +#define jsimd_extrgbx_gray_convert_sse2 jSEXTRGBXGRYS2 +#define jsimd_extbgr_gray_convert_sse2 jSEXTBGRGRYS2 +#define jsimd_extbgrx_gray_convert_sse2 jSEXTBGRXGRYS2 +#define jsimd_extxbgr_gray_convert_sse2 jSEXTXBGRGRYS2 +#define jsimd_extxrgb_gray_convert_sse2 jSEXTXRGBGRYS2 +#define jconst_ycc_rgb_convert_sse2 jSCYCCRGBS2 +#define jsimd_ycc_rgb_convert_sse2 jSYCCRGBS2 +#define jsimd_ycc_extrgb_convert_sse2 jSYCCEXTRGBS2 +#define jsimd_ycc_extrgbx_convert_sse2 jSYCCEXTRGBXS2 +#define jsimd_ycc_extbgr_convert_sse2 jSYCCEXTBGRS2 +#define jsimd_ycc_extbgrx_convert_sse2 jSYCCEXTBGRXS2 +#define jsimd_ycc_extxbgr_convert_sse2 jSYCCEXTXBGRS2 +#define jsimd_ycc_extxrgb_convert_sse2 jSYCCEXTXRGBS2 +#define jsimd_h2v2_downsample_mmx jSDnH2V2M +#define jsimd_h2v1_downsample_mmx jSDnH2V1M +#define jsimd_h2v2_downsample_sse2 jSDnH2V2S2 +#define jsimd_h2v1_downsample_sse2 jSDnH2V1S2 +#define jsimd_h2v2_upsample_mmx jSUpH2V2M +#define jsimd_h2v1_upsample_mmx jSUpH2V1M +#define jsimd_h2v2_fancy_upsample_mmx jSFUpH2V2M +#define jsimd_h2v1_fancy_upsample_mmx jSFUpH2V1M +#define jsimd_h2v2_merged_upsample_mmx jSMUpH2V2M +#define jsimd_h2v2_extrgb_merged_upsample_mmx jSMUpH2V2EXTRGBM +#define jsimd_h2v2_extrgbx_merged_upsample_mmx jSMUpH2V2EXTRGBXM +#define jsimd_h2v2_extbgr_merged_upsample_mmx jSMUpH2V2EXTBGRM +#define jsimd_h2v2_extbgrx_merged_upsample_mmx jSMUpH2V2EXTBGRXM +#define jsimd_h2v2_extxbgr_merged_upsample_mmx jSMUpH2V2EXTXBGRM +#define jsimd_h2v2_extxrgb_merged_upsample_mmx jSMUpH2V2EXTXRGBM +#define jsimd_h2v1_merged_upsample_mmx jSMUpH2V1M +#define jsimd_h2v1_extrgb_merged_upsample_mmx jSMUpH2V1EXTRGBM +#define jsimd_h2v1_extrgbx_merged_upsample_mmx jSMUpH2V1EXTRGBXM +#define jsimd_h2v1_extbgr_merged_upsample_mmx jSMUpH2V1EXTBGRM +#define jsimd_h2v1_extbgrx_merged_upsample_mmx jSMUpH2V1EXTBGRXM +#define jsimd_h2v1_extxbgr_merged_upsample_mmx jSMUpH2V1EXTXBGRM +#define jsimd_h2v1_extxrgb_merged_upsample_mmx jSMUpH2V1EXTXRGBM +#define jsimd_h2v2_upsample_sse2 jSUpH2V2S2 +#define jsimd_h2v1_upsample_sse2 jSUpH2V1S2 +#define jconst_fancy_upsample_sse2 jSCFUpS2 +#define jsimd_h2v2_fancy_upsample_sse2 jSFUpH2V2S2 +#define jsimd_h2v1_fancy_upsample_sse2 jSFUpH2V1S2 +#define jconst_merged_upsample_sse2 jSCMUpS2 +#define jsimd_h2v2_merged_upsample_sse2 jSMUpH2V2S2 +#define jsimd_h2v2_extrgb_merged_upsample_sse2 jSMUpH2V2EXTRGBS2 +#define jsimd_h2v2_extrgbx_merged_upsample_sse2 jSMUpH2V2EXTRGBXS2 +#define jsimd_h2v2_extbgr_merged_upsample_sse2 jSMUpH2V2EXTBGRS2 +#define jsimd_h2v2_extbgrx_merged_upsample_sse2 jSMUpH2V2EXTBGRXS2 +#define jsimd_h2v2_extxbgr_merged_upsample_sse2 jSMUpH2V2EXTXBGRS2 +#define jsimd_h2v2_extxrgb_merged_upsample_sse2 jSMUpH2V2EXTXRGBS2 +#define jsimd_h2v1_merged_upsample_sse2 jSMUpH2V1S2 +#define jsimd_h2v1_extrgb_merged_upsample_sse2 jSMUpH2V1EXTRGBS2 +#define jsimd_h2v1_extrgbx_merged_upsample_sse2 jSMUpH2V1EXTRGBXS2 +#define jsimd_h2v1_extbgr_merged_upsample_sse2 jSMUpH2V1EXTBGRS2 +#define jsimd_h2v1_extbgrx_merged_upsample_sse2 jSMUpH2V1EXTBGRXS2 +#define jsimd_h2v1_extxbgr_merged_upsample_sse2 jSMUpH2V1EXTXBGRS2 +#define jsimd_h2v1_extxrgb_merged_upsample_sse2 jSMUpH2V1EXTXRGBS2 +#define jsimd_convsamp_mmx jSConvM +#define jsimd_convsamp_sse2 jSConvS2 +#define jsimd_convsamp_float_3dnow jSConvF3D +#define jsimd_convsamp_float_sse jSConvFS +#define jsimd_convsamp_float_sse2 jSConvFS2 +#define jsimd_fdct_islow_mmx jSFDMIS +#define jsimd_fdct_ifast_mmx jSFDMIF +#define jconst_fdct_islow_sse2 jSCFDS2IS +#define jsimd_fdct_islow_sse2 jSFDS2IS +#define jconst_fdct_ifast_sse2 jSCFDS2IF +#define jsimd_fdct_ifast_sse2 jSFDS2IF +#define jsimd_fdct_float_3dnow jSFD3DF +#define jconst_fdct_float_sse jSCFDSF +#define jsimd_fdct_float_sse jSFDSF +#define jsimd_quantize_mmx jSQuantM +#define jsimd_quantize_sse2 jSQuantS2 +#define jsimd_quantize_float_3dnow jSQuantF3D +#define jsimd_quantize_float_sse jSQuantFS +#define jsimd_quantize_float_sse2 jSQuantFS2 +#define jsimd_idct_2x2_mmx jSIDM22 +#define jsimd_idct_4x4_mmx jSIDM44 +#define jconst_idct_red_sse2 jSCIDS2R +#define jsimd_idct_2x2_sse2 jSIDS222 +#define jsimd_idct_4x4_sse2 jSIDS244 +#define jsimd_idct_islow_mmx jSIDMIS +#define jsimd_idct_ifast_mmx jSIDMIF +#define jconst_idct_islow_sse2 jSCIDS2IS +#define jsimd_idct_islow_sse2 jSIDS2IS +#define jconst_idct_ifast_sse2 jSCIDS2IF +#define jsimd_idct_ifast_sse2 jSIDS2IF +#define jsimd_idct_float_3dnow jSID3DF +#define jconst_fdct_float_sse jSCIDSF +#define jsimd_idct_float_sse jSIDSF +#define jconst_fdct_float_sse2 jSCIDS2F +#define jsimd_idct_float_sse2 jSIDS2F +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +/* SIMD Ext: retrieve SIMD/CPU information */ +EXTERN(unsigned int) jpeg_simd_cpu_support JPP((void)); + +/* SIMD Color Space Conversion */ +EXTERN(void) jsimd_rgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_rgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_ycc_rgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +extern const int jconst_rgb_ycc_convert_sse2[]; +EXTERN(void) jsimd_rgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +extern const int jconst_rgb_gray_convert_sse2[]; +EXTERN(void) jsimd_rgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +extern const int jconst_ycc_rgb_convert_sse2[]; +EXTERN(void) jsimd_ycc_rgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +EXTERN(void) jsimd_rgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_ycc_rgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +/* SIMD Downsample */ +EXTERN(void) jsimd_h2v2_downsample_mmx + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample_mmx + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +EXTERN(void) jsimd_h2v2_downsample_sse2 + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample_sse2 + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +/* SIMD Upsample */ +EXTERN(void) jsimd_h2v2_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(void) jsimd_h2v2_fancy_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(void) jsimd_h2v2_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); + +EXTERN(void) jsimd_h2v2_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +extern const int jconst_fancy_upsample_sse2[]; +EXTERN(void) jsimd_h2v2_fancy_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +extern const int jconst_merged_upsample_sse2[]; +EXTERN(void) jsimd_h2v2_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); + +EXTERN(void) jsimd_h2v1_fancy_upsample_neon + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +/* SIMD Sample Conversion */ +EXTERN(void) jsimd_convsamp_mmx JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_sse2 JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_neon JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_float_3dnow JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_convsamp_float_sse JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_convsamp_float_sse2 JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +/* SIMD Forward DCT */ +EXTERN(void) jsimd_fdct_islow_mmx JPP((DCTELEM * data)); +EXTERN(void) jsimd_fdct_ifast_mmx JPP((DCTELEM * data)); + +extern const int jconst_fdct_ifast_sse2[]; +EXTERN(void) jsimd_fdct_islow_sse2 JPP((DCTELEM * data)); +extern const int jconst_fdct_islow_sse2[]; +EXTERN(void) jsimd_fdct_ifast_sse2 JPP((DCTELEM * data)); + +EXTERN(void) jsimd_fdct_ifast_neon JPP((DCTELEM * data)); + +EXTERN(void) jsimd_fdct_float_3dnow JPP((FAST_FLOAT * data)); + +extern const int jconst_fdct_float_sse[]; +EXTERN(void) jsimd_fdct_float_sse JPP((FAST_FLOAT * data)); + +/* SIMD Quantization */ +EXTERN(void) jsimd_quantize_mmx JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_sse2 JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_neon JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_float_3dnow JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_quantize_float_sse JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_quantize_float_sse2 JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +/* SIMD Reduced Inverse DCT */ +EXTERN(void) jsimd_idct_2x2_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_red_sse2[]; +EXTERN(void) jsimd_idct_2x2_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_2x2_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +/* SIMD Inverse DCT */ +EXTERN(void) jsimd_idct_islow_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_islow_sse2[]; +EXTERN(void) jsimd_idct_islow_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +extern const int jconst_idct_ifast_sse2[]; +EXTERN(void) jsimd_idct_ifast_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_islow_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_float_3dnow JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_float_sse[]; +EXTERN(void) jsimd_idct_float_sse JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_float_sse2[]; +EXTERN(void) jsimd_idct_float_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimd_i386.c b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimd_i386.c new file mode 100755 index 0000000..e96f5b8 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimd_i386.c @@ -0,0 +1,1048 @@ +/* + * jsimd_i386.c + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2009-2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + * This file contains the interface between the "normal" portions + * of the library and the SIMD implementations when running on a + * 32-bit x86 architecture. + */ + +#define JPEG_INTERNALS +#include "../jinclude.h" +#include "../jpeglib.h" +#include "../jsimd.h" +#include "../jdct.h" +#include "../jsimddct.h" +#include "jsimd.h" + +/* + * In the PIC cases, we have no guarantee that constants will keep + * their alignment. This macro allows us to verify it at runtime. + */ +#define IS_ALIGNED(ptr, order) (((unsigned)ptr & ((1 << order) - 1)) == 0) + +#define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */ + +static unsigned int simd_support = ~0; + +/* + * Check what SIMD accelerations are supported. + * + * FIXME: This code is racy under a multi-threaded environment. + */ +LOCAL(void) +init_simd (void) +{ + char *env = NULL; + + if (simd_support != ~0U) + return; + + simd_support = jpeg_simd_cpu_support(); + + /* Force different settings through environment variables */ + env = getenv("JSIMD_FORCEMMX"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support &= JSIMD_MMX; + env = getenv("JSIMD_FORCE3DNOW"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support &= JSIMD_3DNOW|JSIMD_MMX; + env = getenv("JSIMD_FORCESSE"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support &= JSIMD_SSE|JSIMD_MMX; + env = getenv("JSIMD_FORCESSE2"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support &= JSIMD_SSE2; +} + +GLOBAL(int) +jsimd_can_rgb_ycc (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_rgb_gray (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_ycc_rgb (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_rgb_ycc_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); + void (*mmxfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); + + switch(cinfo->in_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_extrgb_ycc_convert_sse2; + mmxfct=jsimd_extrgb_ycc_convert_mmx; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_extrgbx_ycc_convert_sse2; + mmxfct=jsimd_extrgbx_ycc_convert_mmx; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_extbgr_ycc_convert_sse2; + mmxfct=jsimd_extbgr_ycc_convert_mmx; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_extbgrx_ycc_convert_sse2; + mmxfct=jsimd_extbgrx_ycc_convert_mmx; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_extxbgr_ycc_convert_sse2; + mmxfct=jsimd_extxbgr_ycc_convert_mmx; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_extxrgb_ycc_convert_sse2; + mmxfct=jsimd_extxrgb_ycc_convert_mmx; + break; + default: + sse2fct=jsimd_rgb_ycc_convert_sse2; + mmxfct=jsimd_rgb_ycc_convert_mmx; + break; + } + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2)) + sse2fct(cinfo->image_width, input_buf, + output_buf, output_row, num_rows); + else if (simd_support & JSIMD_MMX) + mmxfct(cinfo->image_width, input_buf, + output_buf, output_row, num_rows); +} + +GLOBAL(void) +jsimd_rgb_gray_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); + void (*mmxfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); + + switch(cinfo->in_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_extrgb_gray_convert_sse2; + mmxfct=jsimd_extrgb_gray_convert_mmx; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_extrgbx_gray_convert_sse2; + mmxfct=jsimd_extrgbx_gray_convert_mmx; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_extbgr_gray_convert_sse2; + mmxfct=jsimd_extbgr_gray_convert_mmx; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_extbgrx_gray_convert_sse2; + mmxfct=jsimd_extbgrx_gray_convert_mmx; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_extxbgr_gray_convert_sse2; + mmxfct=jsimd_extxbgr_gray_convert_mmx; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_extxrgb_gray_convert_sse2; + mmxfct=jsimd_extxrgb_gray_convert_mmx; + break; + default: + sse2fct=jsimd_rgb_gray_convert_sse2; + mmxfct=jsimd_rgb_gray_convert_mmx; + break; + } + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2)) + sse2fct(cinfo->image_width, input_buf, + output_buf, output_row, num_rows); + else if (simd_support & JSIMD_MMX) + mmxfct(cinfo->image_width, input_buf, + output_buf, output_row, num_rows); +} + +GLOBAL(void) +jsimd_ycc_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int); + void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_ycc_extrgb_convert_sse2; + mmxfct=jsimd_ycc_extrgb_convert_mmx; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_ycc_extrgbx_convert_sse2; + mmxfct=jsimd_ycc_extrgbx_convert_mmx; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_ycc_extbgr_convert_sse2; + mmxfct=jsimd_ycc_extbgr_convert_mmx; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_ycc_extbgrx_convert_sse2; + mmxfct=jsimd_ycc_extbgrx_convert_mmx; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_ycc_extxbgr_convert_sse2; + mmxfct=jsimd_ycc_extxbgr_convert_mmx; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_ycc_extxrgb_convert_sse2; + mmxfct=jsimd_ycc_extxrgb_convert_mmx; + break; + default: + sse2fct=jsimd_ycc_rgb_convert_sse2; + mmxfct=jsimd_ycc_rgb_convert_mmx; + break; + } + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2)) + sse2fct(cinfo->output_width, input_buf, + input_row, output_buf, num_rows); + else if (simd_support & JSIMD_MMX) + mmxfct(cinfo->output_width, input_buf, + input_row, output_buf, num_rows); +} + +GLOBAL(int) +jsimd_can_h2v2_downsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_downsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + if (simd_support & JSIMD_SSE2) + jsimd_h2v2_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor, + compptr->v_samp_factor, compptr->width_in_blocks, + input_data, output_data); + else if (simd_support & JSIMD_MMX) + jsimd_h2v2_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor, + compptr->v_samp_factor, compptr->width_in_blocks, + input_data, output_data); +} + +GLOBAL(void) +jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + if (simd_support & JSIMD_SSE2) + jsimd_h2v1_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor, + compptr->v_samp_factor, compptr->width_in_blocks, + input_data, output_data); + else if (simd_support & JSIMD_MMX) + jsimd_h2v1_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor, + compptr->v_samp_factor, compptr->width_in_blocks, + input_data, output_data); +} + +GLOBAL(int) +jsimd_can_h2v2_upsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_upsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + if (simd_support & JSIMD_SSE2) + jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor, + cinfo->output_width, input_data, output_data_ptr); + else if (simd_support & JSIMD_MMX) + jsimd_h2v2_upsample_mmx(cinfo->max_v_samp_factor, + cinfo->output_width, input_data, output_data_ptr); +} + +GLOBAL(void) +jsimd_h2v1_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + if (simd_support & JSIMD_SSE2) + jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor, + cinfo->output_width, input_data, output_data_ptr); + else if (simd_support & JSIMD_MMX) + jsimd_h2v1_upsample_mmx(cinfo->max_v_samp_factor, + cinfo->output_width, input_data, output_data_ptr); +} + +GLOBAL(int) +jsimd_can_h2v2_fancy_upsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_fancy_upsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) + jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor, + compptr->downsampled_width, input_data, output_data_ptr); + else if (simd_support & JSIMD_MMX) + jsimd_h2v2_fancy_upsample_mmx(cinfo->max_v_samp_factor, + compptr->downsampled_width, input_data, output_data_ptr); +} + +GLOBAL(void) +jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) + jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor, + compptr->downsampled_width, input_data, output_data_ptr); + else if (simd_support & JSIMD_MMX) + jsimd_h2v1_fancy_upsample_mmx(cinfo->max_v_samp_factor, + compptr->downsampled_width, input_data, output_data_ptr); +} + +GLOBAL(int) +jsimd_can_h2v2_merged_upsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_merged_upsample (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); + void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_h2v2_extrgb_merged_upsample_sse2; + mmxfct=jsimd_h2v2_extrgb_merged_upsample_mmx; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_h2v2_extrgbx_merged_upsample_sse2; + mmxfct=jsimd_h2v2_extrgbx_merged_upsample_mmx; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_h2v2_extbgr_merged_upsample_sse2; + mmxfct=jsimd_h2v2_extbgr_merged_upsample_mmx; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_h2v2_extbgrx_merged_upsample_sse2; + mmxfct=jsimd_h2v2_extbgrx_merged_upsample_mmx; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_h2v2_extxbgr_merged_upsample_sse2; + mmxfct=jsimd_h2v2_extxbgr_merged_upsample_mmx; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_h2v2_extxrgb_merged_upsample_sse2; + mmxfct=jsimd_h2v2_extxrgb_merged_upsample_mmx; + break; + default: + sse2fct=jsimd_h2v2_merged_upsample_sse2; + mmxfct=jsimd_h2v2_merged_upsample_mmx; + break; + } + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) + sse2fct(cinfo->output_width, input_buf, + in_row_group_ctr, output_buf); + else if (simd_support & JSIMD_MMX) + mmxfct(cinfo->output_width, input_buf, + in_row_group_ctr, output_buf); +} + +GLOBAL(void) +jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); + void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_h2v1_extrgb_merged_upsample_sse2; + mmxfct=jsimd_h2v1_extrgb_merged_upsample_mmx; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_h2v1_extrgbx_merged_upsample_sse2; + mmxfct=jsimd_h2v1_extrgbx_merged_upsample_mmx; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_h2v1_extbgr_merged_upsample_sse2; + mmxfct=jsimd_h2v1_extbgr_merged_upsample_mmx; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_h2v1_extbgrx_merged_upsample_sse2; + mmxfct=jsimd_h2v1_extbgrx_merged_upsample_mmx; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_h2v1_extxbgr_merged_upsample_sse2; + mmxfct=jsimd_h2v1_extxbgr_merged_upsample_mmx; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_h2v1_extxrgb_merged_upsample_sse2; + mmxfct=jsimd_h2v1_extxrgb_merged_upsample_mmx; + break; + default: + sse2fct=jsimd_h2v1_merged_upsample_sse2; + mmxfct=jsimd_h2v1_merged_upsample_mmx; + break; + } + + if ((simd_support & JSIMD_SSE2) && + IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) + sse2fct(cinfo->output_width, input_buf, + in_row_group_ctr, output_buf); + else if (simd_support & JSIMD_MMX) + mmxfct(cinfo->output_width, input_buf, + in_row_group_ctr, output_buf); +} + +GLOBAL(int) +jsimd_can_convsamp (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_convsamp_float (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_SSE) + return 1; + if (simd_support & JSIMD_3DNOW) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, + DCTELEM * workspace) +{ + if (simd_support & JSIMD_SSE2) + jsimd_convsamp_sse2(sample_data, start_col, workspace); + else if (simd_support & JSIMD_MMX) + jsimd_convsamp_mmx(sample_data, start_col, workspace); +} + +GLOBAL(void) +jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, + FAST_FLOAT * workspace) +{ + if (simd_support & JSIMD_SSE2) + jsimd_convsamp_float_sse2(sample_data, start_col, workspace); + else if (simd_support & JSIMD_SSE) + jsimd_convsamp_float_sse(sample_data, start_col, workspace); + else if (simd_support & JSIMD_3DNOW) + jsimd_convsamp_float_3dnow(sample_data, start_col, workspace); +} + +GLOBAL(int) +jsimd_can_fdct_islow (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_fdct_ifast (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_ifast_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_fdct_float (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + + if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse)) + return 1; + if (simd_support & JSIMD_3DNOW) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_fdct_islow (DCTELEM * data) +{ + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2)) + jsimd_fdct_islow_sse2(data); + else if (simd_support & JSIMD_MMX) + jsimd_fdct_islow_mmx(data); +} + +GLOBAL(void) +jsimd_fdct_ifast (DCTELEM * data) +{ + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2)) + jsimd_fdct_ifast_sse2(data); + else if (simd_support & JSIMD_MMX) + jsimd_fdct_ifast_mmx(data); +} + +GLOBAL(void) +jsimd_fdct_float (FAST_FLOAT * data) +{ + if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse)) + jsimd_fdct_float_sse(data); + else if (simd_support & JSIMD_3DNOW) + jsimd_fdct_float_3dnow(data); +} + +GLOBAL(int) +jsimd_can_quantize (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_quantize_float (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + + if (simd_support & JSIMD_SSE2) + return 1; + if (simd_support & JSIMD_SSE) + return 1; + if (simd_support & JSIMD_3DNOW) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors, + DCTELEM * workspace) +{ + if (simd_support & JSIMD_SSE2) + jsimd_quantize_sse2(coef_block, divisors, workspace); + else if (simd_support & JSIMD_MMX) + jsimd_quantize_mmx(coef_block, divisors, workspace); +} + +GLOBAL(void) +jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, + FAST_FLOAT * workspace) +{ + if (simd_support & JSIMD_SSE2) + jsimd_quantize_float_sse2(coef_block, divisors, workspace); + else if (simd_support & JSIMD_SSE) + jsimd_quantize_float_sse(coef_block, divisors, workspace); + else if (simd_support & JSIMD_3DNOW) + jsimd_quantize_float_3dnow(coef_block, divisors, workspace); +} + +GLOBAL(int) +jsimd_can_idct_2x2 (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_4x4 (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2)) + jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf, output_col); + else if (simd_support & JSIMD_MMX) + jsimd_idct_2x2_mmx(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2)) + jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf, output_col); + else if (simd_support & JSIMD_MMX) + jsimd_idct_4x4_mmx(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(int) +jsimd_can_idct_islow (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_ifast (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(IFAST_MULT_TYPE) != 2) + return 0; + if (IFAST_SCALE_BITS != 2) + return 0; + + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2)) + return 1; + if (simd_support & JSIMD_MMX) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_float (void) +{ + init_simd(); + + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + if (sizeof(FLOAT_MULT_TYPE) != 4) + return 0; + + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2)) + return 1; + if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse)) + return 1; + if (simd_support & JSIMD_3DNOW) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2)) + jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf, output_col); + else if (simd_support & JSIMD_MMX) + jsimd_idct_islow_mmx(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2)) + jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf, output_col); + else if (simd_support & JSIMD_MMX) + jsimd_idct_ifast_mmx(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2)) + jsimd_idct_float_sse2(compptr->dct_table, coef_block, + output_buf, output_col); + else if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse)) + jsimd_idct_float_sse(compptr->dct_table, coef_block, + output_buf, output_col); + else if (simd_support & JSIMD_3DNOW) + jsimd_idct_float_3dnow(compptr->dct_table, coef_block, + output_buf, output_col); +} + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdcfg.inc.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdcfg.inc.h new file mode 100755 index 0000000..583b7e3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdcfg.inc.h @@ -0,0 +1,196 @@ +// This file generates the include file for the assembly +// implementations by abusing the C preprocessor. +// +// Note: Some things are manually defined as they need to +// be mapped to NASM types. + +; +; Automatically generated include file from jsimdcfg.inc.h +; + +#define JPEG_INTERNALS + +#include "../jpeglib.h" +#include "../jconfig.h" +#include "../jmorecfg.h" +#include "jsimd.h" + +; +; -- jpeglib.h +; + +%define _cpp_protection_DCTSIZE DCTSIZE +%define _cpp_protection_DCTSIZE2 DCTSIZE2 + +; +; -- jmorecfg.h +; + +%define _cpp_protection_RGB_RED RGB_RED +%define _cpp_protection_RGB_GREEN RGB_GREEN +%define _cpp_protection_RGB_BLUE RGB_BLUE +%define _cpp_protection_RGB_PIXELSIZE RGB_PIXELSIZE + +%define _cpp_protection_EXT_RGB_RED EXT_RGB_RED +%define _cpp_protection_EXT_RGB_GREEN EXT_RGB_GREEN +%define _cpp_protection_EXT_RGB_BLUE EXT_RGB_BLUE +%define _cpp_protection_EXT_RGB_PIXELSIZE EXT_RGB_PIXELSIZE + +%define _cpp_protection_EXT_RGBX_RED EXT_RGBX_RED +%define _cpp_protection_EXT_RGBX_GREEN EXT_RGBX_GREEN +%define _cpp_protection_EXT_RGBX_BLUE EXT_RGBX_BLUE +%define _cpp_protection_EXT_RGBX_PIXELSIZE EXT_RGBX_PIXELSIZE + +%define _cpp_protection_EXT_BGR_RED EXT_BGR_RED +%define _cpp_protection_EXT_BGR_GREEN EXT_BGR_GREEN +%define _cpp_protection_EXT_BGR_BLUE EXT_BGR_BLUE +%define _cpp_protection_EXT_BGR_PIXELSIZE EXT_BGR_PIXELSIZE + +%define _cpp_protection_EXT_BGRX_RED EXT_BGRX_RED +%define _cpp_protection_EXT_BGRX_GREEN EXT_BGRX_GREEN +%define _cpp_protection_EXT_BGRX_BLUE EXT_BGRX_BLUE +%define _cpp_protection_EXT_BGRX_PIXELSIZE EXT_BGRX_PIXELSIZE + +%define _cpp_protection_EXT_XBGR_RED EXT_XBGR_RED +%define _cpp_protection_EXT_XBGR_GREEN EXT_XBGR_GREEN +%define _cpp_protection_EXT_XBGR_BLUE EXT_XBGR_BLUE +%define _cpp_protection_EXT_XBGR_PIXELSIZE EXT_XBGR_PIXELSIZE + +%define _cpp_protection_EXT_XRGB_RED EXT_XRGB_RED +%define _cpp_protection_EXT_XRGB_GREEN EXT_XRGB_GREEN +%define _cpp_protection_EXT_XRGB_BLUE EXT_XRGB_BLUE +%define _cpp_protection_EXT_XRGB_PIXELSIZE EXT_XRGB_PIXELSIZE + +%define RGBX_FILLER_0XFF 1 + +; Representation of a single sample (pixel element value). +; On this SIMD implementation, this must be 'unsigned char'. +; + +%define JSAMPLE byte ; unsigned char +%define SIZEOF_JSAMPLE SIZEOF_BYTE ; sizeof(JSAMPLE) + +%define _cpp_protection_CENTERJSAMPLE CENTERJSAMPLE + +; Representation of a DCT frequency coefficient. +; On this SIMD implementation, this must be 'short'. +; +%define JCOEF word ; short +%define SIZEOF_JCOEF SIZEOF_WORD ; sizeof(JCOEF) + +; Datatype used for image dimensions. +; On this SIMD implementation, this must be 'unsigned int'. +; +%define JDIMENSION dword ; unsigned int +%define SIZEOF_JDIMENSION SIZEOF_DWORD ; sizeof(JDIMENSION) + +%define JSAMPROW POINTER ; JSAMPLE FAR * (jpeglib.h) +%define JSAMPARRAY POINTER ; JSAMPROW * (jpeglib.h) +%define JSAMPIMAGE POINTER ; JSAMPARRAY * (jpeglib.h) +%define JCOEFPTR POINTER ; JCOEF FAR * (jpeglib.h) +%define SIZEOF_JSAMPROW SIZEOF_POINTER ; sizeof(JSAMPROW) +%define SIZEOF_JSAMPARRAY SIZEOF_POINTER ; sizeof(JSAMPARRAY) +%define SIZEOF_JSAMPIMAGE SIZEOF_POINTER ; sizeof(JSAMPIMAGE) +%define SIZEOF_JCOEFPTR SIZEOF_POINTER ; sizeof(JCOEFPTR) + +; +; -- jdct.h +; + +; A forward DCT routine is given a pointer to a work area of type DCTELEM[]; +; the DCT is to be performed in-place in that buffer. +; To maximize parallelism, Type DCTELEM is changed to short (originally, int). +; +%define DCTELEM word ; short +%define SIZEOF_DCTELEM SIZEOF_WORD ; sizeof(DCTELEM) + +%define FAST_FLOAT FP32 ; float +%define SIZEOF_FAST_FLOAT SIZEOF_FP32 ; sizeof(FAST_FLOAT) + +; To maximize parallelism, Type MULTIPLIER is changed to short. +; +%define ISLOW_MULT_TYPE word ; must be short +%define SIZEOF_ISLOW_MULT_TYPE SIZEOF_WORD ; sizeof(ISLOW_MULT_TYPE) + +%define IFAST_MULT_TYPE word ; must be short +%define SIZEOF_IFAST_MULT_TYPE SIZEOF_WORD ; sizeof(IFAST_MULT_TYPE) +%define IFAST_SCALE_BITS 2 ; fractional bits in scale factors + +%define FLOAT_MULT_TYPE FP32 ; must be float +%define SIZEOF_FLOAT_MULT_TYPE SIZEOF_FP32 ; sizeof(FLOAT_MULT_TYPE) + +; +; -- jsimd.h +; + +%define _cpp_protection_JSIMD_NONE JSIMD_NONE +%define _cpp_protection_JSIMD_MMX JSIMD_MMX +%define _cpp_protection_JSIMD_3DNOW JSIMD_3DNOW +%define _cpp_protection_JSIMD_SSE JSIMD_SSE +%define _cpp_protection_JSIMD_SSE2 JSIMD_SSE2 + +; Short forms of external names for systems with brain-damaged linkers. +; +#ifdef NEED_SHORT_EXTERNAL_NAMES +%define _cpp_protection_jpeg_simd_cpu_support jpeg_simd_cpu_support +%define _cpp_protection_jsimd_rgb_ycc_convert_mmx jsimd_rgb_ycc_convert_mmx +%define _cpp_protection_jsimd_ycc_rgb_convert_mmx jsimd_ycc_rgb_convert_mmx +%define _cpp_protection_jconst_rgb_ycc_convert_sse2 jconst_rgb_ycc_convert_sse2 +%define _cpp_protection_jsimd_rgb_ycc_convert_sse2 jsimd_rgb_ycc_convert_sse2 +%define _cpp_protection_jconst_ycc_rgb_convert_sse2 jconst_ycc_rgb_convert_sse2 +%define _cpp_protection_jsimd_ycc_rgb_convert_sse2 jsimd_ycc_rgb_convert_sse2 +%define _cpp_protection_jsimd_h2v2_downsample_mmx jsimd_h2v2_downsample_mmx +%define _cpp_protection_jsimd_h2v1_downsample_mmx jsimd_h2v1_downsample_mmx +%define _cpp_protection_jsimd_h2v2_downsample_sse2 jsimd_h2v2_downsample_sse2 +%define _cpp_protection_jsimd_h2v1_downsample_sse2 jsimd_h2v1_downsample_sse2 +%define _cpp_protection_jsimd_h2v2_upsample_mmx jsimd_h2v2_upsample_mmx +%define _cpp_protection_jsimd_h2v1_upsample_mmx jsimd_h2v1_upsample_mmx +%define _cpp_protection_jsimd_h2v1_fancy_upsample_mmx jsimd_h2v1_fancy_upsample_mmx +%define _cpp_protection_jsimd_h2v2_fancy_upsample_mmx jsimd_h2v2_fancy_upsample_mmx +%define _cpp_protection_jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_merged_upsample_mmx +%define _cpp_protection_jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_merged_upsample_mmx +%define _cpp_protection_jsimd_h2v2_upsample_sse2 jsimd_h2v2_upsample_sse2 +%define _cpp_protection_jsimd_h2v1_upsample_sse2 jsimd_h2v1_upsample_sse2 +%define _cpp_protection_jconst_fancy_upsample_sse2 jconst_fancy_upsample_sse2 +%define _cpp_protection_jsimd_h2v1_fancy_upsample_sse2 jsimd_h2v1_fancy_upsample_sse2 +%define _cpp_protection_jsimd_h2v2_fancy_upsample_sse2 jsimd_h2v2_fancy_upsample_sse2 +%define _cpp_protection_jconst_merged_upsample_sse2 jconst_merged_upsample_sse2 +%define _cpp_protection_jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_merged_upsample_sse2 +%define _cpp_protection_jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_merged_upsample_sse2 +%define _cpp_protection_jsimd_convsamp_mmx jsimd_convsamp_mmx +%define _cpp_protection_jsimd_convsamp_sse2 jsimd_convsamp_sse2 +%define _cpp_protection_jsimd_convsamp_float_3dnow jsimd_convsamp_float_3dnow +%define _cpp_protection_jsimd_convsamp_float_sse jsimd_convsamp_float_sse +%define _cpp_protection_jsimd_convsamp_float_sse2 jsimd_convsamp_float_sse2 +%define _cpp_protection_jsimd_fdct_islow_mmx jsimd_fdct_islow_mmx +%define _cpp_protection_jsimd_fdct_ifast_mmx jsimd_fdct_ifast_mmx +%define _cpp_protection_jconst_fdct_islow_sse2 jconst_fdct_islow_sse2 +%define _cpp_protection_jsimd_fdct_islow_sse2 jsimd_fdct_islow_sse2 +%define _cpp_protection_jconst_fdct_ifast_sse2 jconst_fdct_ifast_sse2 +%define _cpp_protection_jsimd_fdct_ifast_sse2 jsimd_fdct_ifast_sse2 +%define _cpp_protection_jsimd_fdct_float_3dnow jsimd_fdct_float_3dnow +%define _cpp_protection_jconst_fdct_float_sse jconst_fdct_float_sse +%define _cpp_protection_jsimd_fdct_float_sse jsimd_fdct_float_sse +%define _cpp_protection_jsimd_quantize_mmx jsimd_quantize_mmx +%define _cpp_protection_jsimd_quantize_sse2 jsimd_quantize_sse2 +%define _cpp_protection_jsimd_quantize_float_3dnow jsimd_quantize_float_3dnow +%define _cpp_protection_jsimd_quantize_float_sse jsimd_quantize_float_sse +%define _cpp_protection_jsimd_quantize_float_sse2 jsimd_quantize_float_sse2 +%define _cpp_protection_jsimd_idct_2x2_mmx jsimd_idct_2x2_mmx +%define _cpp_protection_jsimd_idct_4x4_mmx jsimd_idct_4x4_mmx +%define _cpp_protection_jconst_idct_red_sse2 jconst_idct_red_sse2 +%define _cpp_protection_jsimd_idct_2x2_sse2 jsimd_idct_2x2_sse2 +%define _cpp_protection_jsimd_idct_4x4_sse2 jsimd_idct_4x4_sse2 +%define _cpp_protection_jsimd_idct_islow_mmx jsimd_idct_islow_mmx +%define _cpp_protection_jsimd_idct_ifast_mmx jsimd_idct_ifast_mmx +%define _cpp_protection_jconst_idct_islow_sse2 jconst_idct_islow_sse2 +%define _cpp_protection_jsimd_idct_islow_sse2 jsimd_idct_islow_sse2 +%define _cpp_protection_jconst_idct_ifast_sse2 jconst_idct_ifast_sse2 +%define _cpp_protection_jsimd_idct_ifast_sse2 jsimd_idct_ifast_sse2 +%define _cpp_protection_jsimd_idct_float_3dnow jsimd_idct_float_3dnow +%define _cpp_protection_jconst_idct_float_sse jconst_idct_float_sse +%define _cpp_protection_jsimd_idct_float_sse jsimd_idct_float_sse +%define _cpp_protection_jconst_idct_float_sse2 jconst_idct_float_sse2 +%define _cpp_protection_jsimd_idct_float_sse2 jsimd_idct_float_sse2 +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdcpu.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdcpu.asm new file mode 100755 index 0000000..bdbcc23 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdcpu.asm @@ -0,0 +1,105 @@ +; +; jsimdcpu.asm - SIMD instruction support check +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 32 +; +; Check if the CPU supports SIMD instructions +; +; GLOBAL(unsigned int) +; jpeg_simd_cpu_support (void) +; + + align 16 + global EXTN(jpeg_simd_cpu_support) + +EXTN(jpeg_simd_cpu_support): + push ebx +; push ecx ; need not be preserved +; push edx ; need not be preserved +; push esi ; unused + push edi + + xor edi,edi ; simd support flag + + pushfd + pop eax + mov edx,eax + xor eax, 1<<21 ; flip ID bit in EFLAGS + push eax + popfd + pushfd + pop eax + xor eax,edx + jz short .return ; CPUID is not supported + + ; Check for MMX instruction support + xor eax,eax + cpuid + test eax,eax + jz short .return + + xor eax,eax + inc eax + cpuid + mov eax,edx ; eax = Standard feature flags + + test eax, 1<<23 ; bit23:MMX + jz short .no_mmx + or edi, byte JSIMD_MMX +.no_mmx: + test eax, 1<<25 ; bit25:SSE + jz short .no_sse + or edi, byte JSIMD_SSE +.no_sse: + test eax, 1<<26 ; bit26:SSE2 + jz short .no_sse2 + or edi, byte JSIMD_SSE2 +.no_sse2: + + ; Check for 3DNow! instruction support + mov eax, 0x80000000 + cpuid + cmp eax, 0x80000000 + jbe short .return + + mov eax, 0x80000001 + cpuid + mov eax,edx ; eax = Extended feature flags + + test eax, 1<<31 ; bit31:3DNow!(vendor independent) + jz short .no_3dnow + or edi, byte JSIMD_3DNOW +.no_3dnow: + +.return: + mov eax,edi + + pop edi +; pop esi ; unused +; pop edx ; need not be preserved +; pop ecx ; need not be preserved + pop ebx + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdext.inc b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdext.inc new file mode 100755 index 0000000..253b897 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-i386/jsimdext.inc @@ -0,0 +1,376 @@ +; +; jsimdext.inc - common declarations +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2010 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library - version 1.02 +; +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source distribution. +; +; [TAB8] + +; ========================================================================== +; System-dependent configurations + +%ifdef WIN32 ; ----(nasm -fwin32 -DWIN32 ...)-------- +; * Microsoft Visual C++ +; * MinGW (Minimalist GNU for Windows) +; * CygWin +; * LCC-Win32 + +; -- segment definition -- +; +%ifdef __YASM_VER__ +%define SEG_TEXT .text align=16 +%define SEG_CONST .rdata align=16 +%else +%define SEG_TEXT .text align=16 public use32 class=CODE +%define SEG_CONST .rdata align=16 public use32 class=CONST +%endif + +%elifdef WIN64 ; ----(nasm -fwin64 -DWIN64 ...)-------- +; * Microsoft Visual C++ + +; -- segment definition -- +; +%ifdef __YASM_VER__ +%define SEG_TEXT .text align=16 +%define SEG_CONST .rdata align=16 +%else +%define SEG_TEXT .text align=16 public use64 class=CODE +%define SEG_CONST .rdata align=16 public use64 class=CONST +%endif +%define EXTN(name) name ; foo() -> foo + +%elifdef OBJ32 ; ----(nasm -fobj -DOBJ32 ...)---------- +; * Borland C++ (Win32) + +; -- segment definition -- +; +%define SEG_TEXT .text align=16 public use32 class=CODE +%define SEG_CONST .data align=16 public use32 class=DATA + +%elifdef ELF ; ----(nasm -felf[64] -DELF ...)------------ +; * Linux +; * *BSD family Unix using elf format +; * Unix System V, including Solaris x86, UnixWare and SCO Unix + +; mark stack as non-executable +section .note.GNU-stack noalloc noexec nowrite progbits + +; -- segment definition -- +; +%ifdef __x86_64__ +%define SEG_TEXT .text progbits align=16 +%define SEG_CONST .rodata progbits align=16 +%else +%define SEG_TEXT .text progbits alloc exec nowrite align=16 +%define SEG_CONST .rodata progbits alloc noexec nowrite align=16 +%endif + +; To make the code position-independent, append -DPIC to the commandline +; +%define GOT_SYMBOL _GLOBAL_OFFSET_TABLE_ ; ELF supports PIC +%define EXTN(name) name ; foo() -> foo + +%elifdef AOUT ; ----(nasm -faoutb/aout -DAOUT ...)---- +; * Older Linux using a.out format (nasm -f aout -DAOUT ...) +; * *BSD family Unix using a.out format (nasm -f aoutb -DAOUT ...) + +; -- segment definition -- +; +%define SEG_TEXT .text +%define SEG_CONST .data + +; To make the code position-independent, append -DPIC to the commandline +; +%define GOT_SYMBOL __GLOBAL_OFFSET_TABLE_ ; BSD-style a.out supports PIC + +%elifdef MACHO ; ----(nasm -fmacho -DMACHO ...)-------- +; * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (Mach-O format) + +; -- segment definition -- +; +%define SEG_TEXT .text ;align=16 ; nasm doesn't accept align=16. why? +%define SEG_CONST .rodata align=16 + +; The generation of position-independent code (PIC) is the default on Darwin. +; +%define PIC +%define GOT_SYMBOL _MACHO_PIC_ ; Mach-O style code-relative addressing + +%else ; ----(Other case)---------------------- + +; -- segment definition -- +; +%define SEG_TEXT .text +%define SEG_CONST .data + +%endif ; ---------------------------------------------- + +; ========================================================================== + +; -------------------------------------------------------------------------- +; Common types +; +%ifdef __x86_64__ +%define POINTER qword ; general pointer type +%define SIZEOF_POINTER SIZEOF_QWORD ; sizeof(POINTER) +%define POINTER_BIT QWORD_BIT ; sizeof(POINTER)*BYTE_BIT +%else +%define POINTER dword ; general pointer type +%define SIZEOF_POINTER SIZEOF_DWORD ; sizeof(POINTER) +%define POINTER_BIT DWORD_BIT ; sizeof(POINTER)*BYTE_BIT +%endif + +%define INT dword ; signed integer type +%define SIZEOF_INT SIZEOF_DWORD ; sizeof(INT) +%define INT_BIT DWORD_BIT ; sizeof(INT)*BYTE_BIT + +%define FP32 dword ; IEEE754 single +%define SIZEOF_FP32 SIZEOF_DWORD ; sizeof(FP32) +%define FP32_BIT DWORD_BIT ; sizeof(FP32)*BYTE_BIT + +%define MMWORD qword ; int64 (MMX register) +%define SIZEOF_MMWORD SIZEOF_QWORD ; sizeof(MMWORD) +%define MMWORD_BIT QWORD_BIT ; sizeof(MMWORD)*BYTE_BIT + +; NASM is buggy and doesn't properly handle operand sizes for SSE +; instructions, so for now we have to define XMMWORD as blank. +%define XMMWORD ; int128 (SSE register) +%define SIZEOF_XMMWORD SIZEOF_OWORD ; sizeof(XMMWORD) +%define XMMWORD_BIT OWORD_BIT ; sizeof(XMMWORD)*BYTE_BIT + +; Similar hacks for when we load a dword or MMWORD into an xmm# register +%define XMM_DWORD +%define XMM_MMWORD + +%define SIZEOF_BYTE 1 ; sizeof(BYTE) +%define SIZEOF_WORD 2 ; sizeof(WORD) +%define SIZEOF_DWORD 4 ; sizeof(DWORD) +%define SIZEOF_QWORD 8 ; sizeof(QWORD) +%define SIZEOF_OWORD 16 ; sizeof(OWORD) + +%define BYTE_BIT 8 ; CHAR_BIT in C +%define WORD_BIT 16 ; sizeof(WORD)*BYTE_BIT +%define DWORD_BIT 32 ; sizeof(DWORD)*BYTE_BIT +%define QWORD_BIT 64 ; sizeof(QWORD)*BYTE_BIT +%define OWORD_BIT 128 ; sizeof(OWORD)*BYTE_BIT + +; -------------------------------------------------------------------------- +; External Symbol Name +; +%ifndef EXTN +%define EXTN(name) _ %+ name ; foo() -> _foo +%endif + +; -------------------------------------------------------------------------- +; Macros for position-independent code (PIC) support +; +%ifndef GOT_SYMBOL +%undef PIC +%endif + +%ifdef PIC ; ------------------------------------------- + +%ifidn GOT_SYMBOL,_MACHO_PIC_ ; -------------------- + +; At present, nasm doesn't seem to support PIC generation for Mach-O. +; The PIC support code below is a little tricky. + + SECTION SEG_CONST +const_base: + +%define GOTOFF(got,sym) (got) + (sym) - const_base + +%imacro get_GOT 1 + ; NOTE: this macro destroys ecx resister. + call %%geteip + add ecx, byte (%%ref - $) + jmp short %%adjust +%%geteip: + mov ecx, POINTER [esp] + ret +%%adjust: + push ebp + xor ebp,ebp ; ebp = 0 +%ifidni %1,ebx ; (%1 == ebx) + ; db 0x8D,0x9C + jmp near const_base = + ; lea ebx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,9C,E9,(offset32) + db 0x8D,0x9C ; 8D,9C + jmp near const_base ; E9,(const_base-%%ref) +%%ref: +%else ; (%1 != ebx) + ; db 0x8D,0x8C + jmp near const_base = + ; lea ecx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,8C,E9,(offset32) + db 0x8D,0x8C ; 8D,8C + jmp near const_base ; E9,(const_base-%%ref) +%%ref: mov %1, ecx +%endif ; (%1 == ebx) + pop ebp +%endmacro + +%else ; GOT_SYMBOL != _MACHO_PIC_ ---------------- + +%define GOTOFF(got,sym) (got) + (sym) wrt ..gotoff + +%imacro get_GOT 1 + extern GOT_SYMBOL + call %%geteip + add %1, GOT_SYMBOL + $$ - $ wrt ..gotpc + jmp short %%done +%%geteip: + mov %1, POINTER [esp] + ret +%%done: +%endmacro + +%endif ; GOT_SYMBOL == _MACHO_PIC_ ---------------- + +%imacro pushpic 1.nolist + push %1 +%endmacro +%imacro poppic 1.nolist + pop %1 +%endmacro +%imacro movpic 2.nolist + mov %1,%2 +%endmacro + +%else ; !PIC ----------------------------------------- + +%define GOTOFF(got,sym) (sym) + +%imacro get_GOT 1.nolist +%endmacro +%imacro pushpic 1.nolist +%endmacro +%imacro poppic 1.nolist +%endmacro +%imacro movpic 2.nolist +%endmacro + +%endif ; PIC ----------------------------------------- + +; -------------------------------------------------------------------------- +; Align the next instruction on {2,4,8,16,..}-byte boundary. +; ".balign n,,m" in GNU as +; +%define MSKLE(x,y) (~(((y) & 0xFFFF) - ((x) & 0xFFFF)) >> 16) +%define FILLB(b,n) (($$-(b)) & ((n)-1)) + +%imacro alignx 1-2.nolist 0xFFFF +%%bs: times MSKLE(FILLB(%%bs,%1),%2) & MSKLE(16,FILLB($,%1)) & FILLB($,%1) \ + db 0x90 ; nop + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/9 \ + db 0x8D,0x9C,0x23,0x00,0x00,0x00,0x00 ; lea ebx,[ebx+0x00000000] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/7 \ + db 0x8D,0xAC,0x25,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/6 \ + db 0x8D,0xAD,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/4 \ + db 0x8D,0x6C,0x25,0x00 ; lea ebp,[ebp+0x00] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/3 \ + db 0x8D,0x6D,0x00 ; lea ebp,[ebp+0x00] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/2 \ + db 0x8B,0xED ; mov ebp,ebp + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/1 \ + db 0x90 ; nop +%endmacro + +; Align the next data on {2,4,8,16,..}-byte boundary. +; +%imacro alignz 1.nolist + align %1, db 0 ; filling zeros +%endmacro + +%ifdef __x86_64__ + +%ifdef WIN64 + +%imacro collect_args 0 + push r12 + push r13 + push r14 + push r15 + mov r10, rcx + mov r11, rdx + mov r12, r8 + mov r13, r9 + mov r14, [rax+48] + mov r15, [rax+56] + push rsi + push rdi + sub rsp, SIZEOF_XMMWORD + movaps XMMWORD [rsp], xmm6 + sub rsp, SIZEOF_XMMWORD + movaps XMMWORD [rsp], xmm7 +%endmacro + +%imacro uncollect_args 0 + movaps xmm7, XMMWORD [rsp] + add rsp, SIZEOF_XMMWORD + movaps xmm6, XMMWORD [rsp] + add rsp, SIZEOF_XMMWORD + pop rdi + pop rsi + pop r15 + pop r14 + pop r13 + pop r12 +%endmacro + +%else + +%imacro collect_args 0 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + mov r10, rdi + mov r11, rsi + mov r12, rdx + mov r13, rcx + mov r14, r8 + mov r15, r9 +%endmacro + +%imacro uncollect_args 0 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 +%endmacro + +%endif + +%endif + +; -------------------------------------------------------------------------- +; Defines picked up from the C headers +; +%include "jsimdcfg.inc" + +; -------------------------------------------------------------------------- diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcclrss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcclrss2-64.asm new file mode 100755 index 0000000..f5d6bed --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcclrss2-64.asm @@ -0,0 +1,485 @@ +; +; jcclrss2-64.asm - colorspace conversion (64-bit SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; Copyright (C) 2009, D. R. Commander. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_rgb_ycc_convert_sse2 (JDIMENSION img_width, +; JSAMPARRAY input_buf, JSAMPIMAGE output_buf, +; JDIMENSION output_row, int num_rows); +; + +; r10 = JDIMENSION img_width +; r11 = JSAMPARRAY input_buf +; r12 = JSAMPIMAGE output_buf +; r13 = JDIMENSION output_row +; r14 = int num_rows + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 8 + + align 16 + + global EXTN(jsimd_rgb_ycc_convert_sse2) + +EXTN(jsimd_rgb_ycc_convert_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + push rbx + + mov rcx, r10 + test rcx,rcx + jz near .return + + push rcx + + mov rsi, r12 + mov rcx, r13 + mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY] + mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY] + mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY] + lea rdi, [rdi+rcx*SIZEOF_JSAMPROW] + lea rbx, [rbx+rcx*SIZEOF_JSAMPROW] + lea rdx, [rdx+rcx*SIZEOF_JSAMPROW] + + pop rcx + + mov rsi, r11 + mov eax, r14d + test rax,rax + jle near .return +.rowloop: + push rdx + push rbx + push rdi + push rsi + push rcx ; col + + mov rsi, JSAMPROW [rsi] ; inptr + mov rdi, JSAMPROW [rdi] ; outptr0 + mov rbx, JSAMPROW [rbx] ; outptr1 + mov rdx, JSAMPROW [rdx] ; outptr2 + + cmp rcx, byte SIZEOF_XMMWORD + jae near .columnloop + +%if RGB_PIXELSIZE == 3 ; --------------- + +.column_ld1: + push rax + push rdx + lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE + test cl, SIZEOF_BYTE + jz short .column_ld2 + sub rcx, byte SIZEOF_BYTE + movzx rax, BYTE [rsi+rcx] +.column_ld2: + test cl, SIZEOF_WORD + jz short .column_ld4 + sub rcx, byte SIZEOF_WORD + movzx rdx, WORD [rsi+rcx] + shl rax, WORD_BIT + or rax,rdx +.column_ld4: + movd xmmA,eax + pop rdx + pop rax + test cl, SIZEOF_DWORD + jz short .column_ld8 + sub rcx, byte SIZEOF_DWORD + movd xmmF, XMM_DWORD [rsi+rcx] + pslldq xmmA, SIZEOF_DWORD + por xmmA,xmmF +.column_ld8: + test cl, SIZEOF_MMWORD + jz short .column_ld16 + sub rcx, byte SIZEOF_MMWORD + movq xmmB, XMM_MMWORD [rsi+rcx] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmB +.column_ld16: + test cl, SIZEOF_XMMWORD + jz short .column_ld32 + movdqa xmmF,xmmA + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + mov rcx, SIZEOF_XMMWORD + jmp short .rgb_ycc_cnv +.column_ld32: + test cl, 2*SIZEOF_XMMWORD + mov rcx, SIZEOF_XMMWORD + jz short .rgb_ycc_cnv + movdqa xmmB,xmmA + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] + jmp short .rgb_ycc_cnv + +.columnloop: + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] + movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD] + +.rgb_ycc_cnv: + ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + movdqa xmmG,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) + psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) + pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) + + punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) + punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) + + movdqa xmmD,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) + psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) + pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) + + punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) + punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) + + movdqa xmmE,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) + psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) + + punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) + + pxor xmmH,xmmH + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmB,xmmE + punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) + + movdqa xmmF,xmmD + punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) + punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +.column_ld1: + test cl, SIZEOF_XMMWORD/16 + jz short .column_ld2 + sub rcx, byte SIZEOF_XMMWORD/16 + movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE] +.column_ld2: + test cl, SIZEOF_XMMWORD/8 + jz short .column_ld4 + sub rcx, byte SIZEOF_XMMWORD/8 + movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmE +.column_ld4: + test cl, SIZEOF_XMMWORD/4 + jz short .column_ld8 + sub rcx, byte SIZEOF_XMMWORD/4 + movdqa xmmE,xmmA + movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE] +.column_ld8: + test cl, SIZEOF_XMMWORD/2 + mov rcx, SIZEOF_XMMWORD + jz short .rgb_ycc_cnv + movdqa xmmF,xmmA + movdqa xmmH,xmmE + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] + jmp short .rgb_ycc_cnv + +.columnloop: + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD] + movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD] + +.rgb_ycc_cnv: + ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) + punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) + + movdqa xmmC,xmmF + punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) + punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) + + movdqa xmmB,xmmA + punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) + punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) + + movdqa xmmG,xmmD + punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) + punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) + + movdqa xmmE,xmmA + punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) + + movdqa xmmH,xmmB + punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) + punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) + + pxor xmmF,xmmF + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmD,xmmB + punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) + + movdqa xmmG,xmmE + punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) + + punpcklbw xmmF,xmmH + punpckhbw xmmH,xmmH + psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) + psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) + +%endif ; RGB_PIXELSIZE ; --------------- + + ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE + ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO + + ; (Original) + ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + ; + ; (This implementation) + ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G + ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE + movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO + movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE + movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO + + movdqa xmm6,xmm1 + punpcklwd xmm1,xmm3 + punpckhwd xmm6,xmm3 + movdqa xmm7,xmm1 + movdqa xmm4,xmm6 + pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) + pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) + pmaddwd xmm7,[rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331) + pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331) + + movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337) + movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337) + + pxor xmm1,xmm1 + pxor xmm6,xmm6 + punpcklwd xmm1,xmm5 ; xmm1=BOL + punpckhwd xmm6,xmm5 ; xmm6=BOH + psrld xmm1,1 ; xmm1=BOL*FIX(0.500) + psrld xmm6,1 ; xmm6=BOH*FIX(0.500) + + movdqa xmm5,[rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ] + + paddd xmm7,xmm1 + paddd xmm4,xmm6 + paddd xmm7,xmm5 + paddd xmm4,xmm5 + psrld xmm7,SCALEBITS ; xmm7=CbOL + psrld xmm4,SCALEBITS ; xmm4=CbOH + packssdw xmm7,xmm4 ; xmm7=CbO + + movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE + + movdqa xmm6,xmm0 + punpcklwd xmm0,xmm2 + punpckhwd xmm6,xmm2 + movdqa xmm5,xmm0 + movdqa xmm4,xmm6 + pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) + pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) + pmaddwd xmm5,[rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331) + pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331) + + movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337) + movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337) + + pxor xmm0,xmm0 + pxor xmm6,xmm6 + punpcklwd xmm0,xmm1 ; xmm0=BEL + punpckhwd xmm6,xmm1 ; xmm6=BEH + psrld xmm0,1 ; xmm0=BEL*FIX(0.500) + psrld xmm6,1 ; xmm6=BEH*FIX(0.500) + + movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ] + + paddd xmm5,xmm0 + paddd xmm4,xmm6 + paddd xmm5,xmm1 + paddd xmm4,xmm1 + psrld xmm5,SCALEBITS ; xmm5=CbEL + psrld xmm4,SCALEBITS ; xmm4=CbEH + packssdw xmm5,xmm4 ; xmm5=CbE + + psllw xmm7,BYTE_BIT + por xmm5,xmm7 ; xmm5=Cb + movdqa XMMWORD [rbx], xmm5 ; Save Cb + + movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO + movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO + + movdqa xmm4,xmm0 + punpcklwd xmm0,xmm3 + punpckhwd xmm4,xmm3 + movdqa xmm7,xmm0 + movdqa xmm5,xmm4 + pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) + pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) + pmaddwd xmm7,[rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418) + pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418) + + movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF] + + paddd xmm0, XMMWORD [wk(4)] + paddd xmm4, XMMWORD [wk(5)] + paddd xmm0,xmm3 + paddd xmm4,xmm3 + psrld xmm0,SCALEBITS ; xmm0=YOL + psrld xmm4,SCALEBITS ; xmm4=YOH + packssdw xmm0,xmm4 ; xmm0=YO + + pxor xmm3,xmm3 + pxor xmm4,xmm4 + punpcklwd xmm3,xmm1 ; xmm3=ROL + punpckhwd xmm4,xmm1 ; xmm4=ROH + psrld xmm3,1 ; xmm3=ROL*FIX(0.500) + psrld xmm4,1 ; xmm4=ROH*FIX(0.500) + + movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ] + + paddd xmm7,xmm3 + paddd xmm5,xmm4 + paddd xmm7,xmm1 + paddd xmm5,xmm1 + psrld xmm7,SCALEBITS ; xmm7=CrOL + psrld xmm5,SCALEBITS ; xmm5=CrOH + packssdw xmm7,xmm5 ; xmm7=CrO + + movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE + + movdqa xmm4,xmm6 + punpcklwd xmm6,xmm2 + punpckhwd xmm4,xmm2 + movdqa xmm1,xmm6 + movdqa xmm5,xmm4 + pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) + pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) + pmaddwd xmm1,[rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418) + pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418) + + movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF] + + paddd xmm6, XMMWORD [wk(6)] + paddd xmm4, XMMWORD [wk(7)] + paddd xmm6,xmm2 + paddd xmm4,xmm2 + psrld xmm6,SCALEBITS ; xmm6=YEL + psrld xmm4,SCALEBITS ; xmm4=YEH + packssdw xmm6,xmm4 ; xmm6=YE + + psllw xmm0,BYTE_BIT + por xmm6,xmm0 ; xmm6=Y + movdqa XMMWORD [rdi], xmm6 ; Save Y + + pxor xmm2,xmm2 + pxor xmm4,xmm4 + punpcklwd xmm2,xmm3 ; xmm2=REL + punpckhwd xmm4,xmm3 ; xmm4=REH + psrld xmm2,1 ; xmm2=REL*FIX(0.500) + psrld xmm4,1 ; xmm4=REH*FIX(0.500) + + movdqa xmm0,[rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ] + + paddd xmm1,xmm2 + paddd xmm5,xmm4 + paddd xmm1,xmm0 + paddd xmm5,xmm0 + psrld xmm1,SCALEBITS ; xmm1=CrEL + psrld xmm5,SCALEBITS ; xmm5=CrEH + packssdw xmm1,xmm5 ; xmm1=CrE + + psllw xmm7,BYTE_BIT + por xmm1,xmm7 ; xmm1=Cr + movdqa XMMWORD [rdx], xmm1 ; Save Cr + + sub rcx, byte SIZEOF_XMMWORD + add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr + add rdi, byte SIZEOF_XMMWORD ; outptr0 + add rbx, byte SIZEOF_XMMWORD ; outptr1 + add rdx, byte SIZEOF_XMMWORD ; outptr2 + cmp rcx, byte SIZEOF_XMMWORD + jae near .columnloop + test rcx,rcx + jnz near .column_ld1 + + pop rcx ; col + pop rsi + pop rdi + pop rbx + pop rdx + + add rsi, byte SIZEOF_JSAMPROW ; input_buf + add rdi, byte SIZEOF_JSAMPROW + add rbx, byte SIZEOF_JSAMPROW + add rdx, byte SIZEOF_JSAMPROW + dec rax ; num_rows + jg near .rowloop + +.return: + pop rbx + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jccolss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jccolss2-64.asm new file mode 100755 index 0000000..ae60148 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jccolss2-64.asm @@ -0,0 +1,120 @@ +; +; jccolss2-64.asm - colorspace conversion (64-bit SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; Copyright (C) 2009, D. R. Commander. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_081 equ 5329 ; FIX(0.08131) +F_0_114 equ 7471 ; FIX(0.11400) +F_0_168 equ 11059 ; FIX(0.16874) +F_0_250 equ 16384 ; FIX(0.25000) +F_0_299 equ 19595 ; FIX(0.29900) +F_0_331 equ 21709 ; FIX(0.33126) +F_0_418 equ 27439 ; FIX(0.41869) +F_0_587 equ 38470 ; FIX(0.58700) +F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_rgb_ycc_convert_sse2) + +EXTN(jconst_rgb_ycc_convert_sse2): + +PW_F0299_F0337 times 4 dw F_0_299, F_0_337 +PW_F0114_F0250 times 4 dw F_0_114, F_0_250 +PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331 +PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418 +PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS) +PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 + +%include "jcclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2 +%include "jcclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2 +%include "jcclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2 +%include "jcclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2 +%include "jcclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2 +%include "jcclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2 +%include "jcclrss2-64.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcgrass2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcgrass2-64.asm new file mode 100755 index 0000000..ba28cc3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcgrass2-64.asm @@ -0,0 +1,113 @@ +; +; jcgrass2-64.asm - grayscale colorspace conversion (64-bit SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; Copyright (C) 2011, D. R. Commander. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_114 equ 7471 ; FIX(0.11400) +F_0_250 equ 16384 ; FIX(0.25000) +F_0_299 equ 19595 ; FIX(0.29900) +F_0_587 equ 38470 ; FIX(0.58700) +F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_rgb_gray_convert_sse2) + +EXTN(jconst_rgb_gray_convert_sse2): + +PW_F0299_F0337 times 4 dw F_0_299, F_0_337 +PW_F0114_F0250 times 4 dw F_0_114, F_0_250 +PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 + +%include "jcgryss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extrgb_gray_convert_sse2 +%include "jcgryss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extrgbx_gray_convert_sse2 +%include "jcgryss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extbgr_gray_convert_sse2 +%include "jcgryss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extbgrx_gray_convert_sse2 +%include "jcgryss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extxbgr_gray_convert_sse2 +%include "jcgryss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_rgb_gray_convert_sse2 jsimd_extxrgb_gray_convert_sse2 +%include "jcgryss2-64.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcgryss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcgryss2-64.asm new file mode 100755 index 0000000..23ae8af --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcgryss2-64.asm @@ -0,0 +1,364 @@ +; +; jcgryss2-64.asm - grayscale colorspace conversion (64-bit SSE2) +; +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; Copyright (C) 2011, D. R. Commander. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_rgb_gray_convert_sse2 (JDIMENSION img_width, +; JSAMPARRAY input_buf, JSAMPIMAGE output_buf, +; JDIMENSION output_row, int num_rows); +; + +; r10 = JDIMENSION img_width +; r11 = JSAMPARRAY input_buf +; r12 = JSAMPIMAGE output_buf +; r13 = JDIMENSION output_row +; r14 = int num_rows + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + + global EXTN(jsimd_rgb_gray_convert_sse2) + +EXTN(jsimd_rgb_gray_convert_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + push rbx + + mov rcx, r10 + test rcx,rcx + jz near .return + + push rcx + + mov rsi, r12 + mov rcx, r13 + mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY] + lea rdi, [rdi+rcx*SIZEOF_JSAMPROW] + + pop rcx + + mov rsi, r11 + mov eax, r14d + test rax,rax + jle near .return +.rowloop: + push rdi + push rsi + push rcx ; col + + mov rsi, JSAMPROW [rsi] ; inptr + mov rdi, JSAMPROW [rdi] ; outptr0 + + cmp rcx, byte SIZEOF_XMMWORD + jae near .columnloop + +%if RGB_PIXELSIZE == 3 ; --------------- + +.column_ld1: + push rax + push rdx + lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE + test cl, SIZEOF_BYTE + jz short .column_ld2 + sub rcx, byte SIZEOF_BYTE + movzx rax, BYTE [rsi+rcx] +.column_ld2: + test cl, SIZEOF_WORD + jz short .column_ld4 + sub rcx, byte SIZEOF_WORD + movzx rdx, WORD [rsi+rcx] + shl rax, WORD_BIT + or rax,rdx +.column_ld4: + movd xmmA,eax + pop rdx + pop rax + test cl, SIZEOF_DWORD + jz short .column_ld8 + sub rcx, byte SIZEOF_DWORD + movd xmmF, XMM_DWORD [rsi+rcx] + pslldq xmmA, SIZEOF_DWORD + por xmmA,xmmF +.column_ld8: + test cl, SIZEOF_MMWORD + jz short .column_ld16 + sub rcx, byte SIZEOF_MMWORD + movq xmmB, XMM_MMWORD [rsi+rcx] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmB +.column_ld16: + test cl, SIZEOF_XMMWORD + jz short .column_ld32 + movdqa xmmF,xmmA + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + mov rcx, SIZEOF_XMMWORD + jmp short .rgb_gray_cnv +.column_ld32: + test cl, 2*SIZEOF_XMMWORD + mov rcx, SIZEOF_XMMWORD + jz short .rgb_gray_cnv + movdqa xmmB,xmmA + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] + jmp short .rgb_gray_cnv + +.columnloop: + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] + movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD] + +.rgb_gray_cnv: + ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + movdqa xmmG,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) + psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) + pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) + + punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) + punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) + + movdqa xmmD,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) + psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) + pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) + + punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) + punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) + + movdqa xmmE,xmmA + pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) + psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) + + punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) + + punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) + + pxor xmmH,xmmH + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmB,xmmE + punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) + + movdqa xmmF,xmmD + punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) + punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +.column_ld1: + test cl, SIZEOF_XMMWORD/16 + jz short .column_ld2 + sub rcx, byte SIZEOF_XMMWORD/16 + movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE] +.column_ld2: + test cl, SIZEOF_XMMWORD/8 + jz short .column_ld4 + sub rcx, byte SIZEOF_XMMWORD/8 + movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE] + pslldq xmmA, SIZEOF_MMWORD + por xmmA,xmmE +.column_ld4: + test cl, SIZEOF_XMMWORD/4 + jz short .column_ld8 + sub rcx, byte SIZEOF_XMMWORD/4 + movdqa xmmE,xmmA + movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE] +.column_ld8: + test cl, SIZEOF_XMMWORD/2 + mov rcx, SIZEOF_XMMWORD + jz short .rgb_gray_cnv + movdqa xmmF,xmmA + movdqa xmmH,xmmE + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] + jmp short .rgb_gray_cnv + +.columnloop: + movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] + movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD] + movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD] + +.rgb_gray_cnv: + ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) + punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) + + movdqa xmmC,xmmF + punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) + punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) + + movdqa xmmB,xmmA + punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) + punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) + + movdqa xmmG,xmmD + punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) + punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) + + movdqa xmmE,xmmA + punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) + punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) + + movdqa xmmH,xmmB + punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) + punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) + + pxor xmmF,xmmF + + movdqa xmmC,xmmA + punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) + punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) + + movdqa xmmD,xmmB + punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) + punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) + + movdqa xmmG,xmmE + punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) + punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) + + punpcklbw xmmF,xmmH + punpckhbw xmmH,xmmH + psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) + psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) + +%endif ; RGB_PIXELSIZE ; --------------- + + ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE + ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO + + ; (Original) + ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + ; + ; (This implementation) + ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G + + movdqa xmm6,xmm1 + punpcklwd xmm1,xmm3 + punpckhwd xmm6,xmm3 + pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) + pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) + + movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337) + + movdqa xmm6,xmm0 + punpcklwd xmm0,xmm2 + punpckhwd xmm6,xmm2 + pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) + pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) + + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337) + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337) + + movdqa xmm0, xmm5 ; xmm0=BO + movdqa xmm6, xmm4 ; xmm6=BE + + movdqa xmm4,xmm0 + punpcklwd xmm0,xmm3 + punpckhwd xmm4,xmm3 + pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) + pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) + + movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF] + + paddd xmm0, xmm1 + paddd xmm4, xmm7 + paddd xmm0,xmm3 + paddd xmm4,xmm3 + psrld xmm0,SCALEBITS ; xmm0=YOL + psrld xmm4,SCALEBITS ; xmm4=YOH + packssdw xmm0,xmm4 ; xmm0=YO + + movdqa xmm4,xmm6 + punpcklwd xmm6,xmm2 + punpckhwd xmm4,xmm2 + pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) + pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) + + movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF] + + paddd xmm6, XMMWORD [wk(0)] + paddd xmm4, XMMWORD [wk(1)] + paddd xmm6,xmm2 + paddd xmm4,xmm2 + psrld xmm6,SCALEBITS ; xmm6=YEL + psrld xmm4,SCALEBITS ; xmm4=YEH + packssdw xmm6,xmm4 ; xmm6=YE + + psllw xmm0,BYTE_BIT + por xmm6,xmm0 ; xmm6=Y + movdqa XMMWORD [rdi], xmm6 ; Save Y + + sub rcx, byte SIZEOF_XMMWORD + add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr + add rdi, byte SIZEOF_XMMWORD ; outptr0 + cmp rcx, byte SIZEOF_XMMWORD + jae near .columnloop + test rcx,rcx + jnz near .column_ld1 + + pop rcx ; col + pop rsi + pop rdi + + add rsi, byte SIZEOF_JSAMPROW ; input_buf + add rdi, byte SIZEOF_JSAMPROW + dec rax ; num_rows + jg near .rowloop + +.return: + pop rbx + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcolsamp.inc b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcolsamp.inc new file mode 100755 index 0000000..79751b7 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcolsamp.inc @@ -0,0 +1,105 @@ +; +; jcolsamp.inc - private declarations for color conversion & up/downsampling +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; [TAB8] + +; -------------------------------------------------------------------------- + +; pseudo-resisters to make ordering of RGB configurable +; +%if RGB_RED == 0 +%define mmA mm0 +%define mmB mm1 +%define xmmA xmm0 +%define xmmB xmm1 +%elif RGB_GREEN == 0 +%define mmA mm2 +%define mmB mm3 +%define xmmA xmm2 +%define xmmB xmm3 +%elif RGB_BLUE == 0 +%define mmA mm4 +%define mmB mm5 +%define xmmA xmm4 +%define xmmB xmm5 +%else +%define mmA mm6 +%define mmB mm7 +%define xmmA xmm6 +%define xmmB xmm7 +%endif + +%if RGB_RED == 1 +%define mmC mm0 +%define mmD mm1 +%define xmmC xmm0 +%define xmmD xmm1 +%elif RGB_GREEN == 1 +%define mmC mm2 +%define mmD mm3 +%define xmmC xmm2 +%define xmmD xmm3 +%elif RGB_BLUE == 1 +%define mmC mm4 +%define mmD mm5 +%define xmmC xmm4 +%define xmmD xmm5 +%else +%define mmC mm6 +%define mmD mm7 +%define xmmC xmm6 +%define xmmD xmm7 +%endif + +%if RGB_RED == 2 +%define mmE mm0 +%define mmF mm1 +%define xmmE xmm0 +%define xmmF xmm1 +%elif RGB_GREEN == 2 +%define mmE mm2 +%define mmF mm3 +%define xmmE xmm2 +%define xmmF xmm3 +%elif RGB_BLUE == 2 +%define mmE mm4 +%define mmF mm5 +%define xmmE xmm4 +%define xmmF xmm5 +%else +%define mmE mm6 +%define mmF mm7 +%define xmmE xmm6 +%define xmmF xmm7 +%endif + +%if RGB_RED == 3 +%define mmG mm0 +%define mmH mm1 +%define xmmG xmm0 +%define xmmH xmm1 +%elif RGB_GREEN == 3 +%define mmG mm2 +%define mmH mm3 +%define xmmG xmm2 +%define xmmH xmm3 +%elif RGB_BLUE == 3 +%define mmG mm4 +%define mmH mm5 +%define xmmG xmm4 +%define xmmH xmm5 +%else +%define mmG mm6 +%define mmH mm7 +%define xmmG xmm6 +%define xmmH xmm7 +%endif + +; -------------------------------------------------------------------------- diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcqnts2f-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcqnts2f-64.asm new file mode 100755 index 0000000..d0efa1b --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcqnts2f-64.asm @@ -0,0 +1,158 @@ +; +; jcqnts2f-64.asm - sample data conversion and quantization (64-bit SSE & SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Load data into workspace, applying unsigned->signed conversion +; +; GLOBAL(void) +; jsimd_convsamp_float_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col, +; FAST_FLOAT * workspace); +; + +; r10 = JSAMPARRAY sample_data +; r11 = JDIMENSION start_col +; r12 = FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_convsamp_float_sse2) + +EXTN(jsimd_convsamp_float_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + push rbx + + pcmpeqw xmm7,xmm7 + psllw xmm7,7 + packsswb xmm7,xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..) + + mov rsi, r10 + mov rax, r11 + mov rdi, r12 + mov rcx, DCTSIZE/2 +.convloop: + mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] + movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] + + psubb xmm0,xmm7 ; xmm0=(01234567) + psubb xmm1,xmm7 ; xmm1=(89ABCDEF) + + punpcklbw xmm0,xmm0 ; xmm0=(*0*1*2*3*4*5*6*7) + punpcklbw xmm1,xmm1 ; xmm1=(*8*9*A*B*C*D*E*F) + + punpcklwd xmm2,xmm0 ; xmm2=(***0***1***2***3) + punpckhwd xmm0,xmm0 ; xmm0=(***4***5***6***7) + punpcklwd xmm3,xmm1 ; xmm3=(***8***9***A***B) + punpckhwd xmm1,xmm1 ; xmm1=(***C***D***E***F) + + psrad xmm2,(DWORD_BIT-BYTE_BIT) ; xmm2=(0123) + psrad xmm0,(DWORD_BIT-BYTE_BIT) ; xmm0=(4567) + cvtdq2ps xmm2,xmm2 ; xmm2=(0123) + cvtdq2ps xmm0,xmm0 ; xmm0=(4567) + psrad xmm3,(DWORD_BIT-BYTE_BIT) ; xmm3=(89AB) + psrad xmm1,(DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF) + cvtdq2ps xmm3,xmm3 ; xmm3=(89AB) + cvtdq2ps xmm1,xmm1 ; xmm1=(CDEF) + + movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1 + + add rsi, byte 2*SIZEOF_JSAMPROW + add rdi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT + dec rcx + jnz short .convloop + + pop rbx + uncollect_args + pop rbp + ret + + +; -------------------------------------------------------------------------- +; +; Quantize/descale the coefficients, and store into coef_block +; +; GLOBAL(void) +; jsimd_quantize_float_sse2 (JCOEFPTR coef_block, FAST_FLOAT * divisors, +; FAST_FLOAT * workspace); +; + +; r10 = JCOEFPTR coef_block +; r11 = FAST_FLOAT * divisors +; r12 = FAST_FLOAT * workspace + + align 16 + global EXTN(jsimd_quantize_float_sse2) + +EXTN(jsimd_quantize_float_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + + mov rsi, r12 + mov rdx, r11 + mov rdi, r10 + mov rax, DCTSIZE2/16 +.quantloop: + movaps xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(0,1,rsi,SIZEOF_FAST_FLOAT)] + mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)] + mulps xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(1,1,rsi,SIZEOF_FAST_FLOAT)] + mulps xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)] + mulps xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)] + + cvtps2dq xmm0,xmm0 + cvtps2dq xmm1,xmm1 + cvtps2dq xmm2,xmm2 + cvtps2dq xmm3,xmm3 + + packssdw xmm0,xmm1 + packssdw xmm2,xmm3 + + movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_JCOEF)], xmm0 + movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_JCOEF)], xmm2 + + add rsi, byte 16*SIZEOF_FAST_FLOAT + add rdx, byte 16*SIZEOF_FAST_FLOAT + add rdi, byte 16*SIZEOF_JCOEF + dec rax + jnz short .quantloop + + uncollect_args + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcqnts2i-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcqnts2i-64.asm new file mode 100755 index 0000000..cc33d59 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcqnts2i-64.asm @@ -0,0 +1,187 @@ +; +; jcqnts2i-64.asm - sample data conversion and quantization (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Load data into workspace, applying unsigned->signed conversion +; +; GLOBAL(void) +; jsimd_convsamp_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col, +; DCTELEM * workspace); +; + +; r10 = JSAMPARRAY sample_data +; r11 = JDIMENSION start_col +; r12 = DCTELEM * workspace + + align 16 + global EXTN(jsimd_convsamp_sse2) + +EXTN(jsimd_convsamp_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + push rbx + + pxor xmm6,xmm6 ; xmm6=(all 0's) + pcmpeqw xmm7,xmm7 + psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} + + mov rsi, r10 + mov rax, r11 + mov rdi, r12 + mov rcx, DCTSIZE/4 +.convloop: + mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] ; xmm0=(01234567) + movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] ; xmm1=(89ABCDEF) + + mov rbx, JSAMPROW [rsi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *) + mov rdx, JSAMPROW [rsi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *) + + movq xmm2, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] ; xmm2=(GHIJKLMN) + movq xmm3, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] ; xmm3=(OPQRSTUV) + + punpcklbw xmm0,xmm6 ; xmm0=(01234567) + punpcklbw xmm1,xmm6 ; xmm1=(89ABCDEF) + paddw xmm0,xmm7 + paddw xmm1,xmm7 + punpcklbw xmm2,xmm6 ; xmm2=(GHIJKLMN) + punpcklbw xmm3,xmm6 ; xmm3=(OPQRSTUV) + paddw xmm2,xmm7 + paddw xmm3,xmm7 + + movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0 + movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1 + movdqa XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2 + movdqa XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3 + + add rsi, byte 4*SIZEOF_JSAMPROW + add rdi, byte 4*DCTSIZE*SIZEOF_DCTELEM + dec rcx + jnz short .convloop + + pop rbx + uncollect_args + pop rbp + ret + +; -------------------------------------------------------------------------- +; +; Quantize/descale the coefficients, and store into coef_block +; +; This implementation is based on an algorithm described in +; "How to optimize for the Pentium family of microprocessors" +; (http://www.agner.org/assem/). +; +; GLOBAL(void) +; jsimd_quantize_sse2 (JCOEFPTR coef_block, DCTELEM * divisors, +; DCTELEM * workspace); +; + +%define RECIPROCAL(m,n,b) XMMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM) +%define CORRECTION(m,n,b) XMMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM) +%define SCALE(m,n,b) XMMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM) + +; r10 = JCOEFPTR coef_block +; r11 = DCTELEM * divisors +; r12 = DCTELEM * workspace + + align 16 + global EXTN(jsimd_quantize_sse2) + +EXTN(jsimd_quantize_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + + mov rsi, r12 + mov rdx, r11 + mov rdi, r10 + mov rax, DCTSIZE2/32 +.quantloop: + movdqa xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_DCTELEM)] + movdqa xmm5, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_DCTELEM)] + movdqa xmm6, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_DCTELEM)] + movdqa xmm7, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_DCTELEM)] + movdqa xmm0,xmm4 + movdqa xmm1,xmm5 + movdqa xmm2,xmm6 + movdqa xmm3,xmm7 + psraw xmm4,(WORD_BIT-1) + psraw xmm5,(WORD_BIT-1) + psraw xmm6,(WORD_BIT-1) + psraw xmm7,(WORD_BIT-1) + pxor xmm0,xmm4 + pxor xmm1,xmm5 + pxor xmm2,xmm6 + pxor xmm3,xmm7 + psubw xmm0,xmm4 ; if (xmm0 < 0) xmm0 = -xmm0; + psubw xmm1,xmm5 ; if (xmm1 < 0) xmm1 = -xmm1; + psubw xmm2,xmm6 ; if (xmm2 < 0) xmm2 = -xmm2; + psubw xmm3,xmm7 ; if (xmm3 < 0) xmm3 = -xmm3; + + paddw xmm0, XMMWORD [CORRECTION(0,0,rdx)] ; correction + roundfactor + paddw xmm1, XMMWORD [CORRECTION(1,0,rdx)] + paddw xmm2, XMMWORD [CORRECTION(2,0,rdx)] + paddw xmm3, XMMWORD [CORRECTION(3,0,rdx)] + pmulhuw xmm0, XMMWORD [RECIPROCAL(0,0,rdx)] ; reciprocal + pmulhuw xmm1, XMMWORD [RECIPROCAL(1,0,rdx)] + pmulhuw xmm2, XMMWORD [RECIPROCAL(2,0,rdx)] + pmulhuw xmm3, XMMWORD [RECIPROCAL(3,0,rdx)] + pmulhuw xmm0, XMMWORD [SCALE(0,0,rdx)] ; scale + pmulhuw xmm1, XMMWORD [SCALE(1,0,rdx)] + pmulhuw xmm2, XMMWORD [SCALE(2,0,rdx)] + pmulhuw xmm3, XMMWORD [SCALE(3,0,rdx)] + + pxor xmm0,xmm4 + pxor xmm1,xmm5 + pxor xmm2,xmm6 + pxor xmm3,xmm7 + psubw xmm0,xmm4 + psubw xmm1,xmm5 + psubw xmm2,xmm6 + psubw xmm3,xmm7 + movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0 + movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1 + movdqa XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2 + movdqa XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3 + + add rsi, byte 32*SIZEOF_DCTELEM + add rdx, byte 32*SIZEOF_DCTELEM + add rdi, byte 32*SIZEOF_JCOEF + dec rax + jnz near .quantloop + + uncollect_args + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcsamss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcsamss2-64.asm new file mode 100755 index 0000000..6a16dc5 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jcsamss2-64.asm @@ -0,0 +1,330 @@ +; +; jcsamss2-64.asm - downsampling (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Downsample pixel values of a single component. +; This version handles the common case of 2:1 horizontal and 1:1 vertical, +; without smoothing. +; +; GLOBAL(void) +; jsimd_h2v1_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, +; JDIMENSION v_samp_factor, JDIMENSION width_blocks, +; JSAMPARRAY input_data, JSAMPARRAY output_data); +; + +; r10 = JDIMENSION image_width +; r11 = int max_v_samp_factor +; r12 = JDIMENSION v_samp_factor +; r13 = JDIMENSION width_blocks +; r14 = JSAMPARRAY input_data +; r15 = JSAMPARRAY output_data + + align 16 + global EXTN(jsimd_h2v1_downsample_sse2) + +EXTN(jsimd_h2v1_downsample_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + + mov rcx, r13 + shl rcx,3 ; imul rcx,DCTSIZE (rcx = output_cols) + jz near .return + + mov rdx, r10 + + ; -- expand_right_edge + + push rcx + shl rcx,1 ; output_cols * 2 + sub rcx,rdx + jle short .expand_end + + mov rax, r11 + test rax,rax + jle short .expand_end + + cld + mov rsi, r14 ; input_data +.expandloop: + push rax + push rcx + + mov rdi, JSAMPROW [rsi] + add rdi,rdx + mov al, JSAMPLE [rdi-1] + + rep stosb + + pop rcx + pop rax + + add rsi, byte SIZEOF_JSAMPROW + dec rax + jg short .expandloop + +.expand_end: + pop rcx ; output_cols + + ; -- h2v1_downsample + + mov rax, r12 ; rowctr + test eax,eax + jle near .return + + mov rdx, 0x00010000 ; bias pattern + movd xmm7,edx + pcmpeqw xmm6,xmm6 + pshufd xmm7,xmm7,0x00 ; xmm7={0, 1, 0, 1, 0, 1, 0, 1} + psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} + + mov rsi, r14 ; input_data + mov rdi, r15 ; output_data +.rowloop: + push rcx + push rdi + push rsi + + mov rsi, JSAMPROW [rsi] ; inptr + mov rdi, JSAMPROW [rdi] ; outptr + + cmp rcx, byte SIZEOF_XMMWORD + jae short .columnloop + +.columnloop_r8: + movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD] + pxor xmm1,xmm1 + mov rcx, SIZEOF_XMMWORD + jmp short .downsample + +.columnloop: + movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqa xmm1, XMMWORD [rsi+1*SIZEOF_XMMWORD] + +.downsample: + movdqa xmm2,xmm0 + movdqa xmm3,xmm1 + + pand xmm0,xmm6 + psrlw xmm2,BYTE_BIT + pand xmm1,xmm6 + psrlw xmm3,BYTE_BIT + + paddw xmm0,xmm2 + paddw xmm1,xmm3 + paddw xmm0,xmm7 + paddw xmm1,xmm7 + psrlw xmm0,1 + psrlw xmm1,1 + + packuswb xmm0,xmm1 + + movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0 + + sub rcx, byte SIZEOF_XMMWORD ; outcol + add rsi, byte 2*SIZEOF_XMMWORD ; inptr + add rdi, byte 1*SIZEOF_XMMWORD ; outptr + cmp rcx, byte SIZEOF_XMMWORD + jae short .columnloop + test rcx,rcx + jnz short .columnloop_r8 + + pop rsi + pop rdi + pop rcx + + add rsi, byte SIZEOF_JSAMPROW ; input_data + add rdi, byte SIZEOF_JSAMPROW ; output_data + dec rax ; rowctr + jg near .rowloop + +.return: + uncollect_args + pop rbp + ret + +; -------------------------------------------------------------------------- +; +; Downsample pixel values of a single component. +; This version handles the standard case of 2:1 horizontal and 2:1 vertical, +; without smoothing. +; +; GLOBAL(void) +; jsimd_h2v2_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, +; JDIMENSION v_samp_factor, JDIMENSION width_blocks, +; JSAMPARRAY input_data, JSAMPARRAY output_data); +; + +; r10 = JDIMENSION image_width +; r11 = int max_v_samp_factor +; r12 = JDIMENSION v_samp_factor +; r13 = JDIMENSION width_blocks +; r14 = JSAMPARRAY input_data +; r15 = JSAMPARRAY output_data + + align 16 + global EXTN(jsimd_h2v2_downsample_sse2) + +EXTN(jsimd_h2v2_downsample_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + + mov rcx, r13 + shl rcx,3 ; imul rcx,DCTSIZE (rcx = output_cols) + jz near .return + + mov rdx, r10 + + ; -- expand_right_edge + + push rcx + shl rcx,1 ; output_cols * 2 + sub rcx,rdx + jle short .expand_end + + mov rax, r11 + test rax,rax + jle short .expand_end + + cld + mov rsi, r14 ; input_data +.expandloop: + push rax + push rcx + + mov rdi, JSAMPROW [rsi] + add rdi,rdx + mov al, JSAMPLE [rdi-1] + + rep stosb + + pop rcx + pop rax + + add rsi, byte SIZEOF_JSAMPROW + dec rax + jg short .expandloop + +.expand_end: + pop rcx ; output_cols + + ; -- h2v2_downsample + + mov rax, r12 ; rowctr + test rax,rax + jle near .return + + mov rdx, 0x00020001 ; bias pattern + movd xmm7,edx + pcmpeqw xmm6,xmm6 + pshufd xmm7,xmm7,0x00 ; xmm7={1, 2, 1, 2, 1, 2, 1, 2} + psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} + + mov rsi, r14 ; input_data + mov rdi, r15 ; output_data +.rowloop: + push rcx + push rdi + push rsi + + mov rdx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; inptr0 + mov rsi, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; inptr1 + mov rdi, JSAMPROW [rdi] ; outptr + + cmp rcx, byte SIZEOF_XMMWORD + jae short .columnloop + +.columnloop_r8: + movdqa xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD] + movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD] + pxor xmm2,xmm2 + pxor xmm3,xmm3 + mov rcx, SIZEOF_XMMWORD + jmp short .downsample + +.columnloop: + movdqa xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD] + movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqa xmm2, XMMWORD [rdx+1*SIZEOF_XMMWORD] + movdqa xmm3, XMMWORD [rsi+1*SIZEOF_XMMWORD] + +.downsample: + movdqa xmm4,xmm0 + movdqa xmm5,xmm1 + pand xmm0,xmm6 + psrlw xmm4,BYTE_BIT + pand xmm1,xmm6 + psrlw xmm5,BYTE_BIT + paddw xmm0,xmm4 + paddw xmm1,xmm5 + + movdqa xmm4,xmm2 + movdqa xmm5,xmm3 + pand xmm2,xmm6 + psrlw xmm4,BYTE_BIT + pand xmm3,xmm6 + psrlw xmm5,BYTE_BIT + paddw xmm2,xmm4 + paddw xmm3,xmm5 + + paddw xmm0,xmm1 + paddw xmm2,xmm3 + paddw xmm0,xmm7 + paddw xmm2,xmm7 + psrlw xmm0,2 + psrlw xmm2,2 + + packuswb xmm0,xmm2 + + movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0 + + sub rcx, byte SIZEOF_XMMWORD ; outcol + add rdx, byte 2*SIZEOF_XMMWORD ; inptr0 + add rsi, byte 2*SIZEOF_XMMWORD ; inptr1 + add rdi, byte 1*SIZEOF_XMMWORD ; outptr + cmp rcx, byte SIZEOF_XMMWORD + jae near .columnloop + test rcx,rcx + jnz near .columnloop_r8 + + pop rsi + pop rdi + pop rcx + + add rsi, byte 2*SIZEOF_JSAMPROW ; input_data + add rdi, byte 1*SIZEOF_JSAMPROW ; output_data + dec rax ; rowctr + jg near .rowloop + +.return: + uncollect_args + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdclrss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdclrss2-64.asm new file mode 100755 index 0000000..9b2e930 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdclrss2-64.asm @@ -0,0 +1,441 @@ +; +; jdclrss2-64.asm - colorspace conversion (64-bit SSE2) +; +; Copyright 2009, 2012 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Convert some rows of samples to the output colorspace. +; +; GLOBAL(void) +; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width, +; JSAMPIMAGE input_buf, JDIMENSION input_row, +; JSAMPARRAY output_buf, int num_rows) +; + +; r10 = JDIMENSION out_width +; r11 = JSAMPIMAGE input_buf +; r12 = JDIMENSION input_row +; r13 = JSAMPARRAY output_buf +; r14 = int num_rows + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_ycc_rgb_convert_sse2) + +EXTN(jsimd_ycc_rgb_convert_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + push rbx + + mov rcx, r10 ; num_cols + test rcx,rcx + jz near .return + + push rcx + + mov rdi, r11 + mov rcx, r12 + mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY] + mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY] + mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY] + lea rsi, [rsi+rcx*SIZEOF_JSAMPROW] + lea rbx, [rbx+rcx*SIZEOF_JSAMPROW] + lea rdx, [rdx+rcx*SIZEOF_JSAMPROW] + + pop rcx + + mov rdi, r13 + mov eax, r14d + test rax,rax + jle near .return +.rowloop: + push rax + push rdi + push rdx + push rbx + push rsi + push rcx ; col + + mov rsi, JSAMPROW [rsi] ; inptr0 + mov rbx, JSAMPROW [rbx] ; inptr1 + mov rdx, JSAMPROW [rdx] ; inptr2 + mov rdi, JSAMPROW [rdi] ; outptr +.columnloop: + + movdqa xmm5, XMMWORD [rbx] ; xmm5=Cb(0123456789ABCDEF) + movdqa xmm1, XMMWORD [rdx] ; xmm1=Cr(0123456789ABCDEF) + + pcmpeqw xmm4,xmm4 + pcmpeqw xmm7,xmm7 + psrlw xmm4,BYTE_BIT + psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} + movdqa xmm0,xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..} + + pand xmm4,xmm5 ; xmm4=Cb(02468ACE)=CbE + psrlw xmm5,BYTE_BIT ; xmm5=Cb(13579BDF)=CbO + pand xmm0,xmm1 ; xmm0=Cr(02468ACE)=CrE + psrlw xmm1,BYTE_BIT ; xmm1=Cr(13579BDF)=CrO + + paddw xmm4,xmm7 + paddw xmm5,xmm7 + paddw xmm0,xmm7 + paddw xmm1,xmm7 + + ; (Original) + ; R = Y + 1.40200 * Cr + ; G = Y - 0.34414 * Cb - 0.71414 * Cr + ; B = Y + 1.77200 * Cb + ; + ; (This implementation) + ; R = Y + 0.40200 * Cr + Cr + ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr + ; B = Y - 0.22800 * Cb + Cb + Cb + + movdqa xmm2,xmm4 ; xmm2=CbE + movdqa xmm3,xmm5 ; xmm3=CbO + paddw xmm4,xmm4 ; xmm4=2*CbE + paddw xmm5,xmm5 ; xmm5=2*CbO + movdqa xmm6,xmm0 ; xmm6=CrE + movdqa xmm7,xmm1 ; xmm7=CrO + paddw xmm0,xmm0 ; xmm0=2*CrE + paddw xmm1,xmm1 ; xmm1=2*CrO + + pmulhw xmm4,[rel PW_MF0228] ; xmm4=(2*CbE * -FIX(0.22800)) + pmulhw xmm5,[rel PW_MF0228] ; xmm5=(2*CbO * -FIX(0.22800)) + pmulhw xmm0,[rel PW_F0402] ; xmm0=(2*CrE * FIX(0.40200)) + pmulhw xmm1,[rel PW_F0402] ; xmm1=(2*CrO * FIX(0.40200)) + + paddw xmm4,[rel PW_ONE] + paddw xmm5,[rel PW_ONE] + psraw xmm4,1 ; xmm4=(CbE * -FIX(0.22800)) + psraw xmm5,1 ; xmm5=(CbO * -FIX(0.22800)) + paddw xmm0,[rel PW_ONE] + paddw xmm1,[rel PW_ONE] + psraw xmm0,1 ; xmm0=(CrE * FIX(0.40200)) + psraw xmm1,1 ; xmm1=(CrO * FIX(0.40200)) + + paddw xmm4,xmm2 + paddw xmm5,xmm3 + paddw xmm4,xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E + paddw xmm5,xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O + paddw xmm0,xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E + paddw xmm1,xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E + movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O + + movdqa xmm4,xmm2 + movdqa xmm5,xmm3 + punpcklwd xmm2,xmm6 + punpckhwd xmm4,xmm6 + pmaddwd xmm2,[rel PW_MF0344_F0285] + pmaddwd xmm4,[rel PW_MF0344_F0285] + punpcklwd xmm3,xmm7 + punpckhwd xmm5,xmm7 + pmaddwd xmm3,[rel PW_MF0344_F0285] + pmaddwd xmm5,[rel PW_MF0344_F0285] + + paddd xmm2,[rel PD_ONEHALF] + paddd xmm4,[rel PD_ONEHALF] + psrad xmm2,SCALEBITS + psrad xmm4,SCALEBITS + paddd xmm3,[rel PD_ONEHALF] + paddd xmm5,[rel PD_ONEHALF] + psrad xmm3,SCALEBITS + psrad xmm5,SCALEBITS + + packssdw xmm2,xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285) + packssdw xmm3,xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285) + psubw xmm2,xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E + psubw xmm3,xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O + + movdqa xmm5, XMMWORD [rsi] ; xmm5=Y(0123456789ABCDEF) + + pcmpeqw xmm4,xmm4 + psrlw xmm4,BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..} + pand xmm4,xmm5 ; xmm4=Y(02468ACE)=YE + psrlw xmm5,BYTE_BIT ; xmm5=Y(13579BDF)=YO + + paddw xmm0,xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE) + paddw xmm1,xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF) + packuswb xmm0,xmm0 ; xmm0=R(02468ACE********) + packuswb xmm1,xmm1 ; xmm1=R(13579BDF********) + + paddw xmm2,xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE) + paddw xmm3,xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF) + packuswb xmm2,xmm2 ; xmm2=G(02468ACE********) + packuswb xmm3,xmm3 ; xmm3=G(13579BDF********) + + paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE) + paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF) + packuswb xmm4,xmm4 ; xmm4=B(02468ACE********) + packuswb xmm5,xmm5 ; xmm5=B(13579BDF********) + +%if RGB_PIXELSIZE == 3 ; --------------- + + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F) + punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F) + + movdqa xmmG,xmmA + movdqa xmmH,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07) + punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F) + + psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --) + psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --) + + movdqa xmmC,xmmD + movdqa xmmB,xmmD + punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18) + punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --) + + psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --) + + movdqa xmmF,xmmE + punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29) + punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --) + + pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03) + movdqa xmmB,xmmE + punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14) + punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07) + punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29) + + pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B) + movdqa xmmB,xmmF + punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C) + punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F) + punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --) + + punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + cmp rcx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test rdi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF +.out0: + add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub rcx, byte SIZEOF_XMMWORD + jz near .nextrow + + add rsi, byte SIZEOF_XMMWORD ; inptr0 + add rbx, byte SIZEOF_XMMWORD ; inptr1 + add rdx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + +.column_st32: + lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE + cmp rcx, byte 2*SIZEOF_XMMWORD + jb short .column_st16 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + add rdi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmF + sub rcx, byte 2*SIZEOF_XMMWORD + jmp short .column_st15 +.column_st16: + cmp rcx, byte SIZEOF_XMMWORD + jb short .column_st15 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + add rdi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub rcx, byte SIZEOF_XMMWORD +.column_st15: + ; Store the lower 8 bytes of xmmA to the output when it has enough + ; space. + cmp rcx, byte SIZEOF_MMWORD + jb short .column_st7 + movq MMWORD [rdi], xmmA + add rdi, byte SIZEOF_MMWORD + sub rcx, byte SIZEOF_MMWORD + psrldq xmmA, SIZEOF_MMWORD +.column_st7: + ; Store the lower 4 bytes of xmmA to the output when it has enough + ; space. + cmp rcx, byte SIZEOF_DWORD + jb short .column_st3 + movd DWORD [rdi], xmmA + add rdi, byte SIZEOF_DWORD + sub rcx, byte SIZEOF_DWORD + psrldq xmmA, SIZEOF_DWORD +.column_st3: + ; Store the lower 2 bytes of rax to the output when it has enough + ; space. + movd eax, xmmA + cmp rcx, byte SIZEOF_WORD + jb short .column_st1 + mov WORD [rdi], ax + add rdi, byte SIZEOF_WORD + sub rcx, byte SIZEOF_WORD + shr rax, 16 +.column_st1: + ; Store the lower 1 byte of rax to the output when it has enough + ; space. + test rcx, rcx + jz short .nextrow + mov BYTE [rdi], al + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +%ifdef RGBX_FILLER_0XFF + pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%else + pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%endif + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E) + punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F) + punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F) + + movdqa xmmC,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36) + punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E) + movdqa xmmG,xmmB + punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37) + punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + movdqa xmmH,xmmC + punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + cmp rcx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test rdi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC + movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC + movdqu XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH +.out0: + add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub rcx, byte SIZEOF_XMMWORD + jz near .nextrow + + add rsi, byte SIZEOF_XMMWORD ; inptr0 + add rbx, byte SIZEOF_XMMWORD ; inptr1 + add rdx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + +.column_st32: + cmp rcx, byte SIZEOF_XMMWORD/2 + jb short .column_st16 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + add rdi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmC + movdqa xmmD,xmmH + sub rcx, byte SIZEOF_XMMWORD/2 +.column_st16: + cmp rcx, byte SIZEOF_XMMWORD/4 + jb short .column_st15 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + add rdi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub rcx, byte SIZEOF_XMMWORD/4 +.column_st15: + ; Store two pixels (8 bytes) of xmmA to the output when it has enough + ; space. + cmp rcx, byte SIZEOF_XMMWORD/8 + jb short .column_st7 + movq MMWORD [rdi], xmmA + add rdi, byte SIZEOF_XMMWORD/8*4 + sub rcx, byte SIZEOF_XMMWORD/8 + psrldq xmmA, SIZEOF_XMMWORD/8*4 +.column_st7: + ; Store one pixel (4 bytes) of xmmA to the output when it has enough + ; space. + test rcx, rcx + jz short .nextrow + movd DWORD [rdi], xmmA + +%endif ; RGB_PIXELSIZE ; --------------- + +.nextrow: + pop rcx + pop rsi + pop rbx + pop rdx + pop rdi + pop rax + + add rsi, byte SIZEOF_JSAMPROW + add rbx, byte SIZEOF_JSAMPROW + add rdx, byte SIZEOF_JSAMPROW + add rdi, byte SIZEOF_JSAMPROW ; output_buf + dec rax ; num_rows + jg near .rowloop + + sfence ; flush the write buffer + +.return: + pop rbx + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdcolss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdcolss2-64.asm new file mode 100755 index 0000000..01b3dce --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdcolss2-64.asm @@ -0,0 +1,120 @@ +; +; jdcolss2-64.asm - colorspace conversion (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_344 equ 22554 ; FIX(0.34414) +F_0_714 equ 46802 ; FIX(0.71414) +F_1_402 equ 91881 ; FIX(1.40200) +F_1_772 equ 116130 ; FIX(1.77200) +F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) +F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) +F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_ycc_rgb_convert_sse2) + +EXTN(jconst_ycc_rgb_convert_sse2): + +PW_F0402 times 8 dw F_0_402 +PW_MF0228 times 8 dw -F_0_228 +PW_MF0344_F0285 times 4 dw -F_0_344, F_0_285 +PW_ONE times 8 dw 1 +PD_ONEHALF times 4 dd 1 << (SCALEBITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 + +%include "jdclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgb_convert_sse2 +%include "jdclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgbx_convert_sse2 +%include "jdclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgr_convert_sse2 +%include "jdclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgrx_convert_sse2 +%include "jdclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxbgr_convert_sse2 +%include "jdclrss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxrgb_convert_sse2 +%include "jdclrss2-64.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdct.inc b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdct.inc new file mode 100755 index 0000000..cc62704 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdct.inc @@ -0,0 +1,28 @@ +; +; jdct.inc - private declarations for forward & reverse DCT subsystems +; +; Copyright 2009 Pierre Ossman for Cendio AB +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; [TAB8] + +; Each IDCT routine is responsible for range-limiting its results and +; converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could +; be quite far out of range if the input data is corrupt, so a bulletproof +; range-limiting step is required. We use a mask-and-table-lookup method +; to do the combined operations quickly. +; +%define RANGE_MASK (MAXJSAMPLE * 4 + 3) ; 2 bits wider than legal samples + +%define ROW(n,b,s) ((b)+(n)*(s)) +%define COL(n,b,s) ((b)+(n)*(s)*DCTSIZE) + +%define DWBLOCK(m,n,b,s) ((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_DWORD) +%define MMBLOCK(m,n,b,s) ((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_MMWORD) +%define XMMBLOCK(m,n,b,s) ((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_XMMWORD) + +; -------------------------------------------------------------------------- diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdmerss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdmerss2-64.asm new file mode 100755 index 0000000..a184ea6 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdmerss2-64.asm @@ -0,0 +1,126 @@ +; +; jdmerss2-64.asm - merged upsampling/color conversion (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + +%define SCALEBITS 16 + +F_0_344 equ 22554 ; FIX(0.34414) +F_0_714 equ 46802 ; FIX(0.71414) +F_1_402 equ 91881 ; FIX(1.40200) +F_1_772 equ 116130 ; FIX(1.77200) +F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) +F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) +F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_merged_upsample_sse2) + +EXTN(jconst_merged_upsample_sse2): + +PW_F0402 times 8 dw F_0_402 +PW_MF0228 times 8 dw -F_0_228 +PW_MF0344_F0285 times 4 dw -F_0_344, F_0_285 +PW_ONE times 8 dw 1 +PD_ONEHALF times 4 dd 1 << (SCALEBITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 + +%include "jdmrgss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGB_RED +%define RGB_GREEN EXT_RGB_GREEN +%define RGB_BLUE EXT_RGB_BLUE +%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgb_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgb_merged_upsample_sse2 +%include "jdmrgss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_RGBX_RED +%define RGB_GREEN EXT_RGBX_GREEN +%define RGB_BLUE EXT_RGBX_BLUE +%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgbx_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgbx_merged_upsample_sse2 +%include "jdmrgss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGR_RED +%define RGB_GREEN EXT_BGR_GREEN +%define RGB_BLUE EXT_BGR_BLUE +%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgr_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgr_merged_upsample_sse2 +%include "jdmrgss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_BGRX_RED +%define RGB_GREEN EXT_BGRX_GREEN +%define RGB_BLUE EXT_BGRX_BLUE +%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgrx_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgrx_merged_upsample_sse2 +%include "jdmrgss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XBGR_RED +%define RGB_GREEN EXT_XBGR_GREEN +%define RGB_BLUE EXT_XBGR_BLUE +%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxbgr_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxbgr_merged_upsample_sse2 +%include "jdmrgss2-64.asm" + +%undef RGB_RED +%undef RGB_GREEN +%undef RGB_BLUE +%undef RGB_PIXELSIZE +%define RGB_RED EXT_XRGB_RED +%define RGB_GREEN EXT_XRGB_GREEN +%define RGB_BLUE EXT_XRGB_BLUE +%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE +%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxrgb_merged_upsample_sse2 +%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxrgb_merged_upsample_sse2 +%include "jdmrgss2-64.asm" diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdmrgss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdmrgss2-64.asm new file mode 100755 index 0000000..5d8fc46 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdmrgss2-64.asm @@ -0,0 +1,538 @@ +; +; jdmrgss2-64.asm - merged upsampling/color conversion (64-bit SSE2) +; +; Copyright 2009, 2012 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jcolsamp.inc" + +; -------------------------------------------------------------------------- +; +; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. +; +; GLOBAL(void) +; jsimd_h2v1_merged_upsample_sse2 (JDIMENSION output_width, +; JSAMPIMAGE input_buf, +; JDIMENSION in_row_group_ctr, +; JSAMPARRAY output_buf); +; + +; r10 = JDIMENSION output_width +; r11 = JSAMPIMAGE input_buf +; r12 = JDIMENSION in_row_group_ctr +; r13 = JSAMPARRAY output_buf + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 3 + + align 16 + global EXTN(jsimd_h2v1_merged_upsample_sse2) + +EXTN(jsimd_h2v1_merged_upsample_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + push rbx + + mov rcx, r10 ; col + test rcx,rcx + jz near .return + + push rcx + + mov rdi, r11 + mov rcx, r12 + mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY] + mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY] + mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY] + mov rdi, r13 + mov rsi, JSAMPROW [rsi+rcx*SIZEOF_JSAMPROW] ; inptr0 + mov rbx, JSAMPROW [rbx+rcx*SIZEOF_JSAMPROW] ; inptr1 + mov rdx, JSAMPROW [rdx+rcx*SIZEOF_JSAMPROW] ; inptr2 + mov rdi, JSAMPROW [rdi] ; outptr + + pop rcx ; col + +.columnloop: + + movdqa xmm6, XMMWORD [rbx] ; xmm6=Cb(0123456789ABCDEF) + movdqa xmm7, XMMWORD [rdx] ; xmm7=Cr(0123456789ABCDEF) + + pxor xmm1,xmm1 ; xmm1=(all 0's) + pcmpeqw xmm3,xmm3 + psllw xmm3,7 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..} + + movdqa xmm4,xmm6 + punpckhbw xmm6,xmm1 ; xmm6=Cb(89ABCDEF)=CbH + punpcklbw xmm4,xmm1 ; xmm4=Cb(01234567)=CbL + movdqa xmm0,xmm7 + punpckhbw xmm7,xmm1 ; xmm7=Cr(89ABCDEF)=CrH + punpcklbw xmm0,xmm1 ; xmm0=Cr(01234567)=CrL + + paddw xmm6,xmm3 + paddw xmm4,xmm3 + paddw xmm7,xmm3 + paddw xmm0,xmm3 + + ; (Original) + ; R = Y + 1.40200 * Cr + ; G = Y - 0.34414 * Cb - 0.71414 * Cr + ; B = Y + 1.77200 * Cb + ; + ; (This implementation) + ; R = Y + 0.40200 * Cr + Cr + ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr + ; B = Y - 0.22800 * Cb + Cb + Cb + + movdqa xmm5,xmm6 ; xmm5=CbH + movdqa xmm2,xmm4 ; xmm2=CbL + paddw xmm6,xmm6 ; xmm6=2*CbH + paddw xmm4,xmm4 ; xmm4=2*CbL + movdqa xmm1,xmm7 ; xmm1=CrH + movdqa xmm3,xmm0 ; xmm3=CrL + paddw xmm7,xmm7 ; xmm7=2*CrH + paddw xmm0,xmm0 ; xmm0=2*CrL + + pmulhw xmm6,[rel PW_MF0228] ; xmm6=(2*CbH * -FIX(0.22800)) + pmulhw xmm4,[rel PW_MF0228] ; xmm4=(2*CbL * -FIX(0.22800)) + pmulhw xmm7,[rel PW_F0402] ; xmm7=(2*CrH * FIX(0.40200)) + pmulhw xmm0,[rel PW_F0402] ; xmm0=(2*CrL * FIX(0.40200)) + + paddw xmm6,[rel PW_ONE] + paddw xmm4,[rel PW_ONE] + psraw xmm6,1 ; xmm6=(CbH * -FIX(0.22800)) + psraw xmm4,1 ; xmm4=(CbL * -FIX(0.22800)) + paddw xmm7,[rel PW_ONE] + paddw xmm0,[rel PW_ONE] + psraw xmm7,1 ; xmm7=(CrH * FIX(0.40200)) + psraw xmm0,1 ; xmm0=(CrL * FIX(0.40200)) + + paddw xmm6,xmm5 + paddw xmm4,xmm2 + paddw xmm6,xmm5 ; xmm6=(CbH * FIX(1.77200))=(B-Y)H + paddw xmm4,xmm2 ; xmm4=(CbL * FIX(1.77200))=(B-Y)L + paddw xmm7,xmm1 ; xmm7=(CrH * FIX(1.40200))=(R-Y)H + paddw xmm0,xmm3 ; xmm0=(CrL * FIX(1.40200))=(R-Y)L + + movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=(B-Y)H + movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(R-Y)H + + movdqa xmm6,xmm5 + movdqa xmm7,xmm2 + punpcklwd xmm5,xmm1 + punpckhwd xmm6,xmm1 + pmaddwd xmm5,[rel PW_MF0344_F0285] + pmaddwd xmm6,[rel PW_MF0344_F0285] + punpcklwd xmm2,xmm3 + punpckhwd xmm7,xmm3 + pmaddwd xmm2,[rel PW_MF0344_F0285] + pmaddwd xmm7,[rel PW_MF0344_F0285] + + paddd xmm5,[rel PD_ONEHALF] + paddd xmm6,[rel PD_ONEHALF] + psrad xmm5,SCALEBITS + psrad xmm6,SCALEBITS + paddd xmm2,[rel PD_ONEHALF] + paddd xmm7,[rel PD_ONEHALF] + psrad xmm2,SCALEBITS + psrad xmm7,SCALEBITS + + packssdw xmm5,xmm6 ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285) + packssdw xmm2,xmm7 ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285) + psubw xmm5,xmm1 ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H + psubw xmm2,xmm3 ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L + + movdqa XMMWORD [wk(2)], xmm5 ; wk(2)=(G-Y)H + + mov al,2 ; Yctr + jmp short .Yloop_1st + +.Yloop_2nd: + movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(R-Y)H + movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(G-Y)H + movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(B-Y)H + +.Yloop_1st: + movdqa xmm7, XMMWORD [rsi] ; xmm7=Y(0123456789ABCDEF) + + pcmpeqw xmm6,xmm6 + psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} + pand xmm6,xmm7 ; xmm6=Y(02468ACE)=YE + psrlw xmm7,BYTE_BIT ; xmm7=Y(13579BDF)=YO + + movdqa xmm1,xmm0 ; xmm1=xmm0=(R-Y)(L/H) + movdqa xmm3,xmm2 ; xmm3=xmm2=(G-Y)(L/H) + movdqa xmm5,xmm4 ; xmm5=xmm4=(B-Y)(L/H) + + paddw xmm0,xmm6 ; xmm0=((R-Y)+YE)=RE=R(02468ACE) + paddw xmm1,xmm7 ; xmm1=((R-Y)+YO)=RO=R(13579BDF) + packuswb xmm0,xmm0 ; xmm0=R(02468ACE********) + packuswb xmm1,xmm1 ; xmm1=R(13579BDF********) + + paddw xmm2,xmm6 ; xmm2=((G-Y)+YE)=GE=G(02468ACE) + paddw xmm3,xmm7 ; xmm3=((G-Y)+YO)=GO=G(13579BDF) + packuswb xmm2,xmm2 ; xmm2=G(02468ACE********) + packuswb xmm3,xmm3 ; xmm3=G(13579BDF********) + + paddw xmm4,xmm6 ; xmm4=((B-Y)+YE)=BE=B(02468ACE) + paddw xmm5,xmm7 ; xmm5=((B-Y)+YO)=BO=B(13579BDF) + packuswb xmm4,xmm4 ; xmm4=B(02468ACE********) + packuswb xmm5,xmm5 ; xmm5=B(13579BDF********) + +%if RGB_PIXELSIZE == 3 ; --------------- + + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F) + punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F) + + movdqa xmmG,xmmA + movdqa xmmH,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07) + punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F) + + psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --) + psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --) + + movdqa xmmC,xmmD + movdqa xmmB,xmmD + punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18) + punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --) + + psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --) + + movdqa xmmF,xmmE + punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29) + punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --) + + pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03) + movdqa xmmB,xmmE + punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14) + punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07) + punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29) + + pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B) + movdqa xmmB,xmmF + punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C) + punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F) + punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --) + + punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) + punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) + punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) + + cmp rcx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test rdi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF +.out0: + add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub rcx, byte SIZEOF_XMMWORD + jz near .endcolumn + + add rsi, byte SIZEOF_XMMWORD ; inptr0 + dec al ; Yctr + jnz near .Yloop_2nd + + add rbx, byte SIZEOF_XMMWORD ; inptr1 + add rdx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + +.column_st32: + lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE + cmp rcx, byte 2*SIZEOF_XMMWORD + jb short .column_st16 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + add rdi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmF + sub rcx, byte 2*SIZEOF_XMMWORD + jmp short .column_st15 +.column_st16: + cmp rcx, byte SIZEOF_XMMWORD + jb short .column_st15 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + add rdi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub rcx, byte SIZEOF_XMMWORD +.column_st15: + ; Store the lower 8 bytes of xmmA to the output when it has enough + ; space. + cmp rcx, byte SIZEOF_MMWORD + jb short .column_st7 + movq MMWORD [rdi], xmmA + add rdi, byte SIZEOF_MMWORD + sub rcx, byte SIZEOF_MMWORD + psrldq xmmA, SIZEOF_MMWORD +.column_st7: + ; Store the lower 4 bytes of xmmA to the output when it has enough + ; space. + cmp rcx, byte SIZEOF_DWORD + jb short .column_st3 + movd DWORD [rdi], xmmA + add rdi, byte SIZEOF_DWORD + sub rcx, byte SIZEOF_DWORD + psrldq xmmA, SIZEOF_DWORD +.column_st3: + ; Store the lower 2 bytes of rax to the output when it has enough + ; space. + movd eax, xmmA + cmp rcx, byte SIZEOF_WORD + jb short .column_st1 + mov WORD [rdi], ax + add rdi, byte SIZEOF_WORD + sub rcx, byte SIZEOF_WORD + shr rax, 16 +.column_st1: + ; Store the lower 1 byte of rax to the output when it has enough + ; space. + test rcx, rcx + jz short .endcolumn + mov BYTE [rdi], al + +%else ; RGB_PIXELSIZE == 4 ; ----------- + +%ifdef RGBX_FILLER_0XFF + pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%else + pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********) + pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********) +%endif + ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) + ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) + ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) + ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) + + punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) + punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E) + punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F) + punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F) + + movdqa xmmC,xmmA + punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36) + punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E) + movdqa xmmG,xmmB + punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37) + punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F) + + movdqa xmmD,xmmA + punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) + punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) + movdqa xmmH,xmmC + punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) + punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) + + cmp rcx, byte SIZEOF_XMMWORD + jb short .column_st32 + + test rdi, SIZEOF_XMMWORD-1 + jnz short .out1 + ; --(aligned)------------------- + movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC + movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH + jmp short .out0 +.out1: ; --(unaligned)----------------- + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC + movdqu XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH +.out0: + add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr + sub rcx, byte SIZEOF_XMMWORD + jz near .endcolumn + + add rsi, byte SIZEOF_XMMWORD ; inptr0 + dec al ; Yctr + jnz near .Yloop_2nd + + add rbx, byte SIZEOF_XMMWORD ; inptr1 + add rdx, byte SIZEOF_XMMWORD ; inptr2 + jmp near .columnloop + +.column_st32: + cmp rcx, byte SIZEOF_XMMWORD/2 + jb short .column_st16 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD + add rdi, byte 2*SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmC + movdqa xmmD,xmmH + sub rcx, byte SIZEOF_XMMWORD/2 +.column_st16: + cmp rcx, byte SIZEOF_XMMWORD/4 + jb short .column_st15 + movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA + add rdi, byte SIZEOF_XMMWORD ; outptr + movdqa xmmA,xmmD + sub rcx, byte SIZEOF_XMMWORD/4 +.column_st15: + ; Store two pixels (8 bytes) of xmmA to the output when it has enough + ; space. + cmp rcx, byte SIZEOF_XMMWORD/8 + jb short .column_st7 + movq MMWORD [rdi], xmmA + add rdi, byte SIZEOF_XMMWORD/8*4 + sub rcx, byte SIZEOF_XMMWORD/8 + psrldq xmmA, SIZEOF_XMMWORD/8*4 +.column_st7: + ; Store one pixel (4 bytes) of xmmA to the output when it has enough + ; space. + test rcx, rcx + jz short .endcolumn + movd DWORD [rdi], xmmA + +%endif ; RGB_PIXELSIZE ; --------------- + +.endcolumn: + sfence ; flush the write buffer + +.return: + pop rbx + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; -------------------------------------------------------------------------- +; +; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. +; +; GLOBAL(void) +; jsimd_h2v2_merged_upsample_sse2 (JDIMENSION output_width, +; JSAMPIMAGE input_buf, +; JDIMENSION in_row_group_ctr, +; JSAMPARRAY output_buf); +; + +; r10 = JDIMENSION output_width +; r11 = JSAMPIMAGE input_buf +; r12 = JDIMENSION in_row_group_ctr +; r13 = JSAMPARRAY output_buf + + align 16 + global EXTN(jsimd_h2v2_merged_upsample_sse2) + +EXTN(jsimd_h2v2_merged_upsample_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + push rbx + + mov rax, r10 + + mov rdi, r11 + mov rcx, r12 + mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY] + mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY] + mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY] + mov rdi, r13 + lea rsi, [rsi+rcx*SIZEOF_JSAMPROW] + + push rdx ; inptr2 + push rbx ; inptr1 + push rsi ; inptr00 + mov rbx,rsp + + push rdi + push rcx + push rax + + %ifdef WIN64 + mov r8, rcx + mov r9, rdi + mov rcx, rax + mov rdx, rbx + %else + mov rdx, rcx + mov rcx, rdi + mov rdi, rax + mov rsi, rbx + %endif + + call EXTN(jsimd_h2v1_merged_upsample_sse2) + + pop rax + pop rcx + pop rdi + pop rsi + pop rbx + pop rdx + + add rdi, byte SIZEOF_JSAMPROW ; outptr1 + add rsi, byte SIZEOF_JSAMPROW ; inptr01 + + push rdx ; inptr2 + push rbx ; inptr1 + push rsi ; inptr00 + mov rbx,rsp + + push rdi + push rcx + push rax + + %ifdef WIN64 + mov r8, rcx + mov r9, rdi + mov rcx, rax + mov rdx, rbx + %else + mov rdx, rcx + mov rcx, rdi + mov rdi, rax + mov rsi, rbx + %endif + + call EXTN(jsimd_h2v1_merged_upsample_sse2) + + pop rax + pop rcx + pop rdi + pop rsi + pop rbx + pop rdx + + pop rbx + uncollect_args + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdsamss2-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdsamss2-64.asm new file mode 100755 index 0000000..f36c156 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jdsamss2-64.asm @@ -0,0 +1,671 @@ +; +; jdsamss2-64.asm - upsampling (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; [TAB8] + +%include "jsimdext.inc" + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fancy_upsample_sse2) + +EXTN(jconst_fancy_upsample_sse2): + +PW_ONE times 8 dw 1 +PW_TWO times 8 dw 2 +PW_THREE times 8 dw 3 +PW_SEVEN times 8 dw 7 +PW_EIGHT times 8 dw 8 + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. +; +; The upsampling algorithm is linear interpolation between pixel centers, +; also known as a "triangle filter". This is a good compromise between +; speed and visual quality. The centers of the output pixels are 1/4 and 3/4 +; of the way between input pixel centers. +; +; GLOBAL(void) +; jsimd_h2v1_fancy_upsample_sse2 (int max_v_samp_factor, +; JDIMENSION downsampled_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +; r10 = int max_v_samp_factor +; r11 = JDIMENSION downsampled_width +; r12 = JSAMPARRAY input_data +; r13 = JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v1_fancy_upsample_sse2) + +EXTN(jsimd_h2v1_fancy_upsample_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + + mov rax, r11 ; colctr + test rax,rax + jz near .return + + mov rcx, r10 ; rowctr + test rcx,rcx + jz near .return + + mov rsi, r12 ; input_data + mov rdi, r13 + mov rdi, JSAMPARRAY [rdi] ; output_data +.rowloop: + push rax ; colctr + push rdi + push rsi + + mov rsi, JSAMPROW [rsi] ; inptr + mov rdi, JSAMPROW [rdi] ; outptr + + test rax, SIZEOF_XMMWORD-1 + jz short .skip + mov dl, JSAMPLE [rsi+(rax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [rsi+rax*SIZEOF_JSAMPLE], dl ; insert a dummy sample +.skip: + pxor xmm0,xmm0 ; xmm0=(all 0's) + pcmpeqb xmm7,xmm7 + psrldq xmm7,(SIZEOF_XMMWORD-1) + pand xmm7, XMMWORD [rsi+0*SIZEOF_XMMWORD] + + add rax, byte SIZEOF_XMMWORD-1 + and rax, byte -SIZEOF_XMMWORD + cmp rax, byte SIZEOF_XMMWORD + ja short .columnloop + +.columnloop_last: + pcmpeqb xmm6,xmm6 + pslldq xmm6,(SIZEOF_XMMWORD-1) + pand xmm6, XMMWORD [rsi+0*SIZEOF_XMMWORD] + jmp short .upsample + +.columnloop: + movdqa xmm6, XMMWORD [rsi+1*SIZEOF_XMMWORD] + pslldq xmm6,(SIZEOF_XMMWORD-1) + +.upsample: + movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD] + movdqa xmm2,xmm1 + movdqa xmm3,xmm1 ; xmm1=( 0 1 2 ... 13 14 15) + pslldq xmm2,1 ; xmm2=(-- 0 1 ... 12 13 14) + psrldq xmm3,1 ; xmm3=( 1 2 3 ... 14 15 --) + + por xmm2,xmm7 ; xmm2=(-1 0 1 ... 12 13 14) + por xmm3,xmm6 ; xmm3=( 1 2 3 ... 14 15 16) + + movdqa xmm7,xmm1 + psrldq xmm7,(SIZEOF_XMMWORD-1) ; xmm7=(15 -- -- ... -- -- --) + + movdqa xmm4,xmm1 + punpcklbw xmm1,xmm0 ; xmm1=( 0 1 2 3 4 5 6 7) + punpckhbw xmm4,xmm0 ; xmm4=( 8 9 10 11 12 13 14 15) + movdqa xmm5,xmm2 + punpcklbw xmm2,xmm0 ; xmm2=(-1 0 1 2 3 4 5 6) + punpckhbw xmm5,xmm0 ; xmm5=( 7 8 9 10 11 12 13 14) + movdqa xmm6,xmm3 + punpcklbw xmm3,xmm0 ; xmm3=( 1 2 3 4 5 6 7 8) + punpckhbw xmm6,xmm0 ; xmm6=( 9 10 11 12 13 14 15 16) + + pmullw xmm1,[rel PW_THREE] + pmullw xmm4,[rel PW_THREE] + paddw xmm2,[rel PW_ONE] + paddw xmm5,[rel PW_ONE] + paddw xmm3,[rel PW_TWO] + paddw xmm6,[rel PW_TWO] + + paddw xmm2,xmm1 + paddw xmm5,xmm4 + psrlw xmm2,2 ; xmm2=OutLE=( 0 2 4 6 8 10 12 14) + psrlw xmm5,2 ; xmm5=OutHE=(16 18 20 22 24 26 28 30) + paddw xmm3,xmm1 + paddw xmm6,xmm4 + psrlw xmm3,2 ; xmm3=OutLO=( 1 3 5 7 9 11 13 15) + psrlw xmm6,2 ; xmm6=OutHO=(17 19 21 23 25 27 29 31) + + psllw xmm3,BYTE_BIT + psllw xmm6,BYTE_BIT + por xmm2,xmm3 ; xmm2=OutL=( 0 1 2 ... 13 14 15) + por xmm5,xmm6 ; xmm5=OutH=(16 17 18 ... 29 30 31) + + movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm5 + + sub rax, byte SIZEOF_XMMWORD + add rsi, byte 1*SIZEOF_XMMWORD ; inptr + add rdi, byte 2*SIZEOF_XMMWORD ; outptr + cmp rax, byte SIZEOF_XMMWORD + ja near .columnloop + test eax,eax + jnz near .columnloop_last + + pop rsi + pop rdi + pop rax + + add rsi, byte SIZEOF_JSAMPROW ; input_data + add rdi, byte SIZEOF_JSAMPROW ; output_data + dec rcx ; rowctr + jg near .rowloop + +.return: + uncollect_args + pop rbp + ret + +; -------------------------------------------------------------------------- +; +; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. +; Again a triangle filter; see comments for h2v1 case, above. +; +; GLOBAL(void) +; jsimd_h2v2_fancy_upsample_sse2 (int max_v_samp_factor, +; JDIMENSION downsampled_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +; r10 = int max_v_samp_factor +; r11 = JDIMENSION downsampled_width +; r12 = JSAMPARRAY input_data +; r13 = JSAMPARRAY * output_data_ptr + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 4 + + align 16 + global EXTN(jsimd_h2v2_fancy_upsample_sse2) + +EXTN(jsimd_h2v2_fancy_upsample_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + push rbx + + mov rax, r11 ; colctr + test rax,rax + jz near .return + + mov rcx, r10 ; rowctr + test rcx,rcx + jz near .return + + mov rsi, r12 ; input_data + mov rdi, r13 + mov rdi, JSAMPARRAY [rdi] ; output_data +.rowloop: + push rax ; colctr + push rcx + push rdi + push rsi + + mov rcx, JSAMPROW [rsi-1*SIZEOF_JSAMPROW] ; inptr1(above) + mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; inptr0 + mov rsi, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; inptr1(below) + mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] ; outptr0 + mov rdi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] ; outptr1 + + test rax, SIZEOF_XMMWORD-1 + jz short .skip + push rdx + mov dl, JSAMPLE [rcx+(rax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [rcx+rax*SIZEOF_JSAMPLE], dl + mov dl, JSAMPLE [rbx+(rax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [rbx+rax*SIZEOF_JSAMPLE], dl + mov dl, JSAMPLE [rsi+(rax-1)*SIZEOF_JSAMPLE] + mov JSAMPLE [rsi+rax*SIZEOF_JSAMPLE], dl ; insert a dummy sample + pop rdx +.skip: + ; -- process the first column block + + movdqa xmm0, XMMWORD [rbx+0*SIZEOF_XMMWORD] ; xmm0=row[ 0][0] + movdqa xmm1, XMMWORD [rcx+0*SIZEOF_XMMWORD] ; xmm1=row[-1][0] + movdqa xmm2, XMMWORD [rsi+0*SIZEOF_XMMWORD] ; xmm2=row[+1][0] + + pxor xmm3,xmm3 ; xmm3=(all 0's) + movdqa xmm4,xmm0 + punpcklbw xmm0,xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7) + punpckhbw xmm4,xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15) + movdqa xmm5,xmm1 + punpcklbw xmm1,xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm5,xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15) + movdqa xmm6,xmm2 + punpcklbw xmm2,xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm6,xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15) + + pmullw xmm0,[rel PW_THREE] + pmullw xmm4,[rel PW_THREE] + + pcmpeqb xmm7,xmm7 + psrldq xmm7,(SIZEOF_XMMWORD-2) + + paddw xmm1,xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7) + paddw xmm5,xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15) + paddw xmm2,xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7) + paddw xmm6,xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15) + + movdqa XMMWORD [rdx+0*SIZEOF_XMMWORD], xmm1 ; temporarily save + movdqa XMMWORD [rdx+1*SIZEOF_XMMWORD], xmm5 ; the intermediate data + movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm6 + + pand xmm1,xmm7 ; xmm1=( 0 -- -- -- -- -- -- --) + pand xmm2,xmm7 ; xmm2=( 0 -- -- -- -- -- -- --) + + movdqa XMMWORD [wk(0)], xmm1 + movdqa XMMWORD [wk(1)], xmm2 + + add rax, byte SIZEOF_XMMWORD-1 + and rax, byte -SIZEOF_XMMWORD + cmp rax, byte SIZEOF_XMMWORD + ja short .columnloop + +.columnloop_last: + ; -- process the last column block + + pcmpeqb xmm1,xmm1 + pslldq xmm1,(SIZEOF_XMMWORD-2) + movdqa xmm2,xmm1 + + pand xmm1, XMMWORD [rdx+1*SIZEOF_XMMWORD] + pand xmm2, XMMWORD [rdi+1*SIZEOF_XMMWORD] + + movdqa XMMWORD [wk(2)], xmm1 ; xmm1=(-- -- -- -- -- -- -- 15) + movdqa XMMWORD [wk(3)], xmm2 ; xmm2=(-- -- -- -- -- -- -- 15) + + jmp near .upsample + +.columnloop: + ; -- process the next column block + + movdqa xmm0, XMMWORD [rbx+1*SIZEOF_XMMWORD] ; xmm0=row[ 0][1] + movdqa xmm1, XMMWORD [rcx+1*SIZEOF_XMMWORD] ; xmm1=row[-1][1] + movdqa xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD] ; xmm2=row[+1][1] + + pxor xmm3,xmm3 ; xmm3=(all 0's) + movdqa xmm4,xmm0 + punpcklbw xmm0,xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7) + punpckhbw xmm4,xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15) + movdqa xmm5,xmm1 + punpcklbw xmm1,xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm5,xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15) + movdqa xmm6,xmm2 + punpcklbw xmm2,xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7) + punpckhbw xmm6,xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15) + + pmullw xmm0,[rel PW_THREE] + pmullw xmm4,[rel PW_THREE] + + paddw xmm1,xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7) + paddw xmm5,xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15) + paddw xmm2,xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7) + paddw xmm6,xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15) + + movdqa XMMWORD [rdx+2*SIZEOF_XMMWORD], xmm1 ; temporarily save + movdqa XMMWORD [rdx+3*SIZEOF_XMMWORD], xmm5 ; the intermediate data + movdqa XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm6 + + pslldq xmm1,(SIZEOF_XMMWORD-2) ; xmm1=(-- -- -- -- -- -- -- 0) + pslldq xmm2,(SIZEOF_XMMWORD-2) ; xmm2=(-- -- -- -- -- -- -- 0) + + movdqa XMMWORD [wk(2)], xmm1 + movdqa XMMWORD [wk(3)], xmm2 + +.upsample: + ; -- process the upper row + + movdqa xmm7, XMMWORD [rdx+0*SIZEOF_XMMWORD] + movdqa xmm3, XMMWORD [rdx+1*SIZEOF_XMMWORD] + + movdqa xmm0,xmm7 ; xmm7=Int0L=( 0 1 2 3 4 5 6 7) + movdqa xmm4,xmm3 ; xmm3=Int0H=( 8 9 10 11 12 13 14 15) + psrldq xmm0,2 ; xmm0=( 1 2 3 4 5 6 7 --) + pslldq xmm4,(SIZEOF_XMMWORD-2) ; xmm4=(-- -- -- -- -- -- -- 8) + movdqa xmm5,xmm7 + movdqa xmm6,xmm3 + psrldq xmm5,(SIZEOF_XMMWORD-2) ; xmm5=( 7 -- -- -- -- -- -- --) + pslldq xmm6,2 ; xmm6=(-- 8 9 10 11 12 13 14) + + por xmm0,xmm4 ; xmm0=( 1 2 3 4 5 6 7 8) + por xmm5,xmm6 ; xmm5=( 7 8 9 10 11 12 13 14) + + movdqa xmm1,xmm7 + movdqa xmm2,xmm3 + pslldq xmm1,2 ; xmm1=(-- 0 1 2 3 4 5 6) + psrldq xmm2,2 ; xmm2=( 9 10 11 12 13 14 15 --) + movdqa xmm4,xmm3 + psrldq xmm4,(SIZEOF_XMMWORD-2) ; xmm4=(15 -- -- -- -- -- -- --) + + por xmm1, XMMWORD [wk(0)] ; xmm1=(-1 0 1 2 3 4 5 6) + por xmm2, XMMWORD [wk(2)] ; xmm2=( 9 10 11 12 13 14 15 16) + + movdqa XMMWORD [wk(0)], xmm4 + + pmullw xmm7,[rel PW_THREE] + pmullw xmm3,[rel PW_THREE] + paddw xmm1,[rel PW_EIGHT] + paddw xmm5,[rel PW_EIGHT] + paddw xmm0,[rel PW_SEVEN] + paddw xmm2,[rel PW_SEVEN] + + paddw xmm1,xmm7 + paddw xmm5,xmm3 + psrlw xmm1,4 ; xmm1=Out0LE=( 0 2 4 6 8 10 12 14) + psrlw xmm5,4 ; xmm5=Out0HE=(16 18 20 22 24 26 28 30) + paddw xmm0,xmm7 + paddw xmm2,xmm3 + psrlw xmm0,4 ; xmm0=Out0LO=( 1 3 5 7 9 11 13 15) + psrlw xmm2,4 ; xmm2=Out0HO=(17 19 21 23 25 27 29 31) + + psllw xmm0,BYTE_BIT + psllw xmm2,BYTE_BIT + por xmm1,xmm0 ; xmm1=Out0L=( 0 1 2 ... 13 14 15) + por xmm5,xmm2 ; xmm5=Out0H=(16 17 18 ... 29 30 31) + + movdqa XMMWORD [rdx+0*SIZEOF_XMMWORD], xmm1 + movdqa XMMWORD [rdx+1*SIZEOF_XMMWORD], xmm5 + + ; -- process the lower row + + movdqa xmm6, XMMWORD [rdi+0*SIZEOF_XMMWORD] + movdqa xmm4, XMMWORD [rdi+1*SIZEOF_XMMWORD] + + movdqa xmm7,xmm6 ; xmm6=Int1L=( 0 1 2 3 4 5 6 7) + movdqa xmm3,xmm4 ; xmm4=Int1H=( 8 9 10 11 12 13 14 15) + psrldq xmm7,2 ; xmm7=( 1 2 3 4 5 6 7 --) + pslldq xmm3,(SIZEOF_XMMWORD-2) ; xmm3=(-- -- -- -- -- -- -- 8) + movdqa xmm0,xmm6 + movdqa xmm2,xmm4 + psrldq xmm0,(SIZEOF_XMMWORD-2) ; xmm0=( 7 -- -- -- -- -- -- --) + pslldq xmm2,2 ; xmm2=(-- 8 9 10 11 12 13 14) + + por xmm7,xmm3 ; xmm7=( 1 2 3 4 5 6 7 8) + por xmm0,xmm2 ; xmm0=( 7 8 9 10 11 12 13 14) + + movdqa xmm1,xmm6 + movdqa xmm5,xmm4 + pslldq xmm1,2 ; xmm1=(-- 0 1 2 3 4 5 6) + psrldq xmm5,2 ; xmm5=( 9 10 11 12 13 14 15 --) + movdqa xmm3,xmm4 + psrldq xmm3,(SIZEOF_XMMWORD-2) ; xmm3=(15 -- -- -- -- -- -- --) + + por xmm1, XMMWORD [wk(1)] ; xmm1=(-1 0 1 2 3 4 5 6) + por xmm5, XMMWORD [wk(3)] ; xmm5=( 9 10 11 12 13 14 15 16) + + movdqa XMMWORD [wk(1)], xmm3 + + pmullw xmm6,[rel PW_THREE] + pmullw xmm4,[rel PW_THREE] + paddw xmm1,[rel PW_EIGHT] + paddw xmm0,[rel PW_EIGHT] + paddw xmm7,[rel PW_SEVEN] + paddw xmm5,[rel PW_SEVEN] + + paddw xmm1,xmm6 + paddw xmm0,xmm4 + psrlw xmm1,4 ; xmm1=Out1LE=( 0 2 4 6 8 10 12 14) + psrlw xmm0,4 ; xmm0=Out1HE=(16 18 20 22 24 26 28 30) + paddw xmm7,xmm6 + paddw xmm5,xmm4 + psrlw xmm7,4 ; xmm7=Out1LO=( 1 3 5 7 9 11 13 15) + psrlw xmm5,4 ; xmm5=Out1HO=(17 19 21 23 25 27 29 31) + + psllw xmm7,BYTE_BIT + psllw xmm5,BYTE_BIT + por xmm1,xmm7 ; xmm1=Out1L=( 0 1 2 ... 13 14 15) + por xmm0,xmm5 ; xmm0=Out1H=(16 17 18 ... 29 30 31) + + movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm1 + movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm0 + + sub rax, byte SIZEOF_XMMWORD + add rcx, byte 1*SIZEOF_XMMWORD ; inptr1(above) + add rbx, byte 1*SIZEOF_XMMWORD ; inptr0 + add rsi, byte 1*SIZEOF_XMMWORD ; inptr1(below) + add rdx, byte 2*SIZEOF_XMMWORD ; outptr0 + add rdi, byte 2*SIZEOF_XMMWORD ; outptr1 + cmp rax, byte SIZEOF_XMMWORD + ja near .columnloop + test rax,rax + jnz near .columnloop_last + + pop rsi + pop rdi + pop rcx + pop rax + + add rsi, byte 1*SIZEOF_JSAMPROW ; input_data + add rdi, byte 2*SIZEOF_JSAMPROW ; output_data + sub rcx, byte 2 ; rowctr + jg near .rowloop + +.return: + pop rbx + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; -------------------------------------------------------------------------- +; +; Fast processing for the common case of 2:1 horizontal and 1:1 vertical. +; It's still a box filter. +; +; GLOBAL(void) +; jsimd_h2v1_upsample_sse2 (int max_v_samp_factor, +; JDIMENSION output_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +; r10 = int max_v_samp_factor +; r11 = JDIMENSION output_width +; r12 = JSAMPARRAY input_data +; r13 = JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v1_upsample_sse2) + +EXTN(jsimd_h2v1_upsample_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + + mov rdx, r11 + add rdx, byte (2*SIZEOF_XMMWORD)-1 + and rdx, byte -(2*SIZEOF_XMMWORD) + jz near .return + + mov rcx, r10 ; rowctr + test rcx,rcx + jz short .return + + mov rsi, r12 ; input_data + mov rdi, r13 + mov rdi, JSAMPARRAY [rdi] ; output_data +.rowloop: + push rdi + push rsi + + mov rsi, JSAMPROW [rsi] ; inptr + mov rdi, JSAMPROW [rdi] ; outptr + mov rax,rdx ; colctr +.columnloop: + + movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD] + + movdqa xmm1,xmm0 + punpcklbw xmm0,xmm0 + punpckhbw xmm1,xmm1 + + movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0 + movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm1 + + sub rax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + movdqa xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD] + + movdqa xmm3,xmm2 + punpcklbw xmm2,xmm2 + punpckhbw xmm3,xmm3 + + movdqa XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm3 + + sub rax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + add rsi, byte 2*SIZEOF_XMMWORD ; inptr + add rdi, byte 4*SIZEOF_XMMWORD ; outptr + jmp short .columnloop + +.nextrow: + pop rsi + pop rdi + + add rsi, byte SIZEOF_JSAMPROW ; input_data + add rdi, byte SIZEOF_JSAMPROW ; output_data + dec rcx ; rowctr + jg short .rowloop + +.return: + uncollect_args + pop rbp + ret + +; -------------------------------------------------------------------------- +; +; Fast processing for the common case of 2:1 horizontal and 2:1 vertical. +; It's still a box filter. +; +; GLOBAL(void) +; jsimd_h2v2_upsample_sse2 (nt max_v_samp_factor, +; JDIMENSION output_width, +; JSAMPARRAY input_data, +; JSAMPARRAY * output_data_ptr); +; + +; r10 = int max_v_samp_factor +; r11 = JDIMENSION output_width +; r12 = JSAMPARRAY input_data +; r13 = JSAMPARRAY * output_data_ptr + + align 16 + global EXTN(jsimd_h2v2_upsample_sse2) + +EXTN(jsimd_h2v2_upsample_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + push rbx + + mov rdx, r11 + add rdx, byte (2*SIZEOF_XMMWORD)-1 + and rdx, byte -(2*SIZEOF_XMMWORD) + jz near .return + + mov rcx, r10 ; rowctr + test rcx,rcx + jz near .return + + mov rsi, r12 ; input_data + mov rdi, r13 + mov rdi, JSAMPARRAY [rdi] ; output_data +.rowloop: + push rdi + push rsi + + mov rsi, JSAMPROW [rsi] ; inptr + mov rbx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] ; outptr0 + mov rdi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] ; outptr1 + mov rax,rdx ; colctr +.columnloop: + + movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD] + + movdqa xmm1,xmm0 + punpcklbw xmm0,xmm0 + punpckhbw xmm1,xmm1 + + movdqa XMMWORD [rbx+0*SIZEOF_XMMWORD], xmm0 + movdqa XMMWORD [rbx+1*SIZEOF_XMMWORD], xmm1 + movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0 + movdqa XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm1 + + sub rax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + movdqa xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD] + + movdqa xmm3,xmm2 + punpcklbw xmm2,xmm2 + punpckhbw xmm3,xmm3 + + movdqa XMMWORD [rbx+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [rbx+3*SIZEOF_XMMWORD], xmm3 + movdqa XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2 + movdqa XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm3 + + sub rax, byte 2*SIZEOF_XMMWORD + jz short .nextrow + + add rsi, byte 2*SIZEOF_XMMWORD ; inptr + add rbx, byte 4*SIZEOF_XMMWORD ; outptr0 + add rdi, byte 4*SIZEOF_XMMWORD ; outptr1 + jmp short .columnloop + +.nextrow: + pop rsi + pop rdi + + add rsi, byte 1*SIZEOF_JSAMPROW ; input_data + add rdi, byte 2*SIZEOF_JSAMPROW ; output_data + sub rcx, byte 2 ; rowctr + jg near .rowloop + +.return: + pop rbx + uncollect_args + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfss2fst-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfss2fst-64.asm new file mode 100755 index 0000000..6953caf --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfss2fst-64.asm @@ -0,0 +1,392 @@ +; +; jfss2fst-64.asm - fast integer FDCT (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a fast, not so accurate integer implementation of +; the forward DCT (Discrete Cosine Transform). The following code is +; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c +; for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 8 ; 14 is also OK. + +%if CONST_BITS == 8 +F_0_382 equ 98 ; FIX(0.382683433) +F_0_541 equ 139 ; FIX(0.541196100) +F_0_707 equ 181 ; FIX(0.707106781) +F_1_306 equ 334 ; FIX(1.306562965) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_382 equ DESCALE( 410903207,30-CONST_BITS) ; FIX(0.382683433) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_707 equ DESCALE( 759250124,30-CONST_BITS) ; FIX(0.707106781) +F_1_306 equ DESCALE(1402911301,30-CONST_BITS) ; FIX(1.306562965) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + +; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow) +; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw) + +%define PRE_MULTIPLY_SCALE_BITS 2 +%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS) + + alignz 16 + global EXTN(jconst_fdct_ifast_sse2) + +EXTN(jconst_fdct_ifast_sse2): + +PW_F0707 times 8 dw F_0_707 << CONST_SHIFT +PW_F0382 times 8 dw F_0_382 << CONST_SHIFT +PW_F0541 times 8 dw F_0_541 << CONST_SHIFT +PW_F1306 times 8 dw F_1_306 << CONST_SHIFT + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_ifast_sse2 (DCTELEM * data) +; + +; r10 = DCTELEM * data + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_fdct_ifast_sse2) + +EXTN(jsimd_fdct_ifast_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + + ; ---- Pass 1: process rows. + + mov rdx, r10 ; (DCTELEM *) + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm2, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)] + + ; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27) + ; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37) + + movdqa xmm4,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm1 ; xmm0=(00 10 01 11 02 12 03 13) + punpckhwd xmm4,xmm1 ; xmm4=(04 14 05 15 06 16 07 17) + movdqa xmm5,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm3 ; xmm2=(20 30 21 31 22 32 23 33) + punpckhwd xmm5,xmm3 ; xmm5=(24 34 25 35 26 36 27 37) + + movdqa xmm6, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm7, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)] + + ; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62) + ; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63) + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(20 30 21 31 22 32 23 33) + movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(24 34 25 35 26 36 27 37) + + movdqa xmm2,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm7 ; xmm6=(40 50 41 51 42 52 43 53) + punpckhwd xmm2,xmm7 ; xmm2=(44 54 45 55 46 56 47 57) + movdqa xmm5,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm3 ; xmm1=(60 70 61 71 62 72 63 73) + punpckhwd xmm5,xmm3 ; xmm5=(64 74 65 75 66 76 67 77) + + movdqa xmm7,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm1 ; xmm6=(40 50 60 70 41 51 61 71) + punpckhdq xmm7,xmm1 ; xmm7=(42 52 62 72 43 53 63 73) + movdqa xmm3,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm5 ; xmm2=(44 54 64 74 45 55 65 75) + punpckhdq xmm3,xmm5 ; xmm3=(46 56 66 76 47 57 67 77) + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(20 30 21 31 22 32 23 33) + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(24 34 25 35 26 36 27 37) + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=(42 52 62 72 43 53 63 73) + movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=(44 54 64 74 45 55 65 75) + + movdqa xmm7,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm1 ; xmm0=(00 10 20 30 01 11 21 31) + punpckhdq xmm7,xmm1 ; xmm7=(02 12 22 32 03 13 23 33) + movdqa xmm2,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm5 ; xmm4=(04 14 24 34 05 15 25 35) + punpckhdq xmm2,xmm5 ; xmm2=(06 16 26 36 07 17 27 37) + + movdqa xmm1,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm6 ; xmm0=(00 10 20 30 40 50 60 70)=data0 + punpckhqdq xmm1,xmm6 ; xmm1=(01 11 21 31 41 51 61 71)=data1 + movdqa xmm5,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm3 ; xmm2=(06 16 26 36 46 56 66 76)=data6 + punpckhqdq xmm5,xmm3 ; xmm5=(07 17 27 37 47 57 67 77)=data7 + + movdqa xmm6,xmm1 + movdqa xmm3,xmm0 + psubw xmm1,xmm2 ; xmm1=data1-data6=tmp6 + psubw xmm0,xmm5 ; xmm0=data0-data7=tmp7 + paddw xmm6,xmm2 ; xmm6=data1+data6=tmp1 + paddw xmm3,xmm5 ; xmm3=data0+data7=tmp0 + + movdqa xmm2, XMMWORD [wk(0)] ; xmm2=(42 52 62 72 43 53 63 73) + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(44 54 64 74 45 55 65 75) + movdqa XMMWORD [wk(0)], xmm1 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp7 + + movdqa xmm1,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm2 ; xmm7=(02 12 22 32 42 52 62 72)=data2 + punpckhqdq xmm1,xmm2 ; xmm1=(03 13 23 33 43 53 63 73)=data3 + movdqa xmm0,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm5 ; xmm4=(04 14 24 34 44 54 64 74)=data4 + punpckhqdq xmm0,xmm5 ; xmm0=(05 15 25 35 45 55 65 75)=data5 + + movdqa xmm2,xmm1 + movdqa xmm5,xmm7 + paddw xmm1,xmm4 ; xmm1=data3+data4=tmp3 + paddw xmm7,xmm0 ; xmm7=data2+data5=tmp2 + psubw xmm2,xmm4 ; xmm2=data3-data4=tmp4 + psubw xmm5,xmm0 ; xmm5=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm4,xmm3 + movdqa xmm0,xmm6 + psubw xmm3,xmm1 ; xmm3=tmp13 + psubw xmm6,xmm7 ; xmm6=tmp12 + paddw xmm4,xmm1 ; xmm4=tmp10 + paddw xmm0,xmm7 ; xmm0=tmp11 + + paddw xmm6,xmm3 + psllw xmm6,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm6,[rel PW_F0707] ; xmm6=z1 + + movdqa xmm1,xmm4 + movdqa xmm7,xmm3 + psubw xmm4,xmm0 ; xmm4=data4 + psubw xmm3,xmm6 ; xmm3=data6 + paddw xmm1,xmm0 ; xmm1=data0 + paddw xmm7,xmm6 ; xmm7=data2 + + movdqa xmm0, XMMWORD [wk(0)] ; xmm0=tmp6 + movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp7 + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=data4 + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=data6 + + ; -- Odd part + + paddw xmm2,xmm5 ; xmm2=tmp10 + paddw xmm5,xmm0 ; xmm5=tmp11 + paddw xmm0,xmm6 ; xmm0=tmp12, xmm6=tmp7 + + psllw xmm2,PRE_MULTIPLY_SCALE_BITS + psllw xmm0,PRE_MULTIPLY_SCALE_BITS + + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm5,[rel PW_F0707] ; xmm5=z3 + + movdqa xmm4,xmm2 ; xmm4=tmp10 + psubw xmm2,xmm0 + pmulhw xmm2,[rel PW_F0382] ; xmm2=z5 + pmulhw xmm4,[rel PW_F0541] ; xmm4=MULTIPLY(tmp10,FIX_0_541196) + pmulhw xmm0,[rel PW_F1306] ; xmm0=MULTIPLY(tmp12,FIX_1_306562) + paddw xmm4,xmm2 ; xmm4=z2 + paddw xmm0,xmm2 ; xmm0=z4 + + movdqa xmm3,xmm6 + psubw xmm6,xmm5 ; xmm6=z13 + paddw xmm3,xmm5 ; xmm3=z11 + + movdqa xmm2,xmm6 + movdqa xmm5,xmm3 + psubw xmm6,xmm4 ; xmm6=data3 + psubw xmm3,xmm0 ; xmm3=data7 + paddw xmm2,xmm4 ; xmm2=data5 + paddw xmm5,xmm0 ; xmm5=data1 + + ; ---- Pass 2: process columns. + + ; xmm1=(00 10 20 30 40 50 60 70), xmm7=(02 12 22 32 42 52 62 72) + ; xmm5=(01 11 21 31 41 51 61 71), xmm6=(03 13 23 33 43 53 63 73) + + movdqa xmm4,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm5 ; xmm1=(00 01 10 11 20 21 30 31) + punpckhwd xmm4,xmm5 ; xmm4=(40 41 50 51 60 61 70 71) + movdqa xmm0,xmm7 ; transpose coefficients(phase 1) + punpcklwd xmm7,xmm6 ; xmm7=(02 03 12 13 22 23 32 33) + punpckhwd xmm0,xmm6 ; xmm0=(42 43 52 53 62 63 72 73) + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=col4 + movdqa xmm6, XMMWORD [wk(1)] ; xmm6=col6 + + ; xmm5=(04 14 24 34 44 54 64 74), xmm6=(06 16 26 36 46 56 66 76) + ; xmm2=(05 15 25 35 45 55 65 75), xmm3=(07 17 27 37 47 57 67 77) + + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=(02 03 12 13 22 23 32 33) + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(42 43 52 53 62 63 72 73) + + movdqa xmm7,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm2 ; xmm5=(04 05 14 15 24 25 34 35) + punpckhwd xmm7,xmm2 ; xmm7=(44 45 54 55 64 65 74 75) + movdqa xmm0,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm3 ; xmm6=(06 07 16 17 26 27 36 37) + punpckhwd xmm0,xmm3 ; xmm0=(46 47 56 57 66 67 76 77) + + movdqa xmm2,xmm5 ; transpose coefficients(phase 2) + punpckldq xmm5,xmm6 ; xmm5=(04 05 06 07 14 15 16 17) + punpckhdq xmm2,xmm6 ; xmm2=(24 25 26 27 34 35 36 37) + movdqa xmm3,xmm7 ; transpose coefficients(phase 2) + punpckldq xmm7,xmm0 ; xmm7=(44 45 46 47 54 55 56 57) + punpckhdq xmm3,xmm0 ; xmm3=(64 65 66 67 74 75 76 77) + + movdqa xmm6, XMMWORD [wk(0)] ; xmm6=(02 03 12 13 22 23 32 33) + movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(42 43 52 53 62 63 72 73) + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(24 25 26 27 34 35 36 37) + movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(44 45 46 47 54 55 56 57) + + movdqa xmm2,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm6 ; xmm1=(00 01 02 03 10 11 12 13) + punpckhdq xmm2,xmm6 ; xmm2=(20 21 22 23 30 31 32 33) + movdqa xmm7,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm0 ; xmm4=(40 41 42 43 50 51 52 53) + punpckhdq xmm7,xmm0 ; xmm7=(60 61 62 63 70 71 72 73) + + movdqa xmm6,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm5 ; xmm1=(00 01 02 03 04 05 06 07)=data0 + punpckhqdq xmm6,xmm5 ; xmm6=(10 11 12 13 14 15 16 17)=data1 + movdqa xmm0,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm3 ; xmm7=(60 61 62 63 64 65 66 67)=data6 + punpckhqdq xmm0,xmm3 ; xmm0=(70 71 72 73 74 75 76 77)=data7 + + movdqa xmm5,xmm6 + movdqa xmm3,xmm1 + psubw xmm6,xmm7 ; xmm6=data1-data6=tmp6 + psubw xmm1,xmm0 ; xmm1=data0-data7=tmp7 + paddw xmm5,xmm7 ; xmm5=data1+data6=tmp1 + paddw xmm3,xmm0 ; xmm3=data0+data7=tmp0 + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(24 25 26 27 34 35 36 37) + movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(44 45 46 47 54 55 56 57) + movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=tmp7 + + movdqa xmm6,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm7 ; xmm2=(20 21 22 23 24 25 26 27)=data2 + punpckhqdq xmm6,xmm7 ; xmm6=(30 31 32 33 34 35 36 37)=data3 + movdqa xmm1,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm0 ; xmm4=(40 41 42 43 44 45 46 47)=data4 + punpckhqdq xmm1,xmm0 ; xmm1=(50 51 52 53 54 55 56 57)=data5 + + movdqa xmm7,xmm6 + movdqa xmm0,xmm2 + paddw xmm6,xmm4 ; xmm6=data3+data4=tmp3 + paddw xmm2,xmm1 ; xmm2=data2+data5=tmp2 + psubw xmm7,xmm4 ; xmm7=data3-data4=tmp4 + psubw xmm0,xmm1 ; xmm0=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm4,xmm3 + movdqa xmm1,xmm5 + psubw xmm3,xmm6 ; xmm3=tmp13 + psubw xmm5,xmm2 ; xmm5=tmp12 + paddw xmm4,xmm6 ; xmm4=tmp10 + paddw xmm1,xmm2 ; xmm1=tmp11 + + paddw xmm5,xmm3 + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm5,[rel PW_F0707] ; xmm5=z1 + + movdqa xmm6,xmm4 + movdqa xmm2,xmm3 + psubw xmm4,xmm1 ; xmm4=data4 + psubw xmm3,xmm5 ; xmm3=data6 + paddw xmm6,xmm1 ; xmm6=data0 + paddw xmm2,xmm5 ; xmm2=data2 + + movdqa XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)], xmm4 + movdqa XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)], xmm3 + movdqa XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)], xmm6 + movdqa XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)], xmm2 + + ; -- Odd part + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=tmp6 + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp7 + + paddw xmm7,xmm0 ; xmm7=tmp10 + paddw xmm0,xmm1 ; xmm0=tmp11 + paddw xmm1,xmm5 ; xmm1=tmp12, xmm5=tmp7 + + psllw xmm7,PRE_MULTIPLY_SCALE_BITS + psllw xmm1,PRE_MULTIPLY_SCALE_BITS + + psllw xmm0,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm0,[rel PW_F0707] ; xmm0=z3 + + movdqa xmm4,xmm7 ; xmm4=tmp10 + psubw xmm7,xmm1 + pmulhw xmm7,[rel PW_F0382] ; xmm7=z5 + pmulhw xmm4,[rel PW_F0541] ; xmm4=MULTIPLY(tmp10,FIX_0_541196) + pmulhw xmm1,[rel PW_F1306] ; xmm1=MULTIPLY(tmp12,FIX_1_306562) + paddw xmm4,xmm7 ; xmm4=z2 + paddw xmm1,xmm7 ; xmm1=z4 + + movdqa xmm3,xmm5 + psubw xmm5,xmm0 ; xmm5=z13 + paddw xmm3,xmm0 ; xmm3=z11 + + movdqa xmm6,xmm5 + movdqa xmm2,xmm3 + psubw xmm5,xmm4 ; xmm5=data3 + psubw xmm3,xmm1 ; xmm3=data7 + paddw xmm6,xmm4 ; xmm6=data5 + paddw xmm2,xmm1 ; xmm2=data1 + + movdqa XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)], xmm5 + movdqa XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)], xmm3 + movdqa XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)], xmm6 + movdqa XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)], xmm2 + + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfss2int-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfss2int-64.asm new file mode 100755 index 0000000..bd1bd45 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfss2int-64.asm @@ -0,0 +1,622 @@ +; +; jfss2int-64.asm - accurate integer FDCT (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a slow-but-accurate integer implementation of the +; forward DCT (Discrete Cosine Transform). The following code is based +; directly on the IJG's original jfdctint.c; see the jfdctint.c for +; more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1 (CONST_BITS-PASS1_BITS) +%define DESCALE_P2 (CONST_BITS+PASS1_BITS) + +%if CONST_BITS == 13 +F_0_298 equ 2446 ; FIX(0.298631336) +F_0_390 equ 3196 ; FIX(0.390180644) +F_0_541 equ 4433 ; FIX(0.541196100) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_175 equ 9633 ; FIX(1.175875602) +F_1_501 equ 12299 ; FIX(1.501321110) +F_1_847 equ 15137 ; FIX(1.847759065) +F_1_961 equ 16069 ; FIX(1.961570560) +F_2_053 equ 16819 ; FIX(2.053119869) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_072 equ 25172 ; FIX(3.072711026) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) +F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) +F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) +F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fdct_islow_sse2) + +EXTN(jconst_fdct_islow_sse2): + +PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541 +PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847) +PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175 +PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390) +PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899 +PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899) +PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562 +PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562) +PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1) +PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1) +PW_DESCALE_P2X times 8 dw 1 << (PASS1_BITS-1) + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_islow_sse2 (DCTELEM * data) +; + +; r10 = DCTELEM * data + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 6 + + align 16 + global EXTN(jsimd_fdct_islow_sse2) + +EXTN(jsimd_fdct_islow_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + + ; ---- Pass 1: process rows. + + mov rdx, r10 ; (DCTELEM *) + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm2, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)] + + ; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27) + ; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37) + + movdqa xmm4,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm1 ; xmm0=(00 10 01 11 02 12 03 13) + punpckhwd xmm4,xmm1 ; xmm4=(04 14 05 15 06 16 07 17) + movdqa xmm5,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm3 ; xmm2=(20 30 21 31 22 32 23 33) + punpckhwd xmm5,xmm3 ; xmm5=(24 34 25 35 26 36 27 37) + + movdqa xmm6, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm7, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm1, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)] + + ; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62) + ; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63) + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=(20 30 21 31 22 32 23 33) + movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(24 34 25 35 26 36 27 37) + + movdqa xmm2,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm7 ; xmm6=(40 50 41 51 42 52 43 53) + punpckhwd xmm2,xmm7 ; xmm2=(44 54 45 55 46 56 47 57) + movdqa xmm5,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm3 ; xmm1=(60 70 61 71 62 72 63 73) + punpckhwd xmm5,xmm3 ; xmm5=(64 74 65 75 66 76 67 77) + + movdqa xmm7,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm1 ; xmm6=(40 50 60 70 41 51 61 71) + punpckhdq xmm7,xmm1 ; xmm7=(42 52 62 72 43 53 63 73) + movdqa xmm3,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm5 ; xmm2=(44 54 64 74 45 55 65 75) + punpckhdq xmm3,xmm5 ; xmm3=(46 56 66 76 47 57 67 77) + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(20 30 21 31 22 32 23 33) + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=(24 34 25 35 26 36 27 37) + movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=(42 52 62 72 43 53 63 73) + movdqa XMMWORD [wk(3)], xmm2 ; wk(3)=(44 54 64 74 45 55 65 75) + + movdqa xmm7,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm1 ; xmm0=(00 10 20 30 01 11 21 31) + punpckhdq xmm7,xmm1 ; xmm7=(02 12 22 32 03 13 23 33) + movdqa xmm2,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm5 ; xmm4=(04 14 24 34 05 15 25 35) + punpckhdq xmm2,xmm5 ; xmm2=(06 16 26 36 07 17 27 37) + + movdqa xmm1,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm6 ; xmm0=(00 10 20 30 40 50 60 70)=data0 + punpckhqdq xmm1,xmm6 ; xmm1=(01 11 21 31 41 51 61 71)=data1 + movdqa xmm5,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm3 ; xmm2=(06 16 26 36 46 56 66 76)=data6 + punpckhqdq xmm5,xmm3 ; xmm5=(07 17 27 37 47 57 67 77)=data7 + + movdqa xmm6,xmm1 + movdqa xmm3,xmm0 + psubw xmm1,xmm2 ; xmm1=data1-data6=tmp6 + psubw xmm0,xmm5 ; xmm0=data0-data7=tmp7 + paddw xmm6,xmm2 ; xmm6=data1+data6=tmp1 + paddw xmm3,xmm5 ; xmm3=data0+data7=tmp0 + + movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(42 52 62 72 43 53 63 73) + movdqa xmm5, XMMWORD [wk(3)] ; xmm5=(44 54 64 74 45 55 65 75) + movdqa XMMWORD [wk(0)], xmm1 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp7 + + movdqa xmm1,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm2 ; xmm7=(02 12 22 32 42 52 62 72)=data2 + punpckhqdq xmm1,xmm2 ; xmm1=(03 13 23 33 43 53 63 73)=data3 + movdqa xmm0,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm5 ; xmm4=(04 14 24 34 44 54 64 74)=data4 + punpckhqdq xmm0,xmm5 ; xmm0=(05 15 25 35 45 55 65 75)=data5 + + movdqa xmm2,xmm1 + movdqa xmm5,xmm7 + paddw xmm1,xmm4 ; xmm1=data3+data4=tmp3 + paddw xmm7,xmm0 ; xmm7=data2+data5=tmp2 + psubw xmm2,xmm4 ; xmm2=data3-data4=tmp4 + psubw xmm5,xmm0 ; xmm5=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm4,xmm3 + movdqa xmm0,xmm6 + paddw xmm3,xmm1 ; xmm3=tmp10 + paddw xmm6,xmm7 ; xmm6=tmp11 + psubw xmm4,xmm1 ; xmm4=tmp13 + psubw xmm0,xmm7 ; xmm0=tmp12 + + movdqa xmm1,xmm3 + paddw xmm3,xmm6 ; xmm3=tmp10+tmp11 + psubw xmm1,xmm6 ; xmm1=tmp10-tmp11 + + psllw xmm3,PASS1_BITS ; xmm3=data0 + psllw xmm1,PASS1_BITS ; xmm1=data4 + + movdqa XMMWORD [wk(2)], xmm3 ; wk(2)=data0 + movdqa XMMWORD [wk(3)], xmm1 ; wk(3)=data4 + + ; (Original) + ; z1 = (tmp12 + tmp13) * 0.541196100; + ; data2 = z1 + tmp13 * 0.765366865; + ; data6 = z1 + tmp12 * -1.847759065; + ; + ; (This implementation) + ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100; + ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065); + + movdqa xmm7,xmm4 ; xmm4=tmp13 + movdqa xmm6,xmm4 + punpcklwd xmm7,xmm0 ; xmm0=tmp12 + punpckhwd xmm6,xmm0 + movdqa xmm4,xmm7 + movdqa xmm0,xmm6 + pmaddwd xmm7,[rel PW_F130_F054] ; xmm7=data2L + pmaddwd xmm6,[rel PW_F130_F054] ; xmm6=data2H + pmaddwd xmm4,[rel PW_F054_MF130] ; xmm4=data6L + pmaddwd xmm0,[rel PW_F054_MF130] ; xmm0=data6H + + paddd xmm7,[rel PD_DESCALE_P1] + paddd xmm6,[rel PD_DESCALE_P1] + psrad xmm7,DESCALE_P1 + psrad xmm6,DESCALE_P1 + paddd xmm4,[rel PD_DESCALE_P1] + paddd xmm0,[rel PD_DESCALE_P1] + psrad xmm4,DESCALE_P1 + psrad xmm0,DESCALE_P1 + + packssdw xmm7,xmm6 ; xmm7=data2 + packssdw xmm4,xmm0 ; xmm4=data6 + + movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=data2 + movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=data6 + + ; -- Odd part + + movdqa xmm3, XMMWORD [wk(0)] ; xmm3=tmp6 + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=tmp7 + + movdqa xmm6,xmm2 ; xmm2=tmp4 + movdqa xmm0,xmm5 ; xmm5=tmp5 + paddw xmm6,xmm3 ; xmm6=z3 + paddw xmm0,xmm1 ; xmm0=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm7,xmm6 + movdqa xmm4,xmm6 + punpcklwd xmm7,xmm0 + punpckhwd xmm4,xmm0 + movdqa xmm6,xmm7 + movdqa xmm0,xmm4 + pmaddwd xmm7,[rel PW_MF078_F117] ; xmm7=z3L + pmaddwd xmm4,[rel PW_MF078_F117] ; xmm4=z3H + pmaddwd xmm6,[rel PW_F117_F078] ; xmm6=z4L + pmaddwd xmm0,[rel PW_F117_F078] ; xmm0=z4H + + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=z3L + movdqa XMMWORD [wk(1)], xmm4 ; wk(1)=z3H + + ; (Original) + ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; + ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869; + ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4; + ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4; + ; + ; (This implementation) + ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223; + ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447; + ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447); + ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223); + ; data7 = tmp4 + z3; data5 = tmp5 + z4; + ; data3 = tmp6 + z3; data1 = tmp7 + z4; + + movdqa xmm7,xmm2 + movdqa xmm4,xmm2 + punpcklwd xmm7,xmm1 + punpckhwd xmm4,xmm1 + movdqa xmm2,xmm7 + movdqa xmm1,xmm4 + pmaddwd xmm7,[rel PW_MF060_MF089] ; xmm7=tmp4L + pmaddwd xmm4,[rel PW_MF060_MF089] ; xmm4=tmp4H + pmaddwd xmm2,[rel PW_MF089_F060] ; xmm2=tmp7L + pmaddwd xmm1,[rel PW_MF089_F060] ; xmm1=tmp7H + + paddd xmm7, XMMWORD [wk(0)] ; xmm7=data7L + paddd xmm4, XMMWORD [wk(1)] ; xmm4=data7H + paddd xmm2,xmm6 ; xmm2=data1L + paddd xmm1,xmm0 ; xmm1=data1H + + paddd xmm7,[rel PD_DESCALE_P1] + paddd xmm4,[rel PD_DESCALE_P1] + psrad xmm7,DESCALE_P1 + psrad xmm4,DESCALE_P1 + paddd xmm2,[rel PD_DESCALE_P1] + paddd xmm1,[rel PD_DESCALE_P1] + psrad xmm2,DESCALE_P1 + psrad xmm1,DESCALE_P1 + + packssdw xmm7,xmm4 ; xmm7=data7 + packssdw xmm2,xmm1 ; xmm2=data1 + + movdqa xmm4,xmm5 + movdqa xmm1,xmm5 + punpcklwd xmm4,xmm3 + punpckhwd xmm1,xmm3 + movdqa xmm5,xmm4 + movdqa xmm3,xmm1 + pmaddwd xmm4,[rel PW_MF050_MF256] ; xmm4=tmp5L + pmaddwd xmm1,[rel PW_MF050_MF256] ; xmm1=tmp5H + pmaddwd xmm5,[rel PW_MF256_F050] ; xmm5=tmp6L + pmaddwd xmm3,[rel PW_MF256_F050] ; xmm3=tmp6H + + paddd xmm4,xmm6 ; xmm4=data5L + paddd xmm1,xmm0 ; xmm1=data5H + paddd xmm5, XMMWORD [wk(0)] ; xmm5=data3L + paddd xmm3, XMMWORD [wk(1)] ; xmm3=data3H + + paddd xmm4,[rel PD_DESCALE_P1] + paddd xmm1,[rel PD_DESCALE_P1] + psrad xmm4,DESCALE_P1 + psrad xmm1,DESCALE_P1 + paddd xmm5,[rel PD_DESCALE_P1] + paddd xmm3,[rel PD_DESCALE_P1] + psrad xmm5,DESCALE_P1 + psrad xmm3,DESCALE_P1 + + packssdw xmm4,xmm1 ; xmm4=data5 + packssdw xmm5,xmm3 ; xmm5=data3 + + ; ---- Pass 2: process columns. + + movdqa xmm6, XMMWORD [wk(2)] ; xmm6=col0 + movdqa xmm0, XMMWORD [wk(4)] ; xmm0=col2 + + ; xmm6=(00 10 20 30 40 50 60 70), xmm0=(02 12 22 32 42 52 62 72) + ; xmm2=(01 11 21 31 41 51 61 71), xmm5=(03 13 23 33 43 53 63 73) + + movdqa xmm1,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm2 ; xmm6=(00 01 10 11 20 21 30 31) + punpckhwd xmm1,xmm2 ; xmm1=(40 41 50 51 60 61 70 71) + movdqa xmm3,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm5 ; xmm0=(02 03 12 13 22 23 32 33) + punpckhwd xmm3,xmm5 ; xmm3=(42 43 52 53 62 63 72 73) + + movdqa xmm2, XMMWORD [wk(3)] ; xmm2=col4 + movdqa xmm5, XMMWORD [wk(5)] ; xmm5=col6 + + ; xmm2=(04 14 24 34 44 54 64 74), xmm5=(06 16 26 36 46 56 66 76) + ; xmm4=(05 15 25 35 45 55 65 75), xmm7=(07 17 27 37 47 57 67 77) + + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=(02 03 12 13 22 23 32 33) + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(42 43 52 53 62 63 72 73) + + movdqa xmm0,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm4 ; xmm2=(04 05 14 15 24 25 34 35) + punpckhwd xmm0,xmm4 ; xmm0=(44 45 54 55 64 65 74 75) + movdqa xmm3,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm7 ; xmm5=(06 07 16 17 26 27 36 37) + punpckhwd xmm3,xmm7 ; xmm3=(46 47 56 57 66 67 76 77) + + movdqa xmm4,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm5 ; xmm2=(04 05 06 07 14 15 16 17) + punpckhdq xmm4,xmm5 ; xmm4=(24 25 26 27 34 35 36 37) + movdqa xmm7,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm3 ; xmm0=(44 45 46 47 54 55 56 57) + punpckhdq xmm7,xmm3 ; xmm7=(64 65 66 67 74 75 76 77) + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=(02 03 12 13 22 23 32 33) + movdqa xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53 62 63 72 73) + movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=(24 25 26 27 34 35 36 37) + movdqa XMMWORD [wk(3)], xmm0 ; wk(3)=(44 45 46 47 54 55 56 57) + + movdqa xmm4,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm5 ; xmm6=(00 01 02 03 10 11 12 13) + punpckhdq xmm4,xmm5 ; xmm4=(20 21 22 23 30 31 32 33) + movdqa xmm0,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm3 ; xmm1=(40 41 42 43 50 51 52 53) + punpckhdq xmm0,xmm3 ; xmm0=(60 61 62 63 70 71 72 73) + + movdqa xmm5,xmm6 ; transpose coefficients(phase 3) + punpcklqdq xmm6,xmm2 ; xmm6=(00 01 02 03 04 05 06 07)=data0 + punpckhqdq xmm5,xmm2 ; xmm5=(10 11 12 13 14 15 16 17)=data1 + movdqa xmm3,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm7 ; xmm0=(60 61 62 63 64 65 66 67)=data6 + punpckhqdq xmm3,xmm7 ; xmm3=(70 71 72 73 74 75 76 77)=data7 + + movdqa xmm2,xmm5 + movdqa xmm7,xmm6 + psubw xmm5,xmm0 ; xmm5=data1-data6=tmp6 + psubw xmm6,xmm3 ; xmm6=data0-data7=tmp7 + paddw xmm2,xmm0 ; xmm2=data1+data6=tmp1 + paddw xmm7,xmm3 ; xmm7=data0+data7=tmp0 + + movdqa xmm0, XMMWORD [wk(2)] ; xmm0=(24 25 26 27 34 35 36 37) + movdqa xmm3, XMMWORD [wk(3)] ; xmm3=(44 45 46 47 54 55 56 57) + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=tmp6 + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 + + movdqa xmm5,xmm4 ; transpose coefficients(phase 3) + punpcklqdq xmm4,xmm0 ; xmm4=(20 21 22 23 24 25 26 27)=data2 + punpckhqdq xmm5,xmm0 ; xmm5=(30 31 32 33 34 35 36 37)=data3 + movdqa xmm6,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm3 ; xmm1=(40 41 42 43 44 45 46 47)=data4 + punpckhqdq xmm6,xmm3 ; xmm6=(50 51 52 53 54 55 56 57)=data5 + + movdqa xmm0,xmm5 + movdqa xmm3,xmm4 + paddw xmm5,xmm1 ; xmm5=data3+data4=tmp3 + paddw xmm4,xmm6 ; xmm4=data2+data5=tmp2 + psubw xmm0,xmm1 ; xmm0=data3-data4=tmp4 + psubw xmm3,xmm6 ; xmm3=data2-data5=tmp5 + + ; -- Even part + + movdqa xmm1,xmm7 + movdqa xmm6,xmm2 + paddw xmm7,xmm5 ; xmm7=tmp10 + paddw xmm2,xmm4 ; xmm2=tmp11 + psubw xmm1,xmm5 ; xmm1=tmp13 + psubw xmm6,xmm4 ; xmm6=tmp12 + + movdqa xmm5,xmm7 + paddw xmm7,xmm2 ; xmm7=tmp10+tmp11 + psubw xmm5,xmm2 ; xmm5=tmp10-tmp11 + + paddw xmm7,[rel PW_DESCALE_P2X] + paddw xmm5,[rel PW_DESCALE_P2X] + psraw xmm7,PASS1_BITS ; xmm7=data0 + psraw xmm5,PASS1_BITS ; xmm5=data4 + + movdqa XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)], xmm7 + movdqa XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)], xmm5 + + ; (Original) + ; z1 = (tmp12 + tmp13) * 0.541196100; + ; data2 = z1 + tmp13 * 0.765366865; + ; data6 = z1 + tmp12 * -1.847759065; + ; + ; (This implementation) + ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100; + ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065); + + movdqa xmm4,xmm1 ; xmm1=tmp13 + movdqa xmm2,xmm1 + punpcklwd xmm4,xmm6 ; xmm6=tmp12 + punpckhwd xmm2,xmm6 + movdqa xmm1,xmm4 + movdqa xmm6,xmm2 + pmaddwd xmm4,[rel PW_F130_F054] ; xmm4=data2L + pmaddwd xmm2,[rel PW_F130_F054] ; xmm2=data2H + pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=data6L + pmaddwd xmm6,[rel PW_F054_MF130] ; xmm6=data6H + + paddd xmm4,[rel PD_DESCALE_P2] + paddd xmm2,[rel PD_DESCALE_P2] + psrad xmm4,DESCALE_P2 + psrad xmm2,DESCALE_P2 + paddd xmm1,[rel PD_DESCALE_P2] + paddd xmm6,[rel PD_DESCALE_P2] + psrad xmm1,DESCALE_P2 + psrad xmm6,DESCALE_P2 + + packssdw xmm4,xmm2 ; xmm4=data2 + packssdw xmm1,xmm6 ; xmm1=data6 + + movdqa XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)], xmm4 + movdqa XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)], xmm1 + + ; -- Odd part + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp6 + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp7 + + movdqa xmm2,xmm0 ; xmm0=tmp4 + movdqa xmm6,xmm3 ; xmm3=tmp5 + paddw xmm2,xmm7 ; xmm2=z3 + paddw xmm6,xmm5 ; xmm6=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm4,xmm2 + movdqa xmm1,xmm2 + punpcklwd xmm4,xmm6 + punpckhwd xmm1,xmm6 + movdqa xmm2,xmm4 + movdqa xmm6,xmm1 + pmaddwd xmm4,[rel PW_MF078_F117] ; xmm4=z3L + pmaddwd xmm1,[rel PW_MF078_F117] ; xmm1=z3H + pmaddwd xmm2,[rel PW_F117_F078] ; xmm2=z4L + pmaddwd xmm6,[rel PW_F117_F078] ; xmm6=z4H + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=z3L + movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=z3H + + ; (Original) + ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; + ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869; + ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4; + ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4; + ; + ; (This implementation) + ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223; + ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447; + ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447); + ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223); + ; data7 = tmp4 + z3; data5 = tmp5 + z4; + ; data3 = tmp6 + z3; data1 = tmp7 + z4; + + movdqa xmm4,xmm0 + movdqa xmm1,xmm0 + punpcklwd xmm4,xmm5 + punpckhwd xmm1,xmm5 + movdqa xmm0,xmm4 + movdqa xmm5,xmm1 + pmaddwd xmm4,[rel PW_MF060_MF089] ; xmm4=tmp4L + pmaddwd xmm1,[rel PW_MF060_MF089] ; xmm1=tmp4H + pmaddwd xmm0,[rel PW_MF089_F060] ; xmm0=tmp7L + pmaddwd xmm5,[rel PW_MF089_F060] ; xmm5=tmp7H + + paddd xmm4, XMMWORD [wk(0)] ; xmm4=data7L + paddd xmm1, XMMWORD [wk(1)] ; xmm1=data7H + paddd xmm0,xmm2 ; xmm0=data1L + paddd xmm5,xmm6 ; xmm5=data1H + + paddd xmm4,[rel PD_DESCALE_P2] + paddd xmm1,[rel PD_DESCALE_P2] + psrad xmm4,DESCALE_P2 + psrad xmm1,DESCALE_P2 + paddd xmm0,[rel PD_DESCALE_P2] + paddd xmm5,[rel PD_DESCALE_P2] + psrad xmm0,DESCALE_P2 + psrad xmm5,DESCALE_P2 + + packssdw xmm4,xmm1 ; xmm4=data7 + packssdw xmm0,xmm5 ; xmm0=data1 + + movdqa XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)], xmm4 + movdqa XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)], xmm0 + + movdqa xmm1,xmm3 + movdqa xmm5,xmm3 + punpcklwd xmm1,xmm7 + punpckhwd xmm5,xmm7 + movdqa xmm3,xmm1 + movdqa xmm7,xmm5 + pmaddwd xmm1,[rel PW_MF050_MF256] ; xmm1=tmp5L + pmaddwd xmm5,[rel PW_MF050_MF256] ; xmm5=tmp5H + pmaddwd xmm3,[rel PW_MF256_F050] ; xmm3=tmp6L + pmaddwd xmm7,[rel PW_MF256_F050] ; xmm7=tmp6H + + paddd xmm1,xmm2 ; xmm1=data5L + paddd xmm5,xmm6 ; xmm5=data5H + paddd xmm3, XMMWORD [wk(0)] ; xmm3=data3L + paddd xmm7, XMMWORD [wk(1)] ; xmm7=data3H + + paddd xmm1,[rel PD_DESCALE_P2] + paddd xmm5,[rel PD_DESCALE_P2] + psrad xmm1,DESCALE_P2 + psrad xmm5,DESCALE_P2 + paddd xmm3,[rel PD_DESCALE_P2] + paddd xmm7,[rel PD_DESCALE_P2] + psrad xmm3,DESCALE_P2 + psrad xmm7,DESCALE_P2 + + packssdw xmm1,xmm5 ; xmm1=data5 + packssdw xmm3,xmm7 ; xmm3=data3 + + movdqa XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)], xmm1 + movdqa XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)], xmm3 + + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfsseflt-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfsseflt-64.asm new file mode 100755 index 0000000..07245d2 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jfsseflt-64.asm @@ -0,0 +1,358 @@ +; +; jfsseflt-64.asm - floating-point FDCT (64-bit SSE) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a floating-point implementation of the forward DCT +; (Discrete Cosine Transform). The following code is based directly on +; the IJG's original jfdctflt.c; see the jfdctflt.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5) + shufps %1,%2,0x44 +%endmacro + +%macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7) + shufps %1,%2,0xEE +%endmacro + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_fdct_float_sse) + +EXTN(jconst_fdct_float_sse): + +PD_0_382 times 4 dd 0.382683432365089771728460 +PD_0_707 times 4 dd 0.707106781186547524400844 +PD_0_541 times 4 dd 0.541196100146196984399723 +PD_1_306 times 4 dd 1.306562964876376527856643 + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Perform the forward DCT on one block of samples. +; +; GLOBAL(void) +; jsimd_fdct_float_sse (FAST_FLOAT * data) +; + +; r10 = FAST_FLOAT * data + +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_fdct_float_sse) + +EXTN(jsimd_fdct_float_sse): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + + ; ---- Pass 1: process rows. + + mov rdx, r10 ; (FAST_FLOAT *) + mov rcx, DCTSIZE/4 +.rowloop: + + movaps xmm0, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(2,1,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(3,1,rdx,SIZEOF_FAST_FLOAT)] + + ; xmm0=(20 21 22 23), xmm2=(24 25 26 27) + ; xmm1=(30 31 32 33), xmm3=(34 35 36 37) + + movaps xmm4,xmm0 ; transpose coefficients(phase 1) + unpcklps xmm0,xmm1 ; xmm0=(20 30 21 31) + unpckhps xmm4,xmm1 ; xmm4=(22 32 23 33) + movaps xmm5,xmm2 ; transpose coefficients(phase 1) + unpcklps xmm2,xmm3 ; xmm2=(24 34 25 35) + unpckhps xmm5,xmm3 ; xmm5=(26 36 27 37) + + movaps xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm7, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)] + + ; xmm6=(00 01 02 03), xmm1=(04 05 06 07) + ; xmm7=(10 11 12 13), xmm3=(14 15 16 17) + + movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 32 23 33) + movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(24 34 25 35) + + movaps xmm4,xmm6 ; transpose coefficients(phase 1) + unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11) + unpckhps xmm4,xmm7 ; xmm4=(02 12 03 13) + movaps xmm2,xmm1 ; transpose coefficients(phase 1) + unpcklps xmm1,xmm3 ; xmm1=(04 14 05 15) + unpckhps xmm2,xmm3 ; xmm2=(06 16 07 17) + + movaps xmm7,xmm6 ; transpose coefficients(phase 2) + unpcklps2 xmm6,xmm0 ; xmm6=(00 10 20 30)=data0 + unpckhps2 xmm7,xmm0 ; xmm7=(01 11 21 31)=data1 + movaps xmm3,xmm2 ; transpose coefficients(phase 2) + unpcklps2 xmm2,xmm5 ; xmm2=(06 16 26 36)=data6 + unpckhps2 xmm3,xmm5 ; xmm3=(07 17 27 37)=data7 + + movaps xmm0,xmm7 + movaps xmm5,xmm6 + subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 + subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 + addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 + addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 + + movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 32 23 33) + movaps xmm3, XMMWORD [wk(1)] ; xmm3=(24 34 25 35) + movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 + movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 + + movaps xmm7,xmm4 ; transpose coefficients(phase 2) + unpcklps2 xmm4,xmm2 ; xmm4=(02 12 22 32)=data2 + unpckhps2 xmm7,xmm2 ; xmm7=(03 13 23 33)=data3 + movaps xmm6,xmm1 ; transpose coefficients(phase 2) + unpcklps2 xmm1,xmm3 ; xmm1=(04 14 24 34)=data4 + unpckhps2 xmm6,xmm3 ; xmm6=(05 15 25 35)=data5 + + movaps xmm2,xmm7 + movaps xmm3,xmm4 + addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 + addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 + subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 + subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 + + ; -- Even part + + movaps xmm1,xmm5 + movaps xmm6,xmm0 + subps xmm5,xmm7 ; xmm5=tmp13 + subps xmm0,xmm4 ; xmm0=tmp12 + addps xmm1,xmm7 ; xmm1=tmp10 + addps xmm6,xmm4 ; xmm6=tmp11 + + addps xmm0,xmm5 + mulps xmm0,[rel PD_0_707] ; xmm0=z1 + + movaps xmm7,xmm1 + movaps xmm4,xmm5 + subps xmm1,xmm6 ; xmm1=data4 + subps xmm5,xmm0 ; xmm5=data6 + addps xmm7,xmm6 ; xmm7=data0 + addps xmm4,xmm0 ; xmm4=data2 + + movaps XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(2,1,rdx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)], xmm4 + + ; -- Odd part + + movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 + movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 + + addps xmm2,xmm3 ; xmm2=tmp10 + addps xmm3,xmm6 ; xmm3=tmp11 + addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 + + mulps xmm3,[rel PD_0_707] ; xmm3=z3 + + movaps xmm1,xmm2 ; xmm1=tmp10 + subps xmm2,xmm6 + mulps xmm2,[rel PD_0_382] ; xmm2=z5 + mulps xmm1,[rel PD_0_541] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) + mulps xmm6,[rel PD_1_306] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) + addps xmm1,xmm2 ; xmm1=z2 + addps xmm6,xmm2 ; xmm6=z4 + + movaps xmm5,xmm0 + subps xmm0,xmm3 ; xmm0=z13 + addps xmm5,xmm3 ; xmm5=z11 + + movaps xmm7,xmm0 + movaps xmm4,xmm5 + subps xmm0,xmm1 ; xmm0=data3 + subps xmm5,xmm6 ; xmm5=data7 + addps xmm7,xmm1 ; xmm7=data5 + addps xmm4,xmm6 ; xmm4=data1 + + movaps XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(3,1,rdx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)], xmm4 + + add rdx, 4*DCTSIZE*SIZEOF_FAST_FLOAT + dec rcx + jnz near .rowloop + + ; ---- Pass 2: process columns. + + mov rdx, r10 ; (FAST_FLOAT *) + mov rcx, DCTSIZE/4 +.columnloop: + + movaps xmm0, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FAST_FLOAT)] + + ; xmm0=(02 12 22 32), xmm2=(42 52 62 72) + ; xmm1=(03 13 23 33), xmm3=(43 53 63 73) + + movaps xmm4,xmm0 ; transpose coefficients(phase 1) + unpcklps xmm0,xmm1 ; xmm0=(02 03 12 13) + unpckhps xmm4,xmm1 ; xmm4=(22 23 32 33) + movaps xmm5,xmm2 ; transpose coefficients(phase 1) + unpcklps xmm2,xmm3 ; xmm2=(42 43 52 53) + unpckhps xmm5,xmm3 ; xmm5=(62 63 72 73) + + movaps xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm7, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FAST_FLOAT)] + + ; xmm6=(00 10 20 30), xmm1=(40 50 60 70) + ; xmm7=(01 11 21 31), xmm3=(41 51 61 71) + + movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 23 32 33) + movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(42 43 52 53) + + movaps xmm4,xmm6 ; transpose coefficients(phase 1) + unpcklps xmm6,xmm7 ; xmm6=(00 01 10 11) + unpckhps xmm4,xmm7 ; xmm4=(20 21 30 31) + movaps xmm2,xmm1 ; transpose coefficients(phase 1) + unpcklps xmm1,xmm3 ; xmm1=(40 41 50 51) + unpckhps xmm2,xmm3 ; xmm2=(60 61 70 71) + + movaps xmm7,xmm6 ; transpose coefficients(phase 2) + unpcklps2 xmm6,xmm0 ; xmm6=(00 01 02 03)=data0 + unpckhps2 xmm7,xmm0 ; xmm7=(10 11 12 13)=data1 + movaps xmm3,xmm2 ; transpose coefficients(phase 2) + unpcklps2 xmm2,xmm5 ; xmm2=(60 61 62 63)=data6 + unpckhps2 xmm3,xmm5 ; xmm3=(70 71 72 73)=data7 + + movaps xmm0,xmm7 + movaps xmm5,xmm6 + subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 + subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 + addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 + addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 + + movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 23 32 33) + movaps xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53) + movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 + movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 + + movaps xmm7,xmm4 ; transpose coefficients(phase 2) + unpcklps2 xmm4,xmm2 ; xmm4=(20 21 22 23)=data2 + unpckhps2 xmm7,xmm2 ; xmm7=(30 31 32 33)=data3 + movaps xmm6,xmm1 ; transpose coefficients(phase 2) + unpcklps2 xmm1,xmm3 ; xmm1=(40 41 42 43)=data4 + unpckhps2 xmm6,xmm3 ; xmm6=(50 51 52 53)=data5 + + movaps xmm2,xmm7 + movaps xmm3,xmm4 + addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 + addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 + subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 + subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 + + ; -- Even part + + movaps xmm1,xmm5 + movaps xmm6,xmm0 + subps xmm5,xmm7 ; xmm5=tmp13 + subps xmm0,xmm4 ; xmm0=tmp12 + addps xmm1,xmm7 ; xmm1=tmp10 + addps xmm6,xmm4 ; xmm6=tmp11 + + addps xmm0,xmm5 + mulps xmm0,[rel PD_0_707] ; xmm0=z1 + + movaps xmm7,xmm1 + movaps xmm4,xmm5 + subps xmm1,xmm6 ; xmm1=data4 + subps xmm5,xmm0 ; xmm5=data6 + addps xmm7,xmm6 ; xmm7=data0 + addps xmm4,xmm0 ; xmm4=data2 + + movaps XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)], xmm4 + + ; -- Odd part + + movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 + movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 + + addps xmm2,xmm3 ; xmm2=tmp10 + addps xmm3,xmm6 ; xmm3=tmp11 + addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 + + mulps xmm3,[rel PD_0_707] ; xmm3=z3 + + movaps xmm1,xmm2 ; xmm1=tmp10 + subps xmm2,xmm6 + mulps xmm2,[rel PD_0_382] ; xmm2=z5 + mulps xmm1,[rel PD_0_541] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) + mulps xmm6,[rel PD_1_306] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) + addps xmm1,xmm2 ; xmm1=z2 + addps xmm6,xmm2 ; xmm6=z4 + + movaps xmm5,xmm0 + subps xmm0,xmm3 ; xmm0=z13 + addps xmm5,xmm3 ; xmm5=z11 + + movaps xmm7,xmm0 + movaps xmm4,xmm5 + subps xmm0,xmm1 ; xmm0=data3 + subps xmm5,xmm6 ; xmm5=data7 + addps xmm7,xmm1 ; xmm7=data5 + addps xmm4,xmm6 ; xmm4=data1 + + movaps XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FAST_FLOAT)], xmm7 + movaps XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)], xmm4 + + add rdx, byte 4*SIZEOF_FAST_FLOAT + dec rcx + jnz near .columnloop + + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2flt-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2flt-64.asm new file mode 100755 index 0000000..6e7e6d4 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2flt-64.asm @@ -0,0 +1,483 @@ +; +; jiss2flt-64.asm - floating-point IDCT (64-bit SSE & SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a floating-point implementation of the inverse DCT +; (Discrete Cosine Transform). The following code is based directly on +; the IJG's original jidctflt.c; see the jidctflt.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5) + shufps %1,%2,0x44 +%endmacro + +%macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7) + shufps %1,%2,0xEE +%endmacro + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_float_sse2) + +EXTN(jconst_idct_float_sse2): + +PD_1_414 times 4 dd 1.414213562373095048801689 +PD_1_847 times 4 dd 1.847759065022573512256366 +PD_1_082 times 4 dd 1.082392200292393968799446 +PD_M2_613 times 4 dd -2.613125929752753055713286 +PD_RNDINT_MAGIC times 4 dd 100663296.0 ; (float)(0x00C00000 << 3) +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_float_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +; r10 = void * dct_table +; r11 = JCOEFPTR coef_block +; r12 = JSAMPARRAY output_buf +; r13 = JDIMENSION output_col + +%define original_rbp rbp+0 +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 +%define workspace wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT + ; FAST_FLOAT workspace[DCTSIZE2] + + align 16 + global EXTN(jsimd_idct_float_sse2) + +EXTN(jsimd_idct_float_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [workspace] + collect_args + push rbx + + ; ---- Pass 1: process columns from input, store into work array. + + mov rdx, r10 ; quantptr + mov rsi, r11 ; inptr + lea rdi, [workspace] ; FAST_FLOAT * wsptr + mov rcx, DCTSIZE/4 ; ctr +.columnloop: +%ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE + mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)] + jnz near .columnDCT + + movq xmm1, XMM_MMWORD [MMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movq xmm2, XMM_MMWORD [MMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + movq xmm3, XMM_MMWORD [MMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + movq xmm4, XMM_MMWORD [MMBLOCK(4,0,rsi,SIZEOF_JCOEF)] + movq xmm5, XMM_MMWORD [MMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + movq xmm6, XMM_MMWORD [MMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + movq xmm7, XMM_MMWORD [MMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + por xmm1,xmm2 + por xmm3,xmm4 + por xmm5,xmm6 + por xmm1,xmm3 + por xmm5,xmm7 + por xmm1,xmm5 + packsswb xmm1,xmm1 + movd eax,xmm1 + test rax,rax + jnz short .columnDCT + + ; -- AC terms all zero + + movq xmm0, XMM_MMWORD [MMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + psrad xmm0,(DWORD_BIT-WORD_BIT) ; xmm0=in0=(00 01 02 03) + cvtdq2ps xmm0,xmm0 ; xmm0=in0=(00 01 02 03) + + mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm1,xmm0 + movaps xmm2,xmm0 + movaps xmm3,xmm0 + + shufps xmm0,xmm0,0x00 ; xmm0=(00 00 00 00) + shufps xmm1,xmm1,0x55 ; xmm1=(01 01 01 01) + shufps xmm2,xmm2,0xAA ; xmm2=(02 02 02 02) + shufps xmm3,xmm3,0xFF ; xmm3=(03 03 03 03) + + movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0 + movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(2,1,rdi,SIZEOF_FAST_FLOAT)], xmm2 + movaps XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(3,1,rdi,SIZEOF_FAST_FLOAT)], xmm3 + jmp near .nextcolumn +%endif +.columnDCT: + + ; -- Even part + + movq xmm0, XMM_MMWORD [MMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + movq xmm1, XMM_MMWORD [MMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + movq xmm2, XMM_MMWORD [MMBLOCK(4,0,rsi,SIZEOF_JCOEF)] + movq xmm3, XMM_MMWORD [MMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + punpcklwd xmm1,xmm1 ; xmm1=(20 20 21 21 22 22 23 23) + psrad xmm0,(DWORD_BIT-WORD_BIT) ; xmm0=in0=(00 01 02 03) + psrad xmm1,(DWORD_BIT-WORD_BIT) ; xmm1=in2=(20 21 22 23) + cvtdq2ps xmm0,xmm0 ; xmm0=in0=(00 01 02 03) + cvtdq2ps xmm1,xmm1 ; xmm1=in2=(20 21 22 23) + + punpcklwd xmm2,xmm2 ; xmm2=(40 40 41 41 42 42 43 43) + punpcklwd xmm3,xmm3 ; xmm3=(60 60 61 61 62 62 63 63) + psrad xmm2,(DWORD_BIT-WORD_BIT) ; xmm2=in4=(40 41 42 43) + psrad xmm3,(DWORD_BIT-WORD_BIT) ; xmm3=in6=(60 61 62 63) + cvtdq2ps xmm2,xmm2 ; xmm2=in4=(40 41 42 43) + cvtdq2ps xmm3,xmm3 ; xmm3=in6=(60 61 62 63) + + mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm4,xmm0 + movaps xmm5,xmm1 + subps xmm0,xmm2 ; xmm0=tmp11 + subps xmm1,xmm3 + addps xmm4,xmm2 ; xmm4=tmp10 + addps xmm5,xmm3 ; xmm5=tmp13 + + mulps xmm1,[rel PD_1_414] + subps xmm1,xmm5 ; xmm1=tmp12 + + movaps xmm6,xmm4 + movaps xmm7,xmm0 + subps xmm4,xmm5 ; xmm4=tmp3 + subps xmm0,xmm1 ; xmm0=tmp2 + addps xmm6,xmm5 ; xmm6=tmp0 + addps xmm7,xmm1 ; xmm7=tmp1 + + movaps XMMWORD [wk(1)], xmm4 ; tmp3 + movaps XMMWORD [wk(0)], xmm0 ; tmp2 + + ; -- Odd part + + movq xmm2, XMM_MMWORD [MMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movq xmm3, XMM_MMWORD [MMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + movq xmm5, XMM_MMWORD [MMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + movq xmm1, XMM_MMWORD [MMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + + punpcklwd xmm2,xmm2 ; xmm2=(10 10 11 11 12 12 13 13) + punpcklwd xmm3,xmm3 ; xmm3=(30 30 31 31 32 32 33 33) + psrad xmm2,(DWORD_BIT-WORD_BIT) ; xmm2=in1=(10 11 12 13) + psrad xmm3,(DWORD_BIT-WORD_BIT) ; xmm3=in3=(30 31 32 33) + cvtdq2ps xmm2,xmm2 ; xmm2=in1=(10 11 12 13) + cvtdq2ps xmm3,xmm3 ; xmm3=in3=(30 31 32 33) + + punpcklwd xmm5,xmm5 ; xmm5=(50 50 51 51 52 52 53 53) + punpcklwd xmm1,xmm1 ; xmm1=(70 70 71 71 72 72 73 73) + psrad xmm5,(DWORD_BIT-WORD_BIT) ; xmm5=in5=(50 51 52 53) + psrad xmm1,(DWORD_BIT-WORD_BIT) ; xmm1=in7=(70 71 72 73) + cvtdq2ps xmm5,xmm5 ; xmm5=in5=(50 51 52 53) + cvtdq2ps xmm1,xmm1 ; xmm1=in7=(70 71 72 73) + + mulps xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm5, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + mulps xmm1, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FLOAT_MULT_TYPE)] + + movaps xmm4,xmm2 + movaps xmm0,xmm5 + addps xmm2,xmm1 ; xmm2=z11 + addps xmm5,xmm3 ; xmm5=z13 + subps xmm4,xmm1 ; xmm4=z12 + subps xmm0,xmm3 ; xmm0=z10 + + movaps xmm1,xmm2 + subps xmm2,xmm5 + addps xmm1,xmm5 ; xmm1=tmp7 + + mulps xmm2,[rel PD_1_414] ; xmm2=tmp11 + + movaps xmm3,xmm0 + addps xmm0,xmm4 + mulps xmm0,[rel PD_1_847] ; xmm0=z5 + mulps xmm3,[rel PD_M2_613] ; xmm3=(z10 * -2.613125930) + mulps xmm4,[rel PD_1_082] ; xmm4=(z12 * 1.082392200) + addps xmm3,xmm0 ; xmm3=tmp12 + subps xmm4,xmm0 ; xmm4=tmp10 + + ; -- Final output stage + + subps xmm3,xmm1 ; xmm3=tmp6 + movaps xmm5,xmm6 + movaps xmm0,xmm7 + addps xmm6,xmm1 ; xmm6=data0=(00 01 02 03) + addps xmm7,xmm3 ; xmm7=data1=(10 11 12 13) + subps xmm5,xmm1 ; xmm5=data7=(70 71 72 73) + subps xmm0,xmm3 ; xmm0=data6=(60 61 62 63) + subps xmm2,xmm3 ; xmm2=tmp5 + + movaps xmm1,xmm6 ; transpose coefficients(phase 1) + unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11) + unpckhps xmm1,xmm7 ; xmm1=(02 12 03 13) + movaps xmm3,xmm0 ; transpose coefficients(phase 1) + unpcklps xmm0,xmm5 ; xmm0=(60 70 61 71) + unpckhps xmm3,xmm5 ; xmm3=(62 72 63 73) + + movaps xmm7, XMMWORD [wk(0)] ; xmm7=tmp2 + movaps xmm5, XMMWORD [wk(1)] ; xmm5=tmp3 + + movaps XMMWORD [wk(0)], xmm0 ; wk(0)=(60 70 61 71) + movaps XMMWORD [wk(1)], xmm3 ; wk(1)=(62 72 63 73) + + addps xmm4,xmm2 ; xmm4=tmp4 + movaps xmm0,xmm7 + movaps xmm3,xmm5 + addps xmm7,xmm2 ; xmm7=data2=(20 21 22 23) + addps xmm5,xmm4 ; xmm5=data4=(40 41 42 43) + subps xmm0,xmm2 ; xmm0=data5=(50 51 52 53) + subps xmm3,xmm4 ; xmm3=data3=(30 31 32 33) + + movaps xmm2,xmm7 ; transpose coefficients(phase 1) + unpcklps xmm7,xmm3 ; xmm7=(20 30 21 31) + unpckhps xmm2,xmm3 ; xmm2=(22 32 23 33) + movaps xmm4,xmm5 ; transpose coefficients(phase 1) + unpcklps xmm5,xmm0 ; xmm5=(40 50 41 51) + unpckhps xmm4,xmm0 ; xmm4=(42 52 43 53) + + movaps xmm3,xmm6 ; transpose coefficients(phase 2) + unpcklps2 xmm6,xmm7 ; xmm6=(00 10 20 30) + unpckhps2 xmm3,xmm7 ; xmm3=(01 11 21 31) + movaps xmm0,xmm1 ; transpose coefficients(phase 2) + unpcklps2 xmm1,xmm2 ; xmm1=(02 12 22 32) + unpckhps2 xmm0,xmm2 ; xmm0=(03 13 23 33) + + movaps xmm7, XMMWORD [wk(0)] ; xmm7=(60 70 61 71) + movaps xmm2, XMMWORD [wk(1)] ; xmm2=(62 72 63 73) + + movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm6 + movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3 + movaps XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_FAST_FLOAT)], xmm1 + movaps XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_FAST_FLOAT)], xmm0 + + movaps xmm6,xmm5 ; transpose coefficients(phase 2) + unpcklps2 xmm5,xmm7 ; xmm5=(40 50 60 70) + unpckhps2 xmm6,xmm7 ; xmm6=(41 51 61 71) + movaps xmm3,xmm4 ; transpose coefficients(phase 2) + unpcklps2 xmm4,xmm2 ; xmm4=(42 52 62 72) + unpckhps2 xmm3,xmm2 ; xmm3=(43 53 63 73) + + movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm5 + movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm6 + movaps XMMWORD [XMMBLOCK(2,1,rdi,SIZEOF_FAST_FLOAT)], xmm4 + movaps XMMWORD [XMMBLOCK(3,1,rdi,SIZEOF_FAST_FLOAT)], xmm3 + +.nextcolumn: + add rsi, byte 4*SIZEOF_JCOEF ; coef_block + add rdx, byte 4*SIZEOF_FLOAT_MULT_TYPE ; quantptr + add rdi, 4*DCTSIZE*SIZEOF_FAST_FLOAT ; wsptr + dec rcx ; ctr + jnz near .columnloop + + ; -- Prefetch the next coefficient block + + prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32] + prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32] + prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32] + prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov rax, [original_rbp] + lea rsi, [workspace] ; FAST_FLOAT * wsptr + mov rdi, r12 ; (JSAMPROW *) + mov rax, r13 + mov rcx, DCTSIZE/4 ; ctr +.rowloop: + + ; -- Even part + + movaps xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_FAST_FLOAT)] + + movaps xmm4,xmm0 + movaps xmm5,xmm1 + subps xmm0,xmm2 ; xmm0=tmp11 + subps xmm1,xmm3 + addps xmm4,xmm2 ; xmm4=tmp10 + addps xmm5,xmm3 ; xmm5=tmp13 + + mulps xmm1,[rel PD_1_414] + subps xmm1,xmm5 ; xmm1=tmp12 + + movaps xmm6,xmm4 + movaps xmm7,xmm0 + subps xmm4,xmm5 ; xmm4=tmp3 + subps xmm0,xmm1 ; xmm0=tmp2 + addps xmm6,xmm5 ; xmm6=tmp0 + addps xmm7,xmm1 ; xmm7=tmp1 + + movaps XMMWORD [wk(1)], xmm4 ; tmp3 + movaps XMMWORD [wk(0)], xmm0 ; tmp2 + + ; -- Odd part + + movaps xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm3, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm5, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_FAST_FLOAT)] + movaps xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_FAST_FLOAT)] + + movaps xmm4,xmm2 + movaps xmm0,xmm5 + addps xmm2,xmm1 ; xmm2=z11 + addps xmm5,xmm3 ; xmm5=z13 + subps xmm4,xmm1 ; xmm4=z12 + subps xmm0,xmm3 ; xmm0=z10 + + movaps xmm1,xmm2 + subps xmm2,xmm5 + addps xmm1,xmm5 ; xmm1=tmp7 + + mulps xmm2,[rel PD_1_414] ; xmm2=tmp11 + + movaps xmm3,xmm0 + addps xmm0,xmm4 + mulps xmm0,[rel PD_1_847] ; xmm0=z5 + mulps xmm3,[rel PD_M2_613] ; xmm3=(z10 * -2.613125930) + mulps xmm4,[rel PD_1_082] ; xmm4=(z12 * 1.082392200) + addps xmm3,xmm0 ; xmm3=tmp12 + subps xmm4,xmm0 ; xmm4=tmp10 + + ; -- Final output stage + + subps xmm3,xmm1 ; xmm3=tmp6 + movaps xmm5,xmm6 + movaps xmm0,xmm7 + addps xmm6,xmm1 ; xmm6=data0=(00 10 20 30) + addps xmm7,xmm3 ; xmm7=data1=(01 11 21 31) + subps xmm5,xmm1 ; xmm5=data7=(07 17 27 37) + subps xmm0,xmm3 ; xmm0=data6=(06 16 26 36) + subps xmm2,xmm3 ; xmm2=tmp5 + + movaps xmm1,[rel PD_RNDINT_MAGIC] ; xmm1=[rel PD_RNDINT_MAGIC] + pcmpeqd xmm3,xmm3 + psrld xmm3,WORD_BIT ; xmm3={0xFFFF 0x0000 0xFFFF 0x0000 ..} + + addps xmm6,xmm1 ; xmm6=roundint(data0/8)=(00 ** 10 ** 20 ** 30 **) + addps xmm7,xmm1 ; xmm7=roundint(data1/8)=(01 ** 11 ** 21 ** 31 **) + addps xmm0,xmm1 ; xmm0=roundint(data6/8)=(06 ** 16 ** 26 ** 36 **) + addps xmm5,xmm1 ; xmm5=roundint(data7/8)=(07 ** 17 ** 27 ** 37 **) + + pand xmm6,xmm3 ; xmm6=(00 -- 10 -- 20 -- 30 --) + pslld xmm7,WORD_BIT ; xmm7=(-- 01 -- 11 -- 21 -- 31) + pand xmm0,xmm3 ; xmm0=(06 -- 16 -- 26 -- 36 --) + pslld xmm5,WORD_BIT ; xmm5=(-- 07 -- 17 -- 27 -- 37) + por xmm6,xmm7 ; xmm6=(00 01 10 11 20 21 30 31) + por xmm0,xmm5 ; xmm0=(06 07 16 17 26 27 36 37) + + movaps xmm1, XMMWORD [wk(0)] ; xmm1=tmp2 + movaps xmm3, XMMWORD [wk(1)] ; xmm3=tmp3 + + addps xmm4,xmm2 ; xmm4=tmp4 + movaps xmm7,xmm1 + movaps xmm5,xmm3 + addps xmm1,xmm2 ; xmm1=data2=(02 12 22 32) + addps xmm3,xmm4 ; xmm3=data4=(04 14 24 34) + subps xmm7,xmm2 ; xmm7=data5=(05 15 25 35) + subps xmm5,xmm4 ; xmm5=data3=(03 13 23 33) + + movaps xmm2,[rel PD_RNDINT_MAGIC] ; xmm2=[rel PD_RNDINT_MAGIC] + pcmpeqd xmm4,xmm4 + psrld xmm4,WORD_BIT ; xmm4={0xFFFF 0x0000 0xFFFF 0x0000 ..} + + addps xmm3,xmm2 ; xmm3=roundint(data4/8)=(04 ** 14 ** 24 ** 34 **) + addps xmm7,xmm2 ; xmm7=roundint(data5/8)=(05 ** 15 ** 25 ** 35 **) + addps xmm1,xmm2 ; xmm1=roundint(data2/8)=(02 ** 12 ** 22 ** 32 **) + addps xmm5,xmm2 ; xmm5=roundint(data3/8)=(03 ** 13 ** 23 ** 33 **) + + pand xmm3,xmm4 ; xmm3=(04 -- 14 -- 24 -- 34 --) + pslld xmm7,WORD_BIT ; xmm7=(-- 05 -- 15 -- 25 -- 35) + pand xmm1,xmm4 ; xmm1=(02 -- 12 -- 22 -- 32 --) + pslld xmm5,WORD_BIT ; xmm5=(-- 03 -- 13 -- 23 -- 33) + por xmm3,xmm7 ; xmm3=(04 05 14 15 24 25 34 35) + por xmm1,xmm5 ; xmm1=(02 03 12 13 22 23 32 33) + + movdqa xmm2,[rel PB_CENTERJSAMP] ; xmm2=[rel PB_CENTERJSAMP] + + packsswb xmm6,xmm3 ; xmm6=(00 01 10 11 20 21 30 31 04 05 14 15 24 25 34 35) + packsswb xmm1,xmm0 ; xmm1=(02 03 12 13 22 23 32 33 06 07 16 17 26 27 36 37) + paddb xmm6,xmm2 + paddb xmm1,xmm2 + + movdqa xmm4,xmm6 ; transpose coefficients(phase 2) + punpcklwd xmm6,xmm1 ; xmm6=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) + punpckhwd xmm4,xmm1 ; xmm4=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) + + movdqa xmm7,xmm6 ; transpose coefficients(phase 3) + punpckldq xmm6,xmm4 ; xmm6=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) + punpckhdq xmm7,xmm4 ; xmm7=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) + + pshufd xmm5,xmm6,0x4E ; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) + pshufd xmm3,xmm7,0x4E ; xmm3=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) + + mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] + mov rbx, JSAMPROW [rdi+2*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6 + movq XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE], xmm7 + mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] + mov rbx, JSAMPROW [rdi+3*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm5 + movq XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE], xmm3 + + add rsi, byte 4*SIZEOF_FAST_FLOAT ; wsptr + add rdi, byte 4*SIZEOF_JSAMPROW + dec rcx ; ctr + jnz near .rowloop + + pop rbx + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2fst-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2fst-64.asm new file mode 100755 index 0000000..0887505 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2fst-64.asm @@ -0,0 +1,492 @@ +; +; jiss2fst-64.asm - fast integer IDCT (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/projecpt/showfiles.php?group_id=6208 +; +; This file contains a fast, not so accurate integer implementation of +; the inverse DCT (Discrete Cosine Transform). The following code is +; based directly on the IJG's original jidctfst.c; see the jidctfst.c +; for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 8 ; 14 is also OK. +%define PASS1_BITS 2 + +%if IFAST_SCALE_BITS != PASS1_BITS +%error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'." +%endif + +%if CONST_BITS == 8 +F_1_082 equ 277 ; FIX(1.082392200) +F_1_414 equ 362 ; FIX(1.414213562) +F_1_847 equ 473 ; FIX(1.847759065) +F_2_613 equ 669 ; FIX(2.613125930) +F_1_613 equ (F_2_613 - 256) ; FIX(2.613125930) - FIX(1) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_1_082 equ DESCALE(1162209775,30-CONST_BITS) ; FIX(1.082392200) +F_1_414 equ DESCALE(1518500249,30-CONST_BITS) ; FIX(1.414213562) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_2_613 equ DESCALE(2805822602,30-CONST_BITS) ; FIX(2.613125930) +F_1_613 equ (F_2_613 - (1 << CONST_BITS)) ; FIX(2.613125930) - FIX(1) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + +; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow) +; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw) + +%define PRE_MULTIPLY_SCALE_BITS 2 +%define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS) + + alignz 16 + global EXTN(jconst_idct_ifast_sse2) + +EXTN(jconst_idct_ifast_sse2): + +PW_F1414 times 8 dw F_1_414 << CONST_SHIFT +PW_F1847 times 8 dw F_1_847 << CONST_SHIFT +PW_MF1613 times 8 dw -F_1_613 << CONST_SHIFT +PW_F1082 times 8 dw F_1_082 << CONST_SHIFT +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_ifast_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +; r10 = jpeg_component_info * compptr +; r11 = JCOEFPTR coef_block +; r12 = JSAMPARRAY output_buf +; r13 = JDIMENSION output_col + +%define original_rbp rbp+0 +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_idct_ifast_sse2) + +EXTN(jsimd_idct_ifast_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + + ; ---- Pass 1: process columns from input. + + mov rdx, r10 ; quantptr + mov rsi, r11 ; inptr + +%ifndef NO_ZERO_COLUMN_TEST_IFAST_SSE2 + mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)] + jnz near .columnDCT + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + por xmm1,xmm0 + packsswb xmm1,xmm1 + packsswb xmm1,xmm1 + movd eax,xmm1 + test rax,rax + jnz short .columnDCT + + ; -- AC terms all zero + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + movdqa xmm7,xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07) + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + punpckhwd xmm7,xmm7 ; xmm7=(04 04 05 05 06 06 07 07) + + pshufd xmm6,xmm0,0x00 ; xmm6=col0=(00 00 00 00 00 00 00 00) + pshufd xmm2,xmm0,0x55 ; xmm2=col1=(01 01 01 01 01 01 01 01) + pshufd xmm5,xmm0,0xAA ; xmm5=col2=(02 02 02 02 02 02 02 02) + pshufd xmm0,xmm0,0xFF ; xmm0=col3=(03 03 03 03 03 03 03 03) + pshufd xmm1,xmm7,0x00 ; xmm1=col4=(04 04 04 04 04 04 04 04) + pshufd xmm4,xmm7,0x55 ; xmm4=col5=(05 05 05 05 05 05 05 05) + pshufd xmm3,xmm7,0xAA ; xmm3=col6=(06 06 06 06 06 06 06 06) + pshufd xmm7,xmm7,0xFF ; xmm7=col7=(07 07 07 07 07 07 07 07) + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=col1 + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=col3 + jmp near .column_end +%endif +.columnDCT: + + ; -- Even part + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + + movdqa xmm4,xmm0 + movdqa xmm5,xmm1 + psubw xmm0,xmm2 ; xmm0=tmp11 + psubw xmm1,xmm3 + paddw xmm4,xmm2 ; xmm4=tmp10 + paddw xmm5,xmm3 ; xmm5=tmp13 + + psllw xmm1,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm1,[rel PW_F1414] + psubw xmm1,xmm5 ; xmm1=tmp12 + + movdqa xmm6,xmm4 + movdqa xmm7,xmm0 + psubw xmm4,xmm5 ; xmm4=tmp3 + psubw xmm0,xmm1 ; xmm0=tmp2 + paddw xmm6,xmm5 ; xmm6=tmp0 + paddw xmm7,xmm1 ; xmm7=tmp1 + + movdqa XMMWORD [wk(1)], xmm4 ; wk(1)=tmp3 + movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=tmp2 + + ; -- Odd part + + movdqa xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + movdqa xmm5, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + pmullw xmm5, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_IFAST_MULT_TYPE)] + + movdqa xmm4,xmm2 + movdqa xmm0,xmm5 + psubw xmm2,xmm1 ; xmm2=z12 + psubw xmm5,xmm3 ; xmm5=z10 + paddw xmm4,xmm1 ; xmm4=z11 + paddw xmm0,xmm3 ; xmm0=z13 + + movdqa xmm1,xmm5 ; xmm1=z10(unscaled) + psllw xmm2,PRE_MULTIPLY_SCALE_BITS + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + + movdqa xmm3,xmm4 + psubw xmm4,xmm0 + paddw xmm3,xmm0 ; xmm3=tmp7 + + psllw xmm4,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm4,[rel PW_F1414] ; xmm4=tmp11 + + ; To avoid overflow... + ; + ; (Original) + ; tmp12 = -2.613125930 * z10 + z5; + ; + ; (This implementation) + ; tmp12 = (-1.613125930 - 1) * z10 + z5; + ; = -1.613125930 * z10 - z10 + z5; + + movdqa xmm0,xmm5 + paddw xmm5,xmm2 + pmulhw xmm5,[rel PW_F1847] ; xmm5=z5 + pmulhw xmm0,[rel PW_MF1613] + pmulhw xmm2,[rel PW_F1082] + psubw xmm0,xmm1 + psubw xmm2,xmm5 ; xmm2=tmp10 + paddw xmm0,xmm5 ; xmm0=tmp12 + + ; -- Final output stage + + psubw xmm0,xmm3 ; xmm0=tmp6 + movdqa xmm1,xmm6 + movdqa xmm5,xmm7 + paddw xmm6,xmm3 ; xmm6=data0=(00 01 02 03 04 05 06 07) + paddw xmm7,xmm0 ; xmm7=data1=(10 11 12 13 14 15 16 17) + psubw xmm1,xmm3 ; xmm1=data7=(70 71 72 73 74 75 76 77) + psubw xmm5,xmm0 ; xmm5=data6=(60 61 62 63 64 65 66 67) + psubw xmm4,xmm0 ; xmm4=tmp5 + + movdqa xmm3,xmm6 ; transpose coefficients(phase 1) + punpcklwd xmm6,xmm7 ; xmm6=(00 10 01 11 02 12 03 13) + punpckhwd xmm3,xmm7 ; xmm3=(04 14 05 15 06 16 07 17) + movdqa xmm0,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm1 ; xmm5=(60 70 61 71 62 72 63 73) + punpckhwd xmm0,xmm1 ; xmm0=(64 74 65 75 66 76 67 77) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp2 + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=tmp3 + + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(60 70 61 71 62 72 63 73) + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(64 74 65 75 66 76 67 77) + + paddw xmm2,xmm4 ; xmm2=tmp4 + movdqa xmm5,xmm7 + movdqa xmm0,xmm1 + paddw xmm7,xmm4 ; xmm7=data2=(20 21 22 23 24 25 26 27) + paddw xmm1,xmm2 ; xmm1=data4=(40 41 42 43 44 45 46 47) + psubw xmm5,xmm4 ; xmm5=data5=(50 51 52 53 54 55 56 57) + psubw xmm0,xmm2 ; xmm0=data3=(30 31 32 33 34 35 36 37) + + movdqa xmm4,xmm7 ; transpose coefficients(phase 1) + punpcklwd xmm7,xmm0 ; xmm7=(20 30 21 31 22 32 23 33) + punpckhwd xmm4,xmm0 ; xmm4=(24 34 25 35 26 36 27 37) + movdqa xmm2,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm5 ; xmm1=(40 50 41 51 42 52 43 53) + punpckhwd xmm2,xmm5 ; xmm2=(44 54 45 55 46 56 47 57) + + movdqa xmm0,xmm3 ; transpose coefficients(phase 2) + punpckldq xmm3,xmm4 ; xmm3=(04 14 24 34 05 15 25 35) + punpckhdq xmm0,xmm4 ; xmm0=(06 16 26 36 07 17 27 37) + movdqa xmm5,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm7 ; xmm6=(00 10 20 30 01 11 21 31) + punpckhdq xmm5,xmm7 ; xmm5=(02 12 22 32 03 13 23 33) + + movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(60 70 61 71 62 72 63 73) + movdqa xmm7, XMMWORD [wk(1)] ; xmm7=(64 74 65 75 66 76 67 77) + + movdqa XMMWORD [wk(0)], xmm3 ; wk(0)=(04 14 24 34 05 15 25 35) + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(06 16 26 36 07 17 27 37) + + movdqa xmm3,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm4 ; xmm1=(40 50 60 70 41 51 61 71) + punpckhdq xmm3,xmm4 ; xmm3=(42 52 62 72 43 53 63 73) + movdqa xmm0,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm7 ; xmm2=(44 54 64 74 45 55 65 75) + punpckhdq xmm0,xmm7 ; xmm0=(46 56 66 76 47 57 67 77) + + movdqa xmm4,xmm6 ; transpose coefficients(phase 3) + punpcklqdq xmm6,xmm1 ; xmm6=col0=(00 10 20 30 40 50 60 70) + punpckhqdq xmm4,xmm1 ; xmm4=col1=(01 11 21 31 41 51 61 71) + movdqa xmm7,xmm5 ; transpose coefficients(phase 3) + punpcklqdq xmm5,xmm3 ; xmm5=col2=(02 12 22 32 42 52 62 72) + punpckhqdq xmm7,xmm3 ; xmm7=col3=(03 13 23 33 43 53 63 73) + + movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(04 14 24 34 05 15 25 35) + movdqa xmm3, XMMWORD [wk(1)] ; xmm3=(06 16 26 36 07 17 27 37) + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=col1 + movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=col3 + + movdqa xmm4,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm2 ; xmm1=col4=(04 14 24 34 44 54 64 74) + punpckhqdq xmm4,xmm2 ; xmm4=col5=(05 15 25 35 45 55 65 75) + movdqa xmm7,xmm3 ; transpose coefficients(phase 3) + punpcklqdq xmm3,xmm0 ; xmm3=col6=(06 16 26 36 46 56 66 76) + punpckhqdq xmm7,xmm0 ; xmm7=col7=(07 17 27 37 47 57 67 77) +.column_end: + + ; -- Prefetch the next coefficient block + + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov rax, [original_rbp] + mov rdi, r12 ; (JSAMPROW *) + mov rax, r13 + + ; -- Even part + + ; xmm6=col0, xmm5=col2, xmm1=col4, xmm3=col6 + + movdqa xmm2,xmm6 + movdqa xmm0,xmm5 + psubw xmm6,xmm1 ; xmm6=tmp11 + psubw xmm5,xmm3 + paddw xmm2,xmm1 ; xmm2=tmp10 + paddw xmm0,xmm3 ; xmm0=tmp13 + + psllw xmm5,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm5,[rel PW_F1414] + psubw xmm5,xmm0 ; xmm5=tmp12 + + movdqa xmm1,xmm2 + movdqa xmm3,xmm6 + psubw xmm2,xmm0 ; xmm2=tmp3 + psubw xmm6,xmm5 ; xmm6=tmp2 + paddw xmm1,xmm0 ; xmm1=tmp0 + paddw xmm3,xmm5 ; xmm3=tmp1 + + movdqa xmm0, XMMWORD [wk(0)] ; xmm0=col1 + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=col3 + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp3 + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=tmp2 + + ; -- Odd part + + ; xmm0=col1, xmm5=col3, xmm4=col5, xmm7=col7 + + movdqa xmm2,xmm0 + movdqa xmm6,xmm4 + psubw xmm0,xmm7 ; xmm0=z12 + psubw xmm4,xmm5 ; xmm4=z10 + paddw xmm2,xmm7 ; xmm2=z11 + paddw xmm6,xmm5 ; xmm6=z13 + + movdqa xmm7,xmm4 ; xmm7=z10(unscaled) + psllw xmm0,PRE_MULTIPLY_SCALE_BITS + psllw xmm4,PRE_MULTIPLY_SCALE_BITS + + movdqa xmm5,xmm2 + psubw xmm2,xmm6 + paddw xmm5,xmm6 ; xmm5=tmp7 + + psllw xmm2,PRE_MULTIPLY_SCALE_BITS + pmulhw xmm2,[rel PW_F1414] ; xmm2=tmp11 + + ; To avoid overflow... + ; + ; (Original) + ; tmp12 = -2.613125930 * z10 + z5; + ; + ; (This implementation) + ; tmp12 = (-1.613125930 - 1) * z10 + z5; + ; = -1.613125930 * z10 - z10 + z5; + + movdqa xmm6,xmm4 + paddw xmm4,xmm0 + pmulhw xmm4,[rel PW_F1847] ; xmm4=z5 + pmulhw xmm6,[rel PW_MF1613] + pmulhw xmm0,[rel PW_F1082] + psubw xmm6,xmm7 + psubw xmm0,xmm4 ; xmm0=tmp10 + paddw xmm6,xmm4 ; xmm6=tmp12 + + ; -- Final output stage + + psubw xmm6,xmm5 ; xmm6=tmp6 + movdqa xmm7,xmm1 + movdqa xmm4,xmm3 + paddw xmm1,xmm5 ; xmm1=data0=(00 10 20 30 40 50 60 70) + paddw xmm3,xmm6 ; xmm3=data1=(01 11 21 31 41 51 61 71) + psraw xmm1,(PASS1_BITS+3) ; descale + psraw xmm3,(PASS1_BITS+3) ; descale + psubw xmm7,xmm5 ; xmm7=data7=(07 17 27 37 47 57 67 77) + psubw xmm4,xmm6 ; xmm4=data6=(06 16 26 36 46 56 66 76) + psraw xmm7,(PASS1_BITS+3) ; descale + psraw xmm4,(PASS1_BITS+3) ; descale + psubw xmm2,xmm6 ; xmm2=tmp5 + + packsswb xmm1,xmm4 ; xmm1=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + packsswb xmm3,xmm7 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp2 + movdqa xmm6, XMMWORD [wk(0)] ; xmm6=tmp3 + + paddw xmm0,xmm2 ; xmm0=tmp4 + movdqa xmm4,xmm5 + movdqa xmm7,xmm6 + paddw xmm5,xmm2 ; xmm5=data2=(02 12 22 32 42 52 62 72) + paddw xmm6,xmm0 ; xmm6=data4=(04 14 24 34 44 54 64 74) + psraw xmm5,(PASS1_BITS+3) ; descale + psraw xmm6,(PASS1_BITS+3) ; descale + psubw xmm4,xmm2 ; xmm4=data5=(05 15 25 35 45 55 65 75) + psubw xmm7,xmm0 ; xmm7=data3=(03 13 23 33 43 53 63 73) + psraw xmm4,(PASS1_BITS+3) ; descale + psraw xmm7,(PASS1_BITS+3) ; descale + + movdqa xmm2,[rel PB_CENTERJSAMP] ; xmm2=[rel PB_CENTERJSAMP] + + packsswb xmm5,xmm6 ; xmm5=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74) + packsswb xmm7,xmm4 ; xmm7=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75) + + paddb xmm1,xmm2 + paddb xmm3,xmm2 + paddb xmm5,xmm2 + paddb xmm7,xmm2 + + movdqa xmm0,xmm1 ; transpose coefficients(phase 1) + punpcklbw xmm1,xmm3 ; xmm1=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71) + punpckhbw xmm0,xmm3 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77) + movdqa xmm6,xmm5 ; transpose coefficients(phase 1) + punpcklbw xmm5,xmm7 ; xmm5=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73) + punpckhbw xmm6,xmm7 ; xmm6=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75) + + movdqa xmm4,xmm1 ; transpose coefficients(phase 2) + punpcklwd xmm1,xmm5 ; xmm1=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) + punpckhwd xmm4,xmm5 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73) + movdqa xmm2,xmm6 ; transpose coefficients(phase 2) + punpcklwd xmm6,xmm0 ; xmm6=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) + punpckhwd xmm2,xmm0 ; xmm2=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77) + + movdqa xmm3,xmm1 ; transpose coefficients(phase 3) + punpckldq xmm1,xmm6 ; xmm1=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) + punpckhdq xmm3,xmm6 ; xmm3=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) + movdqa xmm7,xmm4 ; transpose coefficients(phase 3) + punpckldq xmm4,xmm2 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57) + punpckhdq xmm7,xmm2 ; xmm7=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77) + + pshufd xmm5,xmm1,0x4E ; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) + pshufd xmm0,xmm3,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) + pshufd xmm6,xmm4,0x4E ; xmm6=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47) + pshufd xmm2,xmm7,0x4E ; xmm2=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67) + + mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3 + mov rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm7 + + mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm5 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0 + mov rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2 + + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2int-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2int-64.asm new file mode 100755 index 0000000..13764d6 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2int-64.asm @@ -0,0 +1,848 @@ +; +; jiss2int-64.asm - accurate integer IDCT (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains a slow-but-accurate integer implementation of the +; inverse DCT (Discrete Cosine Transform). The following code is based +; directly on the IJG's original jidctint.c; see the jidctint.c for +; more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1 (CONST_BITS-PASS1_BITS) +%define DESCALE_P2 (CONST_BITS+PASS1_BITS+3) + +%if CONST_BITS == 13 +F_0_298 equ 2446 ; FIX(0.298631336) +F_0_390 equ 3196 ; FIX(0.390180644) +F_0_541 equ 4433 ; FIX(0.541196100) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_175 equ 9633 ; FIX(1.175875602) +F_1_501 equ 12299 ; FIX(1.501321110) +F_1_847 equ 15137 ; FIX(1.847759065) +F_1_961 equ 16069 ; FIX(1.961570560) +F_2_053 equ 16819 ; FIX(2.053119869) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_072 equ 25172 ; FIX(3.072711026) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) +F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) +F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) +F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) +F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_islow_sse2) + +EXTN(jconst_idct_islow_sse2): + +PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541 +PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847) +PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175 +PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390) +PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899 +PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899) +PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562 +PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562) +PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1) +PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1) +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Perform dequantization and inverse DCT on one block of coefficients. +; +; GLOBAL(void) +; jsimd_idct_islow_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +; r10 = jpeg_component_info * compptr +; r11 = JCOEFPTR coef_block +; r12 = JSAMPARRAY output_buf +; r13 = JDIMENSION output_col + +%define original_rbp rbp+0 +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 12 + + align 16 + global EXTN(jsimd_idct_islow_sse2) + +EXTN(jsimd_idct_islow_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + + ; ---- Pass 1: process columns from input. + + mov rdx, r10 ; quantptr + mov rsi, r11 ; inptr + +%ifndef NO_ZERO_COLUMN_TEST_ISLOW_SSE2 + mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)] + jnz near .columnDCT + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + por xmm1,xmm0 + packsswb xmm1,xmm1 + packsswb xmm1,xmm1 + movd eax,xmm1 + test rax,rax + jnz short .columnDCT + + ; -- AC terms all zero + + movdqa xmm5, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + pmullw xmm5, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + psllw xmm5,PASS1_BITS + + movdqa xmm4,xmm5 ; xmm5=in0=(00 01 02 03 04 05 06 07) + punpcklwd xmm5,xmm5 ; xmm5=(00 00 01 01 02 02 03 03) + punpckhwd xmm4,xmm4 ; xmm4=(04 04 05 05 06 06 07 07) + + pshufd xmm7,xmm5,0x00 ; xmm7=col0=(00 00 00 00 00 00 00 00) + pshufd xmm6,xmm5,0x55 ; xmm6=col1=(01 01 01 01 01 01 01 01) + pshufd xmm1,xmm5,0xAA ; xmm1=col2=(02 02 02 02 02 02 02 02) + pshufd xmm5,xmm5,0xFF ; xmm5=col3=(03 03 03 03 03 03 03 03) + pshufd xmm0,xmm4,0x00 ; xmm0=col4=(04 04 04 04 04 04 04 04) + pshufd xmm3,xmm4,0x55 ; xmm3=col5=(05 05 05 05 05 05 05 05) + pshufd xmm2,xmm4,0xAA ; xmm2=col6=(06 06 06 06 06 06 06 06) + pshufd xmm4,xmm4,0xFF ; xmm4=col7=(07 07 07 07 07 07 07 07) + + movdqa XMMWORD [wk(8)], xmm6 ; wk(8)=col1 + movdqa XMMWORD [wk(9)], xmm5 ; wk(9)=col3 + movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 + movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 + jmp near .column_end +%endif +.columnDCT: + + ; -- Even part + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + ; (Original) + ; z1 = (z2 + z3) * 0.541196100; + ; tmp2 = z1 + z3 * -1.847759065; + ; tmp3 = z1 + z2 * 0.765366865; + ; + ; (This implementation) + ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); + ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; + + movdqa xmm4,xmm1 ; xmm1=in2=z2 + movdqa xmm5,xmm1 + punpcklwd xmm4,xmm3 ; xmm3=in6=z3 + punpckhwd xmm5,xmm3 + movdqa xmm1,xmm4 + movdqa xmm3,xmm5 + pmaddwd xmm4,[rel PW_F130_F054] ; xmm4=tmp3L + pmaddwd xmm5,[rel PW_F130_F054] ; xmm5=tmp3H + pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=tmp2L + pmaddwd xmm3,[rel PW_F054_MF130] ; xmm3=tmp2H + + movdqa xmm6,xmm0 + paddw xmm0,xmm2 ; xmm0=in0+in4 + psubw xmm6,xmm2 ; xmm6=in0-in4 + + pxor xmm7,xmm7 + pxor xmm2,xmm2 + punpcklwd xmm7,xmm0 ; xmm7=tmp0L + punpckhwd xmm2,xmm0 ; xmm2=tmp0H + psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS + psrad xmm2,(16-CONST_BITS) ; psrad xmm2,16 & pslld xmm2,CONST_BITS + + movdqa xmm0,xmm7 + paddd xmm7,xmm4 ; xmm7=tmp10L + psubd xmm0,xmm4 ; xmm0=tmp13L + movdqa xmm4,xmm2 + paddd xmm2,xmm5 ; xmm2=tmp10H + psubd xmm4,xmm5 ; xmm4=tmp13H + + movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=tmp10L + movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=tmp10H + movdqa XMMWORD [wk(2)], xmm0 ; wk(2)=tmp13L + movdqa XMMWORD [wk(3)], xmm4 ; wk(3)=tmp13H + + pxor xmm5,xmm5 + pxor xmm7,xmm7 + punpcklwd xmm5,xmm6 ; xmm5=tmp1L + punpckhwd xmm7,xmm6 ; xmm7=tmp1H + psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS + psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS + + movdqa xmm2,xmm5 + paddd xmm5,xmm1 ; xmm5=tmp11L + psubd xmm2,xmm1 ; xmm2=tmp12L + movdqa xmm0,xmm7 + paddd xmm7,xmm3 ; xmm7=tmp11H + psubd xmm0,xmm3 ; xmm0=tmp12H + + movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L + movdqa XMMWORD [wk(5)], xmm7 ; wk(5)=tmp11H + movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=tmp12L + movdqa XMMWORD [wk(7)], xmm0 ; wk(7)=tmp12H + + ; -- Odd part + + movdqa xmm4, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movdqa xmm6, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + pmullw xmm4, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm6, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + pmullw xmm1, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + movdqa xmm5,xmm6 + movdqa xmm7,xmm4 + paddw xmm5,xmm3 ; xmm5=z3 + paddw xmm7,xmm1 ; xmm7=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm2,xmm5 + movdqa xmm0,xmm5 + punpcklwd xmm2,xmm7 + punpckhwd xmm0,xmm7 + movdqa xmm5,xmm2 + movdqa xmm7,xmm0 + pmaddwd xmm2,[rel PW_MF078_F117] ; xmm2=z3L + pmaddwd xmm0,[rel PW_MF078_F117] ; xmm0=z3H + pmaddwd xmm5,[rel PW_F117_F078] ; xmm5=z4L + pmaddwd xmm7,[rel PW_F117_F078] ; xmm7=z4H + + movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=z3L + movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=z3H + + ; (Original) + ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; + ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; + ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; tmp0 += z1 + z3; tmp1 += z2 + z4; + ; tmp2 += z2 + z3; tmp3 += z1 + z4; + ; + ; (This implementation) + ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; + ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; + ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); + ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); + ; tmp0 += z3; tmp1 += z4; + ; tmp2 += z3; tmp3 += z4; + + movdqa xmm2,xmm3 + movdqa xmm0,xmm3 + punpcklwd xmm2,xmm4 + punpckhwd xmm0,xmm4 + movdqa xmm3,xmm2 + movdqa xmm4,xmm0 + pmaddwd xmm2,[rel PW_MF060_MF089] ; xmm2=tmp0L + pmaddwd xmm0,[rel PW_MF060_MF089] ; xmm0=tmp0H + pmaddwd xmm3,[rel PW_MF089_F060] ; xmm3=tmp3L + pmaddwd xmm4,[rel PW_MF089_F060] ; xmm4=tmp3H + + paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp0L + paddd xmm0, XMMWORD [wk(11)] ; xmm0=tmp0H + paddd xmm3,xmm5 ; xmm3=tmp3L + paddd xmm4,xmm7 ; xmm4=tmp3H + + movdqa XMMWORD [wk(8)], xmm2 ; wk(8)=tmp0L + movdqa XMMWORD [wk(9)], xmm0 ; wk(9)=tmp0H + + movdqa xmm2,xmm1 + movdqa xmm0,xmm1 + punpcklwd xmm2,xmm6 + punpckhwd xmm0,xmm6 + movdqa xmm1,xmm2 + movdqa xmm6,xmm0 + pmaddwd xmm2,[rel PW_MF050_MF256] ; xmm2=tmp1L + pmaddwd xmm0,[rel PW_MF050_MF256] ; xmm0=tmp1H + pmaddwd xmm1,[rel PW_MF256_F050] ; xmm1=tmp2L + pmaddwd xmm6,[rel PW_MF256_F050] ; xmm6=tmp2H + + paddd xmm2,xmm5 ; xmm2=tmp1L + paddd xmm0,xmm7 ; xmm0=tmp1H + paddd xmm1, XMMWORD [wk(10)] ; xmm1=tmp2L + paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H + + movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=tmp1L + movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=tmp1H + + ; -- Final output stage + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L + movdqa xmm7, XMMWORD [wk(1)] ; xmm7=tmp10H + + movdqa xmm2,xmm5 + movdqa xmm0,xmm7 + paddd xmm5,xmm3 ; xmm5=data0L + paddd xmm7,xmm4 ; xmm7=data0H + psubd xmm2,xmm3 ; xmm2=data7L + psubd xmm0,xmm4 ; xmm0=data7H + + movdqa xmm3,[rel PD_DESCALE_P1] ; xmm3=[rel PD_DESCALE_P1] + + paddd xmm5,xmm3 + paddd xmm7,xmm3 + psrad xmm5,DESCALE_P1 + psrad xmm7,DESCALE_P1 + paddd xmm2,xmm3 + paddd xmm0,xmm3 + psrad xmm2,DESCALE_P1 + psrad xmm0,DESCALE_P1 + + packssdw xmm5,xmm7 ; xmm5=data0=(00 01 02 03 04 05 06 07) + packssdw xmm2,xmm0 ; xmm2=data7=(70 71 72 73 74 75 76 77) + + movdqa xmm4, XMMWORD [wk(4)] ; xmm4=tmp11L + movdqa xmm3, XMMWORD [wk(5)] ; xmm3=tmp11H + + movdqa xmm7,xmm4 + movdqa xmm0,xmm3 + paddd xmm4,xmm1 ; xmm4=data1L + paddd xmm3,xmm6 ; xmm3=data1H + psubd xmm7,xmm1 ; xmm7=data6L + psubd xmm0,xmm6 ; xmm0=data6H + + movdqa xmm1,[rel PD_DESCALE_P1] ; xmm1=[rel PD_DESCALE_P1] + + paddd xmm4,xmm1 + paddd xmm3,xmm1 + psrad xmm4,DESCALE_P1 + psrad xmm3,DESCALE_P1 + paddd xmm7,xmm1 + paddd xmm0,xmm1 + psrad xmm7,DESCALE_P1 + psrad xmm0,DESCALE_P1 + + packssdw xmm4,xmm3 ; xmm4=data1=(10 11 12 13 14 15 16 17) + packssdw xmm7,xmm0 ; xmm7=data6=(60 61 62 63 64 65 66 67) + + movdqa xmm6,xmm5 ; transpose coefficients(phase 1) + punpcklwd xmm5,xmm4 ; xmm5=(00 10 01 11 02 12 03 13) + punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17) + movdqa xmm1,xmm7 ; transpose coefficients(phase 1) + punpcklwd xmm7,xmm2 ; xmm7=(60 70 61 71 62 72 63 73) + punpckhwd xmm1,xmm2 ; xmm1=(64 74 65 75 66 76 67 77) + + movdqa xmm3, XMMWORD [wk(6)] ; xmm3=tmp12L + movdqa xmm0, XMMWORD [wk(7)] ; xmm0=tmp12H + movdqa xmm4, XMMWORD [wk(10)] ; xmm4=tmp1L + movdqa xmm2, XMMWORD [wk(11)] ; xmm2=tmp1H + + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 01 11 02 12 03 13) + movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=(04 14 05 15 06 16 07 17) + movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=(60 70 61 71 62 72 63 73) + movdqa XMMWORD [wk(5)], xmm1 ; wk(5)=(64 74 65 75 66 76 67 77) + + movdqa xmm5,xmm3 + movdqa xmm6,xmm0 + paddd xmm3,xmm4 ; xmm3=data2L + paddd xmm0,xmm2 ; xmm0=data2H + psubd xmm5,xmm4 ; xmm5=data5L + psubd xmm6,xmm2 ; xmm6=data5H + + movdqa xmm7,[rel PD_DESCALE_P1] ; xmm7=[rel PD_DESCALE_P1] + + paddd xmm3,xmm7 + paddd xmm0,xmm7 + psrad xmm3,DESCALE_P1 + psrad xmm0,DESCALE_P1 + paddd xmm5,xmm7 + paddd xmm6,xmm7 + psrad xmm5,DESCALE_P1 + psrad xmm6,DESCALE_P1 + + packssdw xmm3,xmm0 ; xmm3=data2=(20 21 22 23 24 25 26 27) + packssdw xmm5,xmm6 ; xmm5=data5=(50 51 52 53 54 55 56 57) + + movdqa xmm1, XMMWORD [wk(2)] ; xmm1=tmp13L + movdqa xmm4, XMMWORD [wk(3)] ; xmm4=tmp13H + movdqa xmm2, XMMWORD [wk(8)] ; xmm2=tmp0L + movdqa xmm7, XMMWORD [wk(9)] ; xmm7=tmp0H + + movdqa xmm0,xmm1 + movdqa xmm6,xmm4 + paddd xmm1,xmm2 ; xmm1=data3L + paddd xmm4,xmm7 ; xmm4=data3H + psubd xmm0,xmm2 ; xmm0=data4L + psubd xmm6,xmm7 ; xmm6=data4H + + movdqa xmm2,[rel PD_DESCALE_P1] ; xmm2=[rel PD_DESCALE_P1] + + paddd xmm1,xmm2 + paddd xmm4,xmm2 + psrad xmm1,DESCALE_P1 + psrad xmm4,DESCALE_P1 + paddd xmm0,xmm2 + paddd xmm6,xmm2 + psrad xmm0,DESCALE_P1 + psrad xmm6,DESCALE_P1 + + packssdw xmm1,xmm4 ; xmm1=data3=(30 31 32 33 34 35 36 37) + packssdw xmm0,xmm6 ; xmm0=data4=(40 41 42 43 44 45 46 47) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 01 11 02 12 03 13) + movdqa xmm2, XMMWORD [wk(1)] ; xmm2=(04 14 05 15 06 16 07 17) + + movdqa xmm4,xmm3 ; transpose coefficients(phase 1) + punpcklwd xmm3,xmm1 ; xmm3=(20 30 21 31 22 32 23 33) + punpckhwd xmm4,xmm1 ; xmm4=(24 34 25 35 26 36 27 37) + movdqa xmm6,xmm0 ; transpose coefficients(phase 1) + punpcklwd xmm0,xmm5 ; xmm0=(40 50 41 51 42 52 43 53) + punpckhwd xmm6,xmm5 ; xmm6=(44 54 45 55 46 56 47 57) + + movdqa xmm1,xmm7 ; transpose coefficients(phase 2) + punpckldq xmm7,xmm3 ; xmm7=(00 10 20 30 01 11 21 31) + punpckhdq xmm1,xmm3 ; xmm1=(02 12 22 32 03 13 23 33) + movdqa xmm5,xmm2 ; transpose coefficients(phase 2) + punpckldq xmm2,xmm4 ; xmm2=(04 14 24 34 05 15 25 35) + punpckhdq xmm5,xmm4 ; xmm5=(06 16 26 36 07 17 27 37) + + movdqa xmm3, XMMWORD [wk(4)] ; xmm3=(60 70 61 71 62 72 63 73) + movdqa xmm4, XMMWORD [wk(5)] ; xmm4=(64 74 65 75 66 76 67 77) + + movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=(04 14 24 34 05 15 25 35) + movdqa XMMWORD [wk(7)], xmm5 ; wk(7)=(06 16 26 36 07 17 27 37) + + movdqa xmm2,xmm0 ; transpose coefficients(phase 2) + punpckldq xmm0,xmm3 ; xmm0=(40 50 60 70 41 51 61 71) + punpckhdq xmm2,xmm3 ; xmm2=(42 52 62 72 43 53 63 73) + movdqa xmm5,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm4 ; xmm6=(44 54 64 74 45 55 65 75) + punpckhdq xmm5,xmm4 ; xmm5=(46 56 66 76 47 57 67 77) + + movdqa xmm3,xmm7 ; transpose coefficients(phase 3) + punpcklqdq xmm7,xmm0 ; xmm7=col0=(00 10 20 30 40 50 60 70) + punpckhqdq xmm3,xmm0 ; xmm3=col1=(01 11 21 31 41 51 61 71) + movdqa xmm4,xmm1 ; transpose coefficients(phase 3) + punpcklqdq xmm1,xmm2 ; xmm1=col2=(02 12 22 32 42 52 62 72) + punpckhqdq xmm4,xmm2 ; xmm4=col3=(03 13 23 33 43 53 63 73) + + movdqa xmm0, XMMWORD [wk(6)] ; xmm0=(04 14 24 34 05 15 25 35) + movdqa xmm2, XMMWORD [wk(7)] ; xmm2=(06 16 26 36 07 17 27 37) + + movdqa XMMWORD [wk(8)], xmm3 ; wk(8)=col1 + movdqa XMMWORD [wk(9)], xmm4 ; wk(9)=col3 + + movdqa xmm3,xmm0 ; transpose coefficients(phase 3) + punpcklqdq xmm0,xmm6 ; xmm0=col4=(04 14 24 34 44 54 64 74) + punpckhqdq xmm3,xmm6 ; xmm3=col5=(05 15 25 35 45 55 65 75) + movdqa xmm4,xmm2 ; transpose coefficients(phase 3) + punpcklqdq xmm2,xmm5 ; xmm2=col6=(06 16 26 36 46 56 66 76) + punpckhqdq xmm4,xmm5 ; xmm4=col7=(07 17 27 37 47 57 67 77) + + movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 + movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 +.column_end: + + ; -- Prefetch the next coefficient block + + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows from work array, store into output array. + + mov rax, [original_rbp] + mov rdi, r12 ; (JSAMPROW *) + mov rax, r13 + + ; -- Even part + + ; xmm7=col0, xmm1=col2, xmm0=col4, xmm2=col6 + + ; (Original) + ; z1 = (z2 + z3) * 0.541196100; + ; tmp2 = z1 + z3 * -1.847759065; + ; tmp3 = z1 + z2 * 0.765366865; + ; + ; (This implementation) + ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); + ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; + + movdqa xmm6,xmm1 ; xmm1=in2=z2 + movdqa xmm5,xmm1 + punpcklwd xmm6,xmm2 ; xmm2=in6=z3 + punpckhwd xmm5,xmm2 + movdqa xmm1,xmm6 + movdqa xmm2,xmm5 + pmaddwd xmm6,[rel PW_F130_F054] ; xmm6=tmp3L + pmaddwd xmm5,[rel PW_F130_F054] ; xmm5=tmp3H + pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=tmp2L + pmaddwd xmm2,[rel PW_F054_MF130] ; xmm2=tmp2H + + movdqa xmm3,xmm7 + paddw xmm7,xmm0 ; xmm7=in0+in4 + psubw xmm3,xmm0 ; xmm3=in0-in4 + + pxor xmm4,xmm4 + pxor xmm0,xmm0 + punpcklwd xmm4,xmm7 ; xmm4=tmp0L + punpckhwd xmm0,xmm7 ; xmm0=tmp0H + psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS + psrad xmm0,(16-CONST_BITS) ; psrad xmm0,16 & pslld xmm0,CONST_BITS + + movdqa xmm7,xmm4 + paddd xmm4,xmm6 ; xmm4=tmp10L + psubd xmm7,xmm6 ; xmm7=tmp13L + movdqa xmm6,xmm0 + paddd xmm0,xmm5 ; xmm0=tmp10H + psubd xmm6,xmm5 ; xmm6=tmp13H + + movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=tmp10L + movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp10H + movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=tmp13L + movdqa XMMWORD [wk(3)], xmm6 ; wk(3)=tmp13H + + pxor xmm5,xmm5 + pxor xmm4,xmm4 + punpcklwd xmm5,xmm3 ; xmm5=tmp1L + punpckhwd xmm4,xmm3 ; xmm4=tmp1H + psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS + psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS + + movdqa xmm0,xmm5 + paddd xmm5,xmm1 ; xmm5=tmp11L + psubd xmm0,xmm1 ; xmm0=tmp12L + movdqa xmm7,xmm4 + paddd xmm4,xmm2 ; xmm4=tmp11H + psubd xmm7,xmm2 ; xmm7=tmp12H + + movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L + movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=tmp11H + movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=tmp12L + movdqa XMMWORD [wk(7)], xmm7 ; wk(7)=tmp12H + + ; -- Odd part + + movdqa xmm6, XMMWORD [wk(9)] ; xmm6=col3 + movdqa xmm3, XMMWORD [wk(8)] ; xmm3=col1 + movdqa xmm1, XMMWORD [wk(11)] ; xmm1=col7 + movdqa xmm2, XMMWORD [wk(10)] ; xmm2=col5 + + movdqa xmm5,xmm6 + movdqa xmm4,xmm3 + paddw xmm5,xmm1 ; xmm5=z3 + paddw xmm4,xmm2 ; xmm4=z4 + + ; (Original) + ; z5 = (z3 + z4) * 1.175875602; + ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; + ; z3 += z5; z4 += z5; + ; + ; (This implementation) + ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; + ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); + + movdqa xmm0,xmm5 + movdqa xmm7,xmm5 + punpcklwd xmm0,xmm4 + punpckhwd xmm7,xmm4 + movdqa xmm5,xmm0 + movdqa xmm4,xmm7 + pmaddwd xmm0,[rel PW_MF078_F117] ; xmm0=z3L + pmaddwd xmm7,[rel PW_MF078_F117] ; xmm7=z3H + pmaddwd xmm5,[rel PW_F117_F078] ; xmm5=z4L + pmaddwd xmm4,[rel PW_F117_F078] ; xmm4=z4H + + movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=z3L + movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=z3H + + ; (Original) + ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; + ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; + ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; + ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; + ; tmp0 += z1 + z3; tmp1 += z2 + z4; + ; tmp2 += z2 + z3; tmp3 += z1 + z4; + ; + ; (This implementation) + ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; + ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; + ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); + ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); + ; tmp0 += z3; tmp1 += z4; + ; tmp2 += z3; tmp3 += z4; + + movdqa xmm0,xmm1 + movdqa xmm7,xmm1 + punpcklwd xmm0,xmm3 + punpckhwd xmm7,xmm3 + movdqa xmm1,xmm0 + movdqa xmm3,xmm7 + pmaddwd xmm0,[rel PW_MF060_MF089] ; xmm0=tmp0L + pmaddwd xmm7,[rel PW_MF060_MF089] ; xmm7=tmp0H + pmaddwd xmm1,[rel PW_MF089_F060] ; xmm1=tmp3L + pmaddwd xmm3,[rel PW_MF089_F060] ; xmm3=tmp3H + + paddd xmm0, XMMWORD [wk(10)] ; xmm0=tmp0L + paddd xmm7, XMMWORD [wk(11)] ; xmm7=tmp0H + paddd xmm1,xmm5 ; xmm1=tmp3L + paddd xmm3,xmm4 ; xmm3=tmp3H + + movdqa XMMWORD [wk(8)], xmm0 ; wk(8)=tmp0L + movdqa XMMWORD [wk(9)], xmm7 ; wk(9)=tmp0H + + movdqa xmm0,xmm2 + movdqa xmm7,xmm2 + punpcklwd xmm0,xmm6 + punpckhwd xmm7,xmm6 + movdqa xmm2,xmm0 + movdqa xmm6,xmm7 + pmaddwd xmm0,[rel PW_MF050_MF256] ; xmm0=tmp1L + pmaddwd xmm7,[rel PW_MF050_MF256] ; xmm7=tmp1H + pmaddwd xmm2,[rel PW_MF256_F050] ; xmm2=tmp2L + pmaddwd xmm6,[rel PW_MF256_F050] ; xmm6=tmp2H + + paddd xmm0,xmm5 ; xmm0=tmp1L + paddd xmm7,xmm4 ; xmm7=tmp1H + paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp2L + paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H + + movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=tmp1L + movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=tmp1H + + ; -- Final output stage + + movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L + movdqa xmm4, XMMWORD [wk(1)] ; xmm4=tmp10H + + movdqa xmm0,xmm5 + movdqa xmm7,xmm4 + paddd xmm5,xmm1 ; xmm5=data0L + paddd xmm4,xmm3 ; xmm4=data0H + psubd xmm0,xmm1 ; xmm0=data7L + psubd xmm7,xmm3 ; xmm7=data7H + + movdqa xmm1,[rel PD_DESCALE_P2] ; xmm1=[rel PD_DESCALE_P2] + + paddd xmm5,xmm1 + paddd xmm4,xmm1 + psrad xmm5,DESCALE_P2 + psrad xmm4,DESCALE_P2 + paddd xmm0,xmm1 + paddd xmm7,xmm1 + psrad xmm0,DESCALE_P2 + psrad xmm7,DESCALE_P2 + + packssdw xmm5,xmm4 ; xmm5=data0=(00 10 20 30 40 50 60 70) + packssdw xmm0,xmm7 ; xmm0=data7=(07 17 27 37 47 57 67 77) + + movdqa xmm3, XMMWORD [wk(4)] ; xmm3=tmp11L + movdqa xmm1, XMMWORD [wk(5)] ; xmm1=tmp11H + + movdqa xmm4,xmm3 + movdqa xmm7,xmm1 + paddd xmm3,xmm2 ; xmm3=data1L + paddd xmm1,xmm6 ; xmm1=data1H + psubd xmm4,xmm2 ; xmm4=data6L + psubd xmm7,xmm6 ; xmm7=data6H + + movdqa xmm2,[rel PD_DESCALE_P2] ; xmm2=[rel PD_DESCALE_P2] + + paddd xmm3,xmm2 + paddd xmm1,xmm2 + psrad xmm3,DESCALE_P2 + psrad xmm1,DESCALE_P2 + paddd xmm4,xmm2 + paddd xmm7,xmm2 + psrad xmm4,DESCALE_P2 + psrad xmm7,DESCALE_P2 + + packssdw xmm3,xmm1 ; xmm3=data1=(01 11 21 31 41 51 61 71) + packssdw xmm4,xmm7 ; xmm4=data6=(06 16 26 36 46 56 66 76) + + packsswb xmm5,xmm4 ; xmm5=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + packsswb xmm3,xmm0 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + movdqa xmm6, XMMWORD [wk(6)] ; xmm6=tmp12L + movdqa xmm2, XMMWORD [wk(7)] ; xmm2=tmp12H + movdqa xmm1, XMMWORD [wk(10)] ; xmm1=tmp1L + movdqa xmm7, XMMWORD [wk(11)] ; xmm7=tmp1H + + movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + movdqa xmm4,xmm6 + movdqa xmm0,xmm2 + paddd xmm6,xmm1 ; xmm6=data2L + paddd xmm2,xmm7 ; xmm2=data2H + psubd xmm4,xmm1 ; xmm4=data5L + psubd xmm0,xmm7 ; xmm0=data5H + + movdqa xmm5,[rel PD_DESCALE_P2] ; xmm5=[rel PD_DESCALE_P2] + + paddd xmm6,xmm5 + paddd xmm2,xmm5 + psrad xmm6,DESCALE_P2 + psrad xmm2,DESCALE_P2 + paddd xmm4,xmm5 + paddd xmm0,xmm5 + psrad xmm4,DESCALE_P2 + psrad xmm0,DESCALE_P2 + + packssdw xmm6,xmm2 ; xmm6=data2=(02 12 22 32 42 52 62 72) + packssdw xmm4,xmm0 ; xmm4=data5=(05 15 25 35 45 55 65 75) + + movdqa xmm3, XMMWORD [wk(2)] ; xmm3=tmp13L + movdqa xmm1, XMMWORD [wk(3)] ; xmm1=tmp13H + movdqa xmm7, XMMWORD [wk(8)] ; xmm7=tmp0L + movdqa xmm5, XMMWORD [wk(9)] ; xmm5=tmp0H + + movdqa xmm2,xmm3 + movdqa xmm0,xmm1 + paddd xmm3,xmm7 ; xmm3=data3L + paddd xmm1,xmm5 ; xmm1=data3H + psubd xmm2,xmm7 ; xmm2=data4L + psubd xmm0,xmm5 ; xmm0=data4H + + movdqa xmm7,[rel PD_DESCALE_P2] ; xmm7=[rel PD_DESCALE_P2] + + paddd xmm3,xmm7 + paddd xmm1,xmm7 + psrad xmm3,DESCALE_P2 + psrad xmm1,DESCALE_P2 + paddd xmm2,xmm7 + paddd xmm0,xmm7 + psrad xmm2,DESCALE_P2 + psrad xmm0,DESCALE_P2 + + movdqa xmm5,[rel PB_CENTERJSAMP] ; xmm5=[rel PB_CENTERJSAMP] + + packssdw xmm3,xmm1 ; xmm3=data3=(03 13 23 33 43 53 63 73) + packssdw xmm2,xmm0 ; xmm2=data4=(04 14 24 34 44 54 64 74) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) + movdqa xmm1, XMMWORD [wk(1)] ; xmm1=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) + + packsswb xmm6,xmm2 ; xmm6=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74) + packsswb xmm3,xmm4 ; xmm3=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75) + + paddb xmm7,xmm5 + paddb xmm1,xmm5 + paddb xmm6,xmm5 + paddb xmm3,xmm5 + + movdqa xmm0,xmm7 ; transpose coefficients(phase 1) + punpcklbw xmm7,xmm1 ; xmm7=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71) + punpckhbw xmm0,xmm1 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77) + movdqa xmm2,xmm6 ; transpose coefficients(phase 1) + punpcklbw xmm6,xmm3 ; xmm6=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73) + punpckhbw xmm2,xmm3 ; xmm2=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75) + + movdqa xmm4,xmm7 ; transpose coefficients(phase 2) + punpcklwd xmm7,xmm6 ; xmm7=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) + punpckhwd xmm4,xmm6 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73) + movdqa xmm5,xmm2 ; transpose coefficients(phase 2) + punpcklwd xmm2,xmm0 ; xmm2=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) + punpckhwd xmm5,xmm0 ; xmm5=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77) + + movdqa xmm1,xmm7 ; transpose coefficients(phase 3) + punpckldq xmm7,xmm2 ; xmm7=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) + punpckhdq xmm1,xmm2 ; xmm1=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) + movdqa xmm3,xmm4 ; transpose coefficients(phase 3) + punpckldq xmm4,xmm5 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57) + punpckhdq xmm3,xmm5 ; xmm3=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77) + + pshufd xmm6,xmm7,0x4E ; xmm6=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) + pshufd xmm0,xmm1,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) + pshufd xmm2,xmm4,0x4E ; xmm2=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47) + pshufd xmm5,xmm3,0x4E ; xmm5=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67) + + mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm7 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm1 + mov rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3 + + mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0 + mov rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW] + movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm2 + movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm5 + + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2red-64.asm b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2red-64.asm new file mode 100755 index 0000000..6807f17 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jiss2red-64.asm @@ -0,0 +1,576 @@ +; +; jiss2red-64.asm - reduced-size IDCT (64-bit SSE2) +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2009 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; For conditions of distribution and use, see copyright notice in jsimdext.inc +; +; This file should be assembled with NASM (Netwide Assembler), +; can *not* be assembled with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). +; NASM is available from http://nasm.sourceforge.net/ or +; http://sourceforge.net/project/showfiles.php?group_id=6208 +; +; This file contains inverse-DCT routines that produce reduced-size +; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. +; The following code is based directly on the IJG's original jidctred.c; +; see the jidctred.c for more details. +; +; [TAB8] + +%include "jsimdext.inc" +%include "jdct.inc" + +; -------------------------------------------------------------------------- + +%define CONST_BITS 13 +%define PASS1_BITS 2 + +%define DESCALE_P1_4 (CONST_BITS-PASS1_BITS+1) +%define DESCALE_P2_4 (CONST_BITS+PASS1_BITS+3+1) +%define DESCALE_P1_2 (CONST_BITS-PASS1_BITS+2) +%define DESCALE_P2_2 (CONST_BITS+PASS1_BITS+3+2) + +%if CONST_BITS == 13 +F_0_211 equ 1730 ; FIX(0.211164243) +F_0_509 equ 4176 ; FIX(0.509795579) +F_0_601 equ 4926 ; FIX(0.601344887) +F_0_720 equ 5906 ; FIX(0.720959822) +F_0_765 equ 6270 ; FIX(0.765366865) +F_0_850 equ 6967 ; FIX(0.850430095) +F_0_899 equ 7373 ; FIX(0.899976223) +F_1_061 equ 8697 ; FIX(1.061594337) +F_1_272 equ 10426 ; FIX(1.272758580) +F_1_451 equ 11893 ; FIX(1.451774981) +F_1_847 equ 15137 ; FIX(1.847759065) +F_2_172 equ 17799 ; FIX(2.172734803) +F_2_562 equ 20995 ; FIX(2.562915447) +F_3_624 equ 29692 ; FIX(3.624509785) +%else +; NASM cannot do compile-time arithmetic on floating-point constants. +%define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) +F_0_211 equ DESCALE( 226735879,30-CONST_BITS) ; FIX(0.211164243) +F_0_509 equ DESCALE( 547388834,30-CONST_BITS) ; FIX(0.509795579) +F_0_601 equ DESCALE( 645689155,30-CONST_BITS) ; FIX(0.601344887) +F_0_720 equ DESCALE( 774124714,30-CONST_BITS) ; FIX(0.720959822) +F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) +F_0_850 equ DESCALE( 913142361,30-CONST_BITS) ; FIX(0.850430095) +F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) +F_1_061 equ DESCALE(1139878239,30-CONST_BITS) ; FIX(1.061594337) +F_1_272 equ DESCALE(1366614119,30-CONST_BITS) ; FIX(1.272758580) +F_1_451 equ DESCALE(1558831516,30-CONST_BITS) ; FIX(1.451774981) +F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) +F_2_172 equ DESCALE(2332956230,30-CONST_BITS) ; FIX(2.172734803) +F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) +F_3_624 equ DESCALE(3891787747,30-CONST_BITS) ; FIX(3.624509785) +%endif + +; -------------------------------------------------------------------------- + SECTION SEG_CONST + + alignz 16 + global EXTN(jconst_idct_red_sse2) + +EXTN(jconst_idct_red_sse2): + +PW_F184_MF076 times 4 dw F_1_847,-F_0_765 +PW_F256_F089 times 4 dw F_2_562, F_0_899 +PW_F106_MF217 times 4 dw F_1_061,-F_2_172 +PW_MF060_MF050 times 4 dw -F_0_601,-F_0_509 +PW_F145_MF021 times 4 dw F_1_451,-F_0_211 +PW_F362_MF127 times 4 dw F_3_624,-F_1_272 +PW_F085_MF072 times 4 dw F_0_850,-F_0_720 +PD_DESCALE_P1_4 times 4 dd 1 << (DESCALE_P1_4-1) +PD_DESCALE_P2_4 times 4 dd 1 << (DESCALE_P2_4-1) +PD_DESCALE_P1_2 times 4 dd 1 << (DESCALE_P1_2-1) +PD_DESCALE_P2_2 times 4 dd 1 << (DESCALE_P2_2-1) +PB_CENTERJSAMP times 16 db CENTERJSAMPLE + + alignz 16 + +; -------------------------------------------------------------------------- + SECTION SEG_TEXT + BITS 64 +; +; Perform dequantization and inverse DCT on one block of coefficients, +; producing a reduced-size 4x4 output block. +; +; GLOBAL(void) +; jsimd_idct_4x4_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +; r10 = void * dct_table +; r11 = JCOEFPTR coef_block +; r12 = JSAMPARRAY output_buf +; r13 = JDIMENSION output_col + +%define original_rbp rbp+0 +%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] +%define WK_NUM 2 + + align 16 + global EXTN(jsimd_idct_4x4_sse2) + +EXTN(jsimd_idct_4x4_sse2): + push rbp + mov rax,rsp ; rax = original rbp + sub rsp, byte 4 + and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits + mov [rsp],rax + mov rbp,rsp ; rbp = aligned rbp + lea rsp, [wk(0)] + collect_args + + ; ---- Pass 1: process columns from input. + + mov rdx, r10 ; quantptr + mov rsi, r11 ; inptr + +%ifndef NO_ZERO_COLUMN_TEST_4X4_SSE2 + mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)] + or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)] + jnz short .columnDCT + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + por xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + por xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + por xmm0,xmm1 + packsswb xmm0,xmm0 + packsswb xmm0,xmm0 + movd eax,xmm0 + test rax,rax + jnz short .columnDCT + + ; -- AC terms all zero + + movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + psllw xmm0,PASS1_BITS + + movdqa xmm3,xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07) + punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03) + punpckhwd xmm3,xmm3 ; xmm3=(04 04 05 05 06 06 07 07) + + pshufd xmm1,xmm0,0x50 ; xmm1=[col0 col1]=(00 00 00 00 01 01 01 01) + pshufd xmm0,xmm0,0xFA ; xmm0=[col2 col3]=(02 02 02 02 03 03 03 03) + pshufd xmm6,xmm3,0x50 ; xmm6=[col4 col5]=(04 04 04 04 05 05 05 05) + pshufd xmm3,xmm3,0xFA ; xmm3=[col6 col7]=(06 06 06 06 07 07 07 07) + + jmp near .column_end +%endif +.columnDCT: + + ; -- Odd part + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + movdqa xmm4,xmm0 + movdqa xmm5,xmm0 + punpcklwd xmm4,xmm1 + punpckhwd xmm5,xmm1 + movdqa xmm0,xmm4 + movdqa xmm1,xmm5 + pmaddwd xmm4,[rel PW_F256_F089] ; xmm4=(tmp2L) + pmaddwd xmm5,[rel PW_F256_F089] ; xmm5=(tmp2H) + pmaddwd xmm0,[rel PW_F106_MF217] ; xmm0=(tmp0L) + pmaddwd xmm1,[rel PW_F106_MF217] ; xmm1=(tmp0H) + + movdqa xmm6,xmm2 + movdqa xmm7,xmm2 + punpcklwd xmm6,xmm3 + punpckhwd xmm7,xmm3 + movdqa xmm2,xmm6 + movdqa xmm3,xmm7 + pmaddwd xmm6,[rel PW_MF060_MF050] ; xmm6=(tmp2L) + pmaddwd xmm7,[rel PW_MF060_MF050] ; xmm7=(tmp2H) + pmaddwd xmm2,[rel PW_F145_MF021] ; xmm2=(tmp0L) + pmaddwd xmm3,[rel PW_F145_MF021] ; xmm3=(tmp0H) + + paddd xmm6,xmm4 ; xmm6=tmp2L + paddd xmm7,xmm5 ; xmm7=tmp2H + paddd xmm2,xmm0 ; xmm2=tmp0L + paddd xmm3,xmm1 ; xmm3=tmp0H + + movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp0L + movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=tmp0H + + ; -- Even part + + movdqa xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + movdqa xmm5, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] + movdqa xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] + pmullw xmm4, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm5, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm0, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + pxor xmm1,xmm1 + pxor xmm2,xmm2 + punpcklwd xmm1,xmm4 ; xmm1=tmp0L + punpckhwd xmm2,xmm4 ; xmm2=tmp0H + psrad xmm1,(16-CONST_BITS-1) ; psrad xmm1,16 & pslld xmm1,CONST_BITS+1 + psrad xmm2,(16-CONST_BITS-1) ; psrad xmm2,16 & pslld xmm2,CONST_BITS+1 + + movdqa xmm3,xmm5 ; xmm5=in2=z2 + punpcklwd xmm5,xmm0 ; xmm0=in6=z3 + punpckhwd xmm3,xmm0 + pmaddwd xmm5,[rel PW_F184_MF076] ; xmm5=tmp2L + pmaddwd xmm3,[rel PW_F184_MF076] ; xmm3=tmp2H + + movdqa xmm4,xmm1 + movdqa xmm0,xmm2 + paddd xmm1,xmm5 ; xmm1=tmp10L + paddd xmm2,xmm3 ; xmm2=tmp10H + psubd xmm4,xmm5 ; xmm4=tmp12L + psubd xmm0,xmm3 ; xmm0=tmp12H + + ; -- Final output stage + + movdqa xmm5,xmm1 + movdqa xmm3,xmm2 + paddd xmm1,xmm6 ; xmm1=data0L + paddd xmm2,xmm7 ; xmm2=data0H + psubd xmm5,xmm6 ; xmm5=data3L + psubd xmm3,xmm7 ; xmm3=data3H + + movdqa xmm6,[rel PD_DESCALE_P1_4] ; xmm6=[rel PD_DESCALE_P1_4] + + paddd xmm1,xmm6 + paddd xmm2,xmm6 + psrad xmm1,DESCALE_P1_4 + psrad xmm2,DESCALE_P1_4 + paddd xmm5,xmm6 + paddd xmm3,xmm6 + psrad xmm5,DESCALE_P1_4 + psrad xmm3,DESCALE_P1_4 + + packssdw xmm1,xmm2 ; xmm1=data0=(00 01 02 03 04 05 06 07) + packssdw xmm5,xmm3 ; xmm5=data3=(30 31 32 33 34 35 36 37) + + movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp0L + movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp0H + + movdqa xmm2,xmm4 + movdqa xmm3,xmm0 + paddd xmm4,xmm7 ; xmm4=data1L + paddd xmm0,xmm6 ; xmm0=data1H + psubd xmm2,xmm7 ; xmm2=data2L + psubd xmm3,xmm6 ; xmm3=data2H + + movdqa xmm7,[rel PD_DESCALE_P1_4] ; xmm7=[rel PD_DESCALE_P1_4] + + paddd xmm4,xmm7 + paddd xmm0,xmm7 + psrad xmm4,DESCALE_P1_4 + psrad xmm0,DESCALE_P1_4 + paddd xmm2,xmm7 + paddd xmm3,xmm7 + psrad xmm2,DESCALE_P1_4 + psrad xmm3,DESCALE_P1_4 + + packssdw xmm4,xmm0 ; xmm4=data1=(10 11 12 13 14 15 16 17) + packssdw xmm2,xmm3 ; xmm2=data2=(20 21 22 23 24 25 26 27) + + movdqa xmm6,xmm1 ; transpose coefficients(phase 1) + punpcklwd xmm1,xmm4 ; xmm1=(00 10 01 11 02 12 03 13) + punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17) + movdqa xmm7,xmm2 ; transpose coefficients(phase 1) + punpcklwd xmm2,xmm5 ; xmm2=(20 30 21 31 22 32 23 33) + punpckhwd xmm7,xmm5 ; xmm7=(24 34 25 35 26 36 27 37) + + movdqa xmm0,xmm1 ; transpose coefficients(phase 2) + punpckldq xmm1,xmm2 ; xmm1=[col0 col1]=(00 10 20 30 01 11 21 31) + punpckhdq xmm0,xmm2 ; xmm0=[col2 col3]=(02 12 22 32 03 13 23 33) + movdqa xmm3,xmm6 ; transpose coefficients(phase 2) + punpckldq xmm6,xmm7 ; xmm6=[col4 col5]=(04 14 24 34 05 15 25 35) + punpckhdq xmm3,xmm7 ; xmm3=[col6 col7]=(06 16 26 36 07 17 27 37) +.column_end: + + ; -- Prefetch the next coefficient block + + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows, store into output array. + + mov rax, [original_rbp] + mov rdi, r12 ; (JSAMPROW *) + mov rax, r13 + + ; -- Even part + + pxor xmm4,xmm4 + punpcklwd xmm4,xmm1 ; xmm4=tmp0 + psrad xmm4,(16-CONST_BITS-1) ; psrad xmm4,16 & pslld xmm4,CONST_BITS+1 + + ; -- Odd part + + punpckhwd xmm1,xmm0 + punpckhwd xmm6,xmm3 + movdqa xmm5,xmm1 + movdqa xmm2,xmm6 + pmaddwd xmm1,[rel PW_F256_F089] ; xmm1=(tmp2) + pmaddwd xmm6,[rel PW_MF060_MF050] ; xmm6=(tmp2) + pmaddwd xmm5,[rel PW_F106_MF217] ; xmm5=(tmp0) + pmaddwd xmm2,[rel PW_F145_MF021] ; xmm2=(tmp0) + + paddd xmm6,xmm1 ; xmm6=tmp2 + paddd xmm2,xmm5 ; xmm2=tmp0 + + ; -- Even part + + punpcklwd xmm0,xmm3 + pmaddwd xmm0,[rel PW_F184_MF076] ; xmm0=tmp2 + + movdqa xmm7,xmm4 + paddd xmm4,xmm0 ; xmm4=tmp10 + psubd xmm7,xmm0 ; xmm7=tmp12 + + ; -- Final output stage + + movdqa xmm1,[rel PD_DESCALE_P2_4] ; xmm1=[rel PD_DESCALE_P2_4] + + movdqa xmm5,xmm4 + movdqa xmm3,xmm7 + paddd xmm4,xmm6 ; xmm4=data0=(00 10 20 30) + paddd xmm7,xmm2 ; xmm7=data1=(01 11 21 31) + psubd xmm5,xmm6 ; xmm5=data3=(03 13 23 33) + psubd xmm3,xmm2 ; xmm3=data2=(02 12 22 32) + + paddd xmm4,xmm1 + paddd xmm7,xmm1 + psrad xmm4,DESCALE_P2_4 + psrad xmm7,DESCALE_P2_4 + paddd xmm5,xmm1 + paddd xmm3,xmm1 + psrad xmm5,DESCALE_P2_4 + psrad xmm3,DESCALE_P2_4 + + packssdw xmm4,xmm3 ; xmm4=(00 10 20 30 02 12 22 32) + packssdw xmm7,xmm5 ; xmm7=(01 11 21 31 03 13 23 33) + + movdqa xmm0,xmm4 ; transpose coefficients(phase 1) + punpcklwd xmm4,xmm7 ; xmm4=(00 01 10 11 20 21 30 31) + punpckhwd xmm0,xmm7 ; xmm0=(02 03 12 13 22 23 32 33) + + movdqa xmm6,xmm4 ; transpose coefficients(phase 2) + punpckldq xmm4,xmm0 ; xmm4=(00 01 02 03 10 11 12 13) + punpckhdq xmm6,xmm0 ; xmm6=(20 21 22 23 30 31 32 33) + + packsswb xmm4,xmm6 ; xmm4=(00 01 02 03 10 11 12 13 20 ..) + paddb xmm4,[rel PB_CENTERJSAMP] + + pshufd xmm2,xmm4,0x39 ; xmm2=(10 11 12 13 20 21 22 23 30 ..) + pshufd xmm1,xmm4,0x4E ; xmm1=(20 21 22 23 30 31 32 33 00 ..) + pshufd xmm3,xmm4,0x93 ; xmm3=(30 31 32 33 00 01 02 03 10 ..) + + mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] + movd XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4 + movd XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2 + mov rdx, JSAMPROW [rdi+2*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW] + movd XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1 + movd XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3 + + uncollect_args + mov rsp,rbp ; rsp <- aligned rbp + pop rsp ; rsp <- original rbp + pop rbp + ret + + +; -------------------------------------------------------------------------- +; +; Perform dequantization and inverse DCT on one block of coefficients, +; producing a reduced-size 2x2 output block. +; +; GLOBAL(void) +; jsimd_idct_2x2_sse2 (void * dct_table, JCOEFPTR coef_block, +; JSAMPARRAY output_buf, JDIMENSION output_col) +; + +; r10 = void * dct_table +; r11 = JCOEFPTR coef_block +; r12 = JSAMPARRAY output_buf +; r13 = JDIMENSION output_col + + align 16 + global EXTN(jsimd_idct_2x2_sse2) + +EXTN(jsimd_idct_2x2_sse2): + push rbp + mov rax,rsp + mov rbp,rsp + collect_args + push rbx + + ; ---- Pass 1: process columns from input. + + mov rdx, r10 ; quantptr + mov rsi, r11 ; inptr + + ; | input: | result: | + ; | 00 01 ** 03 ** 05 ** 07 | | + ; | 10 11 ** 13 ** 15 ** 17 | | + ; | ** ** ** ** ** ** ** ** | | + ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 | + ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 | + ; | 50 51 ** 53 ** 55 ** 57 | | + ; | ** ** ** ** ** ** ** ** | | + ; | 70 71 ** 73 ** 75 ** 77 | | + + ; -- Odd part + + movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] + movdqa xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] + pmullw xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + movdqa xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] + movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] + pmullw xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + ; xmm0=(10 11 ** 13 ** 15 ** 17), xmm1=(30 31 ** 33 ** 35 ** 37) + ; xmm2=(50 51 ** 53 ** 55 ** 57), xmm3=(70 71 ** 73 ** 75 ** 77) + + pcmpeqd xmm7,xmm7 + pslld xmm7,WORD_BIT ; xmm7={0x0000 0xFFFF 0x0000 0xFFFF ..} + + movdqa xmm4,xmm0 ; xmm4=(10 11 ** 13 ** 15 ** 17) + movdqa xmm5,xmm2 ; xmm5=(50 51 ** 53 ** 55 ** 57) + punpcklwd xmm4,xmm1 ; xmm4=(10 30 11 31 ** ** 13 33) + punpcklwd xmm5,xmm3 ; xmm5=(50 70 51 71 ** ** 53 73) + pmaddwd xmm4,[rel PW_F362_MF127] + pmaddwd xmm5,[rel PW_F085_MF072] + + psrld xmm0,WORD_BIT ; xmm0=(11 -- 13 -- 15 -- 17 --) + pand xmm1,xmm7 ; xmm1=(-- 31 -- 33 -- 35 -- 37) + psrld xmm2,WORD_BIT ; xmm2=(51 -- 53 -- 55 -- 57 --) + pand xmm3,xmm7 ; xmm3=(-- 71 -- 73 -- 75 -- 77) + por xmm0,xmm1 ; xmm0=(11 31 13 33 15 35 17 37) + por xmm2,xmm3 ; xmm2=(51 71 53 73 55 75 57 77) + pmaddwd xmm0,[rel PW_F362_MF127] + pmaddwd xmm2,[rel PW_F085_MF072] + + paddd xmm4,xmm5 ; xmm4=tmp0[col0 col1 **** col3] + paddd xmm0,xmm2 ; xmm0=tmp0[col1 col3 col5 col7] + + ; -- Even part + + movdqa xmm6, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] + pmullw xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] + + ; xmm6=(00 01 ** 03 ** 05 ** 07) + + movdqa xmm1,xmm6 ; xmm1=(00 01 ** 03 ** 05 ** 07) + pslld xmm6,WORD_BIT ; xmm6=(-- 00 -- ** -- ** -- **) + pand xmm1,xmm7 ; xmm1=(-- 01 -- 03 -- 05 -- 07) + psrad xmm6,(WORD_BIT-CONST_BITS-2) ; xmm6=tmp10[col0 **** **** ****] + psrad xmm1,(WORD_BIT-CONST_BITS-2) ; xmm1=tmp10[col1 col3 col5 col7] + + ; -- Final output stage + + movdqa xmm3,xmm6 + movdqa xmm5,xmm1 + paddd xmm6,xmm4 ; xmm6=data0[col0 **** **** ****]=(A0 ** ** **) + paddd xmm1,xmm0 ; xmm1=data0[col1 col3 col5 col7]=(A1 A3 A5 A7) + psubd xmm3,xmm4 ; xmm3=data1[col0 **** **** ****]=(B0 ** ** **) + psubd xmm5,xmm0 ; xmm5=data1[col1 col3 col5 col7]=(B1 B3 B5 B7) + + movdqa xmm2,[rel PD_DESCALE_P1_2] ; xmm2=[rel PD_DESCALE_P1_2] + + punpckldq xmm6,xmm3 ; xmm6=(A0 B0 ** **) + + movdqa xmm7,xmm1 + punpcklqdq xmm1,xmm5 ; xmm1=(A1 A3 B1 B3) + punpckhqdq xmm7,xmm5 ; xmm7=(A5 A7 B5 B7) + + paddd xmm6,xmm2 + psrad xmm6,DESCALE_P1_2 + + paddd xmm1,xmm2 + paddd xmm7,xmm2 + psrad xmm1,DESCALE_P1_2 + psrad xmm7,DESCALE_P1_2 + + ; -- Prefetch the next coefficient block + + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32] + prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32] + + ; ---- Pass 2: process rows, store into output array. + + mov rdi, r12 ; (JSAMPROW *) + mov rax, r13 + + ; | input:| result:| + ; | A0 B0 | | + ; | A1 B1 | C0 C1 | + ; | A3 B3 | D0 D1 | + ; | A5 B5 | | + ; | A7 B7 | | + + ; -- Odd part + + packssdw xmm1,xmm1 ; xmm1=(A1 A3 B1 B3 A1 A3 B1 B3) + packssdw xmm7,xmm7 ; xmm7=(A5 A7 B5 B7 A5 A7 B5 B7) + pmaddwd xmm1,[rel PW_F362_MF127] + pmaddwd xmm7,[rel PW_F085_MF072] + + paddd xmm1,xmm7 ; xmm1=tmp0[row0 row1 row0 row1] + + ; -- Even part + + pslld xmm6,(CONST_BITS+2) ; xmm6=tmp10[row0 row1 **** ****] + + ; -- Final output stage + + movdqa xmm4,xmm6 + paddd xmm6,xmm1 ; xmm6=data0[row0 row1 **** ****]=(C0 C1 ** **) + psubd xmm4,xmm1 ; xmm4=data1[row0 row1 **** ****]=(D0 D1 ** **) + + punpckldq xmm6,xmm4 ; xmm6=(C0 D0 C1 D1) + + paddd xmm6,[rel PD_DESCALE_P2_2] + psrad xmm6,DESCALE_P2_2 + + packssdw xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1) + packsswb xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1 ..) + paddb xmm6,[rel PB_CENTERJSAMP] + + pextrw ebx,xmm6,0x00 ; ebx=(C0 D0 -- --) + pextrw ecx,xmm6,0x01 ; ecx=(C1 D1 -- --) + + mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] + mov rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] + mov WORD [rdx+rax*SIZEOF_JSAMPLE], bx + mov WORD [rsi+rax*SIZEOF_JSAMPLE], cx + + pop rbx + uncollect_args + pop rbp + ret + +; For some reason, the OS X linker does not honor the request to align the +; segment unless we do this. + align 16 diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimd.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimd.h new file mode 100755 index 0000000..3d4751f --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimd.h @@ -0,0 +1,670 @@ +/* + * simd/jsimd.h + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + */ + +/* Bitmask for supported acceleration methods */ + +#define JSIMD_NONE 0x00 +#define JSIMD_MMX 0x01 +#define JSIMD_3DNOW 0x02 +#define JSIMD_SSE 0x04 +#define JSIMD_SSE2 0x08 +#define JSIMD_ARM_NEON 0x10 + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_simd_cpu_support jSiCpuSupport +#define jsimd_rgb_ycc_convert_mmx jSRGBYCCM +#define jsimd_extrgb_ycc_convert_mmx jSEXTRGBYCCM +#define jsimd_extrgbx_ycc_convert_mmx jSEXTRGBXYCCM +#define jsimd_extbgr_ycc_convert_mmx jSEXTBGRYCCM +#define jsimd_extbgrx_ycc_convert_mmx jSEXTBGRXYCCM +#define jsimd_extxbgr_ycc_convert_mmx jSEXTXBGRYCCM +#define jsimd_extxrgb_ycc_convert_mmx jSEXTXRGBYCCM +#define jsimd_rgb_gray_convert_mmx jSRGBGRYM +#define jsimd_extrgb_gray_convert_mmx jSEXTRGBGRYM +#define jsimd_extrgbx_gray_convert_mmx jSEXTRGBXGRYM +#define jsimd_extbgr_gray_convert_mmx jSEXTBGRGRYM +#define jsimd_extbgrx_gray_convert_mmx jSEXTBGRXGRYM +#define jsimd_extxbgr_gray_convert_mmx jSEXTXBGRGRYM +#define jsimd_extxrgb_gray_convert_mmx jSEXTXRGBGRYM +#define jsimd_ycc_rgb_convert_mmx jSYCCRGBM +#define jsimd_ycc_extrgb_convert_mmx jSYCCEXTRGBM +#define jsimd_ycc_extrgbx_convert_mmx jSYCCEXTRGBXM +#define jsimd_ycc_extbgr_convert_mmx jSYCCEXTBGRM +#define jsimd_ycc_extbgrx_convert_mmx jSYCCEXTBGRXM +#define jsimd_ycc_extxbgr_convert_mmx jSYCCEXTXBGRM +#define jsimd_ycc_extxrgb_convert_mmx jSYCCEXTXRGBM +#define jconst_rgb_ycc_convert_sse2 jSCRGBYCCS2 +#define jsimd_rgb_ycc_convert_sse2 jSRGBYCCS2 +#define jsimd_extrgb_ycc_convert_sse2 jSEXTRGBYCCS2 +#define jsimd_extrgbx_ycc_convert_sse2 jSEXTRGBXYCCS2 +#define jsimd_extbgr_ycc_convert_sse2 jSEXTBGRYCCS2 +#define jsimd_extbgrx_ycc_convert_sse2 jSEXTBGRXYCCS2 +#define jsimd_extxbgr_ycc_convert_sse2 jSEXTXBGRYCCS2 +#define jsimd_extxrgb_ycc_convert_sse2 jSEXTXRGBYCCS2 +#define jconst_rgb_gray_convert_sse2 jSCRGBGRYS2 +#define jsimd_rgb_gray_convert_sse2 jSRGBGRYS2 +#define jsimd_extrgb_gray_convert_sse2 jSEXTRGBGRYS2 +#define jsimd_extrgbx_gray_convert_sse2 jSEXTRGBXGRYS2 +#define jsimd_extbgr_gray_convert_sse2 jSEXTBGRGRYS2 +#define jsimd_extbgrx_gray_convert_sse2 jSEXTBGRXGRYS2 +#define jsimd_extxbgr_gray_convert_sse2 jSEXTXBGRGRYS2 +#define jsimd_extxrgb_gray_convert_sse2 jSEXTXRGBGRYS2 +#define jconst_ycc_rgb_convert_sse2 jSCYCCRGBS2 +#define jsimd_ycc_rgb_convert_sse2 jSYCCRGBS2 +#define jsimd_ycc_extrgb_convert_sse2 jSYCCEXTRGBS2 +#define jsimd_ycc_extrgbx_convert_sse2 jSYCCEXTRGBXS2 +#define jsimd_ycc_extbgr_convert_sse2 jSYCCEXTBGRS2 +#define jsimd_ycc_extbgrx_convert_sse2 jSYCCEXTBGRXS2 +#define jsimd_ycc_extxbgr_convert_sse2 jSYCCEXTXBGRS2 +#define jsimd_ycc_extxrgb_convert_sse2 jSYCCEXTXRGBS2 +#define jsimd_h2v2_downsample_mmx jSDnH2V2M +#define jsimd_h2v1_downsample_mmx jSDnH2V1M +#define jsimd_h2v2_downsample_sse2 jSDnH2V2S2 +#define jsimd_h2v1_downsample_sse2 jSDnH2V1S2 +#define jsimd_h2v2_upsample_mmx jSUpH2V2M +#define jsimd_h2v1_upsample_mmx jSUpH2V1M +#define jsimd_h2v2_fancy_upsample_mmx jSFUpH2V2M +#define jsimd_h2v1_fancy_upsample_mmx jSFUpH2V1M +#define jsimd_h2v2_merged_upsample_mmx jSMUpH2V2M +#define jsimd_h2v2_extrgb_merged_upsample_mmx jSMUpH2V2EXTRGBM +#define jsimd_h2v2_extrgbx_merged_upsample_mmx jSMUpH2V2EXTRGBXM +#define jsimd_h2v2_extbgr_merged_upsample_mmx jSMUpH2V2EXTBGRM +#define jsimd_h2v2_extbgrx_merged_upsample_mmx jSMUpH2V2EXTBGRXM +#define jsimd_h2v2_extxbgr_merged_upsample_mmx jSMUpH2V2EXTXBGRM +#define jsimd_h2v2_extxrgb_merged_upsample_mmx jSMUpH2V2EXTXRGBM +#define jsimd_h2v1_merged_upsample_mmx jSMUpH2V1M +#define jsimd_h2v1_extrgb_merged_upsample_mmx jSMUpH2V1EXTRGBM +#define jsimd_h2v1_extrgbx_merged_upsample_mmx jSMUpH2V1EXTRGBXM +#define jsimd_h2v1_extbgr_merged_upsample_mmx jSMUpH2V1EXTBGRM +#define jsimd_h2v1_extbgrx_merged_upsample_mmx jSMUpH2V1EXTBGRXM +#define jsimd_h2v1_extxbgr_merged_upsample_mmx jSMUpH2V1EXTXBGRM +#define jsimd_h2v1_extxrgb_merged_upsample_mmx jSMUpH2V1EXTXRGBM +#define jsimd_h2v2_upsample_sse2 jSUpH2V2S2 +#define jsimd_h2v1_upsample_sse2 jSUpH2V1S2 +#define jconst_fancy_upsample_sse2 jSCFUpS2 +#define jsimd_h2v2_fancy_upsample_sse2 jSFUpH2V2S2 +#define jsimd_h2v1_fancy_upsample_sse2 jSFUpH2V1S2 +#define jconst_merged_upsample_sse2 jSCMUpS2 +#define jsimd_h2v2_merged_upsample_sse2 jSMUpH2V2S2 +#define jsimd_h2v2_extrgb_merged_upsample_sse2 jSMUpH2V2EXTRGBS2 +#define jsimd_h2v2_extrgbx_merged_upsample_sse2 jSMUpH2V2EXTRGBXS2 +#define jsimd_h2v2_extbgr_merged_upsample_sse2 jSMUpH2V2EXTBGRS2 +#define jsimd_h2v2_extbgrx_merged_upsample_sse2 jSMUpH2V2EXTBGRXS2 +#define jsimd_h2v2_extxbgr_merged_upsample_sse2 jSMUpH2V2EXTXBGRS2 +#define jsimd_h2v2_extxrgb_merged_upsample_sse2 jSMUpH2V2EXTXRGBS2 +#define jsimd_h2v1_merged_upsample_sse2 jSMUpH2V1S2 +#define jsimd_h2v1_extrgb_merged_upsample_sse2 jSMUpH2V1EXTRGBS2 +#define jsimd_h2v1_extrgbx_merged_upsample_sse2 jSMUpH2V1EXTRGBXS2 +#define jsimd_h2v1_extbgr_merged_upsample_sse2 jSMUpH2V1EXTBGRS2 +#define jsimd_h2v1_extbgrx_merged_upsample_sse2 jSMUpH2V1EXTBGRXS2 +#define jsimd_h2v1_extxbgr_merged_upsample_sse2 jSMUpH2V1EXTXBGRS2 +#define jsimd_h2v1_extxrgb_merged_upsample_sse2 jSMUpH2V1EXTXRGBS2 +#define jsimd_convsamp_mmx jSConvM +#define jsimd_convsamp_sse2 jSConvS2 +#define jsimd_convsamp_float_3dnow jSConvF3D +#define jsimd_convsamp_float_sse jSConvFS +#define jsimd_convsamp_float_sse2 jSConvFS2 +#define jsimd_fdct_islow_mmx jSFDMIS +#define jsimd_fdct_ifast_mmx jSFDMIF +#define jconst_fdct_islow_sse2 jSCFDS2IS +#define jsimd_fdct_islow_sse2 jSFDS2IS +#define jconst_fdct_ifast_sse2 jSCFDS2IF +#define jsimd_fdct_ifast_sse2 jSFDS2IF +#define jsimd_fdct_float_3dnow jSFD3DF +#define jconst_fdct_float_sse jSCFDSF +#define jsimd_fdct_float_sse jSFDSF +#define jsimd_quantize_mmx jSQuantM +#define jsimd_quantize_sse2 jSQuantS2 +#define jsimd_quantize_float_3dnow jSQuantF3D +#define jsimd_quantize_float_sse jSQuantFS +#define jsimd_quantize_float_sse2 jSQuantFS2 +#define jsimd_idct_2x2_mmx jSIDM22 +#define jsimd_idct_4x4_mmx jSIDM44 +#define jconst_idct_red_sse2 jSCIDS2R +#define jsimd_idct_2x2_sse2 jSIDS222 +#define jsimd_idct_4x4_sse2 jSIDS244 +#define jsimd_idct_islow_mmx jSIDMIS +#define jsimd_idct_ifast_mmx jSIDMIF +#define jconst_idct_islow_sse2 jSCIDS2IS +#define jsimd_idct_islow_sse2 jSIDS2IS +#define jconst_idct_ifast_sse2 jSCIDS2IF +#define jsimd_idct_ifast_sse2 jSIDS2IF +#define jsimd_idct_float_3dnow jSID3DF +#define jconst_fdct_float_sse jSCIDSF +#define jsimd_idct_float_sse jSIDSF +#define jconst_fdct_float_sse2 jSCIDS2F +#define jsimd_idct_float_sse2 jSIDS2F +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + +/* SIMD Ext: retrieve SIMD/CPU information */ +EXTERN(unsigned int) jpeg_simd_cpu_support JPP((void)); + +/* SIMD Color Space Conversion */ +EXTERN(void) jsimd_rgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_rgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_gray_convert_mmx + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_ycc_rgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_mmx + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +extern const int jconst_rgb_ycc_convert_sse2[]; +EXTERN(void) jsimd_rgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +extern const int jconst_rgb_gray_convert_sse2[]; +EXTERN(void) jsimd_rgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_gray_convert_sse2 + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +extern const int jconst_ycc_rgb_convert_sse2[]; +EXTERN(void) jsimd_ycc_rgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_sse2 + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +EXTERN(void) jsimd_rgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extrgbx_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgr_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extbgrx_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxbgr_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); +EXTERN(void) jsimd_extxrgb_ycc_convert_neon + JPP((JDIMENSION img_width, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + +EXTERN(void) jsimd_ycc_rgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extrgbx_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgr_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extbgrx_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxbgr_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); +EXTERN(void) jsimd_ycc_extxrgb_convert_neon + JPP((JDIMENSION out_width, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + +/* SIMD Downsample */ +EXTERN(void) jsimd_h2v2_downsample_mmx + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample_mmx + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +EXTERN(void) jsimd_h2v2_downsample_sse2 + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); +EXTERN(void) jsimd_h2v1_downsample_sse2 + JPP((JDIMENSION image_width, int max_v_samp_factor, + JDIMENSION v_samp_factor, JDIMENSION width_blocks, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + +/* SIMD Upsample */ +EXTERN(void) jsimd_h2v2_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(void) jsimd_h2v2_fancy_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample_mmx + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +EXTERN(void) jsimd_h2v2_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_mmx + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); + +EXTERN(void) jsimd_h2v2_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION output_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +extern const int jconst_fancy_upsample_sse2[]; +EXTERN(void) jsimd_h2v2_fancy_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); +EXTERN(void) jsimd_h2v1_fancy_upsample_sse2 + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +extern const int jconst_merged_upsample_sse2[]; +EXTERN(void) jsimd_h2v2_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); +EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_sse2 + JPP((JDIMENSION output_width, JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)); + +EXTERN(void) jsimd_h2v1_fancy_upsample_neon + JPP((int max_v_samp_factor, JDIMENSION downsampled_width, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + +/* SIMD Sample Conversion */ +EXTERN(void) jsimd_convsamp_mmx JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_sse2 JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_neon JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + DCTELEM * workspace)); + +EXTERN(void) jsimd_convsamp_float_3dnow JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_convsamp_float_sse JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_convsamp_float_sse2 JPP((JSAMPARRAY sample_data, + JDIMENSION start_col, + FAST_FLOAT * workspace)); + +/* SIMD Forward DCT */ +EXTERN(void) jsimd_fdct_islow_mmx JPP((DCTELEM * data)); +EXTERN(void) jsimd_fdct_ifast_mmx JPP((DCTELEM * data)); + +extern const int jconst_fdct_ifast_sse2[]; +EXTERN(void) jsimd_fdct_islow_sse2 JPP((DCTELEM * data)); +extern const int jconst_fdct_islow_sse2[]; +EXTERN(void) jsimd_fdct_ifast_sse2 JPP((DCTELEM * data)); + +EXTERN(void) jsimd_fdct_ifast_neon JPP((DCTELEM * data)); + +EXTERN(void) jsimd_fdct_float_3dnow JPP((FAST_FLOAT * data)); + +extern const int jconst_fdct_float_sse[]; +EXTERN(void) jsimd_fdct_float_sse JPP((FAST_FLOAT * data)); + +/* SIMD Quantization */ +EXTERN(void) jsimd_quantize_mmx JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_sse2 JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_neon JPP((JCOEFPTR coef_block, + DCTELEM * divisors, + DCTELEM * workspace)); + +EXTERN(void) jsimd_quantize_float_3dnow JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_quantize_float_sse JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +EXTERN(void) jsimd_quantize_float_sse2 JPP((JCOEFPTR coef_block, + FAST_FLOAT * divisors, + FAST_FLOAT * workspace)); + +/* SIMD Reduced Inverse DCT */ +EXTERN(void) jsimd_idct_2x2_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_red_sse2[]; +EXTERN(void) jsimd_idct_2x2_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_2x2_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_4x4_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +/* SIMD Inverse DCT */ +EXTERN(void) jsimd_idct_islow_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast_mmx JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_islow_sse2[]; +EXTERN(void) jsimd_idct_islow_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +extern const int jconst_idct_ifast_sse2[]; +EXTERN(void) jsimd_idct_ifast_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_islow_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); +EXTERN(void) jsimd_idct_ifast_neon JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +EXTERN(void) jsimd_idct_float_3dnow JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_float_sse[]; +EXTERN(void) jsimd_idct_float_sse JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + +extern const int jconst_idct_float_sse2[]; +EXTERN(void) jsimd_idct_float_sse2 JPP((void * dct_table, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, + JDIMENSION output_col)); + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimd_x86_64.c b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimd_x86_64.c new file mode 100755 index 0000000..8d17db3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimd_x86_64.c @@ -0,0 +1,753 @@ +/* + * jsimd_x86_64.c + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2009-2011 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + * This file contains the interface between the "normal" portions + * of the library and the SIMD implementations when running on a + * x86_64 architecture. + */ + +#define JPEG_INTERNALS +#include "../jinclude.h" +#include "../jpeglib.h" +#include "../jsimd.h" +#include "../jdct.h" +#include "../jsimddct.h" +#include "jsimd.h" + +/* + * In the PIC cases, we have no guarantee that constants will keep + * their alignment. This macro allows us to verify it at runtime. + */ +#define IS_ALIGNED(ptr, order) (((size_t)ptr & ((1 << order) - 1)) == 0) + +#define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */ + +GLOBAL(int) +jsimd_can_rgb_ycc (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + + if (!IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_rgb_gray (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + + if (!IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_ycc_rgb (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + + if (!IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2)) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_rgb_ycc_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); + + switch(cinfo->in_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_extrgb_ycc_convert_sse2; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_extrgbx_ycc_convert_sse2; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_extbgr_ycc_convert_sse2; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_extbgrx_ycc_convert_sse2; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_extxbgr_ycc_convert_sse2; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_extxrgb_ycc_convert_sse2; + break; + default: + sse2fct=jsimd_rgb_ycc_convert_sse2; + break; + } + + sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows); +} + +GLOBAL(void) +jsimd_rgb_gray_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ + void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int); + + switch(cinfo->in_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_extrgb_gray_convert_sse2; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_extrgbx_gray_convert_sse2; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_extbgr_gray_convert_sse2; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_extbgrx_gray_convert_sse2; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_extxbgr_gray_convert_sse2; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_extxrgb_gray_convert_sse2; + break; + default: + sse2fct=jsimd_rgb_gray_convert_sse2; + break; + } + + sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows); +} + +GLOBAL(void) +jsimd_ycc_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_ycc_extrgb_convert_sse2; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_ycc_extrgbx_convert_sse2; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_ycc_extbgr_convert_sse2; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_ycc_extbgrx_convert_sse2; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_ycc_extxbgr_convert_sse2; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_ycc_extxrgb_convert_sse2; + break; + default: + sse2fct=jsimd_ycc_rgb_convert_sse2; + break; + } + + sse2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows); +} + +GLOBAL(int) +jsimd_can_h2v2_downsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_h2v1_downsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + jsimd_h2v2_downsample_sse2(cinfo->image_width, + cinfo->max_v_samp_factor, + compptr->v_samp_factor, + compptr->width_in_blocks, + input_data, output_data); +} + +GLOBAL(void) +jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ + jsimd_h2v1_downsample_sse2(cinfo->image_width, + cinfo->max_v_samp_factor, + compptr->v_samp_factor, + compptr->width_in_blocks, + input_data, output_data); +} + +GLOBAL(int) +jsimd_can_h2v2_upsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_h2v1_upsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_h2v2_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor, + cinfo->output_width, + input_data, output_data_ptr); +} + +GLOBAL(void) +jsimd_h2v1_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor, + cinfo->output_width, + input_data, output_data_ptr); +} + +GLOBAL(int) +jsimd_can_h2v2_fancy_upsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (!IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_h2v1_fancy_upsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (!IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor, + compptr->downsampled_width, + input_data, output_data_ptr); +} + +GLOBAL(void) +jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ + jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor, + compptr->downsampled_width, + input_data, output_data_ptr); +} + +GLOBAL(int) +jsimd_can_h2v2_merged_upsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (!IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_h2v1_merged_upsample (void) +{ + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + + if (!IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_h2v2_extrgb_merged_upsample_sse2; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_h2v2_extrgbx_merged_upsample_sse2; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_h2v2_extbgr_merged_upsample_sse2; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_h2v2_extbgrx_merged_upsample_sse2; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_h2v2_extxbgr_merged_upsample_sse2; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_h2v2_extxrgb_merged_upsample_sse2; + break; + default: + sse2fct=jsimd_h2v2_merged_upsample_sse2; + break; + } + + sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf); +} + +GLOBAL(void) +jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ + void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + sse2fct=jsimd_h2v1_extrgb_merged_upsample_sse2; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + sse2fct=jsimd_h2v1_extrgbx_merged_upsample_sse2; + break; + case JCS_EXT_BGR: + sse2fct=jsimd_h2v1_extbgr_merged_upsample_sse2; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + sse2fct=jsimd_h2v1_extbgrx_merged_upsample_sse2; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + sse2fct=jsimd_h2v1_extxbgr_merged_upsample_sse2; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + sse2fct=jsimd_h2v1_extxrgb_merged_upsample_sse2; + break; + default: + sse2fct=jsimd_h2v1_merged_upsample_sse2; + break; + } + + sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf); +} + +GLOBAL(int) +jsimd_can_convsamp (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_convsamp_float (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, + DCTELEM * workspace) +{ + jsimd_convsamp_sse2(sample_data, start_col, workspace); +} + +GLOBAL(void) +jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, + FAST_FLOAT * workspace) +{ + jsimd_convsamp_float_sse2(sample_data, start_col, workspace); +} + +GLOBAL(int) +jsimd_can_fdct_islow (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if (!IS_ALIGNED_SSE(jconst_fdct_islow_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_fdct_ifast (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + if (!IS_ALIGNED_SSE(jconst_fdct_ifast_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_fdct_float (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + + if (!IS_ALIGNED_SSE(jconst_fdct_float_sse)) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_fdct_islow (DCTELEM * data) +{ + jsimd_fdct_islow_sse2(data); +} + +GLOBAL(void) +jsimd_fdct_ifast (DCTELEM * data) +{ + jsimd_fdct_ifast_sse2(data); +} + +GLOBAL(void) +jsimd_fdct_float (FAST_FLOAT * data) +{ + jsimd_fdct_float_sse(data); +} + +GLOBAL(int) +jsimd_can_quantize (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (sizeof(DCTELEM) != 2) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_quantize_float (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors, + DCTELEM * workspace) +{ + jsimd_quantize_sse2(coef_block, divisors, workspace); +} + +GLOBAL(void) +jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, + FAST_FLOAT * workspace) +{ + jsimd_quantize_float_sse2(coef_block, divisors, workspace); +} + +GLOBAL(int) +jsimd_can_idct_2x2 (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if (!IS_ALIGNED_SSE(jconst_idct_red_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_idct_4x4 (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if (!IS_ALIGNED_SSE(jconst_idct_red_sse2)) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(int) +jsimd_can_idct_islow (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if (!IS_ALIGNED_SSE(jconst_idct_islow_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_idct_ifast (void) +{ + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(IFAST_MULT_TYPE) != 2) + return 0; + if (IFAST_SCALE_BITS != 2) + return 0; + + if (!IS_ALIGNED_SSE(jconst_idct_ifast_sse2)) + return 0; + + return 1; +} + +GLOBAL(int) +jsimd_can_idct_float (void) +{ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(FAST_FLOAT) != 4) + return 0; + if (sizeof(FLOAT_MULT_TYPE) != 4) + return 0; + + if (!IS_ALIGNED_SSE(jconst_idct_float_sse2)) + return 0; + + return 1; +} + +GLOBAL(void) +jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + jsimd_idct_float_sse2(compptr->dct_table, coef_block, + output_buf, output_col); +} + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimdcfg.inc.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimdcfg.inc.h new file mode 100755 index 0000000..583b7e3 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimdcfg.inc.h @@ -0,0 +1,196 @@ +// This file generates the include file for the assembly +// implementations by abusing the C preprocessor. +// +// Note: Some things are manually defined as they need to +// be mapped to NASM types. + +; +; Automatically generated include file from jsimdcfg.inc.h +; + +#define JPEG_INTERNALS + +#include "../jpeglib.h" +#include "../jconfig.h" +#include "../jmorecfg.h" +#include "jsimd.h" + +; +; -- jpeglib.h +; + +%define _cpp_protection_DCTSIZE DCTSIZE +%define _cpp_protection_DCTSIZE2 DCTSIZE2 + +; +; -- jmorecfg.h +; + +%define _cpp_protection_RGB_RED RGB_RED +%define _cpp_protection_RGB_GREEN RGB_GREEN +%define _cpp_protection_RGB_BLUE RGB_BLUE +%define _cpp_protection_RGB_PIXELSIZE RGB_PIXELSIZE + +%define _cpp_protection_EXT_RGB_RED EXT_RGB_RED +%define _cpp_protection_EXT_RGB_GREEN EXT_RGB_GREEN +%define _cpp_protection_EXT_RGB_BLUE EXT_RGB_BLUE +%define _cpp_protection_EXT_RGB_PIXELSIZE EXT_RGB_PIXELSIZE + +%define _cpp_protection_EXT_RGBX_RED EXT_RGBX_RED +%define _cpp_protection_EXT_RGBX_GREEN EXT_RGBX_GREEN +%define _cpp_protection_EXT_RGBX_BLUE EXT_RGBX_BLUE +%define _cpp_protection_EXT_RGBX_PIXELSIZE EXT_RGBX_PIXELSIZE + +%define _cpp_protection_EXT_BGR_RED EXT_BGR_RED +%define _cpp_protection_EXT_BGR_GREEN EXT_BGR_GREEN +%define _cpp_protection_EXT_BGR_BLUE EXT_BGR_BLUE +%define _cpp_protection_EXT_BGR_PIXELSIZE EXT_BGR_PIXELSIZE + +%define _cpp_protection_EXT_BGRX_RED EXT_BGRX_RED +%define _cpp_protection_EXT_BGRX_GREEN EXT_BGRX_GREEN +%define _cpp_protection_EXT_BGRX_BLUE EXT_BGRX_BLUE +%define _cpp_protection_EXT_BGRX_PIXELSIZE EXT_BGRX_PIXELSIZE + +%define _cpp_protection_EXT_XBGR_RED EXT_XBGR_RED +%define _cpp_protection_EXT_XBGR_GREEN EXT_XBGR_GREEN +%define _cpp_protection_EXT_XBGR_BLUE EXT_XBGR_BLUE +%define _cpp_protection_EXT_XBGR_PIXELSIZE EXT_XBGR_PIXELSIZE + +%define _cpp_protection_EXT_XRGB_RED EXT_XRGB_RED +%define _cpp_protection_EXT_XRGB_GREEN EXT_XRGB_GREEN +%define _cpp_protection_EXT_XRGB_BLUE EXT_XRGB_BLUE +%define _cpp_protection_EXT_XRGB_PIXELSIZE EXT_XRGB_PIXELSIZE + +%define RGBX_FILLER_0XFF 1 + +; Representation of a single sample (pixel element value). +; On this SIMD implementation, this must be 'unsigned char'. +; + +%define JSAMPLE byte ; unsigned char +%define SIZEOF_JSAMPLE SIZEOF_BYTE ; sizeof(JSAMPLE) + +%define _cpp_protection_CENTERJSAMPLE CENTERJSAMPLE + +; Representation of a DCT frequency coefficient. +; On this SIMD implementation, this must be 'short'. +; +%define JCOEF word ; short +%define SIZEOF_JCOEF SIZEOF_WORD ; sizeof(JCOEF) + +; Datatype used for image dimensions. +; On this SIMD implementation, this must be 'unsigned int'. +; +%define JDIMENSION dword ; unsigned int +%define SIZEOF_JDIMENSION SIZEOF_DWORD ; sizeof(JDIMENSION) + +%define JSAMPROW POINTER ; JSAMPLE FAR * (jpeglib.h) +%define JSAMPARRAY POINTER ; JSAMPROW * (jpeglib.h) +%define JSAMPIMAGE POINTER ; JSAMPARRAY * (jpeglib.h) +%define JCOEFPTR POINTER ; JCOEF FAR * (jpeglib.h) +%define SIZEOF_JSAMPROW SIZEOF_POINTER ; sizeof(JSAMPROW) +%define SIZEOF_JSAMPARRAY SIZEOF_POINTER ; sizeof(JSAMPARRAY) +%define SIZEOF_JSAMPIMAGE SIZEOF_POINTER ; sizeof(JSAMPIMAGE) +%define SIZEOF_JCOEFPTR SIZEOF_POINTER ; sizeof(JCOEFPTR) + +; +; -- jdct.h +; + +; A forward DCT routine is given a pointer to a work area of type DCTELEM[]; +; the DCT is to be performed in-place in that buffer. +; To maximize parallelism, Type DCTELEM is changed to short (originally, int). +; +%define DCTELEM word ; short +%define SIZEOF_DCTELEM SIZEOF_WORD ; sizeof(DCTELEM) + +%define FAST_FLOAT FP32 ; float +%define SIZEOF_FAST_FLOAT SIZEOF_FP32 ; sizeof(FAST_FLOAT) + +; To maximize parallelism, Type MULTIPLIER is changed to short. +; +%define ISLOW_MULT_TYPE word ; must be short +%define SIZEOF_ISLOW_MULT_TYPE SIZEOF_WORD ; sizeof(ISLOW_MULT_TYPE) + +%define IFAST_MULT_TYPE word ; must be short +%define SIZEOF_IFAST_MULT_TYPE SIZEOF_WORD ; sizeof(IFAST_MULT_TYPE) +%define IFAST_SCALE_BITS 2 ; fractional bits in scale factors + +%define FLOAT_MULT_TYPE FP32 ; must be float +%define SIZEOF_FLOAT_MULT_TYPE SIZEOF_FP32 ; sizeof(FLOAT_MULT_TYPE) + +; +; -- jsimd.h +; + +%define _cpp_protection_JSIMD_NONE JSIMD_NONE +%define _cpp_protection_JSIMD_MMX JSIMD_MMX +%define _cpp_protection_JSIMD_3DNOW JSIMD_3DNOW +%define _cpp_protection_JSIMD_SSE JSIMD_SSE +%define _cpp_protection_JSIMD_SSE2 JSIMD_SSE2 + +; Short forms of external names for systems with brain-damaged linkers. +; +#ifdef NEED_SHORT_EXTERNAL_NAMES +%define _cpp_protection_jpeg_simd_cpu_support jpeg_simd_cpu_support +%define _cpp_protection_jsimd_rgb_ycc_convert_mmx jsimd_rgb_ycc_convert_mmx +%define _cpp_protection_jsimd_ycc_rgb_convert_mmx jsimd_ycc_rgb_convert_mmx +%define _cpp_protection_jconst_rgb_ycc_convert_sse2 jconst_rgb_ycc_convert_sse2 +%define _cpp_protection_jsimd_rgb_ycc_convert_sse2 jsimd_rgb_ycc_convert_sse2 +%define _cpp_protection_jconst_ycc_rgb_convert_sse2 jconst_ycc_rgb_convert_sse2 +%define _cpp_protection_jsimd_ycc_rgb_convert_sse2 jsimd_ycc_rgb_convert_sse2 +%define _cpp_protection_jsimd_h2v2_downsample_mmx jsimd_h2v2_downsample_mmx +%define _cpp_protection_jsimd_h2v1_downsample_mmx jsimd_h2v1_downsample_mmx +%define _cpp_protection_jsimd_h2v2_downsample_sse2 jsimd_h2v2_downsample_sse2 +%define _cpp_protection_jsimd_h2v1_downsample_sse2 jsimd_h2v1_downsample_sse2 +%define _cpp_protection_jsimd_h2v2_upsample_mmx jsimd_h2v2_upsample_mmx +%define _cpp_protection_jsimd_h2v1_upsample_mmx jsimd_h2v1_upsample_mmx +%define _cpp_protection_jsimd_h2v1_fancy_upsample_mmx jsimd_h2v1_fancy_upsample_mmx +%define _cpp_protection_jsimd_h2v2_fancy_upsample_mmx jsimd_h2v2_fancy_upsample_mmx +%define _cpp_protection_jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_merged_upsample_mmx +%define _cpp_protection_jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_merged_upsample_mmx +%define _cpp_protection_jsimd_h2v2_upsample_sse2 jsimd_h2v2_upsample_sse2 +%define _cpp_protection_jsimd_h2v1_upsample_sse2 jsimd_h2v1_upsample_sse2 +%define _cpp_protection_jconst_fancy_upsample_sse2 jconst_fancy_upsample_sse2 +%define _cpp_protection_jsimd_h2v1_fancy_upsample_sse2 jsimd_h2v1_fancy_upsample_sse2 +%define _cpp_protection_jsimd_h2v2_fancy_upsample_sse2 jsimd_h2v2_fancy_upsample_sse2 +%define _cpp_protection_jconst_merged_upsample_sse2 jconst_merged_upsample_sse2 +%define _cpp_protection_jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_merged_upsample_sse2 +%define _cpp_protection_jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_merged_upsample_sse2 +%define _cpp_protection_jsimd_convsamp_mmx jsimd_convsamp_mmx +%define _cpp_protection_jsimd_convsamp_sse2 jsimd_convsamp_sse2 +%define _cpp_protection_jsimd_convsamp_float_3dnow jsimd_convsamp_float_3dnow +%define _cpp_protection_jsimd_convsamp_float_sse jsimd_convsamp_float_sse +%define _cpp_protection_jsimd_convsamp_float_sse2 jsimd_convsamp_float_sse2 +%define _cpp_protection_jsimd_fdct_islow_mmx jsimd_fdct_islow_mmx +%define _cpp_protection_jsimd_fdct_ifast_mmx jsimd_fdct_ifast_mmx +%define _cpp_protection_jconst_fdct_islow_sse2 jconst_fdct_islow_sse2 +%define _cpp_protection_jsimd_fdct_islow_sse2 jsimd_fdct_islow_sse2 +%define _cpp_protection_jconst_fdct_ifast_sse2 jconst_fdct_ifast_sse2 +%define _cpp_protection_jsimd_fdct_ifast_sse2 jsimd_fdct_ifast_sse2 +%define _cpp_protection_jsimd_fdct_float_3dnow jsimd_fdct_float_3dnow +%define _cpp_protection_jconst_fdct_float_sse jconst_fdct_float_sse +%define _cpp_protection_jsimd_fdct_float_sse jsimd_fdct_float_sse +%define _cpp_protection_jsimd_quantize_mmx jsimd_quantize_mmx +%define _cpp_protection_jsimd_quantize_sse2 jsimd_quantize_sse2 +%define _cpp_protection_jsimd_quantize_float_3dnow jsimd_quantize_float_3dnow +%define _cpp_protection_jsimd_quantize_float_sse jsimd_quantize_float_sse +%define _cpp_protection_jsimd_quantize_float_sse2 jsimd_quantize_float_sse2 +%define _cpp_protection_jsimd_idct_2x2_mmx jsimd_idct_2x2_mmx +%define _cpp_protection_jsimd_idct_4x4_mmx jsimd_idct_4x4_mmx +%define _cpp_protection_jconst_idct_red_sse2 jconst_idct_red_sse2 +%define _cpp_protection_jsimd_idct_2x2_sse2 jsimd_idct_2x2_sse2 +%define _cpp_protection_jsimd_idct_4x4_sse2 jsimd_idct_4x4_sse2 +%define _cpp_protection_jsimd_idct_islow_mmx jsimd_idct_islow_mmx +%define _cpp_protection_jsimd_idct_ifast_mmx jsimd_idct_ifast_mmx +%define _cpp_protection_jconst_idct_islow_sse2 jconst_idct_islow_sse2 +%define _cpp_protection_jsimd_idct_islow_sse2 jsimd_idct_islow_sse2 +%define _cpp_protection_jconst_idct_ifast_sse2 jconst_idct_ifast_sse2 +%define _cpp_protection_jsimd_idct_ifast_sse2 jsimd_idct_ifast_sse2 +%define _cpp_protection_jsimd_idct_float_3dnow jsimd_idct_float_3dnow +%define _cpp_protection_jconst_idct_float_sse jconst_idct_float_sse +%define _cpp_protection_jsimd_idct_float_sse jsimd_idct_float_sse +%define _cpp_protection_jconst_idct_float_sse2 jconst_idct_float_sse2 +%define _cpp_protection_jsimd_idct_float_sse2 jsimd_idct_float_sse2 +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimdext.inc b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimdext.inc new file mode 100755 index 0000000..253b897 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/simd-x86_64/jsimdext.inc @@ -0,0 +1,376 @@ +; +; jsimdext.inc - common declarations +; +; Copyright 2009 Pierre Ossman for Cendio AB +; Copyright 2010 D. R. Commander +; +; Based on +; x86 SIMD extension for IJG JPEG library - version 1.02 +; +; Copyright (C) 1999-2006, MIYASAKA Masaru. +; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source distribution. +; +; [TAB8] + +; ========================================================================== +; System-dependent configurations + +%ifdef WIN32 ; ----(nasm -fwin32 -DWIN32 ...)-------- +; * Microsoft Visual C++ +; * MinGW (Minimalist GNU for Windows) +; * CygWin +; * LCC-Win32 + +; -- segment definition -- +; +%ifdef __YASM_VER__ +%define SEG_TEXT .text align=16 +%define SEG_CONST .rdata align=16 +%else +%define SEG_TEXT .text align=16 public use32 class=CODE +%define SEG_CONST .rdata align=16 public use32 class=CONST +%endif + +%elifdef WIN64 ; ----(nasm -fwin64 -DWIN64 ...)-------- +; * Microsoft Visual C++ + +; -- segment definition -- +; +%ifdef __YASM_VER__ +%define SEG_TEXT .text align=16 +%define SEG_CONST .rdata align=16 +%else +%define SEG_TEXT .text align=16 public use64 class=CODE +%define SEG_CONST .rdata align=16 public use64 class=CONST +%endif +%define EXTN(name) name ; foo() -> foo + +%elifdef OBJ32 ; ----(nasm -fobj -DOBJ32 ...)---------- +; * Borland C++ (Win32) + +; -- segment definition -- +; +%define SEG_TEXT .text align=16 public use32 class=CODE +%define SEG_CONST .data align=16 public use32 class=DATA + +%elifdef ELF ; ----(nasm -felf[64] -DELF ...)------------ +; * Linux +; * *BSD family Unix using elf format +; * Unix System V, including Solaris x86, UnixWare and SCO Unix + +; mark stack as non-executable +section .note.GNU-stack noalloc noexec nowrite progbits + +; -- segment definition -- +; +%ifdef __x86_64__ +%define SEG_TEXT .text progbits align=16 +%define SEG_CONST .rodata progbits align=16 +%else +%define SEG_TEXT .text progbits alloc exec nowrite align=16 +%define SEG_CONST .rodata progbits alloc noexec nowrite align=16 +%endif + +; To make the code position-independent, append -DPIC to the commandline +; +%define GOT_SYMBOL _GLOBAL_OFFSET_TABLE_ ; ELF supports PIC +%define EXTN(name) name ; foo() -> foo + +%elifdef AOUT ; ----(nasm -faoutb/aout -DAOUT ...)---- +; * Older Linux using a.out format (nasm -f aout -DAOUT ...) +; * *BSD family Unix using a.out format (nasm -f aoutb -DAOUT ...) + +; -- segment definition -- +; +%define SEG_TEXT .text +%define SEG_CONST .data + +; To make the code position-independent, append -DPIC to the commandline +; +%define GOT_SYMBOL __GLOBAL_OFFSET_TABLE_ ; BSD-style a.out supports PIC + +%elifdef MACHO ; ----(nasm -fmacho -DMACHO ...)-------- +; * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (Mach-O format) + +; -- segment definition -- +; +%define SEG_TEXT .text ;align=16 ; nasm doesn't accept align=16. why? +%define SEG_CONST .rodata align=16 + +; The generation of position-independent code (PIC) is the default on Darwin. +; +%define PIC +%define GOT_SYMBOL _MACHO_PIC_ ; Mach-O style code-relative addressing + +%else ; ----(Other case)---------------------- + +; -- segment definition -- +; +%define SEG_TEXT .text +%define SEG_CONST .data + +%endif ; ---------------------------------------------- + +; ========================================================================== + +; -------------------------------------------------------------------------- +; Common types +; +%ifdef __x86_64__ +%define POINTER qword ; general pointer type +%define SIZEOF_POINTER SIZEOF_QWORD ; sizeof(POINTER) +%define POINTER_BIT QWORD_BIT ; sizeof(POINTER)*BYTE_BIT +%else +%define POINTER dword ; general pointer type +%define SIZEOF_POINTER SIZEOF_DWORD ; sizeof(POINTER) +%define POINTER_BIT DWORD_BIT ; sizeof(POINTER)*BYTE_BIT +%endif + +%define INT dword ; signed integer type +%define SIZEOF_INT SIZEOF_DWORD ; sizeof(INT) +%define INT_BIT DWORD_BIT ; sizeof(INT)*BYTE_BIT + +%define FP32 dword ; IEEE754 single +%define SIZEOF_FP32 SIZEOF_DWORD ; sizeof(FP32) +%define FP32_BIT DWORD_BIT ; sizeof(FP32)*BYTE_BIT + +%define MMWORD qword ; int64 (MMX register) +%define SIZEOF_MMWORD SIZEOF_QWORD ; sizeof(MMWORD) +%define MMWORD_BIT QWORD_BIT ; sizeof(MMWORD)*BYTE_BIT + +; NASM is buggy and doesn't properly handle operand sizes for SSE +; instructions, so for now we have to define XMMWORD as blank. +%define XMMWORD ; int128 (SSE register) +%define SIZEOF_XMMWORD SIZEOF_OWORD ; sizeof(XMMWORD) +%define XMMWORD_BIT OWORD_BIT ; sizeof(XMMWORD)*BYTE_BIT + +; Similar hacks for when we load a dword or MMWORD into an xmm# register +%define XMM_DWORD +%define XMM_MMWORD + +%define SIZEOF_BYTE 1 ; sizeof(BYTE) +%define SIZEOF_WORD 2 ; sizeof(WORD) +%define SIZEOF_DWORD 4 ; sizeof(DWORD) +%define SIZEOF_QWORD 8 ; sizeof(QWORD) +%define SIZEOF_OWORD 16 ; sizeof(OWORD) + +%define BYTE_BIT 8 ; CHAR_BIT in C +%define WORD_BIT 16 ; sizeof(WORD)*BYTE_BIT +%define DWORD_BIT 32 ; sizeof(DWORD)*BYTE_BIT +%define QWORD_BIT 64 ; sizeof(QWORD)*BYTE_BIT +%define OWORD_BIT 128 ; sizeof(OWORD)*BYTE_BIT + +; -------------------------------------------------------------------------- +; External Symbol Name +; +%ifndef EXTN +%define EXTN(name) _ %+ name ; foo() -> _foo +%endif + +; -------------------------------------------------------------------------- +; Macros for position-independent code (PIC) support +; +%ifndef GOT_SYMBOL +%undef PIC +%endif + +%ifdef PIC ; ------------------------------------------- + +%ifidn GOT_SYMBOL,_MACHO_PIC_ ; -------------------- + +; At present, nasm doesn't seem to support PIC generation for Mach-O. +; The PIC support code below is a little tricky. + + SECTION SEG_CONST +const_base: + +%define GOTOFF(got,sym) (got) + (sym) - const_base + +%imacro get_GOT 1 + ; NOTE: this macro destroys ecx resister. + call %%geteip + add ecx, byte (%%ref - $) + jmp short %%adjust +%%geteip: + mov ecx, POINTER [esp] + ret +%%adjust: + push ebp + xor ebp,ebp ; ebp = 0 +%ifidni %1,ebx ; (%1 == ebx) + ; db 0x8D,0x9C + jmp near const_base = + ; lea ebx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,9C,E9,(offset32) + db 0x8D,0x9C ; 8D,9C + jmp near const_base ; E9,(const_base-%%ref) +%%ref: +%else ; (%1 != ebx) + ; db 0x8D,0x8C + jmp near const_base = + ; lea ecx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,8C,E9,(offset32) + db 0x8D,0x8C ; 8D,8C + jmp near const_base ; E9,(const_base-%%ref) +%%ref: mov %1, ecx +%endif ; (%1 == ebx) + pop ebp +%endmacro + +%else ; GOT_SYMBOL != _MACHO_PIC_ ---------------- + +%define GOTOFF(got,sym) (got) + (sym) wrt ..gotoff + +%imacro get_GOT 1 + extern GOT_SYMBOL + call %%geteip + add %1, GOT_SYMBOL + $$ - $ wrt ..gotpc + jmp short %%done +%%geteip: + mov %1, POINTER [esp] + ret +%%done: +%endmacro + +%endif ; GOT_SYMBOL == _MACHO_PIC_ ---------------- + +%imacro pushpic 1.nolist + push %1 +%endmacro +%imacro poppic 1.nolist + pop %1 +%endmacro +%imacro movpic 2.nolist + mov %1,%2 +%endmacro + +%else ; !PIC ----------------------------------------- + +%define GOTOFF(got,sym) (sym) + +%imacro get_GOT 1.nolist +%endmacro +%imacro pushpic 1.nolist +%endmacro +%imacro poppic 1.nolist +%endmacro +%imacro movpic 2.nolist +%endmacro + +%endif ; PIC ----------------------------------------- + +; -------------------------------------------------------------------------- +; Align the next instruction on {2,4,8,16,..}-byte boundary. +; ".balign n,,m" in GNU as +; +%define MSKLE(x,y) (~(((y) & 0xFFFF) - ((x) & 0xFFFF)) >> 16) +%define FILLB(b,n) (($$-(b)) & ((n)-1)) + +%imacro alignx 1-2.nolist 0xFFFF +%%bs: times MSKLE(FILLB(%%bs,%1),%2) & MSKLE(16,FILLB($,%1)) & FILLB($,%1) \ + db 0x90 ; nop + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/9 \ + db 0x8D,0x9C,0x23,0x00,0x00,0x00,0x00 ; lea ebx,[ebx+0x00000000] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/7 \ + db 0x8D,0xAC,0x25,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/6 \ + db 0x8D,0xAD,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/4 \ + db 0x8D,0x6C,0x25,0x00 ; lea ebp,[ebp+0x00] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/3 \ + db 0x8D,0x6D,0x00 ; lea ebp,[ebp+0x00] + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/2 \ + db 0x8B,0xED ; mov ebp,ebp + times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/1 \ + db 0x90 ; nop +%endmacro + +; Align the next data on {2,4,8,16,..}-byte boundary. +; +%imacro alignz 1.nolist + align %1, db 0 ; filling zeros +%endmacro + +%ifdef __x86_64__ + +%ifdef WIN64 + +%imacro collect_args 0 + push r12 + push r13 + push r14 + push r15 + mov r10, rcx + mov r11, rdx + mov r12, r8 + mov r13, r9 + mov r14, [rax+48] + mov r15, [rax+56] + push rsi + push rdi + sub rsp, SIZEOF_XMMWORD + movaps XMMWORD [rsp], xmm6 + sub rsp, SIZEOF_XMMWORD + movaps XMMWORD [rsp], xmm7 +%endmacro + +%imacro uncollect_args 0 + movaps xmm7, XMMWORD [rsp] + add rsp, SIZEOF_XMMWORD + movaps xmm6, XMMWORD [rsp] + add rsp, SIZEOF_XMMWORD + pop rdi + pop rsi + pop r15 + pop r14 + pop r13 + pop r12 +%endmacro + +%else + +%imacro collect_args 0 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + mov r10, rdi + mov r11, rsi + mov r12, rdx + mov r13, rcx + mov r14, r8 + mov r15, r9 +%endmacro + +%imacro uncollect_args 0 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 +%endmacro + +%endif + +%endif + +; -------------------------------------------------------------------------- +; Defines picked up from the C headers +; +%include "jsimdcfg.inc" + +; -------------------------------------------------------------------------- diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/tjutil.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/tjutil.h new file mode 100755 index 0000000..bdad348 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/tjutil.h @@ -0,0 +1,47 @@ +/* + * Copyright (C)2011 D. R. Commander. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the libjpeg-turbo Project nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef _WIN32 + #ifndef __MINGW32__ + #include + #define snprintf(str, n, format, ...) \ + _snprintf_s(str, n, _TRUNCATE, format, __VA_ARGS__) + #endif + #define strcasecmp stricmp + #define strncasecmp strnicmp +#endif + +#ifndef min + #define min(a,b) ((a)<(b)?(a):(b)) +#endif + +#ifndef max + #define max(a,b) ((a)>(b)?(a):(b)) +#endif + +extern double gettime(void); diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/transupp.c b/lib-third-party/libturbojpeg-ios/libturbojpeg/transupp.c new file mode 100755 index 0000000..2513691 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/transupp.c @@ -0,0 +1,1613 @@ +/* + * transupp.c + * + * Copyright (C) 1997-2009, Thomas G. Lane, Guido Vollbeding. + * Copyright (C) 2010, D. R. Commander. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains image transformation routines and other utility code + * used by the jpegtran sample application. These are NOT part of the core + * JPEG library. But we keep these routines separate from jpegtran.c to + * ease the task of maintaining jpegtran-like programs that have other user + * interfaces. + */ + +/* Although this file really shouldn't have access to the library internals, + * it's helpful to let it call jround_up() and jcopy_block_row(). + */ +#define JPEG_INTERNALS + +#include "jinclude.h" +#include "jpeglib.h" +#include "transupp.h" /* My own external interface */ +#include "jpegcomp.h" +#include /* to declare isdigit() */ + + +#if JPEG_LIB_VERSION >= 70 +#define dstinfo_min_DCT_h_scaled_size dstinfo->min_DCT_h_scaled_size +#define dstinfo_min_DCT_v_scaled_size dstinfo->min_DCT_v_scaled_size +#else +#define dstinfo_min_DCT_h_scaled_size DCTSIZE +#define dstinfo_min_DCT_v_scaled_size DCTSIZE +#endif + + +#if TRANSFORMS_SUPPORTED + +/* + * Lossless image transformation routines. These routines work on DCT + * coefficient arrays and thus do not require any lossy decompression + * or recompression of the image. + * Thanks to Guido Vollbeding for the initial design and code of this feature, + * and to Ben Jackson for introducing the cropping feature. + * + * Horizontal flipping is done in-place, using a single top-to-bottom + * pass through the virtual source array. It will thus be much the + * fastest option for images larger than main memory. + * + * The other routines require a set of destination virtual arrays, so they + * need twice as much memory as jpegtran normally does. The destination + * arrays are always written in normal scan order (top to bottom) because + * the virtual array manager expects this. The source arrays will be scanned + * in the corresponding order, which means multiple passes through the source + * arrays for most of the transforms. That could result in much thrashing + * if the image is larger than main memory. + * + * If cropping or trimming is involved, the destination arrays may be smaller + * than the source arrays. Note it is not possible to do horizontal flip + * in-place when a nonzero Y crop offset is specified, since we'd have to move + * data from one block row to another but the virtual array manager doesn't + * guarantee we can touch more than one row at a time. So in that case, + * we have to use a separate destination array. + * + * Some notes about the operating environment of the individual transform + * routines: + * 1. Both the source and destination virtual arrays are allocated from the + * source JPEG object, and therefore should be manipulated by calling the + * source's memory manager. + * 2. The destination's component count should be used. It may be smaller + * than the source's when forcing to grayscale. + * 3. Likewise the destination's sampling factors should be used. When + * forcing to grayscale the destination's sampling factors will be all 1, + * and we may as well take that as the effective iMCU size. + * 4. When "trim" is in effect, the destination's dimensions will be the + * trimmed values but the source's will be untrimmed. + * 5. When "crop" is in effect, the destination's dimensions will be the + * cropped values but the source's will be uncropped. Each transform + * routine is responsible for picking up source data starting at the + * correct X and Y offset for the crop region. (The X and Y offsets + * passed to the transform routines are measured in iMCU blocks of the + * destination.) + * 6. All the routines assume that the source and destination buffers are + * padded out to a full iMCU boundary. This is true, although for the + * source buffer it is an undocumented property of jdcoefct.c. + */ + + +LOCAL(void) +do_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* Crop. This is only used when no rotate/flip is requested with the crop. */ +{ + JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks; + int ci, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + jpeg_component_info *compptr; + + /* We simply have to copy the right amount of data (the destination's + * image size) starting at the given X and Y offsets in the source. + */ + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_y + y_crop_blocks, + (JDIMENSION) compptr->v_samp_factor, FALSE); + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, + dst_buffer[offset_y], + compptr->width_in_blocks); + } + } + } +} + + +LOCAL(void) +do_flip_h_no_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, + jvirt_barray_ptr *src_coef_arrays) +/* Horizontal flip; done in-place, so no separate dest array is required. + * NB: this only works when y_crop_offset is zero. + */ +{ + JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks; + int ci, k, offset_y; + JBLOCKARRAY buffer; + JCOEFPTR ptr1, ptr2; + JCOEF temp1, temp2; + jpeg_component_info *compptr; + + /* Horizontal mirroring of DCT blocks is accomplished by swapping + * pairs of blocks in-place. Within a DCT block, we perform horizontal + * mirroring by changing the signs of odd-numbered columns. + * Partial iMCUs at the right edge are left untouched. + */ + MCU_cols = srcinfo->output_width / + (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); + + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + comp_width = MCU_cols * compptr->h_samp_factor; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + for (blk_y = 0; blk_y < compptr->height_in_blocks; + blk_y += compptr->v_samp_factor) { + buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + /* Do the mirroring */ + for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) { + ptr1 = buffer[offset_y][blk_x]; + ptr2 = buffer[offset_y][comp_width - blk_x - 1]; + /* this unrolled loop doesn't need to know which row it's on... */ + for (k = 0; k < DCTSIZE2; k += 2) { + temp1 = *ptr1; /* swap even column */ + temp2 = *ptr2; + *ptr1++ = temp2; + *ptr2++ = temp1; + temp1 = *ptr1; /* swap odd column with sign change */ + temp2 = *ptr2; + *ptr1++ = -temp2; + *ptr2++ = -temp1; + } + } + if (x_crop_blocks > 0) { + /* Now left-justify the portion of the data to be kept. + * We can't use a single jcopy_block_row() call because that routine + * depends on memcpy(), whose behavior is unspecified for overlapping + * source and destination areas. Sigh. + */ + for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) { + jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks, + buffer[offset_y] + blk_x, + (JDIMENSION) 1); + } + } + } + } + } +} + + +LOCAL(void) +do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* Horizontal flip in general cropping case */ +{ + JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; + JDIMENSION x_crop_blocks, y_crop_blocks; + int ci, k, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + JBLOCKROW src_row_ptr, dst_row_ptr; + JCOEFPTR src_ptr, dst_ptr; + jpeg_component_info *compptr; + + /* Here we must output into a separate array because we can't touch + * different rows of a single virtual array simultaneously. Otherwise, + * this is essentially the same as the routine above. + */ + MCU_cols = srcinfo->output_width / + (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); + + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + comp_width = MCU_cols * compptr->h_samp_factor; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_y + y_crop_blocks, + (JDIMENSION) compptr->v_samp_factor, FALSE); + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + dst_row_ptr = dst_buffer[offset_y]; + src_row_ptr = src_buffer[offset_y]; + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Do the mirrorable blocks */ + dst_ptr = dst_row_ptr[dst_blk_x]; + src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; + /* this unrolled loop doesn't need to know which row it's on... */ + for (k = 0; k < DCTSIZE2; k += 2) { + *dst_ptr++ = *src_ptr++; /* copy even column */ + *dst_ptr++ = - *src_ptr++; /* copy odd column with sign change */ + } + } else { + /* Copy last partial block(s) verbatim */ + jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, + dst_row_ptr + dst_blk_x, + (JDIMENSION) 1); + } + } + } + } + } +} + + +LOCAL(void) +do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* Vertical flip */ +{ + JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; + JDIMENSION x_crop_blocks, y_crop_blocks; + int ci, i, j, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + JBLOCKROW src_row_ptr, dst_row_ptr; + JCOEFPTR src_ptr, dst_ptr; + jpeg_component_info *compptr; + + /* We output into a separate array because we can't touch different + * rows of the source virtual array simultaneously. Otherwise, this + * is a pretty straightforward analog of horizontal flip. + * Within a DCT block, vertical mirroring is done by changing the signs + * of odd-numbered rows. + * Partial iMCUs at the bottom edge are copied verbatim. + */ + MCU_rows = srcinfo->output_height / + (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); + + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + comp_height = MCU_rows * compptr->v_samp_factor; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + if (y_crop_blocks + dst_blk_y < comp_height) { + /* Row is within the mirrorable area. */ + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + comp_height - y_crop_blocks - dst_blk_y - + (JDIMENSION) compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } else { + /* Bottom-edge blocks will be copied verbatim. */ + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_y + y_crop_blocks, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + if (y_crop_blocks + dst_blk_y < comp_height) { + /* Row is within the mirrorable area. */ + dst_row_ptr = dst_buffer[offset_y]; + src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; + src_row_ptr += x_crop_blocks; + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; + dst_blk_x++) { + dst_ptr = dst_row_ptr[dst_blk_x]; + src_ptr = src_row_ptr[dst_blk_x]; + for (i = 0; i < DCTSIZE; i += 2) { + /* copy even row */ + for (j = 0; j < DCTSIZE; j++) + *dst_ptr++ = *src_ptr++; + /* copy odd row with sign change */ + for (j = 0; j < DCTSIZE; j++) + *dst_ptr++ = - *src_ptr++; + } + } + } else { + /* Just copy row verbatim. */ + jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, + dst_buffer[offset_y], + compptr->width_in_blocks); + } + } + } + } +} + + +LOCAL(void) +do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* Transpose source into destination */ +{ + JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks; + int ci, i, j, offset_x, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + JCOEFPTR src_ptr, dst_ptr; + jpeg_component_info *compptr; + + /* Transposing pixels within a block just requires transposing the + * DCT coefficients. + * Partial iMCUs at the edges require no special treatment; we simply + * process all the available DCT blocks for every component. + */ + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; + dst_blk_x += compptr->h_samp_factor) { + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_x + x_crop_blocks, + (JDIMENSION) compptr->h_samp_factor, FALSE); + for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { + dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; + src_ptr = src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks]; + for (i = 0; i < DCTSIZE; i++) + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + } + } + } + } + } +} + + +LOCAL(void) +do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* 90 degree rotation is equivalent to + * 1. Transposing the image; + * 2. Horizontal mirroring. + * These two steps are merged into a single processing routine. + */ +{ + JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; + JDIMENSION x_crop_blocks, y_crop_blocks; + int ci, i, j, offset_x, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + JCOEFPTR src_ptr, dst_ptr; + jpeg_component_info *compptr; + + /* Because of the horizontal mirror step, we can't process partial iMCUs + * at the (output) right edge properly. They just get transposed and + * not mirrored. + */ + MCU_cols = srcinfo->output_height / + (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); + + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + comp_width = MCU_cols * compptr->h_samp_factor; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; + dst_blk_x += compptr->h_samp_factor) { + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Block is within the mirrorable area. */ + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + comp_width - x_crop_blocks - dst_blk_x - + (JDIMENSION) compptr->h_samp_factor, + (JDIMENSION) compptr->h_samp_factor, FALSE); + } else { + /* Edge blocks are transposed but not mirrored. */ + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_x + x_crop_blocks, + (JDIMENSION) compptr->h_samp_factor, FALSE); + } + for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { + dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Block is within the mirrorable area. */ + src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] + [dst_blk_y + offset_y + y_crop_blocks]; + for (i = 0; i < DCTSIZE; i++) { + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + i++; + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; + } + } else { + /* Edge blocks are transposed but not mirrored. */ + src_ptr = src_buffer[offset_x] + [dst_blk_y + offset_y + y_crop_blocks]; + for (i = 0; i < DCTSIZE; i++) + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + } + } + } + } + } + } +} + + +LOCAL(void) +do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* 270 degree rotation is equivalent to + * 1. Horizontal mirroring; + * 2. Transposing the image. + * These two steps are merged into a single processing routine. + */ +{ + JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; + JDIMENSION x_crop_blocks, y_crop_blocks; + int ci, i, j, offset_x, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + JCOEFPTR src_ptr, dst_ptr; + jpeg_component_info *compptr; + + /* Because of the horizontal mirror step, we can't process partial iMCUs + * at the (output) bottom edge properly. They just get transposed and + * not mirrored. + */ + MCU_rows = srcinfo->output_width / + (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); + + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + comp_height = MCU_rows * compptr->v_samp_factor; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; + dst_blk_x += compptr->h_samp_factor) { + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_x + x_crop_blocks, + (JDIMENSION) compptr->h_samp_factor, FALSE); + for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { + dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; + if (y_crop_blocks + dst_blk_y < comp_height) { + /* Block is within the mirrorable area. */ + src_ptr = src_buffer[offset_x] + [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; + for (i = 0; i < DCTSIZE; i++) { + for (j = 0; j < DCTSIZE; j++) { + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + j++; + dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; + } + } + } else { + /* Edge blocks are transposed but not mirrored. */ + src_ptr = src_buffer[offset_x] + [dst_blk_y + offset_y + y_crop_blocks]; + for (i = 0; i < DCTSIZE; i++) + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + } + } + } + } + } + } +} + + +LOCAL(void) +do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* 180 degree rotation is equivalent to + * 1. Vertical mirroring; + * 2. Horizontal mirroring. + * These two steps are merged into a single processing routine. + */ +{ + JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; + JDIMENSION x_crop_blocks, y_crop_blocks; + int ci, i, j, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + JBLOCKROW src_row_ptr, dst_row_ptr; + JCOEFPTR src_ptr, dst_ptr; + jpeg_component_info *compptr; + + MCU_cols = srcinfo->output_width / + (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); + MCU_rows = srcinfo->output_height / + (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); + + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + comp_width = MCU_cols * compptr->h_samp_factor; + comp_height = MCU_rows * compptr->v_samp_factor; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + if (y_crop_blocks + dst_blk_y < comp_height) { + /* Row is within the vertically mirrorable area. */ + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + comp_height - y_crop_blocks - dst_blk_y - + (JDIMENSION) compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } else { + /* Bottom-edge rows are only mirrored horizontally. */ + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_y + y_crop_blocks, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + dst_row_ptr = dst_buffer[offset_y]; + if (y_crop_blocks + dst_blk_y < comp_height) { + /* Row is within the mirrorable area. */ + src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { + dst_ptr = dst_row_ptr[dst_blk_x]; + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Process the blocks that can be mirrored both ways. */ + src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; + for (i = 0; i < DCTSIZE; i += 2) { + /* For even row, negate every odd column. */ + for (j = 0; j < DCTSIZE; j += 2) { + *dst_ptr++ = *src_ptr++; + *dst_ptr++ = - *src_ptr++; + } + /* For odd row, negate every even column. */ + for (j = 0; j < DCTSIZE; j += 2) { + *dst_ptr++ = - *src_ptr++; + *dst_ptr++ = *src_ptr++; + } + } + } else { + /* Any remaining right-edge blocks are only mirrored vertically. */ + src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x]; + for (i = 0; i < DCTSIZE; i += 2) { + for (j = 0; j < DCTSIZE; j++) + *dst_ptr++ = *src_ptr++; + for (j = 0; j < DCTSIZE; j++) + *dst_ptr++ = - *src_ptr++; + } + } + } + } else { + /* Remaining rows are just mirrored horizontally. */ + src_row_ptr = src_buffer[offset_y]; + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Process the blocks that can be mirrored. */ + dst_ptr = dst_row_ptr[dst_blk_x]; + src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; + for (i = 0; i < DCTSIZE2; i += 2) { + *dst_ptr++ = *src_ptr++; + *dst_ptr++ = - *src_ptr++; + } + } else { + /* Any remaining right-edge blocks are only copied. */ + jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, + dst_row_ptr + dst_blk_x, + (JDIMENSION) 1); + } + } + } + } + } + } +} + + +LOCAL(void) +do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, + jvirt_barray_ptr *src_coef_arrays, + jvirt_barray_ptr *dst_coef_arrays) +/* Transverse transpose is equivalent to + * 1. 180 degree rotation; + * 2. Transposition; + * or + * 1. Horizontal mirroring; + * 2. Transposition; + * 3. Horizontal mirroring. + * These steps are merged into a single processing routine. + */ +{ + JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; + JDIMENSION x_crop_blocks, y_crop_blocks; + int ci, i, j, offset_x, offset_y; + JBLOCKARRAY src_buffer, dst_buffer; + JCOEFPTR src_ptr, dst_ptr; + jpeg_component_info *compptr; + + MCU_cols = srcinfo->output_height / + (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); + MCU_rows = srcinfo->output_width / + (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); + + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + comp_width = MCU_cols * compptr->h_samp_factor; + comp_height = MCU_rows * compptr->v_samp_factor; + x_crop_blocks = x_crop_offset * compptr->h_samp_factor; + y_crop_blocks = y_crop_offset * compptr->v_samp_factor; + for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; + dst_blk_y += compptr->v_samp_factor) { + dst_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, + (JDIMENSION) compptr->v_samp_factor, TRUE); + for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { + for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; + dst_blk_x += compptr->h_samp_factor) { + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Block is within the mirrorable area. */ + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + comp_width - x_crop_blocks - dst_blk_x - + (JDIMENSION) compptr->h_samp_factor, + (JDIMENSION) compptr->h_samp_factor, FALSE); + } else { + src_buffer = (*srcinfo->mem->access_virt_barray) + ((j_common_ptr) srcinfo, src_coef_arrays[ci], + dst_blk_x + x_crop_blocks, + (JDIMENSION) compptr->h_samp_factor, FALSE); + } + for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { + dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; + if (y_crop_blocks + dst_blk_y < comp_height) { + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Block is within the mirrorable area. */ + src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] + [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; + for (i = 0; i < DCTSIZE; i++) { + for (j = 0; j < DCTSIZE; j++) { + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + j++; + dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; + } + i++; + for (j = 0; j < DCTSIZE; j++) { + dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; + j++; + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + } + } + } else { + /* Right-edge blocks are mirrored in y only */ + src_ptr = src_buffer[offset_x] + [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; + for (i = 0; i < DCTSIZE; i++) { + for (j = 0; j < DCTSIZE; j++) { + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + j++; + dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; + } + } + } + } else { + if (x_crop_blocks + dst_blk_x < comp_width) { + /* Bottom-edge blocks are mirrored in x only */ + src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] + [dst_blk_y + offset_y + y_crop_blocks]; + for (i = 0; i < DCTSIZE; i++) { + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + i++; + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; + } + } else { + /* At lower right corner, just transpose, no mirroring */ + src_ptr = src_buffer[offset_x] + [dst_blk_y + offset_y + y_crop_blocks]; + for (i = 0; i < DCTSIZE; i++) + for (j = 0; j < DCTSIZE; j++) + dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; + } + } + } + } + } + } + } +} + + +/* Parse an unsigned integer: subroutine for jtransform_parse_crop_spec. + * Returns TRUE if valid integer found, FALSE if not. + * *strptr is advanced over the digit string, and *result is set to its value. + */ + +LOCAL(boolean) +jt_read_integer (const char ** strptr, JDIMENSION * result) +{ + const char * ptr = *strptr; + JDIMENSION val = 0; + + for (; isdigit(*ptr); ptr++) { + val = val * 10 + (JDIMENSION) (*ptr - '0'); + } + *result = val; + if (ptr == *strptr) + return FALSE; /* oops, no digits */ + *strptr = ptr; + return TRUE; +} + + +/* Parse a crop specification (written in X11 geometry style). + * The routine returns TRUE if the spec string is valid, FALSE if not. + * + * The crop spec string should have the format + * x{+-}{+-} + * where width, height, xoffset, and yoffset are unsigned integers. + * Each of the elements can be omitted to indicate a default value. + * (A weakness of this style is that it is not possible to omit xoffset + * while specifying yoffset, since they look alike.) + * + * This code is loosely based on XParseGeometry from the X11 distribution. + */ + +GLOBAL(boolean) +jtransform_parse_crop_spec (jpeg_transform_info *info, const char *spec) +{ + info->crop = FALSE; + info->crop_width_set = JCROP_UNSET; + info->crop_height_set = JCROP_UNSET; + info->crop_xoffset_set = JCROP_UNSET; + info->crop_yoffset_set = JCROP_UNSET; + + if (isdigit(*spec)) { + /* fetch width */ + if (! jt_read_integer(&spec, &info->crop_width)) + return FALSE; + info->crop_width_set = JCROP_POS; + } + if (*spec == 'x' || *spec == 'X') { + /* fetch height */ + spec++; + if (! jt_read_integer(&spec, &info->crop_height)) + return FALSE; + info->crop_height_set = JCROP_POS; + } + if (*spec == '+' || *spec == '-') { + /* fetch xoffset */ + info->crop_xoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS; + spec++; + if (! jt_read_integer(&spec, &info->crop_xoffset)) + return FALSE; + } + if (*spec == '+' || *spec == '-') { + /* fetch yoffset */ + info->crop_yoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS; + spec++; + if (! jt_read_integer(&spec, &info->crop_yoffset)) + return FALSE; + } + /* We had better have gotten to the end of the string. */ + if (*spec != '\0') + return FALSE; + info->crop = TRUE; + return TRUE; +} + + +/* Trim off any partial iMCUs on the indicated destination edge */ + +LOCAL(void) +trim_right_edge (jpeg_transform_info *info, JDIMENSION full_width) +{ + JDIMENSION MCU_cols; + + MCU_cols = info->output_width / info->iMCU_sample_width; + if (MCU_cols > 0 && info->x_crop_offset + MCU_cols == + full_width / info->iMCU_sample_width) + info->output_width = MCU_cols * info->iMCU_sample_width; +} + +LOCAL(void) +trim_bottom_edge (jpeg_transform_info *info, JDIMENSION full_height) +{ + JDIMENSION MCU_rows; + + MCU_rows = info->output_height / info->iMCU_sample_height; + if (MCU_rows > 0 && info->y_crop_offset + MCU_rows == + full_height / info->iMCU_sample_height) + info->output_height = MCU_rows * info->iMCU_sample_height; +} + + +/* Request any required workspace. + * + * This routine figures out the size that the output image will be + * (which implies that all the transform parameters must be set before + * it is called). + * + * We allocate the workspace virtual arrays from the source decompression + * object, so that all the arrays (both the original data and the workspace) + * will be taken into account while making memory management decisions. + * Hence, this routine must be called after jpeg_read_header (which reads + * the image dimensions) and before jpeg_read_coefficients (which realizes + * the source's virtual arrays). + * + * This function returns FALSE right away if -perfect is given + * and transformation is not perfect. Otherwise returns TRUE. + */ + +GLOBAL(boolean) +jtransform_request_workspace (j_decompress_ptr srcinfo, + jpeg_transform_info *info) +{ + jvirt_barray_ptr *coef_arrays; + boolean need_workspace, transpose_it; + jpeg_component_info *compptr; + JDIMENSION xoffset, yoffset; + JDIMENSION width_in_iMCUs, height_in_iMCUs; + JDIMENSION width_in_blocks, height_in_blocks; + int ci, h_samp_factor, v_samp_factor; + + /* Determine number of components in output image */ + if (info->force_grayscale && + srcinfo->jpeg_color_space == JCS_YCbCr && + srcinfo->num_components == 3) + /* We'll only process the first component */ + info->num_components = 1; + else + /* Process all the components */ + info->num_components = srcinfo->num_components; + + /* Compute output image dimensions and related values. */ +#if JPEG_LIB_VERSION >= 80 + jpeg_core_output_dimensions(srcinfo); +#else + srcinfo->output_width = srcinfo->image_width; + srcinfo->output_height = srcinfo->image_height; +#endif + + /* Return right away if -perfect is given and transformation is not perfect. + */ + if (info->perfect) { + if (info->num_components == 1) { + if (!jtransform_perfect_transform(srcinfo->output_width, + srcinfo->output_height, + srcinfo->_min_DCT_h_scaled_size, + srcinfo->_min_DCT_v_scaled_size, + info->transform)) + return FALSE; + } else { + if (!jtransform_perfect_transform(srcinfo->output_width, + srcinfo->output_height, + srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size, + srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size, + info->transform)) + return FALSE; + } + } + + /* If there is only one output component, force the iMCU size to be 1; + * else use the source iMCU size. (This allows us to do the right thing + * when reducing color to grayscale, and also provides a handy way of + * cleaning up "funny" grayscale images whose sampling factors are not 1x1.) + */ + switch (info->transform) { + case JXFORM_TRANSPOSE: + case JXFORM_TRANSVERSE: + case JXFORM_ROT_90: + case JXFORM_ROT_270: + info->output_width = srcinfo->output_height; + info->output_height = srcinfo->output_width; + if (info->num_components == 1) { + info->iMCU_sample_width = srcinfo->_min_DCT_v_scaled_size; + info->iMCU_sample_height = srcinfo->_min_DCT_h_scaled_size; + } else { + info->iMCU_sample_width = + srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; + info->iMCU_sample_height = + srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; + } + break; + default: + info->output_width = srcinfo->output_width; + info->output_height = srcinfo->output_height; + if (info->num_components == 1) { + info->iMCU_sample_width = srcinfo->_min_DCT_h_scaled_size; + info->iMCU_sample_height = srcinfo->_min_DCT_v_scaled_size; + } else { + info->iMCU_sample_width = + srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; + info->iMCU_sample_height = + srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; + } + break; + } + + /* If cropping has been requested, compute the crop area's position and + * dimensions, ensuring that its upper left corner falls at an iMCU boundary. + */ + if (info->crop) { + /* Insert default values for unset crop parameters */ + if (info->crop_xoffset_set == JCROP_UNSET) + info->crop_xoffset = 0; /* default to +0 */ + if (info->crop_yoffset_set == JCROP_UNSET) + info->crop_yoffset = 0; /* default to +0 */ + if (info->crop_xoffset >= info->output_width || + info->crop_yoffset >= info->output_height) + ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); + if (info->crop_width_set == JCROP_UNSET) + info->crop_width = info->output_width - info->crop_xoffset; + if (info->crop_height_set == JCROP_UNSET) + info->crop_height = info->output_height - info->crop_yoffset; + /* Ensure parameters are valid */ + if (info->crop_width <= 0 || info->crop_width > info->output_width || + info->crop_height <= 0 || info->crop_height > info->output_height || + info->crop_xoffset > info->output_width - info->crop_width || + info->crop_yoffset > info->output_height - info->crop_height) + ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); + /* Convert negative crop offsets into regular offsets */ + if (info->crop_xoffset_set == JCROP_NEG) + xoffset = info->output_width - info->crop_width - info->crop_xoffset; + else + xoffset = info->crop_xoffset; + if (info->crop_yoffset_set == JCROP_NEG) + yoffset = info->output_height - info->crop_height - info->crop_yoffset; + else + yoffset = info->crop_yoffset; + /* Now adjust so that upper left corner falls at an iMCU boundary */ + info->output_width = + info->crop_width + (xoffset % info->iMCU_sample_width); + info->output_height = + info->crop_height + (yoffset % info->iMCU_sample_height); + /* Save x/y offsets measured in iMCUs */ + info->x_crop_offset = xoffset / info->iMCU_sample_width; + info->y_crop_offset = yoffset / info->iMCU_sample_height; + } else { + info->x_crop_offset = 0; + info->y_crop_offset = 0; + } + + /* Figure out whether we need workspace arrays, + * and if so whether they are transposed relative to the source. + */ + need_workspace = FALSE; + transpose_it = FALSE; + switch (info->transform) { + case JXFORM_NONE: + if (info->x_crop_offset != 0 || info->y_crop_offset != 0) + need_workspace = TRUE; + /* No workspace needed if neither cropping nor transforming */ + break; + case JXFORM_FLIP_H: + if (info->trim) + trim_right_edge(info, srcinfo->output_width); + if (info->y_crop_offset != 0 || info->slow_hflip) + need_workspace = TRUE; + /* do_flip_h_no_crop doesn't need a workspace array */ + break; + case JXFORM_FLIP_V: + if (info->trim) + trim_bottom_edge(info, srcinfo->output_height); + /* Need workspace arrays having same dimensions as source image. */ + need_workspace = TRUE; + break; + case JXFORM_TRANSPOSE: + /* transpose does NOT have to trim anything */ + /* Need workspace arrays having transposed dimensions. */ + need_workspace = TRUE; + transpose_it = TRUE; + break; + case JXFORM_TRANSVERSE: + if (info->trim) { + trim_right_edge(info, srcinfo->output_height); + trim_bottom_edge(info, srcinfo->output_width); + } + /* Need workspace arrays having transposed dimensions. */ + need_workspace = TRUE; + transpose_it = TRUE; + break; + case JXFORM_ROT_90: + if (info->trim) + trim_right_edge(info, srcinfo->output_height); + /* Need workspace arrays having transposed dimensions. */ + need_workspace = TRUE; + transpose_it = TRUE; + break; + case JXFORM_ROT_180: + if (info->trim) { + trim_right_edge(info, srcinfo->output_width); + trim_bottom_edge(info, srcinfo->output_height); + } + /* Need workspace arrays having same dimensions as source image. */ + need_workspace = TRUE; + break; + case JXFORM_ROT_270: + if (info->trim) + trim_bottom_edge(info, srcinfo->output_width); + /* Need workspace arrays having transposed dimensions. */ + need_workspace = TRUE; + transpose_it = TRUE; + break; + } + + /* Allocate workspace if needed. + * Note that we allocate arrays padded out to the next iMCU boundary, + * so that transform routines need not worry about missing edge blocks. + */ + if (need_workspace) { + coef_arrays = (jvirt_barray_ptr *) + (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE, + SIZEOF(jvirt_barray_ptr) * info->num_components); + width_in_iMCUs = (JDIMENSION) + jdiv_round_up((long) info->output_width, + (long) info->iMCU_sample_width); + height_in_iMCUs = (JDIMENSION) + jdiv_round_up((long) info->output_height, + (long) info->iMCU_sample_height); + for (ci = 0; ci < info->num_components; ci++) { + compptr = srcinfo->comp_info + ci; + if (info->num_components == 1) { + /* we're going to force samp factors to 1x1 in this case */ + h_samp_factor = v_samp_factor = 1; + } else if (transpose_it) { + h_samp_factor = compptr->v_samp_factor; + v_samp_factor = compptr->h_samp_factor; + } else { + h_samp_factor = compptr->h_samp_factor; + v_samp_factor = compptr->v_samp_factor; + } + width_in_blocks = width_in_iMCUs * h_samp_factor; + height_in_blocks = height_in_iMCUs * v_samp_factor; + coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) + ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE, + width_in_blocks, height_in_blocks, (JDIMENSION) v_samp_factor); + } + info->workspace_coef_arrays = coef_arrays; + } else + info->workspace_coef_arrays = NULL; + + return TRUE; +} + + +/* Transpose destination image parameters */ + +LOCAL(void) +transpose_critical_parameters (j_compress_ptr dstinfo) +{ + int tblno, i, j, ci, itemp; + jpeg_component_info *compptr; + JQUANT_TBL *qtblptr; + JDIMENSION jtemp; + UINT16 qtemp; + + /* Transpose image dimensions */ + jtemp = dstinfo->image_width; + dstinfo->image_width = dstinfo->image_height; + dstinfo->image_height = jtemp; +#if JPEG_LIB_VERSION >= 70 + itemp = dstinfo->min_DCT_h_scaled_size; + dstinfo->min_DCT_h_scaled_size = dstinfo->min_DCT_v_scaled_size; + dstinfo->min_DCT_v_scaled_size = itemp; +#endif + + /* Transpose sampling factors */ + for (ci = 0; ci < dstinfo->num_components; ci++) { + compptr = dstinfo->comp_info + ci; + itemp = compptr->h_samp_factor; + compptr->h_samp_factor = compptr->v_samp_factor; + compptr->v_samp_factor = itemp; + } + + /* Transpose quantization tables */ + for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { + qtblptr = dstinfo->quant_tbl_ptrs[tblno]; + if (qtblptr != NULL) { + for (i = 0; i < DCTSIZE; i++) { + for (j = 0; j < i; j++) { + qtemp = qtblptr->quantval[i*DCTSIZE+j]; + qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i]; + qtblptr->quantval[j*DCTSIZE+i] = qtemp; + } + } + } + } +} + + +/* Adjust Exif image parameters. + * + * We try to adjust the Tags ExifImageWidth and ExifImageHeight if possible. + */ + +LOCAL(void) +adjust_exif_parameters (JOCTET FAR * data, unsigned int length, + JDIMENSION new_width, JDIMENSION new_height) +{ + boolean is_motorola; /* Flag for byte order */ + unsigned int number_of_tags, tagnum; + unsigned int firstoffset, offset; + JDIMENSION new_value; + + if (length < 12) return; /* Length of an IFD entry */ + + /* Discover byte order */ + if (GETJOCTET(data[0]) == 0x49 && GETJOCTET(data[1]) == 0x49) + is_motorola = FALSE; + else if (GETJOCTET(data[0]) == 0x4D && GETJOCTET(data[1]) == 0x4D) + is_motorola = TRUE; + else + return; + + /* Check Tag Mark */ + if (is_motorola) { + if (GETJOCTET(data[2]) != 0) return; + if (GETJOCTET(data[3]) != 0x2A) return; + } else { + if (GETJOCTET(data[3]) != 0) return; + if (GETJOCTET(data[2]) != 0x2A) return; + } + + /* Get first IFD offset (offset to IFD0) */ + if (is_motorola) { + if (GETJOCTET(data[4]) != 0) return; + if (GETJOCTET(data[5]) != 0) return; + firstoffset = GETJOCTET(data[6]); + firstoffset <<= 8; + firstoffset += GETJOCTET(data[7]); + } else { + if (GETJOCTET(data[7]) != 0) return; + if (GETJOCTET(data[6]) != 0) return; + firstoffset = GETJOCTET(data[5]); + firstoffset <<= 8; + firstoffset += GETJOCTET(data[4]); + } + if (firstoffset > length - 2) return; /* check end of data segment */ + + /* Get the number of directory entries contained in this IFD */ + if (is_motorola) { + number_of_tags = GETJOCTET(data[firstoffset]); + number_of_tags <<= 8; + number_of_tags += GETJOCTET(data[firstoffset+1]); + } else { + number_of_tags = GETJOCTET(data[firstoffset+1]); + number_of_tags <<= 8; + number_of_tags += GETJOCTET(data[firstoffset]); + } + if (number_of_tags == 0) return; + firstoffset += 2; + + /* Search for ExifSubIFD offset Tag in IFD0 */ + for (;;) { + if (firstoffset > length - 12) return; /* check end of data segment */ + /* Get Tag number */ + if (is_motorola) { + tagnum = GETJOCTET(data[firstoffset]); + tagnum <<= 8; + tagnum += GETJOCTET(data[firstoffset+1]); + } else { + tagnum = GETJOCTET(data[firstoffset+1]); + tagnum <<= 8; + tagnum += GETJOCTET(data[firstoffset]); + } + if (tagnum == 0x8769) break; /* found ExifSubIFD offset Tag */ + if (--number_of_tags == 0) return; + firstoffset += 12; + } + + /* Get the ExifSubIFD offset */ + if (is_motorola) { + if (GETJOCTET(data[firstoffset+8]) != 0) return; + if (GETJOCTET(data[firstoffset+9]) != 0) return; + offset = GETJOCTET(data[firstoffset+10]); + offset <<= 8; + offset += GETJOCTET(data[firstoffset+11]); + } else { + if (GETJOCTET(data[firstoffset+11]) != 0) return; + if (GETJOCTET(data[firstoffset+10]) != 0) return; + offset = GETJOCTET(data[firstoffset+9]); + offset <<= 8; + offset += GETJOCTET(data[firstoffset+8]); + } + if (offset > length - 2) return; /* check end of data segment */ + + /* Get the number of directory entries contained in this SubIFD */ + if (is_motorola) { + number_of_tags = GETJOCTET(data[offset]); + number_of_tags <<= 8; + number_of_tags += GETJOCTET(data[offset+1]); + } else { + number_of_tags = GETJOCTET(data[offset+1]); + number_of_tags <<= 8; + number_of_tags += GETJOCTET(data[offset]); + } + if (number_of_tags < 2) return; + offset += 2; + + /* Search for ExifImageWidth and ExifImageHeight Tags in this SubIFD */ + do { + if (offset > length - 12) return; /* check end of data segment */ + /* Get Tag number */ + if (is_motorola) { + tagnum = GETJOCTET(data[offset]); + tagnum <<= 8; + tagnum += GETJOCTET(data[offset+1]); + } else { + tagnum = GETJOCTET(data[offset+1]); + tagnum <<= 8; + tagnum += GETJOCTET(data[offset]); + } + if (tagnum == 0xA002 || tagnum == 0xA003) { + if (tagnum == 0xA002) + new_value = new_width; /* ExifImageWidth Tag */ + else + new_value = new_height; /* ExifImageHeight Tag */ + if (is_motorola) { + data[offset+2] = 0; /* Format = unsigned long (4 octets) */ + data[offset+3] = 4; + data[offset+4] = 0; /* Number Of Components = 1 */ + data[offset+5] = 0; + data[offset+6] = 0; + data[offset+7] = 1; + data[offset+8] = 0; + data[offset+9] = 0; + data[offset+10] = (JOCTET)((new_value >> 8) & 0xFF); + data[offset+11] = (JOCTET)(new_value & 0xFF); + } else { + data[offset+2] = 4; /* Format = unsigned long (4 octets) */ + data[offset+3] = 0; + data[offset+4] = 1; /* Number Of Components = 1 */ + data[offset+5] = 0; + data[offset+6] = 0; + data[offset+7] = 0; + data[offset+8] = (JOCTET)(new_value & 0xFF); + data[offset+9] = (JOCTET)((new_value >> 8) & 0xFF); + data[offset+10] = 0; + data[offset+11] = 0; + } + } + offset += 12; + } while (--number_of_tags); +} + + +/* Adjust output image parameters as needed. + * + * This must be called after jpeg_copy_critical_parameters() + * and before jpeg_write_coefficients(). + * + * The return value is the set of virtual coefficient arrays to be written + * (either the ones allocated by jtransform_request_workspace, or the + * original source data arrays). The caller will need to pass this value + * to jpeg_write_coefficients(). + */ + +GLOBAL(jvirt_barray_ptr *) +jtransform_adjust_parameters (j_decompress_ptr srcinfo, + j_compress_ptr dstinfo, + jvirt_barray_ptr *src_coef_arrays, + jpeg_transform_info *info) +{ + /* If force-to-grayscale is requested, adjust destination parameters */ + if (info->force_grayscale) { + /* First, ensure we have YCbCr or grayscale data, and that the source's + * Y channel is full resolution. (No reasonable person would make Y + * be less than full resolution, so actually coping with that case + * isn't worth extra code space. But we check it to avoid crashing.) + */ + if (((dstinfo->jpeg_color_space == JCS_YCbCr && + dstinfo->num_components == 3) || + (dstinfo->jpeg_color_space == JCS_GRAYSCALE && + dstinfo->num_components == 1)) && + srcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor && + srcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) { + /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed + * properly. Among other things, it sets the target h_samp_factor & + * v_samp_factor to 1, which typically won't match the source. + * We have to preserve the source's quantization table number, however. + */ + int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no; + jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE); + dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no; + } else { + /* Sorry, can't do it */ + ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL); + } + } else if (info->num_components == 1) { + /* For a single-component source, we force the destination sampling factors + * to 1x1, with or without force_grayscale. This is useful because some + * decoders choke on grayscale images with other sampling factors. + */ + dstinfo->comp_info[0].h_samp_factor = 1; + dstinfo->comp_info[0].v_samp_factor = 1; + } + + /* Correct the destination's image dimensions as necessary + * for rotate/flip, resize, and crop operations. + */ +#if JPEG_LIB_VERSION >= 70 + dstinfo->jpeg_width = info->output_width; + dstinfo->jpeg_height = info->output_height; +#endif + + /* Transpose destination image parameters */ + switch (info->transform) { + case JXFORM_TRANSPOSE: + case JXFORM_TRANSVERSE: + case JXFORM_ROT_90: + case JXFORM_ROT_270: +#if JPEG_LIB_VERSION < 70 + dstinfo->image_width = info->output_height; + dstinfo->image_height = info->output_width; +#endif + transpose_critical_parameters(dstinfo); + break; + default: +#if JPEG_LIB_VERSION < 70 + dstinfo->image_width = info->output_width; + dstinfo->image_height = info->output_height; +#endif + break; + } + + /* Adjust Exif properties */ + if (srcinfo->marker_list != NULL && + srcinfo->marker_list->marker == JPEG_APP0+1 && + srcinfo->marker_list->data_length >= 6 && + GETJOCTET(srcinfo->marker_list->data[0]) == 0x45 && + GETJOCTET(srcinfo->marker_list->data[1]) == 0x78 && + GETJOCTET(srcinfo->marker_list->data[2]) == 0x69 && + GETJOCTET(srcinfo->marker_list->data[3]) == 0x66 && + GETJOCTET(srcinfo->marker_list->data[4]) == 0 && + GETJOCTET(srcinfo->marker_list->data[5]) == 0) { + /* Suppress output of JFIF marker */ + dstinfo->write_JFIF_header = FALSE; +#if JPEG_LIB_VERSION >= 70 + /* Adjust Exif image parameters */ + if (dstinfo->jpeg_width != srcinfo->image_width || + dstinfo->jpeg_height != srcinfo->image_height) + /* Align data segment to start of TIFF structure for parsing */ + adjust_exif_parameters(srcinfo->marker_list->data + 6, + srcinfo->marker_list->data_length - 6, + dstinfo->jpeg_width, dstinfo->jpeg_height); +#endif + } + + /* Return the appropriate output data set */ + if (info->workspace_coef_arrays != NULL) + return info->workspace_coef_arrays; + return src_coef_arrays; +} + + +/* Execute the actual transformation, if any. + * + * This must be called *after* jpeg_write_coefficients, because it depends + * on jpeg_write_coefficients to have computed subsidiary values such as + * the per-component width and height fields in the destination object. + * + * Note that some transformations will modify the source data arrays! + */ + +GLOBAL(void) +jtransform_execute_transform (j_decompress_ptr srcinfo, + j_compress_ptr dstinfo, + jvirt_barray_ptr *src_coef_arrays, + jpeg_transform_info *info) +{ + jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays; + + /* Note: conditions tested here should match those in switch statement + * in jtransform_request_workspace() + */ + switch (info->transform) { + case JXFORM_NONE: + if (info->x_crop_offset != 0 || info->y_crop_offset != 0) + do_crop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + break; + case JXFORM_FLIP_H: + if (info->y_crop_offset != 0 || info->slow_hflip) + do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + else + do_flip_h_no_crop(srcinfo, dstinfo, info->x_crop_offset, + src_coef_arrays); + break; + case JXFORM_FLIP_V: + do_flip_v(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + break; + case JXFORM_TRANSPOSE: + do_transpose(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + break; + case JXFORM_TRANSVERSE: + do_transverse(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + break; + case JXFORM_ROT_90: + do_rot_90(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + break; + case JXFORM_ROT_180: + do_rot_180(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + break; + case JXFORM_ROT_270: + do_rot_270(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, + src_coef_arrays, dst_coef_arrays); + break; + } +} + +/* jtransform_perfect_transform + * + * Determine whether lossless transformation is perfectly + * possible for a specified image and transformation. + * + * Inputs: + * image_width, image_height: source image dimensions. + * MCU_width, MCU_height: pixel dimensions of MCU. + * transform: transformation identifier. + * Parameter sources from initialized jpeg_struct + * (after reading source header): + * image_width = cinfo.image_width + * image_height = cinfo.image_height + * MCU_width = cinfo.max_h_samp_factor * cinfo.block_size + * MCU_height = cinfo.max_v_samp_factor * cinfo.block_size + * Result: + * TRUE = perfect transformation possible + * FALSE = perfect transformation not possible + * (may use custom action then) + */ + +GLOBAL(boolean) +jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height, + int MCU_width, int MCU_height, + JXFORM_CODE transform) +{ + boolean result = TRUE; /* initialize TRUE */ + + switch (transform) { + case JXFORM_FLIP_H: + case JXFORM_ROT_270: + if (image_width % (JDIMENSION) MCU_width) + result = FALSE; + break; + case JXFORM_FLIP_V: + case JXFORM_ROT_90: + if (image_height % (JDIMENSION) MCU_height) + result = FALSE; + break; + case JXFORM_TRANSVERSE: + case JXFORM_ROT_180: + if (image_width % (JDIMENSION) MCU_width) + result = FALSE; + if (image_height % (JDIMENSION) MCU_height) + result = FALSE; + break; + default: + break; + } + + return result; +} + +#endif /* TRANSFORMS_SUPPORTED */ + + +/* Setup decompression object to save desired markers in memory. + * This must be called before jpeg_read_header() to have the desired effect. + */ + +GLOBAL(void) +jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option) +{ +#ifdef SAVE_MARKERS_SUPPORTED + int m; + + /* Save comments except under NONE option */ + if (option != JCOPYOPT_NONE) { + jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF); + } + /* Save all types of APPn markers iff ALL option */ + if (option == JCOPYOPT_ALL) { + for (m = 0; m < 16; m++) + jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF); + } +#endif /* SAVE_MARKERS_SUPPORTED */ +} + +/* Copy markers saved in the given source object to the destination object. + * This should be called just after jpeg_start_compress() or + * jpeg_write_coefficients(). + * Note that those routines will have written the SOI, and also the + * JFIF APP0 or Adobe APP14 markers if selected. + */ + +GLOBAL(void) +jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JCOPY_OPTION option) +{ + jpeg_saved_marker_ptr marker; + + /* In the current implementation, we don't actually need to examine the + * option flag here; we just copy everything that got saved. + * But to avoid confusion, we do not output JFIF and Adobe APP14 markers + * if the encoder library already wrote one. + */ + for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) { + if (dstinfo->write_JFIF_header && + marker->marker == JPEG_APP0 && + marker->data_length >= 5 && + GETJOCTET(marker->data[0]) == 0x4A && + GETJOCTET(marker->data[1]) == 0x46 && + GETJOCTET(marker->data[2]) == 0x49 && + GETJOCTET(marker->data[3]) == 0x46 && + GETJOCTET(marker->data[4]) == 0) + continue; /* reject duplicate JFIF */ + if (dstinfo->write_Adobe_marker && + marker->marker == JPEG_APP0+14 && + marker->data_length >= 5 && + GETJOCTET(marker->data[0]) == 0x41 && + GETJOCTET(marker->data[1]) == 0x64 && + GETJOCTET(marker->data[2]) == 0x6F && + GETJOCTET(marker->data[3]) == 0x62 && + GETJOCTET(marker->data[4]) == 0x65) + continue; /* reject duplicate Adobe */ +#ifdef NEED_FAR_POINTERS + /* We could use jpeg_write_marker if the data weren't FAR... */ + { + unsigned int i; + jpeg_write_m_header(dstinfo, marker->marker, marker->data_length); + for (i = 0; i < marker->data_length; i++) + jpeg_write_m_byte(dstinfo, marker->data[i]); + } +#else + jpeg_write_marker(dstinfo, marker->marker, + marker->data, marker->data_length); +#endif + } +} diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/transupp.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/transupp.h new file mode 100755 index 0000000..122d448 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/transupp.h @@ -0,0 +1,217 @@ +/* + * transupp.h + * + * Copyright (C) 1997-2009, Thomas G. Lane, Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains declarations for image transformation routines and + * other utility code used by the jpegtran sample application. These are + * NOT part of the core JPEG library. But we keep these routines separate + * from jpegtran.c to ease the task of maintaining jpegtran-like programs + * that have other user interfaces. + * + * NOTE: all the routines declared here have very specific requirements + * about when they are to be executed during the reading and writing of the + * source and destination files. See the comments in transupp.c, or see + * jpegtran.c for an example of correct usage. + */ + +/* If you happen not to want the image transform support, disable it here */ +#ifndef TRANSFORMS_SUPPORTED +#define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */ +#endif + +/* + * Although rotating and flipping data expressed as DCT coefficients is not + * hard, there is an asymmetry in the JPEG format specification for images + * whose dimensions aren't multiples of the iMCU size. The right and bottom + * image edges are padded out to the next iMCU boundary with junk data; but + * no padding is possible at the top and left edges. If we were to flip + * the whole image including the pad data, then pad garbage would become + * visible at the top and/or left, and real pixels would disappear into the + * pad margins --- perhaps permanently, since encoders & decoders may not + * bother to preserve DCT blocks that appear to be completely outside the + * nominal image area. So, we have to exclude any partial iMCUs from the + * basic transformation. + * + * Transpose is the only transformation that can handle partial iMCUs at the + * right and bottom edges completely cleanly. flip_h can flip partial iMCUs + * at the bottom, but leaves any partial iMCUs at the right edge untouched. + * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched. + * The other transforms are defined as combinations of these basic transforms + * and process edge blocks in a way that preserves the equivalence. + * + * The "trim" option causes untransformable partial iMCUs to be dropped; + * this is not strictly lossless, but it usually gives the best-looking + * result for odd-size images. Note that when this option is active, + * the expected mathematical equivalences between the transforms may not hold. + * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim + * followed by -rot 180 -trim trims both edges.) + * + * We also offer a lossless-crop option, which discards data outside a given + * image region but losslessly preserves what is inside. Like the rotate and + * flip transforms, lossless crop is restricted by the JPEG format: the upper + * left corner of the selected region must fall on an iMCU boundary. If this + * does not hold for the given crop parameters, we silently move the upper left + * corner up and/or left to make it so, simultaneously increasing the region + * dimensions to keep the lower right crop corner unchanged. (Thus, the + * output image covers at least the requested region, but may cover more.) + * + * We also provide a lossless-resize option, which is kind of a lossless-crop + * operation in the DCT coefficient block domain - it discards higher-order + * coefficients and losslessly preserves lower-order coefficients of a + * sub-block. + * + * Rotate/flip transform, resize, and crop can be requested together in a + * single invocation. The crop is applied last --- that is, the crop region + * is specified in terms of the destination image after transform/resize. + * + * We also offer a "force to grayscale" option, which simply discards the + * chrominance channels of a YCbCr image. This is lossless in the sense that + * the luminance channel is preserved exactly. It's not the same kind of + * thing as the rotate/flip transformations, but it's convenient to handle it + * as part of this package, mainly because the transformation routines have to + * be aware of the option to know how many components to work on. + */ + + +/* Short forms of external names for systems with brain-damaged linkers. */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jtransform_parse_crop_spec jTrParCrop +#define jtransform_request_workspace jTrRequest +#define jtransform_adjust_parameters jTrAdjust +#define jtransform_execute_transform jTrExec +#define jtransform_perfect_transform jTrPerfect +#define jcopy_markers_setup jCMrkSetup +#define jcopy_markers_execute jCMrkExec +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + + +/* + * Codes for supported types of image transformations. + */ + +typedef enum { + JXFORM_NONE, /* no transformation */ + JXFORM_FLIP_H, /* horizontal flip */ + JXFORM_FLIP_V, /* vertical flip */ + JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ + JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ + JXFORM_ROT_90, /* 90-degree clockwise rotation */ + JXFORM_ROT_180, /* 180-degree rotation */ + JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */ +} JXFORM_CODE; + +/* + * Codes for crop parameters, which can individually be unspecified, + * positive, or negative. (Negative width or height makes no sense, though.) + */ + +typedef enum { + JCROP_UNSET, + JCROP_POS, + JCROP_NEG +} JCROP_CODE; + +/* + * Transform parameters struct. + * NB: application must not change any elements of this struct after + * calling jtransform_request_workspace. + */ + +typedef struct { + /* Options: set by caller */ + JXFORM_CODE transform; /* image transform operator */ + boolean perfect; /* if TRUE, fail if partial MCUs are requested */ + boolean trim; /* if TRUE, trim partial MCUs as needed */ + boolean force_grayscale; /* if TRUE, convert color image to grayscale */ + boolean crop; /* if TRUE, crop source image */ + boolean slow_hflip; /* For best performance, the JXFORM_FLIP_H transform + normally modifies the source coefficients in place. + Setting this to TRUE will instead use a slower, + double-buffered algorithm, which leaves the source + coefficients in tact (necessary if other transformed + images must be generated from the same set of + coefficients. */ + + /* Crop parameters: application need not set these unless crop is TRUE. + * These can be filled in by jtransform_parse_crop_spec(). + */ + JDIMENSION crop_width; /* Width of selected region */ + JCROP_CODE crop_width_set; + JDIMENSION crop_height; /* Height of selected region */ + JCROP_CODE crop_height_set; + JDIMENSION crop_xoffset; /* X offset of selected region */ + JCROP_CODE crop_xoffset_set; /* (negative measures from right edge) */ + JDIMENSION crop_yoffset; /* Y offset of selected region */ + JCROP_CODE crop_yoffset_set; /* (negative measures from bottom edge) */ + + /* Internal workspace: caller should not touch these */ + int num_components; /* # of components in workspace */ + jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */ + JDIMENSION output_width; /* cropped destination dimensions */ + JDIMENSION output_height; + JDIMENSION x_crop_offset; /* destination crop offsets measured in iMCUs */ + JDIMENSION y_crop_offset; + int iMCU_sample_width; /* destination iMCU size */ + int iMCU_sample_height; +} jpeg_transform_info; + + +#if TRANSFORMS_SUPPORTED + +/* Parse a crop specification (written in X11 geometry style) */ +EXTERN(boolean) jtransform_parse_crop_spec + JPP((jpeg_transform_info *info, const char *spec)); +/* Request any required workspace */ +EXTERN(boolean) jtransform_request_workspace + JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info)); +/* Adjust output image parameters */ +EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters + JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + jvirt_barray_ptr *src_coef_arrays, + jpeg_transform_info *info)); +/* Execute the actual transformation, if any */ +EXTERN(void) jtransform_execute_transform + JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + jvirt_barray_ptr *src_coef_arrays, + jpeg_transform_info *info)); +/* Determine whether lossless transformation is perfectly + * possible for a specified image and transformation. + */ +EXTERN(boolean) jtransform_perfect_transform + JPP((JDIMENSION image_width, JDIMENSION image_height, + int MCU_width, int MCU_height, + JXFORM_CODE transform)); + +/* jtransform_execute_transform used to be called + * jtransform_execute_transformation, but some compilers complain about + * routine names that long. This macro is here to avoid breaking any + * old source code that uses the original name... + */ +#define jtransform_execute_transformation jtransform_execute_transform + +#endif /* TRANSFORMS_SUPPORTED */ + + +/* + * Support for copying optional markers from source to destination file. + */ + +typedef enum { + JCOPYOPT_NONE, /* copy no optional markers */ + JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */ + JCOPYOPT_ALL /* copy all optional markers */ +} JCOPY_OPTION; + +#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */ + +/* Setup decompression object to save desired markers in memory */ +EXTERN(void) jcopy_markers_setup + JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option)); +/* Copy markers saved in the given source object to the destination object */ +EXTERN(void) jcopy_markers_execute + JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, + JCOPY_OPTION option)); diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg-mapfile b/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg-mapfile new file mode 100755 index 0000000..bd1ac71 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg-mapfile @@ -0,0 +1,38 @@ +TURBOJPEG_1.0 +{ + global: + tjInitCompress; + tjCompress; + TJBUFSIZE; + tjInitDecompress; + tjDecompressHeader; + tjDecompress; + tjDestroy; + tjGetErrorStr; + local: + *; +}; + +TURBOJPEG_1.1 +{ + global: + TJBUFSIZEYUV; + tjDecompressHeader2; + tjDecompressToYUV; + tjEncodeYUV; +} TURBOJPEG_1.0; + +TURBOJPEG_1.2 +{ + global: + tjAlloc; + tjBufSize; + tjBufSizeYUV; + tjCompress2; + tjDecompress2; + tjEncodeYUV2; + tjFree; + tjGetScalingFactors; + tjInitTransform; + tjTransform; +} TURBOJPEG_1.1; diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg.c b/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg.c new file mode 100755 index 0000000..21599c8 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg.c @@ -0,0 +1,1328 @@ +/* + * Copyright (C)2009-2012 D. R. Commander. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the libjpeg-turbo Project nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* TurboJPEG/OSS: this implements the TurboJPEG API using libjpeg-turbo */ + +#include +#include +#include +#define JPEG_INTERNALS +#include +#include +#include +#include "./turbojpeg.h" +#include "./tjutil.h" +#include "transupp.h" + +extern void jpeg_mem_dest_tj(j_compress_ptr, unsigned char **, + unsigned long *, boolean); +extern void jpeg_mem_src_tj(j_decompress_ptr, unsigned char *, unsigned long); + +#define PAD(v, p) ((v+(p)-1)&(~((p)-1))) + + +/* Error handling (based on example in example.c) */ + +static char errStr[JMSG_LENGTH_MAX]="No error"; + +struct my_error_mgr +{ + struct jpeg_error_mgr pub; + jmp_buf setjmp_buffer; +}; +typedef struct my_error_mgr *my_error_ptr; + +static void my_error_exit(j_common_ptr cinfo) +{ + my_error_ptr myerr=(my_error_ptr)cinfo->err; + (*cinfo->err->output_message)(cinfo); + longjmp(myerr->setjmp_buffer, 1); +} + +/* Based on output_message() in jerror.c */ + +static void my_output_message(j_common_ptr cinfo) +{ + (*cinfo->err->format_message)(cinfo, errStr); +} + + +/* Global structures, macros, etc. */ + +enum {COMPRESS=1, DECOMPRESS=2}; + +typedef struct _tjinstance +{ + struct jpeg_compress_struct cinfo; + struct jpeg_decompress_struct dinfo; + struct my_error_mgr jerr; + int init; +} tjinstance; + +static const int pixelsize[TJ_NUMSAMP]={3, 3, 3, 1, 3}; + +static const JXFORM_CODE xformtypes[TJ_NUMXOP]= +{ + JXFORM_NONE, JXFORM_FLIP_H, JXFORM_FLIP_V, JXFORM_TRANSPOSE, + JXFORM_TRANSVERSE, JXFORM_ROT_90, JXFORM_ROT_180, JXFORM_ROT_270 +}; + +#define NUMSF 16 +static const tjscalingfactor sf[NUMSF]={ + {2, 1}, + {15, 8}, + {7, 4}, + {13, 8}, + {3, 2}, + {11, 8}, + {5, 4}, + {9, 8}, + {1, 1}, + {7, 8}, + {3, 4}, + {5, 8}, + {1, 2}, + {3, 8}, + {1, 4}, + {1, 8} +}; + +#define _throw(m) {snprintf(errStr, JMSG_LENGTH_MAX, "%s", m); \ + retval=-1; goto bailout;} +#define getinstance(handle) tjinstance *this=(tjinstance *)handle; \ + j_compress_ptr cinfo=NULL; j_decompress_ptr dinfo=NULL; \ + if(!this) {snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \ + return -1;} \ + cinfo=&this->cinfo; dinfo=&this->dinfo; + +static int getPixelFormat(int pixelSize, int flags) +{ + if(pixelSize==1) return TJPF_GRAY; + if(pixelSize==3) + { + if(flags&TJ_BGR) return TJPF_BGR; + else return TJPF_RGB; + } + if(pixelSize==4) + { + if(flags&TJ_ALPHAFIRST) + { + if(flags&TJ_BGR) return TJPF_XBGR; + else return TJPF_XRGB; + } + else + { + if(flags&TJ_BGR) return TJPF_BGRX; + else return TJPF_RGBX; + } + } + return -1; +} + +static int setCompDefaults(struct jpeg_compress_struct *cinfo, + int pixelFormat, int subsamp, int jpegQual, int flags) +{ + int retval=0; + + switch(pixelFormat) + { + case TJPF_GRAY: + cinfo->in_color_space=JCS_GRAYSCALE; break; + #if JCS_EXTENSIONS==1 + case TJPF_RGB: + cinfo->in_color_space=JCS_EXT_RGB; break; + case TJPF_BGR: + cinfo->in_color_space=JCS_EXT_BGR; break; + case TJPF_RGBX: + case TJPF_RGBA: + cinfo->in_color_space=JCS_EXT_RGBX; break; + case TJPF_BGRX: + case TJPF_BGRA: + cinfo->in_color_space=JCS_EXT_BGRX; break; + case TJPF_XRGB: + case TJPF_ARGB: + cinfo->in_color_space=JCS_EXT_XRGB; break; + case TJPF_XBGR: + case TJPF_ABGR: + cinfo->in_color_space=JCS_EXT_XBGR; break; + #else + case TJPF_RGB: + case TJPF_BGR: + case TJPF_RGBX: + case TJPF_BGRX: + case TJPF_XRGB: + case TJPF_XBGR: + case TJPF_RGBA: + case TJPF_BGRA: + case TJPF_ARGB: + case TJPF_ABGR: + cinfo->in_color_space=JCS_RGB; pixelFormat=TJPF_RGB; + break; + #endif + } + + cinfo->input_components=tjPixelSize[pixelFormat]; + jpeg_set_defaults(cinfo); + if(jpegQual>=0) + { + jpeg_set_quality(cinfo, jpegQual, TRUE); + if(jpegQual>=96 || flags&TJFLAG_ACCURATEDCT) cinfo->dct_method=JDCT_ISLOW; + else cinfo->dct_method=JDCT_FASTEST; + } + if(subsamp==TJSAMP_GRAY) + jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); + else + jpeg_set_colorspace(cinfo, JCS_YCbCr); + + cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8; + cinfo->comp_info[1].h_samp_factor=1; + cinfo->comp_info[2].h_samp_factor=1; + cinfo->comp_info[0].v_samp_factor=tjMCUHeight[subsamp]/8; + cinfo->comp_info[1].v_samp_factor=1; + cinfo->comp_info[2].v_samp_factor=1; + + return retval; +} + +static int setDecompDefaults(struct jpeg_decompress_struct *dinfo, + int pixelFormat, int flags) +{ + int retval=0; + + switch(pixelFormat) + { + case TJPF_GRAY: + dinfo->out_color_space=JCS_GRAYSCALE; break; + #if JCS_EXTENSIONS==1 + case TJPF_RGB: + dinfo->out_color_space=JCS_EXT_RGB; break; + case TJPF_BGR: + dinfo->out_color_space=JCS_EXT_BGR; break; + case TJPF_RGBX: + dinfo->out_color_space=JCS_EXT_RGBX; break; + case TJPF_BGRX: + dinfo->out_color_space=JCS_EXT_BGRX; break; + case TJPF_XRGB: + dinfo->out_color_space=JCS_EXT_XRGB; break; + case TJPF_XBGR: + dinfo->out_color_space=JCS_EXT_XBGR; break; + #if JCS_ALPHA_EXTENSIONS==1 + case TJPF_RGBA: + dinfo->out_color_space=JCS_EXT_RGBA; break; + case TJPF_BGRA: + dinfo->out_color_space=JCS_EXT_BGRA; break; + case TJPF_ARGB: + dinfo->out_color_space=JCS_EXT_ARGB; break; + case TJPF_ABGR: + dinfo->out_color_space=JCS_EXT_ABGR; break; + #endif + #else + case TJPF_RGB: + case TJPF_BGR: + case TJPF_RGBX: + case TJPF_BGRX: + case TJPF_XRGB: + case TJPF_XBGR: + case TJPF_RGBA: + case TJPF_BGRA: + case TJPF_ARGB: + case TJPF_ABGR: + dinfo->out_color_space=JCS_RGB; break; + #endif + default: + _throw("Unsupported pixel format"); + } + + if(flags&TJFLAG_FASTDCT) dinfo->dct_method=JDCT_FASTEST; + + bailout: + return retval; +} + + +static int getSubsamp(j_decompress_ptr dinfo) +{ + int retval=-1, i, k; + for(i=0; inum_components==pixelsize[i]) + { + if(dinfo->comp_info[0].h_samp_factor==tjMCUWidth[i]/8 + && dinfo->comp_info[0].v_samp_factor==tjMCUHeight[i]/8) + { + int match=0; + for(k=1; knum_components; k++) + { + if(dinfo->comp_info[k].h_samp_factor==1 + && dinfo->comp_info[k].v_samp_factor==1) + match++; + } + if(match==dinfo->num_components-1) + { + retval=i; break; + } + } + } + } + return retval; +} + + +#ifndef JCS_EXTENSIONS + +/* Conversion functions to emulate the colorspace extensions. This allows the + TurboJPEG wrapper to be used with libjpeg */ + +#define TORGB(PS, ROFFSET, GOFFSET, BOFFSET) { \ + int rowPad=pitch-width*PS; \ + while(height--) \ + { \ + unsigned char *endOfRow=src+width*PS; \ + while(srcjerr.setjmp_buffer)) return -1; + if(this->init&COMPRESS) jpeg_destroy_compress(cinfo); + if(this->init&DECOMPRESS) jpeg_destroy_decompress(dinfo); + free(this); + return 0; +} + + +/* These are exposed mainly because Windows can't malloc() and free() across + DLL boundaries except when the CRT DLL is used, and we don't use the CRT DLL + with turbojpeg.dll for compatibility reasons. However, these functions + can potentially be used for other purposes by different implementations. */ + +DLLEXPORT void DLLCALL tjFree(unsigned char *buf) +{ + if(buf) free(buf); +} + + +DLLEXPORT unsigned char *DLLCALL tjAlloc(int bytes) +{ + return (unsigned char *)malloc(bytes); +} + + +/* Compressor */ + +static tjhandle _tjInitCompress(tjinstance *this) +{ + unsigned char buffer[1], *buf=buffer; unsigned long size=1; + + /* This is also straight out of example.c */ + this->cinfo.err=jpeg_std_error(&this->jerr.pub); + this->jerr.pub.error_exit=my_error_exit; + this->jerr.pub.output_message=my_output_message; + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + if(this) free(this); return NULL; + } + + jpeg_create_compress(&this->cinfo); + /* Make an initial call so it will create the destination manager */ + jpeg_mem_dest_tj(&this->cinfo, &buf, &size, 0); + + this->init|=COMPRESS; + return (tjhandle)this; +} + +DLLEXPORT tjhandle DLLCALL tjInitCompress(void) +{ + tjinstance *this=NULL; + if((this=(tjinstance *)malloc(sizeof(tjinstance)))==NULL) + { + snprintf(errStr, JMSG_LENGTH_MAX, + "tjInitCompress(): Memory allocation failure"); + return NULL; + } + MEMZERO(this, sizeof(tjinstance)); + return _tjInitCompress(this); +} + + +DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height, + int jpegSubsamp) +{ + unsigned long retval=0; int mcuw, mcuh, chromasf; + if(width<1 || height<1 || jpegSubsamp<0 || jpegSubsamp>=NUMSUBOPT) + _throw("tjBufSize(): Invalid argument"); + + // This allows for rare corner cases in which a JPEG image can actually be + // larger than the uncompressed input (we wouldn't mention it if it hadn't + // happened before.) + mcuw=tjMCUWidth[jpegSubsamp]; + mcuh=tjMCUHeight[jpegSubsamp]; + chromasf=jpegSubsamp==TJSAMP_GRAY? 0: 4*64/(mcuw*mcuh); + retval=PAD(width, mcuw) * PAD(height, mcuh) * (2 + chromasf) + 2048; + + bailout: + return retval; +} + + +DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height) +{ + unsigned long retval=0; + if(width<1 || height<1) + _throw("TJBUFSIZE(): Invalid argument"); + + // This allows for rare corner cases in which a JPEG image can actually be + // larger than the uncompressed input (we wouldn't mention it if it hadn't + // happened before.) + retval=PAD(width, 16) * PAD(height, 16) * 6 + 2048; + + bailout: + return retval; +} + + +DLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height, + int subsamp) +{ + unsigned long retval=0; + int pw, ph, cw, ch; + if(width<1 || height<1 || subsamp<0 || subsamp>=NUMSUBOPT) + _throw("tjBufSizeYUV(): Invalid argument"); + pw=PAD(width, tjMCUWidth[subsamp]/8); + ph=PAD(height, tjMCUHeight[subsamp]/8); + cw=pw*8/tjMCUWidth[subsamp]; ch=ph*8/tjMCUHeight[subsamp]; + retval=PAD(pw, 4)*ph + (subsamp==TJSAMP_GRAY? 0:PAD(cw, 4)*ch*2); + + bailout: + return retval; +} + + +DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height, + int subsamp) +{ + return tjBufSizeYUV(width, height, subsamp); +} + + +DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, + int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, + unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags) +{ + int i, retval=0, alloc=1; JSAMPROW *row_pointer=NULL; + #ifndef JCS_EXTENSIONS + unsigned char *rgbBuf=NULL; + #endif + + getinstance(handle) + if((this->init&COMPRESS)==0) + _throw("tjCompress2(): Instance has not been initialized for compression"); + + if(srcBuf==NULL || width<=0 || pitch<0 || height<=0 || pixelFormat<0 + || pixelFormat>=TJ_NUMPF || jpegBuf==NULL || jpegSize==NULL + || jpegSubsamp<0 || jpegSubsamp>=NUMSUBOPT || jpegQual<0 || jpegQual>100) + _throw("tjCompress2(): Invalid argument"); + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; + goto bailout; + } + + if(pitch==0) pitch=width*tjPixelSize[pixelFormat]; + + #ifndef JCS_EXTENSIONS + if(pixelFormat!=TJPF_GRAY) + { + rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE); + if(!rgbBuf) _throw("tjCompress2(): Memory allocation failure"); + srcBuf=toRGB(srcBuf, width, pitch, height, pixelFormat, rgbBuf); + pitch=width*RGB_PIXELSIZE; + } + #endif + + cinfo->image_width=width; + cinfo->image_height=height; + + if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); + else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); + else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); + + if(flags&TJFLAG_NOREALLOC) + { + alloc=0; *jpegSize=tjBufSize(width, height, jpegSubsamp); + } + jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); + if(setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual, flags)==-1) + return -1; + + jpeg_start_compress(cinfo, TRUE); + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) + _throw("tjCompress2(): Memory allocation failure"); + for(i=0; inext_scanlineimage_height) + { + jpeg_write_scanlines(cinfo, &row_pointer[cinfo->next_scanline], + cinfo->image_height-cinfo->next_scanline); + } + jpeg_finish_compress(cinfo); + + bailout: + if(cinfo->global_state>CSTATE_START) jpeg_abort_compress(cinfo); + #ifndef JCS_EXTENSIONS + if(rgbBuf) free(rgbBuf); + #endif + if(row_pointer) free(row_pointer); + return retval; +} + +DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf, + int width, int pitch, int height, int pixelSize, unsigned char *jpegBuf, + unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags) +{ + int retval=0; unsigned long size; + if(flags&TJ_YUV) + { + size=tjBufSizeYUV(width, height, jpegSubsamp); + retval=tjEncodeYUV2(handle, srcBuf, width, pitch, height, + getPixelFormat(pixelSize, flags), jpegBuf, jpegSubsamp, flags); + } + else + { + retval=tjCompress2(handle, srcBuf, width, pitch, height, + getPixelFormat(pixelSize, flags), &jpegBuf, &size, jpegSubsamp, jpegQual, + flags|TJFLAG_NOREALLOC); + } + *jpegSize=size; + return retval; +} + + +DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, + int width, int pitch, int height, int pixelFormat, unsigned char *dstBuf, + int subsamp, int flags) +{ + int i, retval=0; JSAMPROW *row_pointer=NULL; + JSAMPLE *_tmpbuf[MAX_COMPONENTS], *_tmpbuf2[MAX_COMPONENTS]; + JSAMPROW *tmpbuf[MAX_COMPONENTS], *tmpbuf2[MAX_COMPONENTS]; + JSAMPROW *outbuf[MAX_COMPONENTS]; + int row, pw, ph, cw[MAX_COMPONENTS], ch[MAX_COMPONENTS]; + JSAMPLE *ptr=dstBuf; + unsigned long yuvsize=0; + jpeg_component_info *compptr; + #ifndef JCS_EXTENSIONS + unsigned char *rgbBuf=NULL; + #endif + + getinstance(handle); + if((this->init&COMPRESS)==0) + _throw("tjEncodeYUV2(): Instance has not been initialized for compression"); + + for(i=0; i=TJ_NUMPF || dstBuf==NULL || subsamp<0 + || subsamp>=NUMSUBOPT) + _throw("tjEncodeYUV2(): Invalid argument"); + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; + goto bailout; + } + + if(pitch==0) pitch=width*tjPixelSize[pixelFormat]; + + #ifndef JCS_EXTENSIONS + if(pixelFormat!=TJPF_GRAY) + { + rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE); + if(!rgbBuf) _throw("tjEncodeYUV2(): Memory allocation failure"); + srcBuf=toRGB(srcBuf, width, pitch, height, pixelFormat, rgbBuf); + pitch=width*RGB_PIXELSIZE; + } + #endif + + cinfo->image_width=width; + cinfo->image_height=height; + + if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); + else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); + else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); + + yuvsize=tjBufSizeYUV(width, height, subsamp); + jpeg_mem_dest_tj(cinfo, &dstBuf, &yuvsize, 0); + if(setCompDefaults(cinfo, pixelFormat, subsamp, -1, flags)==-1) return -1; + + jpeg_start_compress(cinfo, TRUE); + pw=PAD(width, cinfo->max_h_samp_factor); + ph=PAD(height, cinfo->max_v_samp_factor); + + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) + _throw("tjEncodeYUV2(): Memory allocation failure"); + for(i=0; inum_components; i++) + { + compptr=&cinfo->comp_info[i]; + _tmpbuf[i]=(JSAMPLE *)malloc( + PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE) + /compptr->h_samp_factor, 16) * cinfo->max_v_samp_factor + 16); + if(!_tmpbuf[i]) _throw("tjEncodeYUV2(): Memory allocation failure"); + tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*cinfo->max_v_samp_factor); + if(!tmpbuf[i]) _throw("tjEncodeYUV2(): Memory allocation failure"); + for(row=0; rowmax_v_samp_factor; row++) + { + unsigned char *_tmpbuf_aligned= + (unsigned char *)PAD((size_t)_tmpbuf[i], 16); + tmpbuf[i][row]=&_tmpbuf_aligned[ + PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE) + /compptr->h_samp_factor, 16) * row]; + } + _tmpbuf2[i]=(JSAMPLE *)malloc(PAD(compptr->width_in_blocks*DCTSIZE, 16) + * compptr->v_samp_factor + 16); + if(!_tmpbuf2[i]) _throw("tjEncodeYUV2(): Memory allocation failure"); + tmpbuf2[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*compptr->v_samp_factor); + if(!tmpbuf2[i]) _throw("tjEncodeYUV2(): Memory allocation failure"); + for(row=0; rowv_samp_factor; row++) + { + unsigned char *_tmpbuf2_aligned= + (unsigned char *)PAD((size_t)_tmpbuf2[i], 16); + tmpbuf2[i][row]=&_tmpbuf2_aligned[ + PAD(compptr->width_in_blocks*DCTSIZE, 16) * row]; + } + cw[i]=pw*compptr->h_samp_factor/cinfo->max_h_samp_factor; + ch[i]=ph*compptr->v_samp_factor/cinfo->max_v_samp_factor; + outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]); + if(!outbuf[i]) _throw("tjEncodeYUV2(): Memory allocation failure"); + for(row=0; rowmax_v_samp_factor) + { + (*cinfo->cconvert->color_convert)(cinfo, &row_pointer[row], tmpbuf, 0, + cinfo->max_v_samp_factor); + (cinfo->downsample->downsample)(cinfo, tmpbuf, 0, tmpbuf2, 0); + for(i=0, compptr=cinfo->comp_info; inum_components; i++, compptr++) + jcopy_sample_rows(tmpbuf2[i], 0, outbuf[i], + row*compptr->v_samp_factor/cinfo->max_v_samp_factor, + compptr->v_samp_factor, cw[i]); + } + cinfo->next_scanline+=height; + jpeg_abort_compress(cinfo); + + bailout: + if(cinfo->global_state>CSTATE_START) jpeg_abort_compress(cinfo); + #ifndef JCS_EXTENSIONS + if(rgbBuf) free(rgbBuf); + #endif + if(row_pointer) free(row_pointer); + for(i=0; idinfo.err=jpeg_std_error(&this->jerr.pub); + this->jerr.pub.error_exit=my_error_exit; + this->jerr.pub.output_message=my_output_message; + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + if(this) free(this); return NULL; + } + + jpeg_create_decompress(&this->dinfo); + /* Make an initial call so it will create the source manager */ + jpeg_mem_src_tj(&this->dinfo, buffer, 1); + + this->init|=DECOMPRESS; + return (tjhandle)this; +} + +DLLEXPORT tjhandle DLLCALL tjInitDecompress(void) +{ + tjinstance *this; + if((this=(tjinstance *)malloc(sizeof(tjinstance)))==NULL) + { + snprintf(errStr, JMSG_LENGTH_MAX, + "tjInitDecompress(): Memory allocation failure"); + return NULL; + } + MEMZERO(this, sizeof(tjinstance)); + return _tjInitDecompress(this); +} + + +DLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, + int *jpegSubsamp) +{ + int retval=0; + + getinstance(handle); + if((this->init&DECOMPRESS)==0) + _throw("tjDecompressHeader2(): Instance has not been initialized for decompression"); + + if(jpegBuf==NULL || jpegSize<=0 || width==NULL || height==NULL + || jpegSubsamp==NULL) + _throw("tjDecompressHeader2(): Invalid argument"); + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + return -1; + } + + jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); + jpeg_read_header(dinfo, TRUE); + + *width=dinfo->image_width; + *height=dinfo->image_height; + *jpegSubsamp=getSubsamp(dinfo); + + jpeg_abort_decompress(dinfo); + + if(*jpegSubsamp<0) + _throw("tjDecompressHeader2(): Could not determine subsampling type for JPEG image"); + if(*width<1 || *height<1) + _throw("tjDecompressHeader2(): Invalid data returned in header"); + + bailout: + return retval; +} + +DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height) +{ + int jpegSubsamp; + return tjDecompressHeader2(handle, jpegBuf, jpegSize, width, height, + &jpegSubsamp); +} + + +DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors) +{ + if(numscalingfactors==NULL) + { + snprintf(errStr, JMSG_LENGTH_MAX, + "tjGetScalingFactors(): Invalid argument"); + return NULL; + } + + *numscalingfactors=NUMSF; + return (tjscalingfactor *)sf; +} + + +DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, unsigned char *jpegBuf, + unsigned long jpegSize, unsigned char *dstBuf, int width, int pitch, + int height, int pixelFormat, int flags) +{ + int i, retval=0; JSAMPROW *row_pointer=NULL; + int jpegwidth, jpegheight, scaledw, scaledh; + #ifndef JCS_EXTENSIONS + unsigned char *rgbBuf=NULL; + unsigned char *_dstBuf=NULL; int _pitch=0; + #endif + + getinstance(handle); + if((this->init&DECOMPRESS)==0) + _throw("tjDecompress2(): Instance has not been initialized for decompression"); + + if(jpegBuf==NULL || jpegSize<=0 || dstBuf==NULL || width<0 || pitch<0 + || height<0 || pixelFormat<0 || pixelFormat>=TJ_NUMPF) + _throw("tjDecompress2(): Invalid argument"); + + if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); + else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); + else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; + goto bailout; + } + + jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); + jpeg_read_header(dinfo, TRUE); + if(setDecompDefaults(dinfo, pixelFormat, flags)==-1) + { + retval=-1; goto bailout; + } + + if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE; + + jpegwidth=dinfo->image_width; jpegheight=dinfo->image_height; + if(width==0) width=jpegwidth; + if(height==0) height=jpegheight; + for(i=0; iwidth || scaledh>height) + _throw("tjDecompress2(): Could not scale down to desired image dimensions"); + width=scaledw; height=scaledh; + dinfo->scale_num=sf[i].num; + dinfo->scale_denom=sf[i].denom; + + jpeg_start_decompress(dinfo); + if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat]; + + #ifndef JCS_EXTENSIONS + if(pixelFormat!=TJPF_GRAY && + (RGB_RED!=tjRedOffset[pixelFormat] || + RGB_GREEN!=tjGreenOffset[pixelFormat] || + RGB_BLUE!=tjBlueOffset[pixelFormat] || + RGB_PIXELSIZE!=tjPixelSize[pixelFormat])) + { + rgbBuf=(unsigned char *)malloc(width*height*3); + if(!rgbBuf) _throw("tjDecompress2(): Memory allocation failure"); + _pitch=pitch; pitch=width*3; + _dstBuf=dstBuf; dstBuf=rgbBuf; + } + #endif + + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW) + *dinfo->output_height))==NULL) + _throw("tjDecompress2(): Memory allocation failure"); + for(i=0; i<(int)dinfo->output_height; i++) + { + if(flags&TJFLAG_BOTTOMUP) + row_pointer[i]=&dstBuf[(dinfo->output_height-i-1)*pitch]; + else row_pointer[i]=&dstBuf[i*pitch]; + } + while(dinfo->output_scanlineoutput_height) + { + jpeg_read_scanlines(dinfo, &row_pointer[dinfo->output_scanline], + dinfo->output_height-dinfo->output_scanline); + } + jpeg_finish_decompress(dinfo); + + #ifndef JCS_EXTENSIONS + fromRGB(rgbBuf, _dstBuf, width, _pitch, height, pixelFormat); + #endif + + bailout: + if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo); + #ifndef JCS_EXTENSIONS + if(rgbBuf) free(rgbBuf); + #endif + if(row_pointer) free(row_pointer); + return retval; +} + +DLLEXPORT int DLLCALL tjDecompress(tjhandle handle, unsigned char *jpegBuf, + unsigned long jpegSize, unsigned char *dstBuf, int width, int pitch, + int height, int pixelSize, int flags) +{ + if(flags&TJ_YUV) + return tjDecompressToYUV(handle, jpegBuf, jpegSize, dstBuf, flags); + else + return tjDecompress2(handle, jpegBuf, jpegSize, dstBuf, width, pitch, + height, getPixelFormat(pixelSize, flags), flags); +} + + +DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, + int flags) +{ + int i, row, retval=0; JSAMPROW *outbuf[MAX_COMPONENTS]; + int cw[MAX_COMPONENTS], ch[MAX_COMPONENTS], iw[MAX_COMPONENTS], + tmpbufsize=0, usetmpbuf=0, th[MAX_COMPONENTS]; + JSAMPLE *_tmpbuf=NULL, *ptr=dstBuf; JSAMPROW *tmpbuf[MAX_COMPONENTS]; + + getinstance(handle); + if((this->init&DECOMPRESS)==0) + _throw("tjDecompressToYUV(): Instance has not been initialized for decompression"); + + for(i=0; ijerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; + goto bailout; + } + + jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); + jpeg_read_header(dinfo, TRUE); + + for(i=0; inum_components; i++) + { + jpeg_component_info *compptr=&dinfo->comp_info[i]; + int ih; + iw[i]=compptr->width_in_blocks*DCTSIZE; + ih=compptr->height_in_blocks*DCTSIZE; + cw[i]=PAD(dinfo->image_width, dinfo->max_h_samp_factor) + *compptr->h_samp_factor/dinfo->max_h_samp_factor; + ch[i]=PAD(dinfo->image_height, dinfo->max_v_samp_factor) + *compptr->v_samp_factor/dinfo->max_v_samp_factor; + if(iw[i]!=cw[i] || ih!=ch[i]) usetmpbuf=1; + th[i]=compptr->v_samp_factor*DCTSIZE; + tmpbufsize+=iw[i]*th[i]; + if((outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]))==NULL) + _throw("tjDecompressToYUV(): Memory allocation failure"); + for(row=0; rownum_components; i++) + { + if((tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*th[i]))==NULL) + _throw("tjDecompressToYUV(): Memory allocation failure"); + for(row=0; rowdo_fancy_upsampling=FALSE; + if(flags&TJFLAG_FASTDCT) dinfo->dct_method=JDCT_FASTEST; + dinfo->raw_data_out=TRUE; + + jpeg_start_decompress(dinfo); + for(row=0; row<(int)dinfo->output_height; + row+=dinfo->max_v_samp_factor*DCTSIZE) + { + JSAMPARRAY yuvptr[MAX_COMPONENTS]; + int crow[MAX_COMPONENTS]; + for(i=0; inum_components; i++) + { + jpeg_component_info *compptr=&dinfo->comp_info[i]; + crow[i]=row*compptr->v_samp_factor/dinfo->max_v_samp_factor; + if(usetmpbuf) yuvptr[i]=tmpbuf[i]; + else yuvptr[i]=&outbuf[i][crow[i]]; + } + jpeg_read_raw_data(dinfo, yuvptr, dinfo->max_v_samp_factor*DCTSIZE); + if(usetmpbuf) + { + int j; + for(i=0; inum_components; i++) + { + for(j=0; jglobal_state>DSTATE_START) jpeg_abort_decompress(dinfo); + for(i=0; iinit&COMPRESS)==0 || (this->init&DECOMPRESS)==0) + _throw("tjTransform(): Instance has not been initialized for transformation"); + + if(jpegBuf==NULL || jpegSize<=0 || n<1 || dstBufs==NULL || dstSizes==NULL + || t==NULL || flags<0) + _throw("tjTransform(): Invalid argument"); + + if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); + else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); + else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; + goto bailout; + } + + jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); + + if((xinfo=(jpeg_transform_info *)malloc(sizeof(jpeg_transform_info)*n)) + ==NULL) + _throw("tjTransform(): Memory allocation failure"); + MEMZERO(xinfo, sizeof(jpeg_transform_info)*n); + + for(i=0; iimage_width; h=dinfo->image_height; + } + else + { + w=xinfo[i].crop_width; h=xinfo[i].crop_height; + } + if(flags&TJFLAG_NOREALLOC) + { + alloc=0; dstSizes[i]=tjBufSize(w, h, jpegSubsamp); + } + if(!(t[i].options&TJXOPT_NOOUTPUT)) + jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i], alloc); + jpeg_copy_critical_parameters(dinfo, cinfo); + dstcoefs=jtransform_adjust_parameters(dinfo, cinfo, srccoefs, + &xinfo[i]); + if(!(t[i].options&TJXOPT_NOOUTPUT)) + { + jpeg_write_coefficients(cinfo, dstcoefs); + jcopy_markers_execute(dinfo, cinfo, JCOPYOPT_ALL); + } + else jinit_c_master_control(cinfo, TRUE); + jtransform_execute_transformation(dinfo, cinfo, srccoefs, + &xinfo[i]); + if(t[i].customFilter) + { + int ci, y; JDIMENSION by; + for(ci=0; cinum_components; ci++) + { + jpeg_component_info *compptr=&cinfo->comp_info[ci]; + tjregion arrayRegion={0, 0, compptr->width_in_blocks*DCTSIZE, + DCTSIZE}; + tjregion planeRegion={0, 0, compptr->width_in_blocks*DCTSIZE, + compptr->height_in_blocks*DCTSIZE}; + for(by=0; byheight_in_blocks; by+=compptr->v_samp_factor) + { + JBLOCKARRAY barray=(dinfo->mem->access_virt_barray) + ((j_common_ptr)dinfo, dstcoefs[ci], by, compptr->v_samp_factor, + TRUE); + for(y=0; yv_samp_factor; y++) + { + if(t[i].customFilter(barray[y][0], arrayRegion, planeRegion, + ci, i, &t[i])==-1) + _throw("tjTransform(): Error in custom filter"); + arrayRegion.y+=DCTSIZE; + } + } + } + } + if(!(t[i].options&TJXOPT_NOOUTPUT)) jpeg_finish_compress(cinfo); + } + + jpeg_finish_decompress(dinfo); + + bailout: + if(cinfo->global_state>CSTATE_START) jpeg_abort_compress(cinfo); + if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo); + if(xinfo) free(xinfo); + return retval; +} diff --git a/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg.h b/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg.h new file mode 100755 index 0000000..7610221 --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/libturbojpeg/turbojpeg.h @@ -0,0 +1,917 @@ +/* + * Copyright (C)2009-2012 D. R. Commander. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the libjpeg-turbo Project nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __TURBOJPEG_H__ +#define __TURBOJPEG_H__ + +#if defined(_WIN32) && defined(DLLDEFINE) +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif +#define DLLCALL + + +/** + * @addtogroup TurboJPEG + * TurboJPEG API. This API provides an interface for generating, decoding, and + * transforming planar YUV and JPEG images in memory. + * + * @{ + */ + + +/** + * The number of chrominance subsampling options + */ +#define TJ_NUMSAMP 5 + +/** + * Chrominance subsampling options. + * When an image is converted from the RGB to the YCbCr colorspace as part of + * the JPEG compression process, some of the Cb and Cr (chrominance) components + * can be discarded or averaged together to produce a smaller image with little + * perceptible loss of image clarity (the human eye is more sensitive to small + * changes in brightness than small changes in color.) This is called + * "chrominance subsampling". + */ +enum TJSAMP +{ + /** + * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or + * YUV image will contain one chrominance component for every pixel in the + * source image. + */ + TJSAMP_444=0, + /** + * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one + * chrominance component for every 2x1 block of pixels in the source image. + */ + TJSAMP_422, + /** + * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one + * chrominance component for every 2x2 block of pixels in the source image. + */ + TJSAMP_420, + /** + * Grayscale. The JPEG or YUV image will contain no chrominance components. + */ + TJSAMP_GRAY, + /** + * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one + * chrominance component for every 1x2 block of pixels in the source image. + */ + TJSAMP_440 +}; + +/** + * MCU block width (in pixels) for a given level of chrominance subsampling. + * MCU block sizes: + * - 8x8 for no subsampling or grayscale + * - 16x8 for 4:2:2 + * - 8x16 for 4:4:0 + * - 16x16 for 4:2:0 + */ +static const int tjMCUWidth[TJ_NUMSAMP] = {8, 16, 16, 8, 8}; + +/** + * MCU block height (in pixels) for a given level of chrominance subsampling. + * MCU block sizes: + * - 8x8 for no subsampling or grayscale + * - 16x8 for 4:2:2 + * - 8x16 for 4:4:0 + * - 16x16 for 4:2:0 + */ +static const int tjMCUHeight[TJ_NUMSAMP] = {8, 8, 16, 8, 16}; + + +/** + * The number of pixel formats + */ +#define TJ_NUMPF 11 + +/** + * Pixel formats + */ +enum TJPF +{ + /** + * RGB pixel format. The red, green, and blue components in the image are + * stored in 3-byte pixels in the order R, G, B from lowest to highest byte + * address within each pixel. + */ + TJPF_RGB=0, + /** + * BGR pixel format. The red, green, and blue components in the image are + * stored in 3-byte pixels in the order B, G, R from lowest to highest byte + * address within each pixel. + */ + TJPF_BGR, + /** + * RGBX pixel format. The red, green, and blue components in the image are + * stored in 4-byte pixels in the order R, G, B from lowest to highest byte + * address within each pixel. The X component is ignored when compressing + * and undefined when decompressing. + */ + TJPF_RGBX, + /** + * BGRX pixel format. The red, green, and blue components in the image are + * stored in 4-byte pixels in the order B, G, R from lowest to highest byte + * address within each pixel. The X component is ignored when compressing + * and undefined when decompressing. + */ + TJPF_BGRX, + /** + * XBGR pixel format. The red, green, and blue components in the image are + * stored in 4-byte pixels in the order R, G, B from highest to lowest byte + * address within each pixel. The X component is ignored when compressing + * and undefined when decompressing. + */ + TJPF_XBGR, + /** + * XRGB pixel format. The red, green, and blue components in the image are + * stored in 4-byte pixels in the order B, G, R from highest to lowest byte + * address within each pixel. The X component is ignored when compressing + * and undefined when decompressing. + */ + TJPF_XRGB, + /** + * Grayscale pixel format. Each 1-byte pixel represents a luminance + * (brightness) level from 0 to 255. + */ + TJPF_GRAY, + /** + * RGBA pixel format. This is the same as @ref TJPF_RGBX, except that when + * decompressing, the X component is guaranteed to be 0xFF, which can be + * interpreted as an opaque alpha channel. + */ + TJPF_RGBA, + /** + * BGRA pixel format. This is the same as @ref TJPF_BGRX, except that when + * decompressing, the X component is guaranteed to be 0xFF, which can be + * interpreted as an opaque alpha channel. + */ + TJPF_BGRA, + /** + * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when + * decompressing, the X component is guaranteed to be 0xFF, which can be + * interpreted as an opaque alpha channel. + */ + TJPF_ABGR, + /** + * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when + * decompressing, the X component is guaranteed to be 0xFF, which can be + * interpreted as an opaque alpha channel. + */ + TJPF_ARGB +}; + +/** + * Red offset (in bytes) for a given pixel format. This specifies the number + * of bytes that the red component is offset from the start of the pixel. For + * instance, if a pixel of format TJ_BGRX is stored in char pixel[], + * then the red component will be pixel[tjRedOffset[TJ_BGRX]]. + */ +static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1}; +/** + * Green offset (in bytes) for a given pixel format. This specifies the number + * of bytes that the green component is offset from the start of the pixel. + * For instance, if a pixel of format TJ_BGRX is stored in + * char pixel[], then the green component will be + * pixel[tjGreenOffset[TJ_BGRX]]. + */ +static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2}; +/** + * Blue offset (in bytes) for a given pixel format. This specifies the number + * of bytes that the Blue component is offset from the start of the pixel. For + * instance, if a pixel of format TJ_BGRX is stored in char pixel[], + * then the blue component will be pixel[tjBlueOffset[TJ_BGRX]]. + */ +static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3}; + +/** + * Pixel size (in bytes) for a given pixel format. + */ +static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4}; + + +/** + * The uncompressed source/destination image is stored in bottom-up (Windows, + * OpenGL) order, not top-down (X11) order. + */ +#define TJFLAG_BOTTOMUP 2 +/** + * Turn off CPU auto-detection and force TurboJPEG to use MMX code (if the + * underlying codec supports it.) + */ +#define TJFLAG_FORCEMMX 8 +/** + * Turn off CPU auto-detection and force TurboJPEG to use SSE code (if the + * underlying codec supports it.) + */ +#define TJFLAG_FORCESSE 16 +/** + * Turn off CPU auto-detection and force TurboJPEG to use SSE2 code (if the + * underlying codec supports it.) + */ +#define TJFLAG_FORCESSE2 32 +/** + * Turn off CPU auto-detection and force TurboJPEG to use SSE3 code (if the + * underlying codec supports it.) + */ +#define TJFLAG_FORCESSE3 128 +/** + * When decompressing, use the fastest chrominance upsampling algorithm + * available in the underlying codec. The default is to use smooth upsampling, + * which creates a smooth transition between neighboring chrominance components + * in order to reduce upsampling artifacts in the decompressed image. + */ +#define TJFLAG_FASTUPSAMPLE 256 +/** + * Disable buffer (re)allocation. If passed to #tjCompress2() or + * #tjTransform(), this flag will cause those functions to generate an error if + * the JPEG image buffer is invalid or too small rather than attempting to + * allocate or reallocate that buffer. This reproduces the behavior of earlier + * versions of TurboJPEG. + */ +#define TJFLAG_NOREALLOC 1024 +/** + * Use the fastest DCT/IDCT algorithm available in the underlying codec. The + * default if this flag is not specified is implementation-specific. The + * libjpeg implementation, for example, uses the fast algorithm by default when + * compressing, because this has been shown to have only a very slight effect + * on accuracy, but it uses the accurate algorithm when decompressing, because + * this has been shown to have a larger effect. + */ +#define TJFLAG_FASTDCT 2048 +/** + * Use the most accurate DCT/IDCT algorithm available in the underlying codec. + * The default if this flag is not specified is implementation-specific. The + * libjpeg implementation, for example, uses the fast algorithm by default when + * compressing, because this has been shown to have only a very slight effect + * on accuracy, but it uses the accurate algorithm when decompressing, because + * this has been shown to have a larger effect. + */ +#define TJFLAG_ACCURATEDCT 4096 + + +/** + * Number of transform operations + */ +#define TJ_NUMXOP 8 + +/** + * Transform operations for #tjTransform() + */ +enum TJXOP +{ + /** + * Do not transform the position of the image pixels + */ + TJXOP_NONE=0, + /** + * Flip (mirror) image horizontally. This transform is imperfect if there + * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.) + */ + TJXOP_HFLIP, + /** + * Flip (mirror) image vertically. This transform is imperfect if there are + * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.) + */ + TJXOP_VFLIP, + /** + * Transpose image (flip/mirror along upper left to lower right axis.) This + * transform is always perfect. + */ + TJXOP_TRANSPOSE, + /** + * Transverse transpose image (flip/mirror along upper right to lower left + * axis.) This transform is imperfect if there are any partial MCU blocks in + * the image (see #TJXOPT_PERFECT.) + */ + TJXOP_TRANSVERSE, + /** + * Rotate image clockwise by 90 degrees. This transform is imperfect if + * there are any partial MCU blocks on the bottom edge (see + * #TJXOPT_PERFECT.) + */ + TJXOP_ROT90, + /** + * Rotate image 180 degrees. This transform is imperfect if there are any + * partial MCU blocks in the image (see #TJXOPT_PERFECT.) + */ + TJXOP_ROT180, + /** + * Rotate image counter-clockwise by 90 degrees. This transform is imperfect + * if there are any partial MCU blocks on the right edge (see + * #TJXOPT_PERFECT.) + */ + TJXOP_ROT270 +}; + + +/** + * This option will cause #tjTransform() to return an error if the transform is + * not perfect. Lossless transforms operate on MCU blocks, whose size depends + * on the level of chrominance subsampling used (see #tjMCUWidth + * and #tjMCUHeight.) If the image's width or height is not evenly divisible + * by the MCU block size, then there will be partial MCU blocks on the right + * and/or bottom edges. It is not possible to move these partial MCU blocks to + * the top or left of the image, so any transform that would require that is + * "imperfect." If this option is not specified, then any partial MCU blocks + * that cannot be transformed will be left in place, which will create + * odd-looking strips on the right or bottom edge of the image. + */ +#define TJXOPT_PERFECT 1 +/** + * This option will cause #tjTransform() to discard any partial MCU blocks that + * cannot be transformed. + */ +#define TJXOPT_TRIM 2 +/** + * This option will enable lossless cropping. See #tjTransform() for more + * information. + */ +#define TJXOPT_CROP 4 +/** + * This option will discard the color data in the input image and produce + * a grayscale output image. + */ +#define TJXOPT_GRAY 8 +/** + * This option will prevent #tjTransform() from outputting a JPEG image for + * this particular transform (this can be used in conjunction with a custom + * filter to capture the transformed DCT coefficients without transcoding + * them.) + */ +#define TJXOPT_NOOUTPUT 16 + + +/** + * Scaling factor + */ +typedef struct +{ + /** + * Numerator + */ + int num; + /** + * Denominator + */ + int denom; +} tjscalingfactor; + +/** + * Cropping region + */ +typedef struct +{ + /** + * The left boundary of the cropping region. This must be evenly divisible + * by the MCU block width (see #tjMCUWidth.) + */ + int x; + /** + * The upper boundary of the cropping region. This must be evenly divisible + * by the MCU block height (see #tjMCUHeight.) + */ + int y; + /** + * The width of the cropping region. Setting this to 0 is the equivalent of + * setting it to the width of the source JPEG image - x. + */ + int w; + /** + * The height of the cropping region. Setting this to 0 is the equivalent of + * setting it to the height of the source JPEG image - y. + */ + int h; +} tjregion; + +/** + * Lossless transform + */ +typedef struct tjtransform +{ + /** + * Cropping region + */ + tjregion r; + /** + * One of the @ref TJXOP "transform operations" + */ + int op; + /** + * The bitwise OR of one of more of the @ref TJXOPT_CROP "transform options" + */ + int options; + /** + * Arbitrary data that can be accessed within the body of the callback + * function + */ + void *data; + /** + * A callback function that can be used to modify the DCT coefficients + * after they are losslessly transformed but before they are transcoded to a + * new JPEG file. This allows for custom filters or other transformations to + * be applied in the frequency domain. + * + * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE: + * this pointer is not guaranteed to be valid once the callback + * returns, so applications wishing to hand off the DCT coefficients + * to another function or library should make a copy of them within + * the body of the callback.) + * @param arrayRegion #tjregion structure containing the width and height of + * the array pointed to by coeffs as well as its offset + * relative to the component plane. TurboJPEG implementations may + * choose to split each component plane into multiple DCT coefficient + * arrays and call the callback function once for each array. + * @param planeRegion #tjregion structure containing the width and height of + * the component plane to which coeffs belongs + * @param componentID ID number of the component plane to which + * coeffs belongs (Y, Cb, and Cr have, respectively, ID's of + * 0, 1, and 2 in typical JPEG images.) + * @param transformID ID number of the transformed image to which + * coeffs belongs. This is the same as the index of the + * transform in the transforms array that was passed to + * #tjTransform(). + * @param transform a pointer to a #tjtransform structure that specifies the + * parameters and/or cropping region for this transform + * + * @return 0 if the callback was successful, or -1 if an error occurred. + */ + int (*customFilter)(short *coeffs, tjregion arrayRegion, + tjregion planeRegion, int componentIndex, int transformIndex, + struct tjtransform *transform); +} tjtransform; + +/** + * TurboJPEG instance handle + */ +typedef void* tjhandle; + + +/** + * Pad the given width to the nearest 32-bit boundary + */ +#define TJPAD(width) (((width)+3)&(~3)) + +/** + * Compute the scaled value of dimension using the given scaling + * factor. This macro performs the integer equivalent of ceil(dimension * + * scalingFactor). + */ +#define TJSCALED(dimension, scalingFactor) ((dimension * scalingFactor.num \ + + scalingFactor.denom - 1) / scalingFactor.denom) + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Create a TurboJPEG compressor instance. + * + * @return a handle to the newly-created instance, or NULL if an error + * occurred (see #tjGetErrorStr().) + */ +DLLEXPORT tjhandle DLLCALL tjInitCompress(void); + + +/** + * Compress an RGB or grayscale image into a JPEG image. + * + * @param handle a handle to a TurboJPEG compressor or transformer instance + * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels + * to be compressed + * @param width width (in pixels) of the source image + * @param pitch bytes per line of the source image. Normally, this should be + * width * #tjPixelSize[pixelFormat] if the image is unpadded, + * or #TJPAD(width * #tjPixelSize[pixelFormat]) if each line of + * the image is padded to the nearest 32-bit boundary, as is the case + * for Windows bitmaps. You can also be clever and use this parameter + * to skip lines, etc. Setting this parameter to 0 is the equivalent of + * setting it to width * #tjPixelSize[pixelFormat]. + * @param height height (in pixels) of the source image + * @param pixelFormat pixel format of the source image (see @ref TJPF + * "Pixel formats".) + * @param jpegBuf address of a pointer to an image buffer that will receive the + * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer + * to accommodate the size of the JPEG image. Thus, you can choose to: + * -# pre-allocate the JPEG buffer with an arbitrary size using + * #tjAlloc() and let TurboJPEG grow the buffer as needed, + * -# set *jpegBuf to NULL to tell TurboJPEG to allocate the + * buffer for you, or + * -# pre-allocate the buffer to a "worst case" size determined by + * calling #tjBufSize(). This should ensure that the buffer never has + * to be re-allocated (setting #TJFLAG_NOREALLOC guarantees this.) + * . + * If you choose option 1, *jpegSize should be set to the + * size of your pre-allocated buffer. In any case, unless you have + * set #TJFLAG_NOREALLOC, you should always check *jpegBuf upon + * return from this function, as it may have changed. + * @param jpegSize pointer to an unsigned long variable that holds the size of + * the JPEG image buffer. If *jpegBuf points to a + * pre-allocated buffer, then *jpegSize should be set to the + * size of the buffer. Upon return, *jpegSize will contain the + * size of the JPEG image (in bytes.) + * @param jpegSubsamp the level of chrominance subsampling to be used when + * generating the JPEG image (see @ref TJSAMP + * "Chrominance subsampling options".) + * @param jpegQual the image quality of the generated JPEG image (1 = worst, + 100 = best) + * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP + * "flags". + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) +*/ +DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, + int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, + unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags); + + +/** + * The maximum size of the buffer (in bytes) required to hold a JPEG image with + * the given parameters. The number of bytes returned by this function is + * larger than the size of the uncompressed source image. The reason for this + * is that the JPEG format uses 16-bit coefficients, and it is thus possible + * for a very high-quality JPEG image with very high frequency content to + * expand rather than compress when converted to the JPEG format. Such images + * represent a very rare corner case, but since there is no way to predict the + * size of a JPEG image prior to compression, the corner case has to be + * handled. + * + * @param width width of the image (in pixels) + * @param height height of the image (in pixels) + * @param jpegSubsamp the level of chrominance subsampling to be used when + * generating the JPEG image (see @ref TJSAMP + * "Chrominance subsampling options".) + * + * @return the maximum size of the buffer (in bytes) required to hold the + * image, or -1 if the arguments are out of bounds. + */ +DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height, + int jpegSubsamp); + + +/** + * The size of the buffer (in bytes) required to hold a YUV planar image with + * the given parameters. + * + * @param width width of the image (in pixels) + * @param height height of the image (in pixels) + * @param subsamp level of chrominance subsampling in the image (see + * @ref TJSAMP "Chrominance subsampling options".) + * + * @return the size of the buffer (in bytes) required to hold the image, or + * -1 if the arguments are out of bounds. + */ +DLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height, + int subsamp); + + +/** + * Encode an RGB or grayscale image into a YUV planar image. This function + * uses the accelerated color conversion routines in TurboJPEG's underlying + * codec to produce a planar YUV image that is suitable for X Video. + * Specifically, if the chrominance components are subsampled along the + * horizontal dimension, then the width of the luminance plane is padded to 2 + * in the output image (same goes for the height of the luminance plane, if the + * chrominance components are subsampled along the vertical dimension.) Also, + * each line of each plane in the output image is padded to 4 bytes. Although + * this will work with any subsampling option, it is really only useful in + * combination with TJ_420, which produces an image compatible with the I420 + * (AKA "YUV420P") format. + * + * @param handle a handle to a TurboJPEG compressor or transformer instance + * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels + * to be encoded + * @param width width (in pixels) of the source image + * @param pitch bytes per line of the source image. Normally, this should be + * width * #tjPixelSize[pixelFormat] if the image is unpadded, + * or #TJPAD(width * #tjPixelSize[pixelFormat]) if each line of + * the image is padded to the nearest 32-bit boundary, as is the case + * for Windows bitmaps. You can also be clever and use this parameter + * to skip lines, etc. Setting this parameter to 0 is the equivalent of + * setting it to width * #tjPixelSize[pixelFormat]. + * @param height height (in pixels) of the source image + * @param pixelFormat pixel format of the source image (see @ref TJPF + * "Pixel formats".) + * @param dstBuf pointer to an image buffer that will receive the YUV image. + * Use #tjBufSizeYUV() to determine the appropriate size for this buffer + * based on the image width, height, and level of chrominance + * subsampling. + * @param subsamp the level of chrominance subsampling to be used when + * generating the YUV image (see @ref TJSAMP + * "Chrominance subsampling options".) + * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP + * "flags". + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) +*/ +DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle, + unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, + unsigned char *dstBuf, int subsamp, int flags); + + +/** + * Create a TurboJPEG decompressor instance. + * + * @return a handle to the newly-created instance, or NULL if an error + * occurred (see #tjGetErrorStr().) +*/ +DLLEXPORT tjhandle DLLCALL tjInitDecompress(void); + + +/** + * Retrieve information about a JPEG image without decompressing it. + * + * @param handle a handle to a TurboJPEG decompressor or transformer instance + * @param jpegBuf pointer to a buffer containing a JPEG image + * @param jpegSize size of the JPEG image (in bytes) + * @param width pointer to an integer variable that will receive the width (in + * pixels) of the JPEG image + * @param height pointer to an integer variable that will receive the height + * (in pixels) of the JPEG image + * @param jpegSubsamp pointer to an integer variable that will receive the + * level of chrominance subsampling used when compressing the JPEG image + * (see @ref TJSAMP "Chrominance subsampling options".) + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) +*/ +DLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, + int *jpegSubsamp); + + +/** + * Returns a list of fractional scaling factors that the JPEG decompressor in + * this implementation of TurboJPEG supports. + * + * @param numscalingfactors pointer to an integer variable that will receive + * the number of elements in the list + * + * @return a pointer to a list of fractional scaling factors, or NULL if an + * error is encountered (see #tjGetErrorStr().) +*/ +DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); + + +/** + * Decompress a JPEG image to an RGB or grayscale image. + * + * @param handle a handle to a TurboJPEG decompressor or transformer instance + * @param jpegBuf pointer to a buffer containing the JPEG image to decompress + * @param jpegSize size of the JPEG image (in bytes) + * @param dstBuf pointer to an image buffer that will receive the decompressed + * image. This buffer should normally be pitch * scaledHeight + * bytes in size, where scaledHeight can be determined by + * calling #TJSCALED() with the JPEG image height and one of the scaling + * factors returned by #tjGetScalingFactors(). The dstBuf pointer may + * also be used to decompress into a specific region of a larger buffer. + * @param width desired width (in pixels) of the destination image. If this is + * smaller than the width of the JPEG image being decompressed, then + * TurboJPEG will use scaling in the JPEG decompressor to generate the + * largest possible image that will fit within the desired width. If + * width is set to 0, then only the height will be considered when + * determining the scaled image size. + * @param pitch bytes per line of the destination image. Normally, this is + * scaledWidth * #tjPixelSize[pixelFormat] if the decompressed + * image is unpadded, else #TJPAD(scaledWidth * + * #tjPixelSize[pixelFormat]) if each line of the decompressed + * image is padded to the nearest 32-bit boundary, as is the case for + * Windows bitmaps. (NOTE: scaledWidth can be determined by + * calling #TJSCALED() with the JPEG image width and one of the scaling + * factors returned by #tjGetScalingFactors().) You can also be clever + * and use the pitch parameter to skip lines, etc. Setting this + * parameter to 0 is the equivalent of setting it to scaledWidth + * * #tjPixelSize[pixelFormat]. + * @param height desired height (in pixels) of the destination image. If this + * is smaller than the height of the JPEG image being decompressed, then + * TurboJPEG will use scaling in the JPEG decompressor to generate the + * largest possible image that will fit within the desired height. If + * height is set to 0, then only the width will be considered when + * determining the scaled image size. + * @param pixelFormat pixel format of the destination image (see @ref + * TJPF "Pixel formats".) + * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP + * "flags". + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) + */ +DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, + int width, int pitch, int height, int pixelFormat, int flags); + + +/** + * Decompress a JPEG image to a YUV planar image. This function performs JPEG + * decompression but leaves out the color conversion step, so a planar YUV + * image is generated instead of an RGB image. The padding of the planes in + * this image is the same as the images generated by #tjEncodeYUV2(). Note + * that, if the width or height of the image is not an even multiple of the MCU + * block size (see #tjMCUWidth and #tjMCUHeight), then an intermediate buffer + * copy will be performed within TurboJPEG. + * + * @param handle a handle to a TurboJPEG decompressor or transformer instance + * @param jpegBuf pointer to a buffer containing the JPEG image to decompress + * @param jpegSize size of the JPEG image (in bytes) + * @param dstBuf pointer to an image buffer that will receive the YUV image. + * Use #tjBufSizeYUV to determine the appropriate size for this buffer + * based on the image width, height, and level of subsampling. + * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP + * "flags". + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) + */ +DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, + int flags); + + +/** + * Create a new TurboJPEG transformer instance. + * + * @return a handle to the newly-created instance, or NULL if an error + * occurred (see #tjGetErrorStr().) + */ +DLLEXPORT tjhandle DLLCALL tjInitTransform(void); + + +/** + * Losslessly transform a JPEG image into another JPEG image. Lossless + * transforms work by moving the raw coefficients from one JPEG image structure + * to another without altering the values of the coefficients. While this is + * typically faster than decompressing the image, transforming it, and + * re-compressing it, lossless transforms are not free. Each lossless + * transform requires reading and Huffman decoding all of the coefficients in + * the source image, regardless of the size of the destination image. Thus, + * this function provides a means of generating multiple transformed images + * from the same source or of applying multiple transformations simultaneously, + * in order to eliminate the need to read the source coefficients multiple + * times. + * + * @param handle a handle to a TurboJPEG transformer instance + * @param jpegBuf pointer to a buffer containing the JPEG image to transform + * @param jpegSize size of the JPEG image (in bytes) + * @param n the number of transformed JPEG images to generate + * @param dstBufs pointer to an array of n image buffers. dstBufs[i] + * will receive a JPEG image that has been transformed using the + * parameters in transforms[i]. TurboJPEG has the ability to + * reallocate the JPEG buffer to accommodate the size of the JPEG image. + * Thus, you can choose to: + * -# pre-allocate the JPEG buffer with an arbitrary size using + * #tjAlloc() and let TurboJPEG grow the buffer as needed, + * -# set dstBufs[i] to NULL to tell TurboJPEG to allocate the + * buffer for you, or + * -# pre-allocate the buffer to a "worst case" size determined by + * calling #tjBufSize() with the cropped width and height. This should + * ensure that the buffer never has to be re-allocated (setting + * #TJFLAG_NOREALLOC guarantees this.) + * . + * If you choose option 1, dstSizes[i] should be set to + * the size of your pre-allocated buffer. In any case, unless you have + * set #TJFLAG_NOREALLOC, you should always check dstBufs[i] + * upon return from this function, as it may have changed. + * @param dstSizes pointer to an array of n unsigned long variables that will + * receive the actual sizes (in bytes) of each transformed JPEG image. + * If dstBufs[i] points to a pre-allocated buffer, then + * dstSizes[i] should be set to the size of the buffer. Upon + * return, dstSizes[i] will contain the size of the JPEG image + * (in bytes.) + * @param transforms pointer to an array of n tjtransform structures, each of + * which specifies the transform parameters and/or cropping region for + * the corresponding transformed output image. + * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP + * "flags". + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) + */ +DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf, + unsigned long jpegSize, int n, unsigned char **dstBufs, + unsigned long *dstSizes, tjtransform *transforms, int flags); + + +/** + * Destroy a TurboJPEG compressor, decompressor, or transformer instance. + * + * @param handle a handle to a TurboJPEG compressor, decompressor or + * transformer instance + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) + */ +DLLEXPORT int DLLCALL tjDestroy(tjhandle handle); + + +/** + * Allocate an image buffer for use with TurboJPEG. You should always use + * this function to allocate the JPEG destination buffer(s) for #tjCompress2() + * and #tjTransform() unless you are disabling automatic buffer + * (re)allocation (by setting #TJFLAG_NOREALLOC.) + * + * @param bytes the number of bytes to allocate + * + * @return a pointer to a newly-allocated buffer with the specified number of + * bytes + * + * @sa tjFree() + */ +DLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes); + + +/** + * Free an image buffer previously allocated by TurboJPEG. You should always + * use this function to free JPEG destination buffer(s) that were automatically + * (re)allocated by #tjCompress2() or #tjTransform() or that were manually + * allocated using #tjAlloc(). + * + * @param buffer address of the buffer to free + * + * @sa tjAlloc() + */ +DLLEXPORT void DLLCALL tjFree(unsigned char *buffer); + + +/** + * Returns a descriptive error message explaining why the last command failed. + * + * @return a descriptive error message explaining why the last command failed. + */ +DLLEXPORT char* DLLCALL tjGetErrorStr(void); + + +/* Backward compatibility functions and macros (nothing to see here) */ +#define NUMSUBOPT TJ_NUMSAMP +#define TJ_444 TJSAMP_444 +#define TJ_422 TJSAMP_422 +#define TJ_420 TJSAMP_420 +#define TJ_411 TJSAMP_420 +#define TJ_GRAYSCALE TJSAMP_GRAY + +#define TJ_BGR 1 +#define TJ_BOTTOMUP TJFLAG_BOTTOMUP +#define TJ_FORCEMMX TJFLAG_FORCEMMX +#define TJ_FORCESSE TJFLAG_FORCESSE +#define TJ_FORCESSE2 TJFLAG_FORCESSE2 +#define TJ_ALPHAFIRST 64 +#define TJ_FORCESSE3 TJFLAG_FORCESSE3 +#define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE +#define TJ_YUV 512 + +DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height); + +DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height, + int jpegSubsamp); + +DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf, + int width, int pitch, int height, int pixelSize, unsigned char *dstBuf, + unsigned long *compressedSize, int jpegSubsamp, int jpegQual, int flags); + +DLLEXPORT int DLLCALL tjEncodeYUV(tjhandle handle, + unsigned char *srcBuf, int width, int pitch, int height, int pixelSize, + unsigned char *dstBuf, int subsamp, int flags); + +DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height); + +DLLEXPORT int DLLCALL tjDecompress(tjhandle handle, + unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, + int width, int pitch, int height, int pixelSize, int flags); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib-third-party/libturbojpeg-ios/scripts/gas-preprocessor.pl b/lib-third-party/libturbojpeg-ios/scripts/gas-preprocessor.pl new file mode 100755 index 0000000..082f71b --- /dev/null +++ b/lib-third-party/libturbojpeg-ios/scripts/gas-preprocessor.pl @@ -0,0 +1,526 @@ +#!/usr/bin/env perl +# by David Conrad +# This code is licensed under GPLv2 or later; go to gnu.org to read it +# (not that it much matters for an asm preprocessor) +# usage: set your assembler to be something like "perl gas-preprocessor.pl gcc" +use strict; + +# Apple's gas is ancient and doesn't support modern preprocessing features like +# .rept and has ugly macro syntax, among other things. Thus, this script +# implements the subset of the gas preprocessor used by x264 and ffmpeg +# that isn't supported by Apple's gas. + +my @gcc_cmd = @ARGV; +my @preprocess_c_cmd; + +my $fix_unreq = $^O eq "darwin"; + +if ($gcc_cmd[0] eq "-fix-unreq") { + $fix_unreq = 1; + shift @gcc_cmd; +} elsif ($gcc_cmd[0] eq "-no-fix-unreq") { + $fix_unreq = 0; + shift @gcc_cmd; +} + +if (grep /\.c$/, @gcc_cmd) { + # C file (inline asm?) - compile + @preprocess_c_cmd = (@gcc_cmd, "-S"); +} elsif (grep /\.[sS]$/, @gcc_cmd) { + # asm file, just do C preprocessor + @preprocess_c_cmd = (@gcc_cmd, "-E"); +} else { + die "Unrecognized input filetype"; +} + +# if compiling, avoid creating an output file named '-.o' +if ((grep /^-c$/, @gcc_cmd) && !(grep /^-o/, @gcc_cmd)) { + foreach my $i (@gcc_cmd) { + if ($i =~ /\.[csS]$/) { + my $outputfile = $i; + $outputfile =~ s/\.[csS]$/.o/; + push(@gcc_cmd, "-o"); + push(@gcc_cmd, $outputfile); + last; + } + } +} +@gcc_cmd = map { /\.[csS]$/ ? qw(-x assembler -) : $_ } @gcc_cmd; +@preprocess_c_cmd = map { /\.o$/ ? "-" : $_ } @preprocess_c_cmd; + +my $comm; + +# detect architecture from gcc binary name +if ($gcc_cmd[0] =~ /arm/) { + $comm = '@'; +} elsif ($gcc_cmd[0] =~ /powerpc|ppc/) { + $comm = '#'; +} + +# look for -arch flag +foreach my $i (1 .. $#gcc_cmd-1) { + if ($gcc_cmd[$i] eq "-arch") { + if ($gcc_cmd[$i+1] =~ /arm/) { + $comm = '@'; + } elsif ($gcc_cmd[$i+1] =~ /powerpc|ppc/) { + $comm = '#'; + } + } +} + +# assume we're not cross-compiling if no -arch or the binary doesn't have the arch name +if (!$comm) { + my $native_arch = qx/arch/; + if ($native_arch =~ /arm/) { + $comm = '@'; + } elsif ($native_arch =~ /powerpc|ppc/) { + $comm = '#'; + } +} + +if (!$comm) { + die "Unable to identify target architecture"; +} + +my %ppc_spr = (ctr => 9, + vrsave => 256); + +open(ASMFILE, "-|", @preprocess_c_cmd) || die "Error running preprocessor"; + +my $current_macro = ''; +my $macro_level = 0; +my %macro_lines; +my %macro_args; +my %macro_args_default; +my $macro_count = 0; +my $altmacro = 0; + +my @pass1_lines; +my @ifstack; + +my %symbols; + +# pass 1: parse .macro +# note that the handling of arguments is probably overly permissive vs. gas +# but it should be the same for valid cases +while () { + # remove all comments (to avoid interfering with evaluating directives) + s/(? 0) { + $ifstack[-1] = -$ifstack[-1]; + } + return; + } elsif (/\.else/) { + $ifstack[-1] = !$ifstack[-1]; + return; + } elsif (handle_if($line)) { + return; + } + + # discard lines in false .if blocks + foreach my $i (0 .. $#ifstack) { + if ($ifstack[$i] <= 0) { + return; + } + } + } + + if (/\.macro/) { + $macro_level++; + if ($macro_level > 1 && !$current_macro) { + die "nested macros but we don't have master macro"; + } + } elsif (/\.endm/) { + $macro_level--; + if ($macro_level < 0) { + die "unmatched .endm"; + } elsif ($macro_level == 0) { + $current_macro = ''; + return; + } + } + + if ($macro_level > 1) { + push(@{$macro_lines{$current_macro}}, $line); + } elsif ($macro_level == 0) { + expand_macros($line); + } else { + if ($line =~ /\.macro\s+([\d\w\.]+)\s*(.*)/) { + $current_macro = $1; + + # commas in the argument list are optional, so only use whitespace as the separator + my $arglist = $2; + $arglist =~ s/,/ /g; + + my @args = split(/\s+/, $arglist); + foreach my $i (0 .. $#args) { + my @argpair = split(/=/, $args[$i]); + $macro_args{$current_macro}[$i] = $argpair[0]; + $argpair[0] =~ s/:vararg$//; + $macro_args_default{$current_macro}{$argpair[0]} = $argpair[1]; + } + # ensure %macro_lines has the macro name added as a key + $macro_lines{$current_macro} = []; + + } elsif ($current_macro) { + push(@{$macro_lines{$current_macro}}, $line); + } else { + die "macro level without a macro name"; + } + } +} + +sub expand_macros { + my $line = @_[0]; + + # handle .if directives; apple's assembler doesn't support important non-basic ones + # evaluating them is also needed to handle recursive macros + if (handle_if($line)) { + return; + } + + if (/\.purgem\s+([\d\w\.]+)/) { + delete $macro_lines{$1}; + delete $macro_args{$1}; + delete $macro_args_default{$1}; + return; + } + + if ($line =~ /\.altmacro/) { + $altmacro = 1; + return; + } + + if ($line =~ /\.noaltmacro/) { + $altmacro = 0; + return; + } + + $line =~ s/\%([^,]*)/eval_expr($1)/eg if $altmacro; + + if ($line =~ /\.set\s+(.*),\s*(.*)/) { + $symbols{$1} = eval_expr($2); + } + + if ($line =~ /(\S+:|)\s*([\w\d\.]+)\s*(.*)/ && exists $macro_lines{$2}) { + push(@pass1_lines, $1); + my $macro = $2; + + # commas are optional here too, but are syntactically important because + # parameters can be blank + my @arglist = split(/,/, $3); + my @args; + my @args_seperator; + + my $comma_sep_required = 0; + foreach (@arglist) { + # allow arithmetic/shift operators in macro arguments + $_ =~ s/\s*(\+|-|\*|\/|<<|>>)\s*/$1/g; + + my @whitespace_split = split(/\s+/, $_); + if (!@whitespace_split) { + push(@args, ''); + push(@args_seperator, ''); + } else { + foreach (@whitespace_split) { + #print ("arglist = \"$_\"\n"); + if (length($_)) { + push(@args, $_); + my $sep = $comma_sep_required ? "," : " "; + push(@args_seperator, $sep); + #print ("sep = \"$sep\", arg = \"$_\"\n"); + $comma_sep_required = 0; + } + } + } + + $comma_sep_required = 1; + } + + my %replacements; + if ($macro_args_default{$macro}){ + %replacements = %{$macro_args_default{$macro}}; + } + + # construct hashtable of text to replace + foreach my $i (0 .. $#args) { + my $argname = $macro_args{$macro}[$i]; + my @macro_args = @{ $macro_args{$macro} }; + if ($args[$i] =~ m/=/) { + # arg=val references the argument name + # XXX: I'm not sure what the expected behaviour if a lot of + # these are mixed with unnamed args + my @named_arg = split(/=/, $args[$i]); + $replacements{$named_arg[0]} = $named_arg[1]; + } elsif ($i > $#{$macro_args{$macro}}) { + # more args given than the macro has named args + # XXX: is vararg allowed on arguments before the last? + $argname = $macro_args{$macro}[-1]; + if ($argname =~ s/:vararg$//) { + #print "macro = $macro, args[$i] = $args[$i], args_seperator=@args_seperator, argname = $argname, arglist[$i] = $arglist[$i], arglist = @arglist, args=@args, macro_args=@macro_args\n"; + #$replacements{$argname} .= ", $args[$i]"; + $replacements{$argname} .= "$args_seperator[$i] $args[$i]"; + } else { + die "Too many arguments to macro $macro"; + } + } else { + $argname =~ s/:vararg$//; + $replacements{$argname} = $args[$i]; + } + } + + my $count = $macro_count++; + + # apply replacements as regex + foreach (@{$macro_lines{$macro}}) { + my $macro_line = $_; + # do replacements by longest first, this avoids wrong replacement + # when argument names are subsets of each other + foreach (reverse sort {length $a <=> length $b} keys %replacements) { + $macro_line =~ s/\\$_/$replacements{$_}/g; + } + $macro_line =~ s/\\\@/$count/g; + $macro_line =~ s/\\\(\)//g; # remove \() + parse_line($macro_line); + } + } else { + push(@pass1_lines, $line); + } +} + +close(ASMFILE) or exit 1; +open(ASMFILE, "|-", @gcc_cmd) or die "Error running assembler"; +#open(ASMFILE, ">/tmp/a.S") or die "Error running assembler"; + +my @sections; +my $num_repts; +my $rept_lines; + +my %literal_labels; # for ldr , = +my $literal_num = 0; + +my $thumb = 0; + +my %thumb_labels; +my %call_targets; + +my $in_irp = 0; +my @irp_args; +my $irp_param; + +# pass 2: parse .rept and .if variants +# NOTE: since we don't implement a proper parser, using .rept with a +# variable assigned from .set is not supported +foreach my $line (@pass1_lines) { + # handle .previous (only with regard to .section not .subsection) + if ($line =~ /\.(section|text|const_data)/) { + push(@sections, $line); + } elsif ($line =~ /\.previous/) { + if (!$sections[-2]) { + die ".previous without a previous section"; + } + $line = $sections[-2]; + push(@sections, $line); + } + + $thumb = 1 if $line =~ /\.code\s+16|\.thumb/; + $thumb = 0 if $line =~ /\.code\s+32|\.arm/; + + # handle ldr , = + if ($line =~ /(.*)\s*ldr([\w\s\d]+)\s*,\s*=(.*)/) { + my $label = $literal_labels{$3}; + if (!$label) { + $label = "Literal_$literal_num"; + $literal_num++; + $literal_labels{$3} = $label; + } + $line = "$1 ldr$2, $label\n"; + } elsif ($line =~ /\.ltorg/) { + $line .= ".align 2\n"; + foreach my $literal (keys %literal_labels) { + $line .= "$literal_labels{$literal}:\n .word $literal\n"; + } + %literal_labels = (); + } + + # thumb add with large immediate needs explicit add.w + if ($thumb and $line =~ /add\s+.*#([^@]+)/) { + $line =~ s/add/add.w/ if eval_expr($1) > 255; + } + + # mach-o local symbol names start with L (no dot) + $line =~ s/(? lo16() @ha -> ha16() + $line =~ s/,\s+([^,]+)\@l\b/, lo16($1)/g; + $line =~ s/,\s+([^,]+)\@ha\b/, ha16($1)/g; + + # move to/from SPR + if ($line =~ /(\s+)(m[ft])([a-z]+)\s+(\w+)/ and exists $ppc_spr{$3}) { + if ($2 eq 'mt') { + $line = "$1${2}spr $ppc_spr{$3}, $4\n"; + } else { + $line = "$1${2}spr $4, $ppc_spr{$3}\n"; + } + } + + # old gas versions store upper and lower case names on .req, + # but they remove only one on .unreq + if ($fix_unreq) { + if ($line =~ /\.unreq\s+(.*)/) { + $line = ".unreq " . lc($1) . "\n"; + print ASMFILE ".unreq " . uc($1) . "\n"; + } + } + + if ($line =~ /\.rept\s+(.*)/) { + $num_repts = $1; + $rept_lines = "\n"; + + # handle the possibility of repeating another directive on the same line + # .endr on the same line is not valid, I don't know if a non-directive is + if ($num_repts =~ s/(\.\w+.*)//) { + $rept_lines .= "$1\n"; + } + $num_repts = eval($num_repts); + } elsif ($line =~ /\.irp\s+([\d\w\.]+)\s*(.*)/) { + $in_irp = 1; + $num_repts = 1; + $rept_lines = "\n"; + $irp_param = $1; + + # only use whitespace as the separator + my $irp_arglist = $2; + $irp_arglist =~ s/,/ /g; + $irp_arglist =~ s/^\s+//; + @irp_args = split(/\s+/, $irp_arglist); + } elsif ($line =~ /\.irpc\s+([\d\w\.]+)\s*(.*)/) { + $in_irp = 1; + $num_repts = 1; + $rept_lines = "\n"; + $irp_param = $1; + + my $irp_arglist = $2; + $irp_arglist =~ s/,/ /g; + $irp_arglist =~ s/^\s+//; + @irp_args = split(//, $irp_arglist); + } elsif ($line =~ /\.endr/) { + if ($in_irp != 0) { + foreach my $i (@irp_args) { + my $line = $rept_lines; + $line =~ s/\\$irp_param/$i/g; + $line =~ s/\\\(\)//g; # remove \() + print ASMFILE $line; + } + } else { + for (1 .. $num_repts) { + print ASMFILE $rept_lines; + } + } + $rept_lines = ''; + $in_irp = 0; + @irp_args = ''; + } elsif ($rept_lines) { + $rept_lines .= $line; + } else { + print ASMFILE $line; + } +} + +print ASMFILE ".text\n"; +print ASMFILE ".align 2\n"; +foreach my $literal (keys %literal_labels) { + print ASMFILE "$literal_labels{$literal}:\n .word $literal\n"; +} + +map print(ASMFILE ".thumb_func $_\n"), + grep exists $thumb_labels{$_}, keys %call_targets; + +close(ASMFILE) or exit 1; +#exit 1 diff --git a/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.h b/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.h index 6cebb93..ba0bd01 100755 --- a/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.h +++ b/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.h @@ -3,14 +3,17 @@ #import @protocol JFFAsyncOperationInterface; -typedef id< JFFAsyncOperationInterface >(^JFFAsyncOperationInstanceBuilder)(void); +typedef id (^JFFAsyncOperationInstanceBuilder)(void); #ifdef __cplusplus extern "C" { #endif JFFAsyncOperation buildAsyncOperationWithAdapterFactory(JFFAsyncOperationInstanceBuilder factory); - + + JFFAsyncOperation buildAsyncOperationWithAdapterFactoryWithDispatchQueue(JFFAsyncOperationInstanceBuilder factory, + dispatch_queue_t callbacksQueue); + #ifdef __cplusplus } /* closing brace for extern "C" */ #endif diff --git a/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.m b/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.m index 2b19ec3..f694a9b 100755 --- a/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.m +++ b/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationBuilder.m @@ -23,21 +23,29 @@ - (void)notifyCallbackWithResult:(id)result error:(NSError *)error @end //JTODO test -JFFAsyncOperation buildAsyncOperationWithAdapterFactory(JFFAsyncOperationInstanceBuilder objectFactory) +JFFAsyncOperation buildAsyncOperationWithAdapterFactoryWithDispatchQueue(JFFAsyncOperationInstanceBuilder objectFactory, + dispatch_queue_t callbacksQueue) { objectFactory = [objectFactory copy]; return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, JFFCancelAsyncOperationHandler cancelCallback, JFFDidFinishAsyncOperationHandler doneCallback) { - id< JFFAsyncOperationInterface > asyncObject = objectFactory(); - __unsafe_unretained id< JFFAsyncOperationInterface > unretaintedAsyncObject = asyncObject; + __block id asyncObject = objectFactory(); + __unsafe_unretained id unretaintedAsyncObject = asyncObject; doneCallback = [doneCallback copy]; void (^completionHandler)(id, NSError*) = [^(id result, NSError *error) { //use asyncObject in if to own it while waiting result - if (doneCallback && asyncObject) + + if (!asyncObject) + return; + + if (doneCallback) { doneCallback(result, error); + } + + asyncObject = nil; } copy]; progressCallback = [progressCallback copy]; __block void (^progressHandler)(id) = [^(id data) { @@ -46,25 +54,39 @@ __block void (^progressHandler)(id) = [^(id data) { } copy]; completionHandler = [completionHandler copy]; - JFFObjectFactory factory = ^id() { - JFFComplitionHandlerNotifier *result = [JFFComplitionHandlerNotifier new]; - result.completionHandler = completionHandler; - return result; - }; - __block JFFComplitionHandlerNotifier* proxy = (JFFComplitionHandlerNotifier*) - [JFFSingleThreadProxy singleThreadProxyWithTargetFactory:factory - dispatchQueue:dispatch_get_current_queue()]; + __block JFFComplitionHandlerNotifier *proxy = [JFFComplitionHandlerNotifier new]; + proxy.completionHandler = completionHandler; __block JFFCancelAsyncOperationHandler cancelCallbackHolder = [cancelCallback copy]; + NSThread *currntThread = [NSThread currentThread]; + void (^completionHandlerWrapper)(id, NSError *) = [^(id result, NSError *error) { - JFFComplitionHandlerNotifier* proxyOwner = proxy; - proxy = nil; - progressHandler = nil; - cancelCallbackHolder = nil;//TODO what about other thread? - [proxyOwner notifyCallbackWithResult:result error:error]; + if (!asyncObject) + return; + + void (^completionHandler)(id, NSError *) = ^(id result, NSError *error) { + JFFComplitionHandlerNotifier *proxyOwner = proxy; + proxy = nil; + progressHandler = nil; + cancelCallbackHolder = nil; + [proxyOwner notifyCallbackWithResult:result error:error]; + }; + + if ([asyncObject respondsToSelector:@selector(isForeignThreadResultCallback)] + && [asyncObject isForeignThreadResultCallback]) { + + dispatch_async(callbacksQueue, ^() { + + completionHandler(result, error); + }); + } else { + + NSCAssert(currntThread == [NSThread currentThread], @"the same thread expected"); + completionHandler(result, error); + } } copy]; void (^progressHandlerWrapper)(id) = [^(id data) { @@ -98,7 +120,9 @@ __block void (^progressHandler)(id) = [^(id data) { return; } - [unretaintedAsyncObject cancel:canceled]; + if ([unretaintedAsyncObject respondsToSelector:@selector(cancel:)]) { + [unretaintedAsyncObject cancel:canceled]; + } proxy = nil; progressHandler = nil; @@ -111,3 +135,9 @@ __block void (^progressHandler)(id) = [^(id data) { }; }; } + +JFFAsyncOperation buildAsyncOperationWithAdapterFactory(JFFAsyncOperationInstanceBuilder factory) +{ + NSCAssert([NSThread isMainThread], @"main thread expected"); + return buildAsyncOperationWithAdapterFactoryWithDispatchQueue(factory, dispatch_get_main_queue()); +} diff --git a/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationInterface.h b/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationInterface.h index 6ac8b3e..653828a 100644 --- a/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationInterface.h +++ b/lib/JFFAsyncOperations/AsyncOperartionsBuilder/JFFAsyncOperationInterface.h @@ -6,12 +6,16 @@ typedef void (^JFFAsyncOperationInterfaceResultHandler)(id, NSError *); typedef void (^JFFAsyncOperationInterfaceCancelHandler)(BOOL canceled); typedef void (^JFFAsyncOperationInterfaceProgressHandler)(id); -@protocol JFFAsyncOperationInterface < NSObject > +@protocol JFFAsyncOperationInterface +@required - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress; +@optional - (void)cancel:(BOOL)canceled; +- (BOOL)isForeignThreadResultCallback; + @end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/JFFObjectRelatedPropertyData.h b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/JFFObjectRelatedPropertyData.h index 31d61d6..2c8611d 100644 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/JFFObjectRelatedPropertyData.h +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/JFFObjectRelatedPropertyData.h @@ -4,9 +4,9 @@ @interface JFFObjectRelatedPropertyData : NSObject -@property ( nonatomic ) NSMutableArray* delegates; -@property ( nonatomic, copy ) JFFAsyncOperation asyncLoader; -@property ( nonatomic, copy ) JFFDidFinishAsyncOperationHandler didFinishBlock; -@property ( nonatomic, copy ) JFFCancelAsyncOperation cancelBlock; +@property (nonatomic) NSMutableArray *delegates; +@property (nonatomic, copy) JFFAsyncOperation asyncLoader; +@property (nonatomic, copy) JFFDidFinishAsyncOperationHandler didFinishBlock; +@property (nonatomic, copy) JFFCancelAsyncOperation cancelBlock; @end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.h b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.h index bd0e6d4..176887c 100644 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.h +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.h @@ -5,9 +5,9 @@ @interface NSObject (PropertyExtractor) -@property ( nonatomic, readonly ) NSMutableDictionary* propertyDataByPropertyName; +@property (nonatomic, readonly) NSMutableDictionary *propertyDataByPropertyName; --(JFFObjectRelatedPropertyData*)propertyDataForPropertPath:( JFFPropertyPath* )property_path_; --(void)setPropertyData:( JFFObjectRelatedPropertyData* )property_ forPropertPath:( JFFPropertyPath* )property_path_; +- (JFFObjectRelatedPropertyData *)propertyDataForPropertPath:(JFFPropertyPath *)propertyPath; +- (void)setPropertyData:(JFFObjectRelatedPropertyData *)property forPropertPath:(JFFPropertyPath *)propertyPath; @end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.m b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.m index a29ae8d..a51eb24 100755 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.m +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSObject+PropertyExtractor.m @@ -2,10 +2,6 @@ #import "JFFPropertyPath.h" -#include - -static char propertyDataPropertyKey; - @interface NSObject (PropertyExtractorPrivate) @property (nonatomic) NSMutableDictionary *propertyDataByPropertyName; @@ -14,13 +10,20 @@ @interface NSObject (PropertyExtractorPrivate) @implementation NSObject (PropertyExtractor) +@dynamic propertyDataByPropertyName; + ++ (void)load +{ + jClass_implementProperty(self, NSStringFromSelector(@selector(propertyDataByPropertyName))); +} + - (JFFObjectRelatedPropertyData *)propertyDataForPropertPath:(JFFPropertyPath *)propertyPath { id data = self.propertyDataByPropertyName[propertyPath.name]; if (propertyPath.key == nil) { return data; } - return [data objectForKey: propertyPath.key]; + return [data objectForKey:propertyPath.key]; } //JTODO test @@ -33,11 +36,11 @@ - (void)removePropertyForPropertPath:(JFFPropertyPath *)propertyPath [self.propertyDataByPropertyName removeObjectForKey:propertyPath.name]; } } else { - [ self.propertyDataByPropertyName removeObjectForKey:propertyPath.name ]; + [self.propertyDataByPropertyName removeObjectForKey:propertyPath.name]; } //clear property - if ( [ self.propertyDataByPropertyName count ] == 0 ) { + if ([self.propertyDataByPropertyName count] == 0) { self.propertyDataByPropertyName = nil; } } @@ -68,14 +71,4 @@ - (void)setPropertyData:(JFFObjectRelatedPropertyData *)property self.propertyDataByPropertyName[propertyPath.name] = property; } -- (NSMutableDictionary *)propertyDataByPropertyName -{ - return objc_getAssociatedObject(self, &propertyDataPropertyKey); -} - -- (void)setPropertyDataByPropertyName:( NSMutableDictionary* )dictionary -{ - objc_setAssociatedObject(self, &propertyDataPropertyKey, dictionary, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - @end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSThread+AsyncPropertyReader.h b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSThread+AsyncPropertyReader.h deleted file mode 100644 index ac73b6d..0000000 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSThread+AsyncPropertyReader.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface NSThread (AsyncPropertyReader) - -- (NSObject *)lazyLoaderMergeObject; - -@end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSThread+AsyncPropertyReader.m b/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSThread+AsyncPropertyReader.m deleted file mode 100644 index dded71e..0000000 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/Detail/NSThread+AsyncPropertyReader.m +++ /dev/null @@ -1,22 +0,0 @@ -#import "NSThread+AsyncPropertyReader.h" - -#include - -static char _loaderMergeObjectKey; - -@implementation NSThread (AsyncPropertyReader) - -- (NSObject *)lazyLoaderMergeObject -{ - id result = objc_getAssociatedObject(self, &_loaderMergeObjectKey); - if (!result) { - result = [NSObject new]; - objc_setAssociatedObject(self, - &_loaderMergeObjectKey, - result, - OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } - return result; -} - -@end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.h b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.h index ae49908..79ed45f 100644 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.h +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.h @@ -6,17 +6,17 @@ @interface JFFPropertyExtractor : NSObject -@property ( nonatomic ) JFFPropertyPath* propertyPath; -@property ( nonatomic ) NSObject* object; +@property (nonatomic) JFFPropertyPath *propertyPath; +@property (nonatomic) NSObject *object; //object related data -@property ( nonatomic ) NSMutableArray* delegates; -@property ( nonatomic, copy ) JFFCancelAsyncOperation cancelBlock; -@property ( nonatomic, copy ) JFFAsyncOperation asyncLoader; -@property ( nonatomic, copy ) JFFDidFinishAsyncOperationHandler didFinishBlock; +@property (nonatomic) NSMutableArray *delegates; +@property (nonatomic, copy) JFFCancelAsyncOperation cancelBlock; +@property (nonatomic, copy) JFFAsyncOperation asyncLoader; +@property (nonatomic, copy) JFFDidFinishAsyncOperationHandler didFinishBlock; -@property ( nonatomic ) id property; +@property (nonatomic) id property; --(void)clearData; +- (void)clearData; @end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.m b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.m index e462cbd..3b09d1b 100644 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.m +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyExtractor.m @@ -11,7 +11,7 @@ @interface JFFPropertyExtractor () -@property ( nonatomic ) JFFObjectRelatedPropertyData* objectPropertyData; +@property (nonatomic) JFFObjectRelatedPropertyData *objectPropertyData; @end @@ -21,21 +21,22 @@ @implementation JFFPropertyExtractor SEL _propertySetSelector; } -@dynamic delegates -, asyncLoader -, didFinishBlock -, cancelBlock; +@dynamic +delegates, +asyncLoader, +didFinishBlock, +cancelBlock; --(void)clearData +- (void)clearData { self.objectPropertyData = nil; - + jff_retainAutorelease(_object); _object = nil; //self.propertyPath = nil; } --(SEL)propertyGetSelector +- (SEL)propertyGetSelector { if (!_propertyGetSelector) { _propertyGetSelector = NSSelectorFromString(self.propertyPath.name); @@ -43,7 +44,7 @@ -(SEL)propertyGetSelector return _propertyGetSelector; } --(SEL)propertySetSelector +- (SEL)propertySetSelector { if (!_propertySetSelector) { NSString *setPropertyName = [self.propertyPath.name propertySetNameForPropertyName]; @@ -64,7 +65,7 @@ - (void)setProperty:(id)property objc_msgSend(self.object, self.propertySetSelector, property); return; } - + NSMutableDictionary* dict = objc_msgSend(self.object, self.propertyGetSelector); if (!dict) { diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.h b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.h index aabd745..deb638a 100644 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.h +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.h @@ -2,10 +2,10 @@ @interface JFFPropertyPath : NSObject -@property ( nonatomic, readonly ) NSString* name; -@property ( nonatomic, readonly ) id< NSCopying, NSObject > key; +@property (nonatomic, readonly) NSString *name; +@property (nonatomic, readonly) id key; --(id)initWithName:( NSString* )name_ - key:( id< NSCopying, NSObject > )key_; +- (instancetype)initWithName:(NSString *)name + key:(id< NSCopying, NSObject >)key; @end diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.m b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.m index 30268c4..e45b5c8 100755 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.m +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/JFFPropertyPath.m @@ -2,8 +2,8 @@ @implementation JFFPropertyPath -- (id)initWithName:(NSString *)name - key:(id< NSCopying, NSObject >)key +- (instancetype)initWithName:(NSString *)name + key:(id)key { self = [super init]; diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.h b/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.h index d5d028e..c6aba6c 100755 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.h +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.h @@ -2,8 +2,9 @@ #import -@class JFFPropertyPath; -@class JFFPropertyExtractor; +@class +JFFPropertyPath, +JFFPropertyExtractor; typedef JFFPropertyExtractor *(^JFFPropertyExtractorFactoryBlock)(void); diff --git a/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.m b/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.m index dd9d882..c22c220 100644 --- a/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.m +++ b/lib/JFFAsyncOperations/CachedAsyncOperations/NSObject+AsyncPropertyReader.m @@ -7,9 +7,6 @@ #import "JFFAsyncOperationsPredefinedBlocks.h" #import "NSObject+PropertyExtractor.h" -#import "NSThread+AsyncPropertyReader.h" - -#include @interface JFFCachePropertyExtractor : JFFPropertyExtractor @end @@ -98,7 +95,7 @@ static JFFCancelAsyncOperation cancelBlock(JFFPropertyExtractor *propertyExtract cancel = [cancel copy]; if (cancelOperation) { - cancel( YES ); + cancel(YES); clearDataForPropertyExtractor(propertyExtractor); } else { [propertyExtractor.delegates removeObject:callbacks]; @@ -116,11 +113,15 @@ static JFFCancelAsyncOperation cancelBlock(JFFPropertyExtractor *propertyExtract static JFFDidFinishAsyncOperationHandler doneCallbackBlock(JFFPropertyExtractor *propertyExtractor) { return ^void(id result, NSError *error) { - if (!result && !error) { - NSLog(@"Assert propertyPath object: %@ propertyPath: %@", - propertyExtractor.object, - propertyExtractor.propertyPath); - assert(0);//"should be result or error" + if (!((result != nil) ^ (error != nil))) { + + NSString *errorDescription = [[NSString alloc] initWithFormat:@"Assert propertyPath object: %@ propertyPath: %@ result: %@ error: %@", + propertyExtractor.object, + propertyExtractor.propertyPath, + result, + error]; + + NSCAssert(0, errorDescription); } NSArray *copyDelegates = [propertyExtractor.delegates map:^id(id obj) { @@ -159,7 +160,7 @@ static JFFCancelAsyncOperation performNativeLoader(JFFPropertyExtractor *propert JFFCallbacksBlocksHolder *objCallback = obj; if (objCallback.onProgressBlock) objCallback.onProgressBlock(progressInfo); - } ]; + }]; }; JFFDidFinishAsyncOperationHandler doneCallback = doneCallbackBlock(propertyExtractor); @@ -211,6 +212,7 @@ - (JFFAsyncOperation)privateAsyncOperationForPropertyWithPath:(JFFPropertyPath * propertyExtractor.propertyPath = propertyPath; id result = propertyExtractor.property; + if (result) { if (doneCallback) doneCallback(result, nil); @@ -274,12 +276,12 @@ - (JFFAsyncOperation)privateAsyncOperationForPropertyWithPath:(JFFPropertyPath * didFinishLoadDataBlock:didFinishOperation]; } --(JFFAsyncOperation)asyncOperationForPropertyWithName:( NSString* )property_name_ - asyncOperation:( JFFAsyncOperation )asyncOperation_ +- (JFFAsyncOperation)asyncOperationForPropertyWithName:(NSString *)propertyName + asyncOperation:(JFFAsyncOperation)asyncOperation { - return [ self asyncOperationForPropertyWithName: property_name_ - asyncOperation: asyncOperation_ - didFinishLoadDataBlock: nil ]; + return [self asyncOperationForPropertyWithName:propertyName + asyncOperation:asyncOperation + didFinishLoadDataBlock:nil]; } - (JFFAsyncOperation)asyncOperationForPropertyWithName:(NSString *)propertyName @@ -312,8 +314,8 @@ - (JFFAsyncOperation)asyncOperationForPropertyWithPath:(JFFPropertyPath *)proper didFinishLoadDataBlock:didFinishOperation]; } --(JFFAsyncOperation)asyncOperationMergeLoaders:(JFFAsyncOperation)asyncOperation - withArgument:(id< NSCopying, NSObject >)argument +- (JFFAsyncOperation)privateAsyncOperationMergeLoaders:(JFFAsyncOperation)asyncOperation + withArgument:(id< NSCopying, NSObject >)argument { static NSString *const name = @".__JFF_MERGE_LOADERS_BY_ARGUMENTS__."; JFFPropertyPath *propertyPath = [[JFFPropertyPath alloc] initWithName:name @@ -328,12 +330,18 @@ -(JFFAsyncOperation)asyncOperationMergeLoaders:(JFFAsyncOperation)asyncOperation didFinishLoadDataBlock:nil]; } -+ (JFFAsyncOperation)asyncOperationMergeLoaders:(JFFAsyncOperation)asyncOperation +- (JFFAsyncOperation)asyncOperationMergeLoaders:(JFFAsyncOperation)asyncOperation withArgument:(id< NSCopying, NSObject >)argument { - id object = [[NSThread currentThread] lazyLoaderMergeObject]; - return [object asyncOperationMergeLoaders:asyncOperation - withArgument:argument]; + return [self privateAsyncOperationMergeLoaders:asyncOperation + withArgument:argument]; +} + ++ (JFFAsyncOperation)asyncOperationMergeLoaders:(JFFAsyncOperation)asyncOperation + withArgument:(id)argument +{ + return [self privateAsyncOperationMergeLoaders:asyncOperation + withArgument:argument]; } @end diff --git a/lib/JFFAsyncOperations/Extensions/NSArray+AsyncMap.h b/lib/JFFAsyncOperations/Categories/NSArray+AsyncMap.h old mode 100755 new mode 100644 similarity index 79% rename from lib/JFFAsyncOperations/Extensions/NSArray+AsyncMap.h rename to lib/JFFAsyncOperations/Categories/NSArray+AsyncMap.h index 97704a2..023cdcd --- a/lib/JFFAsyncOperations/Extensions/NSArray+AsyncMap.h +++ b/lib/JFFAsyncOperations/Categories/NSArray+AsyncMap.h @@ -6,6 +6,8 @@ - (JFFAsyncOperation)asyncMap:(JFFAsyncOperationBinder)block; +- (JFFAsyncOperation)asyncWaitAllMap:(JFFAsyncOperationBinder)block; + - (JFFAsyncOperation)tolerantFaultAsyncMap:(JFFAsyncOperationBinder)block; @end diff --git a/lib/JFFAsyncOperations/Extensions/NSArray+AsyncMap.m b/lib/JFFAsyncOperations/Categories/NSArray+AsyncMap.m old mode 100755 new mode 100644 similarity index 78% rename from lib/JFFAsyncOperations/Extensions/NSArray+AsyncMap.m rename to lib/JFFAsyncOperations/Categories/NSArray+AsyncMap.m index b060182..a1c158a --- a/lib/JFFAsyncOperations/Extensions/NSArray+AsyncMap.m +++ b/lib/JFFAsyncOperations/Categories/NSArray+AsyncMap.m @@ -9,10 +9,18 @@ - (JFFAsyncOperation)asyncMap:(JFFAsyncOperationBinder)block { NSArray *asyncOperations = [self map:^id(id object) { return block(object); - } ]; + }]; return failOnFirstErrorGroupOfAsyncOperationsArray(asyncOperations); } +- (JFFAsyncOperation)asyncWaitAllMap:(JFFAsyncOperationBinder)block +{ + NSArray *asyncOperations = [self map:^id(id object) { + return block(object); + }]; + return groupOfAsyncOperationsArray(asyncOperations); +} + - (JFFAsyncOperation)tolerantFaultAsyncMap:(JFFAsyncOperationBinder)block { NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[self count]]; @@ -20,12 +28,10 @@ - (JFFAsyncOperation)tolerantFaultAsyncMap:(JFFAsyncOperationBinder)block NSArray *asyncOperations = [self map:^id(id object) { JFFAsyncOperation loader = block(object); - JFFDidFinishAsyncOperationHandler finishCallbackBlock = ^void(id localResult, NSError *error) - { + JFFDidFinishAsyncOperationHandler finishCallbackBlock = ^void(id localResult, NSError *error) { + if (localResult) - { [result addObject:localResult]; - } }; return asyncOperationWithFinishCallbackBlock(loader, finishCallbackBlock); }]; diff --git a/lib/JFFAsyncOperations/Extensions/NSDictionary+AsyncMap.h b/lib/JFFAsyncOperations/Categories/NSDictionary+AsyncMap.h old mode 100755 new mode 100644 similarity index 100% rename from lib/JFFAsyncOperations/Extensions/NSDictionary+AsyncMap.h rename to lib/JFFAsyncOperations/Categories/NSDictionary+AsyncMap.h diff --git a/lib/JFFAsyncOperations/Extensions/NSDictionary+AsyncMap.m b/lib/JFFAsyncOperations/Categories/NSDictionary+AsyncMap.m old mode 100755 new mode 100644 similarity index 99% rename from lib/JFFAsyncOperations/Extensions/NSDictionary+AsyncMap.m rename to lib/JFFAsyncOperations/Categories/NSDictionary+AsyncMap.m index 32ad9e4..ccc139d --- a/lib/JFFAsyncOperations/Extensions/NSDictionary+AsyncMap.m +++ b/lib/JFFAsyncOperations/Categories/NSDictionary+AsyncMap.m @@ -28,7 +28,7 @@ - (JFFAsyncOperation)asyncMap:(JFFAsyncDictMappingBlock)block loader = asyncOperationWithFinishHookBlock(loader, finishCallbackHook); [asyncOperations addObject:loader]; - } ]; + }]; JFFAsyncOperation loader = failOnFirstErrorGroupOfAsyncOperationsArray(asyncOperations); JFFChangedResultBuilder resultBuilder = ^id(id localResult) { @@ -36,7 +36,7 @@ - (JFFAsyncOperation)asyncMap:(JFFAsyncDictMappingBlock)block return [finalResult copy]; }; loader = asyncOperationWithChangedResult(loader, resultBuilder); - + return loader; } diff --git a/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.h b/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.h index 7176a4a..1245f63 100644 --- a/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.h +++ b/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.h @@ -9,14 +9,15 @@ @class JFFBlockOperation; -@interface JFFAsyncOperationAdapter : NSObject < JFFAsyncOperationInterface > +@interface JFFAsyncOperationAdapter : NSObject -@property ( nonatomic, copy ) JFFSyncOperationWithProgress loadDataBlock; -@property ( nonatomic ) JFFBlockOperation* operation; -@property ( nonatomic ) std::string queueName; -@property ( nonatomic ) BOOL barrier; +@property (nonatomic, copy) JFFSyncOperationWithProgress loadDataBlock; +@property (nonatomic) JFFBlockOperation *operation; +@property (nonatomic) std::string queueName; +@property (nonatomic) BOOL barrier; //DISPATCH_QUEUE_CONCURRENT by default -@property ( nonatomic ) dispatch_queue_attr_t queueAttributes; +@property (nonatomic) dispatch_queue_t currentQueue; +@property (nonatomic) dispatch_queue_attr_t queueAttributes; @end diff --git a/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.mm b/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.mm index a1bfe1e..e52b8fc 100644 --- a/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.mm +++ b/lib/JFFAsyncOperations/Detail/JFFAsyncOperationAdapter.mm @@ -4,16 +4,15 @@ @implementation JFFAsyncOperationAdapter --(id)init +- (instancetype)init { - self = [ super init ]; - if ( nil == self ) - { + self = [super init]; + if (nil == self) { return nil; } - - self->_queueAttributes = DISPATCH_QUEUE_CONCURRENT; - + + _queueAttributes = DISPATCH_QUEUE_CONCURRENT; + return self; } @@ -21,19 +20,20 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { - self.operation = [JFFBlockOperation performOperationWithQueueName:self.queueName.c_str() - loadDataBlock:self.loadDataBlock + self.operation = [JFFBlockOperation performOperationWithQueueName:_queueName.c_str() + loadDataBlock:_loadDataBlock didLoadDataBlock:handler progressBlock:progress - barrier:self.barrier - serialOrConcurrent:self->_queueAttributes]; + barrier:_barrier + currentQueue:_currentQueue + serialOrConcurrent:_queueAttributes]; } - (void)cancel:(BOOL)canceled { if (canceled) { - [self.operation cancel]; - self.operation = nil; + [_operation cancel]; + _operation = nil; } } diff --git a/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.h b/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.h index bd90223..8a76bb5 100755 --- a/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.h +++ b/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.h @@ -8,8 +8,8 @@ @property (nonatomic, copy) JFFCancelAsyncOperationHandler onCancelBlock; @property (nonatomic, copy) JFFDidFinishAsyncOperationHandler didLoadDataBlock; -- (id)initWithOnProgressBlock:(JFFAsyncOperationProgressHandler)onProgressBlock - onCancelBlock:(JFFCancelAsyncOperationHandler)onCancelBlock - didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock; +- (instancetype)initWithOnProgressBlock:(JFFAsyncOperationProgressHandler)onProgressBlock + onCancelBlock:(JFFCancelAsyncOperationHandler)onCancelBlock + didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock; @end diff --git a/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.m b/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.m index 586db42..8a5ddb5 100755 --- a/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.m +++ b/lib/JFFAsyncOperations/Detail/JFFCallbacksBlocksHolder.m @@ -2,19 +2,19 @@ @implementation JFFCallbacksBlocksHolder -- (id)initWithOnProgressBlock:(JFFAsyncOperationProgressHandler)onProgressBlock - onCancelBlock:(JFFCancelAsyncOperationHandler)onCancelBlock - didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock +- (instancetype)initWithOnProgressBlock:(JFFAsyncOperationProgressHandler)onProgressBlock + onCancelBlock:(JFFCancelAsyncOperationHandler)onCancelBlock + didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock { - self = [ super init ]; - + self = [super init]; + if (self) { self.onProgressBlock = onProgressBlock; self.onCancelBlock = onCancelBlock; self.didLoadDataBlock = didLoadDataBlock; } - + return self; } diff --git a/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.h b/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.h index 0d9ab31..4400466 100755 --- a/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.h +++ b/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.h @@ -3,8 +3,8 @@ @interface NSError (ResultOwnerships) //lazy load property, any object can be added to this array -@property ( nonatomic ) NSMutableArray* resultOwnerships; +@property (nonatomic) NSMutableArray *resultOwnerships; -@property ( nonatomic, readonly ) NSMutableArray* lazyResultOwnerships; +@property (nonatomic, readonly) NSMutableArray *lazyResultOwnerships; @end diff --git a/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.m b/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.m index f207164..ce37704 100755 --- a/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.m +++ b/lib/JFFAsyncOperations/Detail/NSError+ResultOwnerships.m @@ -15,7 +15,7 @@ - (NSMutableArray *)resultOwnerships - (NSMutableArray *)lazyResultOwnerships { if (!objc_getAssociatedObject(self, &resultOwnershipsKey)) { - self.resultOwnerships = [ NSMutableArray new ]; + self.resultOwnerships = [NSMutableArray new]; } return objc_getAssociatedObject(self, &resultOwnershipsKey); } diff --git a/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.h b/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.h index 0d9e336..2390399 100644 --- a/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.h +++ b/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.h @@ -4,7 +4,7 @@ @interface JFFAsyncOperationProgressBlockHolder : NSObject -@property ( nonatomic, copy ) JFFAsyncOperationProgressHandler progressBlock; +@property (nonatomic, copy) JFFAsyncOperationProgressHandler progressBlock; - (void)performProgressBlockWithArgument:(id)progressInfo; diff --git a/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.m b/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.m index 85777c5..27dfbad 100755 --- a/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.m +++ b/lib/JFFAsyncOperations/Helpers/JFFAsyncOperationProgressBlockHolder.m @@ -4,8 +4,8 @@ @implementation JFFAsyncOperationProgressBlockHolder - (void)performProgressBlockWithArgument:(id)progressInfo { - if ( self.progressBlock ) - self.progressBlock(progressInfo); + if (_progressBlock) + _progressBlock(progressInfo); } @end diff --git a/lib/JFFAsyncOperations/Helpers/JFFCancelAsyncOperationBlockHolder.h b/lib/JFFAsyncOperations/Helpers/JFFCancelAsyncOperationBlockHolder.h index 3af8640..3bbe232 100644 --- a/lib/JFFAsyncOperations/Helpers/JFFCancelAsyncOperationBlockHolder.h +++ b/lib/JFFAsyncOperations/Helpers/JFFCancelAsyncOperationBlockHolder.h @@ -4,7 +4,7 @@ @interface JFFCancelAsyncOperationBlockHolder : NSObject -@property ( nonatomic, copy ) JFFCancelAsyncOperation cancelBlock; -@property ( nonatomic, copy, readonly ) JFFCancelAsyncOperation onceCancelBlock; +@property (nonatomic, copy) JFFCancelAsyncOperation cancelBlock; +@property (nonatomic, copy, readonly) JFFCancelAsyncOperation onceCancelBlock; @end diff --git a/lib/JFFAsyncOperations/Helpers/JFFDidFinishAsyncOperationBlockHolder.h b/lib/JFFAsyncOperations/Helpers/JFFDidFinishAsyncOperationBlockHolder.h index 27e41d7..9f619ba 100755 --- a/lib/JFFAsyncOperations/Helpers/JFFDidFinishAsyncOperationBlockHolder.h +++ b/lib/JFFAsyncOperations/Helpers/JFFDidFinishAsyncOperationBlockHolder.h @@ -4,7 +4,7 @@ @interface JFFDidFinishAsyncOperationBlockHolder : NSObject -@property ( nonatomic, copy ) JFFDidFinishAsyncOperationHandler didFinishBlock; -@property ( nonatomic, copy, readonly ) JFFDidFinishAsyncOperationHandler onceDidFinishBlock; +@property (nonatomic, copy) JFFDidFinishAsyncOperationHandler didFinishBlock; +@property (nonatomic, copy, readonly) JFFDidFinishAsyncOperationHandler onceDidFinishBlock; @end diff --git a/lib/JFFAsyncOperations/JFFAsyncOpNoARC.xcodeproj/project.pbxproj b/lib/JFFAsyncOperations/JFFAsyncOpNoARC.xcodeproj/project.pbxproj deleted file mode 100644 index 666b3f2..0000000 --- a/lib/JFFAsyncOperations/JFFAsyncOpNoARC.xcodeproj/project.pbxproj +++ /dev/null @@ -1,324 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 1B0857D61451711D001DDE0A /* JFFCallbacksBlocksHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B0857D51451711D001DDE0A /* JFFCallbacksBlocksHolder.h */; }; - 1B0857DA1451717C001DDE0A /* JFFAsyncOperationProgressBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B0857D71451717C001DDE0A /* JFFAsyncOperationProgressBlockHolder.h */; }; - 1B0857DB1451717C001DDE0A /* JFFCancelAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B0857D81451717C001DDE0A /* JFFCancelAsyncOperationBlockHolder.h */; }; - 1B0857DC1451717C001DDE0A /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B0857D91451717C001DDE0A /* JFFDidFinishAsyncOperationBlockHolder.h */; }; - 1B9026C1143F35F800D3B0A0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B9026C0143F35F800D3B0A0 /* Foundation.framework */; }; - 1B9026DA143F36A100D3B0A0 /* JFFAsyncOperations_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 1B9026D9143F36A100D3B0A0 /* JFFAsyncOperations_Prefix.pch */; }; - 1B902724143F36B700D3B0A0 /* JFFAsyncOperationsBlockDefinitions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B9026F6143F36B700D3B0A0 /* JFFAsyncOperationsBlockDefinitions.h */; }; - 1B90272D143F36B700D3B0A0 /* JFFActiveLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B902701143F36B700D3B0A0 /* JFFActiveLoaderData.h */; }; - 1B90272E143F36B700D3B0A0 /* JFFActiveLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B902702143F36B700D3B0A0 /* JFFActiveLoaderData.m */; }; - 1B90272F143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B902703143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.h */; }; - 1B902730143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B902704143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.m */; }; - 1B902731143F36B700D3B0A0 /* JFFContextLoaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B902705143F36B700D3B0A0 /* JFFContextLoaders.h */; }; - 1B902732143F36B700D3B0A0 /* JFFContextLoaders.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B902706143F36B700D3B0A0 /* JFFContextLoaders.m */; }; - 1B902733143F36B700D3B0A0 /* JFFPedingLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B902707143F36B700D3B0A0 /* JFFPedingLoaderData.h */; }; - 1B902734143F36B700D3B0A0 /* JFFPedingLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B902708143F36B700D3B0A0 /* JFFPedingLoaderData.m */; }; - 1B902735143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B902709143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.h */; }; - 1B902736143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B90270A143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.m */; }; - 6532667E14C1EB3A004E90B0 /* JFFAsyncOperationsPredefinedBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 6532667D14C1EB3A004E90B0 /* JFFAsyncOperationsPredefinedBlocks.h */; }; - 65359BD2151A7FEF0099D6FE /* JFFAsyncOperationBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 65359BD1151A7FEF0099D6FE /* JFFAsyncOperationBuilder.h */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 1B0857D51451711D001DDE0A /* JFFCallbacksBlocksHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JFFCallbacksBlocksHolder.h; path = Detail/JFFCallbacksBlocksHolder.h; sourceTree = SOURCE_ROOT; }; - 1B0857D71451717C001DDE0A /* JFFAsyncOperationProgressBlockHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JFFAsyncOperationProgressBlockHolder.h; path = Helpers/JFFAsyncOperationProgressBlockHolder.h; sourceTree = SOURCE_ROOT; }; - 1B0857D81451717C001DDE0A /* JFFCancelAsyncOperationBlockHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JFFCancelAsyncOperationBlockHolder.h; path = Helpers/JFFCancelAsyncOperationBlockHolder.h; sourceTree = SOURCE_ROOT; }; - 1B0857D91451717C001DDE0A /* JFFDidFinishAsyncOperationBlockHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JFFDidFinishAsyncOperationBlockHolder.h; path = Helpers/JFFDidFinishAsyncOperationBlockHolder.h; sourceTree = SOURCE_ROOT; }; - 1B9026BD143F35F800D3B0A0 /* libJFFAsyncOpNoARC.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFAsyncOpNoARC.a; sourceTree = BUILT_PRODUCTS_DIR; }; - 1B9026C0143F35F800D3B0A0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - 1B9026D9143F36A100D3B0A0 /* JFFAsyncOperations_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperations_Prefix.pch; sourceTree = SOURCE_ROOT; }; - 1B9026F6143F36B700D3B0A0 /* JFFAsyncOperationsBlockDefinitions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationsBlockDefinitions.h; sourceTree = SOURCE_ROOT; }; - 1B902701143F36B700D3B0A0 /* JFFActiveLoaderData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFActiveLoaderData.h; sourceTree = ""; }; - 1B902702143F36B700D3B0A0 /* JFFActiveLoaderData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFActiveLoaderData.m; sourceTree = ""; }; - 1B902703143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationLoadBalancerContexts.h; sourceTree = ""; }; - 1B902704143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationLoadBalancerContexts.m; sourceTree = ""; }; - 1B902705143F36B700D3B0A0 /* JFFContextLoaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFContextLoaders.h; sourceTree = ""; }; - 1B902706143F36B700D3B0A0 /* JFFContextLoaders.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFContextLoaders.m; sourceTree = ""; }; - 1B902707143F36B700D3B0A0 /* JFFPedingLoaderData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPedingLoaderData.h; sourceTree = ""; }; - 1B902708143F36B700D3B0A0 /* JFFPedingLoaderData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFPedingLoaderData.m; sourceTree = ""; }; - 1B902709143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationLoadBalancer.h; sourceTree = ""; }; - 1B90270A143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationLoadBalancer.m; sourceTree = ""; }; - 6532667D14C1EB3A004E90B0 /* JFFAsyncOperationsPredefinedBlocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationsPredefinedBlocks.h; sourceTree = SOURCE_ROOT; }; - 65359BD1151A7FEF0099D6FE /* JFFAsyncOperationBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JFFAsyncOperationBuilder.h; path = AsyncOperartionsBuilder/JFFAsyncOperationBuilder.h; sourceTree = SOURCE_ROOT; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 1B9026BA143F35F800D3B0A0 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 1B9026C1143F35F800D3B0A0 /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 1B9026B2143F35F800D3B0A0 = { - isa = PBXGroup; - children = ( - 1B9026C2143F35F800D3B0A0 /* JFFAsyncOpNoARC */, - 1B9026BF143F35F800D3B0A0 /* Frameworks */, - 1B9026BE143F35F800D3B0A0 /* Products */, - ); - sourceTree = ""; - }; - 1B9026BE143F35F800D3B0A0 /* Products */ = { - isa = PBXGroup; - children = ( - 1B9026BD143F35F800D3B0A0 /* libJFFAsyncOpNoARC.a */, - ); - name = Products; - sourceTree = ""; - }; - 1B9026BF143F35F800D3B0A0 /* Frameworks */ = { - isa = PBXGroup; - children = ( - 1B9026C0143F35F800D3B0A0 /* Foundation.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - 1B9026C2143F35F800D3B0A0 /* JFFAsyncOpNoARC */ = { - isa = PBXGroup; - children = ( - 65359BD1151A7FEF0099D6FE /* JFFAsyncOperationBuilder.h */, - 6532667D14C1EB3A004E90B0 /* JFFAsyncOperationsPredefinedBlocks.h */, - 1B0857D71451717C001DDE0A /* JFFAsyncOperationProgressBlockHolder.h */, - 1B0857D81451717C001DDE0A /* JFFCancelAsyncOperationBlockHolder.h */, - 1B0857D91451717C001DDE0A /* JFFDidFinishAsyncOperationBlockHolder.h */, - 1B0857D51451711D001DDE0A /* JFFCallbacksBlocksHolder.h */, - 1B9026FF143F36B700D3B0A0 /* LoadBalancer */, - 1B9026F6143F36B700D3B0A0 /* JFFAsyncOperationsBlockDefinitions.h */, - 1B9026C3143F35F800D3B0A0 /* Supporting Files */, - ); - path = JFFAsyncOpNoARC; - sourceTree = ""; - }; - 1B9026C3143F35F800D3B0A0 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 1B9026D9143F36A100D3B0A0 /* JFFAsyncOperations_Prefix.pch */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 1B9026FF143F36B700D3B0A0 /* LoadBalancer */ = { - isa = PBXGroup; - children = ( - 1B902700143F36B700D3B0A0 /* Detail */, - 1B902709143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.h */, - 1B90270A143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.m */, - ); - path = LoadBalancer; - sourceTree = SOURCE_ROOT; - }; - 1B902700143F36B700D3B0A0 /* Detail */ = { - isa = PBXGroup; - children = ( - 1B902701143F36B700D3B0A0 /* JFFActiveLoaderData.h */, - 1B902702143F36B700D3B0A0 /* JFFActiveLoaderData.m */, - 1B902703143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.h */, - 1B902704143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.m */, - 1B902705143F36B700D3B0A0 /* JFFContextLoaders.h */, - 1B902706143F36B700D3B0A0 /* JFFContextLoaders.m */, - 1B902707143F36B700D3B0A0 /* JFFPedingLoaderData.h */, - 1B902708143F36B700D3B0A0 /* JFFPedingLoaderData.m */, - ); - path = Detail; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 1B9026BB143F35F800D3B0A0 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 1B9026DA143F36A100D3B0A0 /* JFFAsyncOperations_Prefix.pch in Headers */, - 1B902724143F36B700D3B0A0 /* JFFAsyncOperationsBlockDefinitions.h in Headers */, - 1B90272D143F36B700D3B0A0 /* JFFActiveLoaderData.h in Headers */, - 1B90272F143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.h in Headers */, - 1B902731143F36B700D3B0A0 /* JFFContextLoaders.h in Headers */, - 1B902733143F36B700D3B0A0 /* JFFPedingLoaderData.h in Headers */, - 1B902735143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.h in Headers */, - 1B0857D61451711D001DDE0A /* JFFCallbacksBlocksHolder.h in Headers */, - 1B0857DA1451717C001DDE0A /* JFFAsyncOperationProgressBlockHolder.h in Headers */, - 1B0857DB1451717C001DDE0A /* JFFCancelAsyncOperationBlockHolder.h in Headers */, - 1B0857DC1451717C001DDE0A /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */, - 6532667E14C1EB3A004E90B0 /* JFFAsyncOperationsPredefinedBlocks.h in Headers */, - 65359BD2151A7FEF0099D6FE /* JFFAsyncOperationBuilder.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 1B9026BC143F35F800D3B0A0 /* JFFAsyncOpNoARC */ = { - isa = PBXNativeTarget; - buildConfigurationList = 1B9026CA143F35F800D3B0A0 /* Build configuration list for PBXNativeTarget "JFFAsyncOpNoARC" */; - buildPhases = ( - 1B9026B9143F35F800D3B0A0 /* Sources */, - 1B9026BA143F35F800D3B0A0 /* Frameworks */, - 1B9026BB143F35F800D3B0A0 /* Headers */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = JFFAsyncOpNoARC; - productName = JFFAsyncOpNoARC; - productReference = 1B9026BD143F35F800D3B0A0 /* libJFFAsyncOpNoARC.a */; - productType = "com.apple.product-type.library.static"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 1B9026B4143F35F800D3B0A0 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0460; - }; - buildConfigurationList = 1B9026B7143F35F800D3B0A0 /* Build configuration list for PBXProject "JFFAsyncOpNoARC" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 1B9026B2143F35F800D3B0A0; - productRefGroup = 1B9026BE143F35F800D3B0A0 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 1B9026BC143F35F800D3B0A0 /* JFFAsyncOpNoARC */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 1B9026B9143F35F800D3B0A0 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 1B90272E143F36B700D3B0A0 /* JFFActiveLoaderData.m in Sources */, - 1B902730143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancerContexts.m in Sources */, - 1B902732143F36B700D3B0A0 /* JFFContextLoaders.m in Sources */, - 1B902734143F36B700D3B0A0 /* JFFPedingLoaderData.m in Sources */, - 1B902736143F36B700D3B0A0 /* JFFAsyncOperationLoadBalancer.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 1B9026C8143F35F800D3B0A0 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 1B9026C9143F35F800D3B0A0 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; - SDKROOT = iphoneos; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 1B9026CB143F35F800D3B0A0 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - DSTROOT = /tmp/JFFAsyncOpNoARC.dst; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = JFFAsyncOperations_Prefix.pch; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 1B9026CC143F35F800D3B0A0 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - DSTROOT = /tmp/JFFAsyncOpNoARC.dst; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = JFFAsyncOperations_Prefix.pch; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 1B9026B7143F35F800D3B0A0 /* Build configuration list for PBXProject "JFFAsyncOpNoARC" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 1B9026C8143F35F800D3B0A0 /* Debug */, - 1B9026C9143F35F800D3B0A0 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 1B9026CA143F35F800D3B0A0 /* Build configuration list for PBXNativeTarget "JFFAsyncOpNoARC" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 1B9026CB143F35F800D3B0A0 /* Debug */, - 1B9026CC143F35F800D3B0A0 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 1B9026B4143F35F800D3B0A0 /* Project object */; -} diff --git a/lib/JFFAsyncOperations/JFFAsyncOperationContinuity.m b/lib/JFFAsyncOperations/JFFAsyncOperationContinuity.m index df59b26..d532541 100755 --- a/lib/JFFAsyncOperations/JFFAsyncOperationContinuity.m +++ b/lib/JFFAsyncOperations/JFFAsyncOperationContinuity.m @@ -144,9 +144,7 @@ JFFAsyncOperation accumulateSequenceResult(NSArray *loaders, JFFSequenceResultAc resultAccumulator = [resultAccumulator copy]; - NSMutableArray *binders = [[NSMutableArray alloc] initWithCapacity:[loaders count]]; - - for (NSUInteger index = 0; index < [loaders count]; ++index) { + NSArray *binders = [NSArray arrayWithSize:[loaders count] producer:^id(NSUInteger index) { JFFAsyncOperationBinder binder = [^JFFAsyncOperation(id waterfallResult) { @@ -159,14 +157,15 @@ JFFAsyncOperation accumulateSequenceResult(NSArray *loaders, JFFSequenceResultAc :waterfallResult; id newResult = resultAccumulator(currWaterfallResult, result, error); + NSCAssert((newResult != nil) ^ (error != nil), nil); if (doneCallback) doneCallback(newResult, newResult?nil:error); }); } copy]; - [binders addObject:binder]; - } + return binder; + }]; JFFWaterwallFirstObject *instance = [JFFWaterwallFirstObject sharedWaterwallFirstObject]; return bindSequenceOfAsyncOperationsArray(asyncOperationWithResult(instance), binders); diff --git a/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.h b/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.h index ba67fb3..ce52a0d 100644 --- a/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.h +++ b/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.h @@ -14,56 +14,63 @@ extern "C" { ///////////////////////// ADD OBSERVERS OF ASYNC OP. RESULT //////////////////////// -JFFAsyncOperation asyncOperationWithResult(id result); -JFFAsyncOperation asyncOperationWithError(NSError *error); - -JFFAsyncOperation asyncOperationWithSyncOperationInCurrentQueue(JFFSyncOperation block); + JFFAsyncOperation asyncOperationWithResult(id result); + JFFAsyncOperation asyncOperationWithError(NSError *error); + JFFAsyncOperation asyncOperationWithCancelFlag(BOOL canceled); + JFFAsyncOperation neverFinishAsyncOperation(void); + + JFFAsyncOperation asyncOperationWithSyncOperationInCurrentQueue(JFFSyncOperation block); + + //finish_callback_block_ called before loader_'s JFFDidFinishAsyncOperationHandler + JFFAsyncOperation asyncOperationWithFinishCallbackBlock(JFFAsyncOperation loader, + JFFDidFinishAsyncOperationHandler finishCallbackBlock); + + //finish_callback_hook_ called instead loader_'s JFFDidFinishAsyncOperationHandler + JFFAsyncOperation asyncOperationWithFinishHookBlock(JFFAsyncOperation loader, + JFFDidFinishAsyncOperationHook finishCallbackHook); + + JFFAsyncOperation asyncOperationWithStartAndFinishBlocks(JFFAsyncOperation loader, + JFFSimpleBlock startBlock, + JFFDidFinishAsyncOperationHandler finishCallback); + + JFFAsyncOperation asyncOperationWithOptionalStartAndFinishBlocks(JFFAsyncOperation loader, + JFFSimpleBlock startBlock, + JFFDidFinishAsyncOperationHandler finishCallback); -//finish_callback_block_ called before loader_'s JFFDidFinishAsyncOperationHandler -JFFAsyncOperation asyncOperationWithFinishCallbackBlock(JFFAsyncOperation loader, - JFFDidFinishAsyncOperationHandler finishCallbackBlock); - -//finish_callback_hook_ called instead loader_'s JFFDidFinishAsyncOperationHandler -JFFAsyncOperation asyncOperationWithFinishHookBlock(JFFAsyncOperation loader, - JFFDidFinishAsyncOperationHook finishCallbackHook); - -JFFAsyncOperation asyncOperationWithStartAndFinishBlocks(JFFAsyncOperation loader, - JFFSimpleBlock startBlock, - JFFDidFinishAsyncOperationHandler finishCallback); - - //TODO20 immediately cancel callback JFFAsyncOperation asyncOperationWithStartAndDoneBlocks(JFFAsyncOperation loader, JFFSimpleBlock startBlock, JFFSimpleBlock doneBlock); - -JFFAsyncOperation asyncOperationWithAnalyzer(id data, JFFAnalyzer analyzer); - -JFFAsyncOperationBinder asyncOperationBinderWithAnalyzer(JFFAnalyzer analyzer); - -typedef id (^JFFChangedResultBuilder)(id result); -JFFAsyncOperation asyncOperationWithChangedResult(JFFAsyncOperation loader, - JFFChangedResultBuilder resultBuilder); - -JFFAsyncOperation asyncOperationResultAsProgress(JFFAsyncOperation loader); - -typedef NSError* (^JFFChangedErrorBuilder)(NSError *error); -JFFAsyncOperation asyncOperationWithChangedError(JFFAsyncOperation loader, - JFFChangedErrorBuilder errorBuilder); - -JFFAsyncOperation asyncOperationWithResultOrError(JFFAsyncOperation loader, - id result, - NSError *error); - -JFFAsyncOperation asyncOperationWithDelay(NSTimeInterval delay); - -JFFAsyncOperation ignorePregressLoader(JFFAsyncOperation loader); -JFFAsyncOperationBinder ignorePregressBinder(JFFAsyncOperationBinder binder); - - JFFAsyncOperation loaderWithAdditionalParalelLoaders(JFFAsyncOperation original, JFFAsyncOperation additionalLoader, ...); -///////////////////////////////////// SEQUENCE ///////////////////////////////////// - -JFFAnalyzer analyzerAsSequenceOfAnalyzers(JFFAnalyzer firstAnalyzer, ...) NS_REQUIRES_NIL_TERMINATION; + JFFAsyncOperation asyncOperationWithAnalyzer(id data, JFFAnalyzer analyzer); + + JFFAsyncOperationBinder asyncOperationBinderWithAnalyzer(JFFAnalyzer analyzer); + + typedef id (^JFFChangedResultBuilder)(id result); + JFFAsyncOperation asyncOperationWithChangedResult(JFFAsyncOperation loader, + JFFChangedResultBuilder resultBuilder); + JFFAsyncOperation asyncOperationWithChangedProgress(JFFAsyncOperation loader, + JFFChangedResultBuilder resultBuilder); + + JFFAsyncOperation asyncOperationResultAsProgress(JFFAsyncOperation loader); + + typedef NSError *(^JFFChangedErrorBuilder)(NSError *error); + JFFAsyncOperation asyncOperationWithChangedError(JFFAsyncOperation loader, + JFFChangedErrorBuilder errorBuilder); + + JFFAsyncOperation asyncOperationWithResultOrError(JFFAsyncOperation loader, + id result, + NSError *error); + + JFFAsyncOperation asyncOperationWithDelay(NSTimeInterval delay); + + JFFAsyncOperation ignorePregressLoader(JFFAsyncOperation loader); + JFFAsyncOperationBinder ignorePregressBinder(JFFAsyncOperationBinder binder); + + JFFAsyncOperation loaderWithAdditionalParalelLoaders(JFFAsyncOperation original, JFFAsyncOperation additionalLoader, ...) NS_REQUIRES_NIL_TERMINATION; + + ///////////////////////////////////// SEQUENCE ///////////////////////////////////// + + JFFAnalyzer analyzerAsSequenceOfAnalyzers(JFFAnalyzer firstAnalyzer, ...) NS_REQUIRES_NIL_TERMINATION; #ifdef __cplusplus } /* closing brace for extern "C" */ diff --git a/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.m b/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.m index 71f2195..59fe7aa 100644 --- a/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.m +++ b/lib/JFFAsyncOperations/JFFAsyncOperationHelpers.m @@ -10,29 +10,29 @@ @implementation JFFAsyncTimerResult : NSObject @end -@interface JFFAsyncOperationScheduler : NSObject < JFFAsyncOperationInterface > - -@property (nonatomic) NSTimeInterval duration; - +@interface JFFAsyncOperationScheduler : NSObject @end @implementation JFFAsyncOperationScheduler { JFFScheduler *_scheduler; +@public + NSTimeInterval _duration; + NSTimeInterval _leeway; } - (void)asyncOperationWithResultHandler:(void(^)(id, NSError *))handler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { - handler = [handler copy]; + handler = [handler copy]; _scheduler = [JFFScheduler new]; [_scheduler addBlock:^(JFFCancelScheduledBlock cancel){ cancel(); if (handler) handler([JFFAsyncTimerResult new], nil); - } duration:self.duration]; + } duration:_duration leeway:_leeway]; } - (void)cancel:(BOOL)canceled @@ -44,7 +44,7 @@ - (void)cancel:(BOOL)canceled JFFAsyncOperation asyncOperationWithResult(id result) { - assert(result); + NSCParameterAssert(result); return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, JFFCancelAsyncOperationHandler cancelCallback, JFFDidFinishAsyncOperationHandler doneCallback) { @@ -65,9 +65,42 @@ JFFAsyncOperation asyncOperationWithError(NSError *error) }; } +JFFAsyncOperation asyncOperationWithCancelFlag(BOOL canceled) +{ + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + if (cancelCallback) + cancelCallback(canceled); + return JFFStubCancelAsyncOperationBlock; + }; +} + +JFFAsyncOperation neverFinishAsyncOperation(void) +{ + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + __block BOOL wasCanceled = NO; + + cancelCallback = [cancelCallback copy]; + + return ^(BOOL canceled) { + + if (wasCanceled) + return; + + wasCanceled = YES; + if (cancelCallback) + cancelCallback(canceled); + }; + }; +} + JFFAsyncOperation asyncOperationWithSyncOperationInCurrentQueue(JFFSyncOperation block) { - assert(block); + NSCParameterAssert(block); block = [block copy]; return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, @@ -75,7 +108,7 @@ JFFAsyncOperation asyncOperationWithSyncOperationInCurrentQueue(JFFSyncOperation JFFDidFinishAsyncOperationHandler doneCallback) { NSError *error; id result = block(&error); - assert((result || error) && (!result || !error)); + NSCAssert(((result != nil) ^ (error != nil)), @"result xor error expected"); if (doneCallback) doneCallback(result, error); @@ -87,7 +120,7 @@ JFFAsyncOperation asyncOperationWithSyncOperationInCurrentQueue(JFFSyncOperation JFFAsyncOperation asyncOperationWithFinishCallbackBlock(JFFAsyncOperation loader, JFFDidFinishAsyncOperationHandler finishCallbackBlock) { - assert(loader); + NSCParameterAssert(loader); finishCallbackBlock = [finishCallbackBlock copy]; loader = [loader copy]; return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, @@ -106,13 +139,15 @@ JFFAsyncOperation asyncOperationWithFinishCallbackBlock(JFFAsyncOperation loader JFFAsyncOperation asyncOperationWithFinishHookBlock(JFFAsyncOperation loader, JFFDidFinishAsyncOperationHook finishCallbackHook) { - assert(loader);// should not be nil" - assert(finishCallbackHook);// should not be nil" + NSCParameterAssert(loader );// should not be nil" + NSCParameterAssert(finishCallbackHook);// should not be nil" finishCallbackHook = [finishCallbackHook copy]; loader = [loader copy]; + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, JFFCancelAsyncOperationHandler cancelCallback, JFFDidFinishAsyncOperationHandler doneCallback) { + doneCallback = [doneCallback copy]; return loader(progressCallback, cancelCallback, ^void(id result, NSError *error) { finishCallbackHook(result, error, doneCallback); @@ -145,11 +180,59 @@ JFFAsyncOperation asyncOperationWithStartAndFinishBlocks(JFFAsyncOperation loade }; } +JFFAsyncOperation asyncOperationWithOptionalStartAndFinishBlocks(JFFAsyncOperation loader, + JFFSimpleBlock startBlock, + JFFDidFinishAsyncOperationHandler finishCallback) +{ + loader = [loader copy]; + startBlock = [startBlock copy]; + finishCallback = [finishCallback copy]; + + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + __block BOOL loading = YES; + + cancelCallback = [cancelCallback copy]; + JFFCancelAsyncOperationHandler wrappedCancelCallback = ^(BOOL canceled) { + + loading = NO; + + if (cancelCallback) + cancelCallback(canceled); + }; + + doneCallback = [doneCallback copy]; + JFFDidFinishAsyncOperationHandler wrappedDoneCallback = ^(id result, NSError *error) { + + loading = NO; + + if (finishCallback) + finishCallback(result, error); + if (doneCallback) + doneCallback(result, error); + }; + + JFFCancelAsyncOperation cancel = loader(progressCallback, wrappedCancelCallback, wrappedDoneCallback); + + if (loading) { + + if (startBlock) + startBlock(); + + return cancel; + } + + return JFFStubCancelAsyncOperationBlock; + }; +} + JFFAsyncOperation asyncOperationWithStartAndDoneBlocks(JFFAsyncOperation loader, JFFSimpleBlock startBlock, JFFSimpleBlock doneBlock) { - assert(loader); + NSCParameterAssert(loader); startBlock = [startBlock copy]; doneBlock = [doneBlock copy]; @@ -193,7 +276,7 @@ JFFAsyncOperation asyncOperationWithAnalyzer(id data, JFFAnalyzer analyzer) JFFDidFinishAsyncOperationHandler doneCallback) { NSError *localError; id localResult = analyzer(data, &localError); - assert((localResult || localError) && !(localResult && localError)); + NSCAssert(((localResult != nil) ^ (localError != nil)), @"localResult xor localError expected"); if (doneCallback) doneCallback(localError?nil:localResult, localError); @@ -216,15 +299,39 @@ JFFAsyncOperation asyncOperationWithChangedResult(JFFAsyncOperation loader, resultBuilder = [resultBuilder copy]; JFFAsyncOperationBinder secondLoaderBinder = asyncOperationBinderWithAnalyzer(^id(id result, NSError **error) { - assert(result);//@"can not be nil"; + NSCAssert(result, @"result can not be nil"); id newResult = resultBuilder?resultBuilder(result):result; - assert(newResult);//@"can not be nil"; + NSCAssert(newResult, @"newResult can not be nil"); return newResult; }); return bindSequenceOfAsyncOperations(loader, secondLoaderBinder, nil); } +JFFAsyncOperation asyncOperationWithChangedProgress(JFFAsyncOperation loader, + JFFChangedResultBuilder resultBuilder) +{ + if (!resultBuilder) + return loader; + + loader = [loader copy]; + resultBuilder = [resultBuilder copy]; + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + JFFAsyncOperationProgressHandler progressCallbackWrapper = ^(id info) { + + if (progressCallback) { + info = resultBuilder(info); + progressCallback(info); + } + }; + + return loader(progressCallbackWrapper, cancelCallback, doneCallback); + }; +} + JFFAsyncOperation asyncOperationResultAsProgress(JFFAsyncOperation loader) { loader = [loader copy]; @@ -278,7 +385,7 @@ JFFAsyncOperation asyncOperationWithDelay(NSTimeInterval delay) { JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { JFFAsyncOperationScheduler *asyncObject = [JFFAsyncOperationScheduler new]; - asyncObject.duration = delay; + asyncObject->_duration = delay; return asyncObject; }; return buildAsyncOperationWithAdapterFactory(factory); @@ -286,7 +393,7 @@ JFFAsyncOperation asyncOperationWithDelay(NSTimeInterval delay) JFFAsyncOperation loaderWithAdditionalParalelLoaders(JFFAsyncOperation original, JFFAsyncOperation additionalLoader, ...) { - assert(original); + NSCParameterAssert(original); NSMutableArray *loaders = [[NSMutableArray alloc] initWithObjects:original, nil]; diff --git a/lib/JFFAsyncOperations/JFFAsyncOperationUtils.h b/lib/JFFAsyncOperations/JFFAsyncOperationUtils.h index 1e15e05..a8fc713 100755 --- a/lib/JFFAsyncOperations/JFFAsyncOperationUtils.h +++ b/lib/JFFAsyncOperations/JFFAsyncOperationUtils.h @@ -5,15 +5,15 @@ extern "C" { #endif JFFAsyncOperation asyncOperationWithSyncOperation(JFFSyncOperation loadDataBlock); - + JFFAsyncOperation asyncOperationWithSyncOperationAndQueue(JFFSyncOperation loadDataBlock, const char *queueName); - - JFFAsyncOperation asyncOperationWithSyncOperationAndConfigurableQueue( JFFSyncOperation loadDataBlock_, const char* queueName_, BOOL isSerialQueue_ ); - + + JFFAsyncOperation asyncOperationWithSyncOperationAndConfigurableQueue(JFFSyncOperation loadDataBlock, const char *queueName, BOOL isSerialQueue); + JFFAsyncOperation barrierAsyncOperationWithSyncOperationAndQueue(JFFSyncOperation loadDataBlock, const char *queueName); - + JFFAsyncOperation asyncOperationWithSyncOperationWithProgressBlock(JFFSyncOperationWithProgress progressLoadDataBlock); #ifdef __cplusplus diff --git a/lib/JFFAsyncOperations/JFFAsyncOperationUtils.mm b/lib/JFFAsyncOperations/JFFAsyncOperationUtils.mm index e1bc06b..0c4777e 100644 --- a/lib/JFFAsyncOperations/JFFAsyncOperationUtils.mm +++ b/lib/JFFAsyncOperations/JFFAsyncOperationUtils.mm @@ -5,31 +5,36 @@ #import "JFFAsyncOperationAdapter.h" +static const char *const defaultQueueName = "com.jff.async_operations_library.general_queue"; + static JFFAsyncOperation asyncOperationWithSyncOperationWithProgressBlockAndQueue(JFFSyncOperationWithProgress progressLoadDataBlock, const char *queueName, BOOL barrier, + dispatch_queue_t currentQueue, dispatch_queue_attr_t attr) { + NSCParameterAssert(queueName != NULL); + NSString *str = @(queueName); progressLoadDataBlock = [progressLoadDataBlock copy]; - NSString *str = @(queueName?:""); - JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + JFFAsyncOperationInstanceBuilder factory = ^id() { + JFFAsyncOperationAdapter *asyncObject = [JFFAsyncOperationAdapter new]; - asyncObject.loadDataBlock = progressLoadDataBlock; - asyncObject.queueName = [str cStringUsingEncoding:NSUTF8StringEncoding]; - asyncObject.barrier = barrier; + asyncObject.loadDataBlock = progressLoadDataBlock; + asyncObject.queueName = [str cStringUsingEncoding:NSUTF8StringEncoding]; + asyncObject.barrier = barrier; + asyncObject.currentQueue = currentQueue; asyncObject.queueAttributes = attr; - return asyncObject; }; return buildAsyncOperationWithAdapterFactory(factory); } -static JFFAsyncOperation privateAsyncOperationWithSyncOperationAndQueue( - JFFSyncOperation loadDataBlock, - const char *queueName, - BOOL barrier, - dispatch_queue_attr_t attr ) +static JFFAsyncOperation privateAsyncOperationWithSyncOperationAndQueue(JFFSyncOperation loadDataBlock, + const char *queueName, + BOOL barrier, + dispatch_queue_t currentQueue, + dispatch_queue_attr_t attr) { loadDataBlock = [loadDataBlock copy]; JFFSyncOperationWithProgress progressLoadDataBlock= ^id(NSError *__autoreleasing *error, @@ -43,43 +48,54 @@ static JFFAsyncOperation privateAsyncOperationWithSyncOperationAndQueue( return asyncOperationWithSyncOperationWithProgressBlockAndQueue(progressLoadDataBlock, queueName, barrier, - attr ); + currentQueue, + attr); } JFFAsyncOperation asyncOperationWithSyncOperationAndQueue(JFFSyncOperation loadDataBlock, const char *queueName) { + NSCParameterAssert([NSThread isMainThread]); return privateAsyncOperationWithSyncOperationAndQueue(loadDataBlock, queueName, NO, - DISPATCH_QUEUE_CONCURRENT ); + dispatch_get_main_queue(), + DISPATCH_QUEUE_CONCURRENT); } JFFAsyncOperation barrierAsyncOperationWithSyncOperationAndQueue(JFFSyncOperation loadDataBlock, const char *queueName) { + NSCParameterAssert([NSThread isMainThread]); return privateAsyncOperationWithSyncOperationAndQueue(loadDataBlock, queueName, YES, - DISPATCH_QUEUE_CONCURRENT ); + dispatch_get_main_queue(), + DISPATCH_QUEUE_CONCURRENT); +} + +JFFAsyncOperation asyncOperationWithSyncOperationAndConfigurableQueue(JFFSyncOperation loadDataBlock, const char *queueName, BOOL isSerialQueue) +{ + NSCParameterAssert([NSThread isMainThread]); + dispatch_queue_attr_t attr = isSerialQueue?DISPATCH_QUEUE_SERIAL:DISPATCH_QUEUE_CONCURRENT; + + return privateAsyncOperationWithSyncOperationAndQueue(loadDataBlock, + queueName, + NO, + dispatch_get_main_queue(), + attr); } -//TODO check using of all asyncOperationWithSyncOperation (without queue name) or remove asyncOperationWithSyncOperation at all JFFAsyncOperation asyncOperationWithSyncOperation(JFFSyncOperation loadDataBlock) { - return asyncOperationWithSyncOperationAndQueue(loadDataBlock, nil); + return asyncOperationWithSyncOperationAndQueue(loadDataBlock, defaultQueueName); } JFFAsyncOperation asyncOperationWithSyncOperationWithProgressBlock(JFFSyncOperationWithProgress progressLoadDataBlock) { + NSCParameterAssert([NSThread isMainThread]); return asyncOperationWithSyncOperationWithProgressBlockAndQueue(progressLoadDataBlock, - nil, + defaultQueueName, NO, + dispatch_get_main_queue(), DISPATCH_QUEUE_CONCURRENT); } - -JFFAsyncOperation asyncOperationWithSyncOperationAndConfigurableQueue( JFFSyncOperation loadDataBlock_, const char* queueName_, BOOL isSerialQueue_ ) -{ - dispatch_queue_attr_t attr_ = isSerialQueue_ ? DISPATCH_QUEUE_SERIAL : DISPATCH_QUEUE_CONCURRENT; - - return privateAsyncOperationWithSyncOperationAndQueue( loadDataBlock_, queueName_, NO, attr_ ); -} diff --git a/lib/JFFAsyncOperations/JFFAsyncOperations.h b/lib/JFFAsyncOperations/JFFAsyncOperations.h index 024b51f..91ff00c 100755 --- a/lib/JFFAsyncOperations/JFFAsyncOperations.h +++ b/lib/JFFAsyncOperations/JFFAsyncOperations.h @@ -13,8 +13,8 @@ #import #import -#import -#import +#import +#import #import #import diff --git a/lib/JFFAsyncOperations/JFFAsyncOperations.xcodeproj/project.pbxproj b/lib/JFFAsyncOperations/JFFAsyncOperations.xcodeproj/project.pbxproj index 9cc9e08..2b77730 100644 --- a/lib/JFFAsyncOperations/JFFAsyncOperations.xcodeproj/project.pbxproj +++ b/lib/JFFAsyncOperations/JFFAsyncOperations.xcodeproj/project.pbxproj @@ -19,15 +19,39 @@ 1B2A67E5143F4CAB00BC284F /* JFFDidFinishAsyncOperationBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1B3D6E13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.m */; }; 1B2A682B143F532500BC284F /* JFFCancelAsyncOperationBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 65347F6C13B7EEE50002CF73 /* JFFCancelAsyncOperationBlockHolder.m */; }; 1B2A682E143F537B00BC284F /* JFFAsyncOperationProgressBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 6534804B13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.m */; }; - 1B3474551502469800973C6B /* NSArray+AsyncMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B3474531502469800973C6B /* NSArray+AsyncMap.h */; }; - 1B3474561502469800973C6B /* NSArray+AsyncMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B3474541502469800973C6B /* NSArray+AsyncMap.m */; }; - 1B34746115024EAA00973C6B /* NSDictionary+AsyncMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B34745F15024EAA00973C6B /* NSDictionary+AsyncMap.h */; }; - 1B34746215024EAA00973C6B /* NSDictionary+AsyncMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B34746015024EAA00973C6B /* NSDictionary+AsyncMap.m */; }; 1B835B33142CBA2200FC004C /* JFFAsyncOperationsPredefinedBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B835B31142CBA2200FC004C /* JFFAsyncOperationsPredefinedBlocks.h */; }; - 1B90273B143F370100D3B0A0 /* libJFFAsyncOpNoARC.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B9026D7143F368B00D3B0A0 /* libJFFAsyncOpNoARC.a */; }; 1B9528FC1500E67900C9B979 /* NSError+ResultOwnerships.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B9528FA1500E67900C9B979 /* NSError+ResultOwnerships.h */; }; 1B9528FD1500E67900C9B979 /* NSError+ResultOwnerships.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B9528FB1500E67900C9B979 /* NSError+ResultOwnerships.m */; }; 1BA2551C1443109B00C9B2BE /* JFFAsyncOperationContinuity.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1661391928400DD6890 /* JFFAsyncOperationContinuity.m */; }; + 4C6DFB0E1718446600D86975 /* JFFBaseStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C6DFB0C1718446500D86975 /* JFFBaseStrategy.h */; }; + 4C6DFB0F1718446600D86975 /* JFFBaseStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DFB0D1718446600D86975 /* JFFBaseStrategy.m */; }; + 4CB5CDE7174F54E200F2B600 /* NSArray+AsyncMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB5CDE5174F54E100F2B600 /* NSArray+AsyncMap.h */; }; + 4CB5CDE8174F54E200F2B600 /* NSArray+AsyncMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB5CDE6174F54E100F2B600 /* NSArray+AsyncMap.m */; }; + 4CB5CDEB174F551300F2B600 /* NSDictionary+AsyncMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB5CDE9174F551200F2B600 /* NSDictionary+AsyncMap.h */; }; + 4CB5CDEC174F551300F2B600 /* NSDictionary+AsyncMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB5CDEA174F551300F2B600 /* NSDictionary+AsyncMap.m */; }; + 4CBBDBEC17173B36004D670D /* JFFBaseLoaderOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB316FDB6FE00DAE2BB /* JFFBaseLoaderOwner.m */; }; + 4CBBDBED17173B36004D670D /* JFFBaseLoaderOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB316FDB6FE00DAE2BB /* JFFBaseLoaderOwner.m */; }; + 4CBBDBEE17173B37004D670D /* JFFBaseLoaderOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB316FDB6FE00DAE2BB /* JFFBaseLoaderOwner.m */; }; + 4CBBDCBF171741C8004D670D /* JFFAsyncOperationLoadBalancer.m in Sources */ = {isa = PBXBuildFile; fileRef = 65347F9513B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.m */; }; + 4CBBDCC0171741DB004D670D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CF62FB016FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.h */; }; + 4CBBDCC1171741DC004D670D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CF62FB016FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.h */; }; + 4CBBDCC2171741DC004D670D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CF62FB016FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.h */; }; + 4CBBDCC317174217004D670D /* JFFLimitedLoadersQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4031CB163D266B00FE6427 /* JFFLimitedLoadersQueue.m */; }; + 4CBBDCC417174217004D670D /* JFFLimitedLoadersQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4031CB163D266B00FE6427 /* JFFLimitedLoadersQueue.m */; }; + 4CBBDCC517174222004D670D /* JFFActiveLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FAF16FDB6FE00DAE2BB /* JFFActiveLoaderData.m */; }; + 4CBBDCC617174222004D670D /* JFFActiveLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FAF16FDB6FE00DAE2BB /* JFFActiveLoaderData.m */; }; + 4CBBDCC717174223004D670D /* JFFActiveLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FAF16FDB6FE00DAE2BB /* JFFActiveLoaderData.m */; }; + 4CBBDCC817174226004D670D /* JFFAsyncOperationLoadBalancerContexts.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB116FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.m */; }; + 4CBBDCC917174226004D670D /* JFFAsyncOperationLoadBalancerContexts.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB116FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.m */; }; + 4CBBDCCA17174227004D670D /* JFFAsyncOperationLoadBalancerContexts.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB116FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.m */; }; + 4CBBDCCB17174229004D670D /* JFFContextLoaders.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB516FDB6FE00DAE2BB /* JFFContextLoaders.m */; }; + 4CBBDCCC1717422A004D670D /* JFFContextLoaders.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB516FDB6FE00DAE2BB /* JFFContextLoaders.m */; }; + 4CBBDCCD1717422A004D670D /* JFFContextLoaders.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB516FDB6FE00DAE2BB /* JFFContextLoaders.m */; }; + 4CBBDCCE1717422D004D670D /* JFFPedingLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB716FDB6FE00DAE2BB /* JFFPedingLoaderData.m */; }; + 4CBBDCCF1717422E004D670D /* JFFPedingLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB716FDB6FE00DAE2BB /* JFFPedingLoaderData.m */; }; + 4CBBDCD01717422E004D670D /* JFFPedingLoaderData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF62FB716FDB6FE00DAE2BB /* JFFPedingLoaderData.m */; }; + 4CF62FCD16FDBA3800DAE2BB /* JFFAsyncOperationLoadBalancer.m in Sources */ = {isa = PBXBuildFile; fileRef = 65347F9513B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.m */; }; + 4CF62FCE16FDBA3800DAE2BB /* JFFAsyncOperationLoadBalancer.m in Sources */ = {isa = PBXBuildFile; fileRef = 65347F9513B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.m */; }; 5391035714A88BB5007315A3 /* JFFAsyncOperations_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* JFFAsyncOperations_Prefix.pch */; }; 5391035814A88BB5007315A3 /* JFFAsyncOperationsBlockDefinitions.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1611391913300DD6890 /* JFFAsyncOperationsBlockDefinitions.h */; }; 5391035914A88BB5007315A3 /* JFFAsyncOperationContinuity.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1651391928400DD6890 /* JFFAsyncOperationContinuity.h */; }; @@ -38,11 +62,7 @@ 5391035F14A88BB5007315A3 /* NSObject+AutoCancelAsyncOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 655ADDDE13B68E45005A6D3F /* NSObject+AutoCancelAsyncOperation.h */; }; 5391036014A88BB5007315A3 /* JFFCancelAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347F6B13B7EEE50002CF73 /* JFFCancelAsyncOperationBlockHolder.h */; }; 5391036114A88BB5007315A3 /* JFFAsyncOperationLoadBalancer.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347F9413B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.h */; }; - 5391036214A88BB5007315A3 /* JFFContextLoaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347FED13B8142A0002CF73 /* JFFContextLoaders.h */; }; - 5391036314A88BB5007315A3 /* JFFAsyncOperationLoadBalancerContexts.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347FF513B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.h */; }; - 5391036414A88BB5007315A3 /* JFFActiveLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 6534802313B81DAE0002CF73 /* JFFActiveLoaderData.h */; }; 5391036514A88BB5007315A3 /* JFFAsyncOperationProgressBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 6534804A13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.h */; }; - 5391036614A88BB5007315A3 /* JFFPedingLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1B3D2913B87A4900410ECB /* JFFPedingLoaderData.h */; }; 5391036714A88BB5007315A3 /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1B3D6D13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.h */; }; 5391036814A88BB5007315A3 /* JFFPropertyPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D9827F713F2B9D5009DD73B /* JFFPropertyPath.h */; }; 5391036914A88BB5007315A3 /* NSObject+AsyncPropertyReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D9827F913F2B9D5009DD73B /* NSObject+AsyncPropertyReader.h */; }; @@ -55,16 +75,12 @@ 5391037214A88BB5007315A3 /* JFFAsyncOperationProgressBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 6534804B13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.m */; }; 5391037314A88BB5007315A3 /* JFFAsyncOperationContinuity.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1661391928400DD6890 /* JFFAsyncOperationContinuity.m */; }; 5391037414A88BB5007315A3 /* JFFCallbacksBlocksHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648BAE1392407F001E163C /* JFFCallbacksBlocksHolder.m */; }; - 5391037614A88BB5007315A3 /* libJFFAsyncOpNoARC.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B9026D7143F368B00D3B0A0 /* libJFFAsyncOpNoARC.a */; }; 5391037714A88BB5007315A3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; 651BE1621391913300DD6890 /* JFFAsyncOperationsBlockDefinitions.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1611391913300DD6890 /* JFFAsyncOperationsBlockDefinitions.h */; }; 651BE1671391928400DD6890 /* JFFAsyncOperationContinuity.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1651391928400DD6890 /* JFFAsyncOperationContinuity.h */; }; 6532667C14C1EB27004E90B0 /* JFFAsyncOperationsPredefinedBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B835B31142CBA2200FC004C /* JFFAsyncOperationsPredefinedBlocks.h */; }; 65347F6D13B7EEE50002CF73 /* JFFCancelAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347F6B13B7EEE50002CF73 /* JFFCancelAsyncOperationBlockHolder.h */; }; 65347F9613B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347F9413B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.h */; }; - 65347FEF13B8142A0002CF73 /* JFFContextLoaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347FED13B8142A0002CF73 /* JFFContextLoaders.h */; }; - 65347FF713B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347FF513B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.h */; }; - 6534802513B81DAE0002CF73 /* JFFActiveLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 6534802313B81DAE0002CF73 /* JFFActiveLoaderData.h */; }; 6534804C13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 6534804A13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.h */; }; 65462C9514D8811100685ED8 /* JFFBlockOperation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65648BD413924220001E163C /* JFFBlockOperation.mm */; }; 655ADDE013B68E45005A6D3F /* NSObject+AutoCancelAsyncOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 655ADDDE13B68E45005A6D3F /* NSObject+AutoCancelAsyncOperation.h */; }; @@ -130,10 +146,6 @@ 7E8F210A14F94C6100588C7D /* JFFCancelAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347F6B13B7EEE50002CF73 /* JFFCancelAsyncOperationBlockHolder.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E8F210C14F94C6100588C7D /* JFFAsyncOperationProgressBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 6534804A13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E8F210E14F94C6100588C7D /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1B3D6D13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E8F211014F94C6100588C7D /* JFFActiveLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 6534802313B81DAE0002CF73 /* JFFActiveLoaderData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E8F211214F94C6100588C7D /* JFFPedingLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1B3D2913B87A4900410ECB /* JFFPedingLoaderData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E8F211414F94C6100588C7D /* JFFContextLoaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347FED13B8142A0002CF73 /* JFFContextLoaders.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E8F211614F94C6100588C7D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347FF513B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E8F211814F94C6100588C7D /* JFFAsyncOperationLoadBalancer.h in Headers */ = {isa = PBXBuildFile; fileRef = 65347F9413B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E8F211A14F94C6100588C7D /* JFFAsyncOperationsBlockDefinitions.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1611391913300DD6890 /* JFFAsyncOperationsBlockDefinitions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E8F211B14F94C6100588C7D /* JFFAsyncOperationsPredefinedBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B835B31142CBA2200FC004C /* JFFAsyncOperationsPredefinedBlocks.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -142,7 +154,6 @@ 7E8F212114F94C6100588C7D /* JFFAsyncOperationUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648C381392490F001E163C /* JFFAsyncOperationUtils.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E8F212314F94C6100588C7D /* JFFAsyncOperationContinuity.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1651391928400DD6890 /* JFFAsyncOperationContinuity.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E8F212514F94C6100588C7D /* JFFAsyncOperations.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648C5013924A77001E163C /* JFFAsyncOperations.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 8D1B3D2B13B87A4900410ECB /* JFFPedingLoaderData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1B3D2913B87A4900410ECB /* JFFPedingLoaderData.h */; }; 8D1B3D6F13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1B3D6D13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.h */; }; 8D61CD2C13F2BC8A0003AC4A /* JFFObjectRelatedPropertyData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D61CD2A13F2BC8A0003AC4A /* JFFObjectRelatedPropertyData.h */; }; 8D61CD3113F2BCE40003AC4A /* NSObject+PropertyExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D61CD2F13F2BCE40003AC4A /* NSObject+PropertyExtractor.h */; }; @@ -153,36 +164,8 @@ AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; CE4031CC163D266B00FE6427 /* JFFLimitedLoadersQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = CE4031CA163D266A00FE6427 /* JFFLimitedLoadersQueue.h */; }; CE4031CD163D266B00FE6427 /* JFFLimitedLoadersQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4031CB163D266B00FE6427 /* JFFLimitedLoadersQueue.m */; }; - CE7787E8163D2DBE009473A1 /* JFFBaseLoaderOwner.h in Headers */ = {isa = PBXBuildFile; fileRef = CE7787E6163D2DBE009473A1 /* JFFBaseLoaderOwner.h */; }; - CE7787E9163D2DBE009473A1 /* JFFBaseLoaderOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = CE7787E7163D2DBE009473A1 /* JFFBaseLoaderOwner.m */; }; - CE90A694162C346C00428011 /* NSThread+AsyncPropertyReader.h in Headers */ = {isa = PBXBuildFile; fileRef = CE90A692162C346C00428011 /* NSThread+AsyncPropertyReader.h */; }; - CE90A695162C346C00428011 /* NSThread+AsyncPropertyReader.m in Sources */ = {isa = PBXBuildFile; fileRef = CE90A693162C346C00428011 /* NSThread+AsyncPropertyReader.m */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 1B9026D6143F368B00D3B0A0 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 1B9026CF143F368B00D3B0A0 /* JFFAsyncOpNoARC.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1B9026BD143F35F800D3B0A0; - remoteInfo = JFFAsyncOpNoARC; - }; - 1B902739143F36FA00D3B0A0 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 1B9026CF143F368B00D3B0A0 /* JFFAsyncOpNoARC.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 1B9026BC143F35F800D3B0A0; - remoteInfo = JFFAsyncOpNoARC; - }; - 5391035514A88BB5007315A3 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 1B9026CF143F368B00D3B0A0 /* JFFAsyncOpNoARC.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 1B9026BC143F35F800D3B0A0; - remoteInfo = JFFAsyncOpNoARC; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXFileReference section */ 1B0D88C11519F81F00EC4A92 /* JFFAsyncOperationBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationBuilder.h; sourceTree = ""; }; 1B0D88C21519F81F00EC4A92 /* JFFAsyncOperationBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationBuilder.m; sourceTree = ""; }; @@ -190,16 +173,27 @@ 1B0E83A81563954B00825E3C /* JFFAsyncOperationAdapter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JFFAsyncOperationAdapter.mm; sourceTree = ""; }; 1B0FB885150604850056F14E /* JFFAsyncOperationHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationHelpers.h; sourceTree = ""; }; 1B0FB886150604850056F14E /* JFFAsyncOperationHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationHelpers.m; sourceTree = ""; }; - 1B3474531502469800973C6B /* NSArray+AsyncMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+AsyncMap.h"; sourceTree = ""; }; - 1B3474541502469800973C6B /* NSArray+AsyncMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+AsyncMap.m"; sourceTree = ""; }; - 1B34745F15024EAA00973C6B /* NSDictionary+AsyncMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+AsyncMap.h"; sourceTree = ""; }; - 1B34746015024EAA00973C6B /* NSDictionary+AsyncMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+AsyncMap.m"; sourceTree = ""; }; 1B835B31142CBA2200FC004C /* JFFAsyncOperationsPredefinedBlocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationsPredefinedBlocks.h; sourceTree = ""; }; 1B835B32142CBA2200FC004C /* JFFAsyncOperationsPredefinedBlocks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationsPredefinedBlocks.m; sourceTree = ""; }; - 1B9026CF143F368B00D3B0A0 /* JFFAsyncOpNoARC.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = JFFAsyncOpNoARC.xcodeproj; sourceTree = ""; }; 1B9368DF156504D800F8A394 /* JFFAsyncOperationInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationInterface.h; sourceTree = ""; }; 1B9528FA1500E67900C9B979 /* NSError+ResultOwnerships.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+ResultOwnerships.h"; sourceTree = ""; }; 1B9528FB1500E67900C9B979 /* NSError+ResultOwnerships.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+ResultOwnerships.m"; sourceTree = ""; }; + 4C6DFB0C1718446500D86975 /* JFFBaseStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFBaseStrategy.h; sourceTree = ""; }; + 4C6DFB0D1718446600D86975 /* JFFBaseStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFBaseStrategy.m; sourceTree = ""; }; + 4CB5CDE5174F54E100F2B600 /* NSArray+AsyncMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+AsyncMap.h"; sourceTree = ""; }; + 4CB5CDE6174F54E100F2B600 /* NSArray+AsyncMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+AsyncMap.m"; sourceTree = ""; }; + 4CB5CDE9174F551200F2B600 /* NSDictionary+AsyncMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+AsyncMap.h"; sourceTree = ""; }; + 4CB5CDEA174F551300F2B600 /* NSDictionary+AsyncMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+AsyncMap.m"; sourceTree = ""; }; + 4CF62FAE16FDB6FE00DAE2BB /* JFFActiveLoaderData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFActiveLoaderData.h; sourceTree = ""; }; + 4CF62FAF16FDB6FE00DAE2BB /* JFFActiveLoaderData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFActiveLoaderData.m; sourceTree = ""; }; + 4CF62FB016FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationLoadBalancerContexts.h; sourceTree = ""; }; + 4CF62FB116FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationLoadBalancerContexts.m; sourceTree = ""; }; + 4CF62FB216FDB6FE00DAE2BB /* JFFBaseLoaderOwner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFBaseLoaderOwner.h; sourceTree = ""; }; + 4CF62FB316FDB6FE00DAE2BB /* JFFBaseLoaderOwner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFBaseLoaderOwner.m; sourceTree = ""; }; + 4CF62FB416FDB6FE00DAE2BB /* JFFContextLoaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFContextLoaders.h; sourceTree = ""; }; + 4CF62FB516FDB6FE00DAE2BB /* JFFContextLoaders.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFContextLoaders.m; sourceTree = ""; }; + 4CF62FB616FDB6FE00DAE2BB /* JFFPedingLoaderData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPedingLoaderData.h; sourceTree = ""; }; + 4CF62FB716FDB6FE00DAE2BB /* JFFPedingLoaderData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFPedingLoaderData.m; sourceTree = ""; }; 5391037B14A88BB5007315A3 /* libJFFAsyncOperations-clang.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libJFFAsyncOperations-clang.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 651BE1611391913300DD6890 /* JFFAsyncOperationsBlockDefinitions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationsBlockDefinitions.h; sourceTree = ""; }; 651BE1651391928400DD6890 /* JFFAsyncOperationContinuity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationContinuity.h; sourceTree = ""; }; @@ -208,12 +202,6 @@ 65347F6C13B7EEE50002CF73 /* JFFCancelAsyncOperationBlockHolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCancelAsyncOperationBlockHolder.m; sourceTree = ""; }; 65347F9413B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationLoadBalancer.h; sourceTree = ""; }; 65347F9513B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationLoadBalancer.m; sourceTree = ""; }; - 65347FED13B8142A0002CF73 /* JFFContextLoaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFContextLoaders.h; sourceTree = ""; }; - 65347FEE13B8142A0002CF73 /* JFFContextLoaders.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFContextLoaders.m; sourceTree = ""; }; - 65347FF513B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationLoadBalancerContexts.h; sourceTree = ""; }; - 65347FF613B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationLoadBalancerContexts.m; sourceTree = ""; }; - 6534802313B81DAE0002CF73 /* JFFActiveLoaderData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFActiveLoaderData.h; sourceTree = ""; }; - 6534802413B81DAE0002CF73 /* JFFActiveLoaderData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFActiveLoaderData.m; sourceTree = ""; }; 6534804A13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncOperationProgressBlockHolder.h; sourceTree = ""; }; 6534804B13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncOperationProgressBlockHolder.m; sourceTree = ""; }; 655ADDDE13B68E45005A6D3F /* NSObject+AutoCancelAsyncOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+AutoCancelAsyncOperation.h"; sourceTree = ""; }; @@ -241,8 +229,6 @@ 7E8F20CD14F94BDF00588C7D /* JFFAsyncOperationsFW-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JFFAsyncOperationsFW-Info.plist"; sourceTree = ""; }; 7E8F20CF14F94BDF00588C7D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 7E8F20D114F94BDF00588C7D /* JFFAsyncOperationsFW-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JFFAsyncOperationsFW-Prefix.pch"; sourceTree = ""; }; - 8D1B3D2913B87A4900410ECB /* JFFPedingLoaderData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPedingLoaderData.h; sourceTree = ""; }; - 8D1B3D2A13B87A4900410ECB /* JFFPedingLoaderData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFPedingLoaderData.m; sourceTree = ""; }; 8D1B3D6D13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFDidFinishAsyncOperationBlockHolder.h; sourceTree = ""; }; 8D1B3D6E13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFDidFinishAsyncOperationBlockHolder.m; sourceTree = ""; }; 8D61CD2A13F2BC8A0003AC4A /* JFFObjectRelatedPropertyData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFObjectRelatedPropertyData.h; sourceTree = ""; }; @@ -259,10 +245,6 @@ AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; CE4031CA163D266A00FE6427 /* JFFLimitedLoadersQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFLimitedLoadersQueue.h; sourceTree = ""; }; CE4031CB163D266B00FE6427 /* JFFLimitedLoadersQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFLimitedLoadersQueue.m; sourceTree = ""; }; - CE7787E6163D2DBE009473A1 /* JFFBaseLoaderOwner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFBaseLoaderOwner.h; sourceTree = ""; }; - CE7787E7163D2DBE009473A1 /* JFFBaseLoaderOwner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFBaseLoaderOwner.m; sourceTree = ""; }; - CE90A692162C346C00428011 /* NSThread+AsyncPropertyReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSThread+AsyncPropertyReader.h"; sourceTree = ""; }; - CE90A693162C346C00428011 /* NSThread+AsyncPropertyReader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSThread+AsyncPropertyReader.m"; sourceTree = ""; }; D2AAC07E0554694100DB518D /* libJFFAsyncOperations.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFAsyncOperations.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -271,7 +253,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 5391037614A88BB5007315A3 /* libJFFAsyncOpNoARC.a in Frameworks */, 5391037714A88BB5007315A3 /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -288,7 +269,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 1B90273B143F370100D3B0A0 /* libJFFAsyncOpNoARC.a in Frameworks */, AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -330,8 +310,8 @@ 08FB77AEFE84172EC02AAC07 /* Classes */ = { isa = PBXGroup; children = ( + 4CB5CDE4174F54CA00F2B600 /* Categories */, 1B0D88BF1519F80C00EC4A92 /* AsyncOperartionsBuilder */, - 1B3474511502468200973C6B /* Extensions */, 8D9827F613F2B9AF009DD73B /* CachedAsyncOperations */, 65648AF913923C47001E163C /* Detail */, 65347F2E13B7ECDB0002CF73 /* Helpers */, @@ -364,39 +344,47 @@ path = AsyncOperartionsBuilder; sourceTree = ""; }; - 1B3474511502468200973C6B /* Extensions */ = { + 1B9026CD143F364D00D3B0A0 /* Dependencies */ = { isa = PBXGroup; children = ( - 1B3474531502469800973C6B /* NSArray+AsyncMap.h */, - 1B3474541502469800973C6B /* NSArray+AsyncMap.m */, - 1B34745F15024EAA00973C6B /* NSDictionary+AsyncMap.h */, - 1B34746015024EAA00973C6B /* NSDictionary+AsyncMap.m */, ); - path = Extensions; + name = Dependencies; sourceTree = ""; }; - 1B9026CD143F364D00D3B0A0 /* Dependencies */ = { + 32C88DFF0371C24200C91783 /* Other Sources */ = { isa = PBXGroup; children = ( - 1B9026CF143F368B00D3B0A0 /* JFFAsyncOpNoARC.xcodeproj */, + AA747D9E0F9514B9006C5449 /* JFFAsyncOperations_Prefix.pch */, ); - name = Dependencies; + name = "Other Sources"; sourceTree = ""; }; - 1B9026D0143F368B00D3B0A0 /* Products */ = { + 4CB5CDE4174F54CA00F2B600 /* Categories */ = { isa = PBXGroup; children = ( - 1B9026D7143F368B00D3B0A0 /* libJFFAsyncOpNoARC.a */, + 4CB5CDE5174F54E100F2B600 /* NSArray+AsyncMap.h */, + 4CB5CDE6174F54E100F2B600 /* NSArray+AsyncMap.m */, + 4CB5CDE9174F551200F2B600 /* NSDictionary+AsyncMap.h */, + 4CB5CDEA174F551300F2B600 /* NSDictionary+AsyncMap.m */, ); - name = Products; + path = Categories; sourceTree = ""; }; - 32C88DFF0371C24200C91783 /* Other Sources */ = { + 4CF62FAD16FDB6FE00DAE2BB /* Detail */ = { isa = PBXGroup; children = ( - AA747D9E0F9514B9006C5449 /* JFFAsyncOperations_Prefix.pch */, + 4CF62FB216FDB6FE00DAE2BB /* JFFBaseLoaderOwner.h */, + 4CF62FB316FDB6FE00DAE2BB /* JFFBaseLoaderOwner.m */, + 4CF62FAE16FDB6FE00DAE2BB /* JFFActiveLoaderData.h */, + 4CF62FAF16FDB6FE00DAE2BB /* JFFActiveLoaderData.m */, + 4CF62FB016FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.h */, + 4CF62FB116FDB6FE00DAE2BB /* JFFAsyncOperationLoadBalancerContexts.m */, + 4CF62FB416FDB6FE00DAE2BB /* JFFContextLoaders.h */, + 4CF62FB516FDB6FE00DAE2BB /* JFFContextLoaders.m */, + 4CF62FB616FDB6FE00DAE2BB /* JFFPedingLoaderData.h */, + 4CF62FB716FDB6FE00DAE2BB /* JFFPedingLoaderData.m */, ); - name = "Other Sources"; + path = Detail; sourceTree = ""; }; 65347F2E13B7ECDB0002CF73 /* Helpers */ = { @@ -416,8 +404,7 @@ isa = PBXGroup; children = ( 7E79064916E4975D00CFC696 /* QueueStrategies */, - CE7787E4163D2D8F009473A1 /* Details2 */, - 65347FEC13B8141F0002CF73 /* Detail */, + 4CF62FAD16FDB6FE00DAE2BB /* Detail */, 65347F9413B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.h */, 65347F9513B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.m */, CE4031CA163D266A00FE6427 /* JFFLimitedLoadersQueue.h */, @@ -427,21 +414,6 @@ path = LoadBalancer; sourceTree = ""; }; - 65347FEC13B8141F0002CF73 /* Detail */ = { - isa = PBXGroup; - children = ( - 6534802313B81DAE0002CF73 /* JFFActiveLoaderData.h */, - 6534802413B81DAE0002CF73 /* JFFActiveLoaderData.m */, - 8D1B3D2913B87A4900410ECB /* JFFPedingLoaderData.h */, - 8D1B3D2A13B87A4900410ECB /* JFFPedingLoaderData.m */, - 65347FED13B8142A0002CF73 /* JFFContextLoaders.h */, - 65347FEE13B8142A0002CF73 /* JFFContextLoaders.m */, - 65347FF513B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.h */, - 65347FF613B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.m */, - ); - path = Detail; - sourceTree = ""; - }; 65648AF913923C47001E163C /* Detail */ = { isa = PBXGroup; children = ( @@ -463,6 +435,8 @@ 7E79065416E4984400CFC696 /* JFFQueueState.m */, 7E79065B16E49DD900CFC696 /* JFFQueueStrategyFactory.h */, 7E79065C16E49DD900CFC696 /* JFFQueueStrategyFactory.m */, + 4C6DFB0C1718446500D86975 /* JFFBaseStrategy.h */, + 4C6DFB0D1718446600D86975 /* JFFBaseStrategy.m */, 7E79064B16E4981700CFC696 /* JFFStrategyFifo.h */, 7E79064C16E4981700CFC696 /* JFFStrategyFifo.m */, 7E79066316E49F8000CFC696 /* JFFStrategyStack.h */, @@ -512,21 +486,10 @@ 8D61CD2B13F2BC8A0003AC4A /* JFFObjectRelatedPropertyData.m */, 8D61CD2F13F2BCE40003AC4A /* NSObject+PropertyExtractor.h */, 8D61CD3013F2BCE40003AC4A /* NSObject+PropertyExtractor.m */, - CE90A692162C346C00428011 /* NSThread+AsyncPropertyReader.h */, - CE90A693162C346C00428011 /* NSThread+AsyncPropertyReader.m */, ); path = Detail; sourceTree = ""; }; - CE7787E4163D2D8F009473A1 /* Details2 */ = { - isa = PBXGroup; - children = ( - CE7787E6163D2DBE009473A1 /* JFFBaseLoaderOwner.h */, - CE7787E7163D2DBE009473A1 /* JFFBaseLoaderOwner.m */, - ); - path = Details2; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -544,11 +507,7 @@ 5391035F14A88BB5007315A3 /* NSObject+AutoCancelAsyncOperation.h in Headers */, 5391036014A88BB5007315A3 /* JFFCancelAsyncOperationBlockHolder.h in Headers */, 5391036114A88BB5007315A3 /* JFFAsyncOperationLoadBalancer.h in Headers */, - 5391036214A88BB5007315A3 /* JFFContextLoaders.h in Headers */, - 5391036314A88BB5007315A3 /* JFFAsyncOperationLoadBalancerContexts.h in Headers */, - 5391036414A88BB5007315A3 /* JFFActiveLoaderData.h in Headers */, 5391036514A88BB5007315A3 /* JFFAsyncOperationProgressBlockHolder.h in Headers */, - 5391036614A88BB5007315A3 /* JFFPedingLoaderData.h in Headers */, 5391036714A88BB5007315A3 /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */, 5391036814A88BB5007315A3 /* JFFPropertyPath.h in Headers */, 5391036914A88BB5007315A3 /* NSObject+AsyncPropertyReader.h in Headers */, @@ -561,6 +520,7 @@ 7E79065E16E49DD900CFC696 /* JFFQueueStrategyFactory.h in Headers */, 7E79066616E49F8000CFC696 /* JFFStrategyStack.h in Headers */, 7E79066E16E4A49B00CFC696 /* JFFStrategyRandom.h in Headers */, + 4CBBDCC1171741DC004D670D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -577,10 +537,6 @@ 7E8F210A14F94C6100588C7D /* JFFCancelAsyncOperationBlockHolder.h in Headers */, 7E8F210C14F94C6100588C7D /* JFFAsyncOperationProgressBlockHolder.h in Headers */, 7E8F210E14F94C6100588C7D /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */, - 7E8F211014F94C6100588C7D /* JFFActiveLoaderData.h in Headers */, - 7E8F211214F94C6100588C7D /* JFFPedingLoaderData.h in Headers */, - 7E8F211414F94C6100588C7D /* JFFContextLoaders.h in Headers */, - 7E8F211614F94C6100588C7D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */, 7E8F211814F94C6100588C7D /* JFFAsyncOperationLoadBalancer.h in Headers */, 7E8F211A14F94C6100588C7D /* JFFAsyncOperationsBlockDefinitions.h in Headers */, 7E8F211B14F94C6100588C7D /* JFFAsyncOperationsPredefinedBlocks.h in Headers */, @@ -594,6 +550,7 @@ 7E79065F16E49DD900CFC696 /* JFFQueueStrategyFactory.h in Headers */, 7E79066716E49F8000CFC696 /* JFFStrategyStack.h in Headers */, 7E79066F16E4A49B00CFC696 /* JFFStrategyRandom.h in Headers */, + 4CBBDCC2171741DC004D670D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -611,11 +568,7 @@ 655ADDE013B68E45005A6D3F /* NSObject+AutoCancelAsyncOperation.h in Headers */, 65347F6D13B7EEE50002CF73 /* JFFCancelAsyncOperationBlockHolder.h in Headers */, 65347F9613B7F0BD0002CF73 /* JFFAsyncOperationLoadBalancer.h in Headers */, - 65347FEF13B8142A0002CF73 /* JFFContextLoaders.h in Headers */, - 65347FF713B8147C0002CF73 /* JFFAsyncOperationLoadBalancerContexts.h in Headers */, - 6534802513B81DAE0002CF73 /* JFFActiveLoaderData.h in Headers */, 6534804C13B822F00002CF73 /* JFFAsyncOperationProgressBlockHolder.h in Headers */, - 8D1B3D2B13B87A4900410ECB /* JFFPedingLoaderData.h in Headers */, 8D1B3D6F13B88A2700410ECB /* JFFDidFinishAsyncOperationBlockHolder.h in Headers */, 8D9827FB13F2B9D5009DD73B /* JFFPropertyPath.h in Headers */, 8D9827FD13F2B9D5009DD73B /* NSObject+AsyncPropertyReader.h in Headers */, @@ -624,19 +577,19 @@ 8D61CD3113F2BCE40003AC4A /* NSObject+PropertyExtractor.h in Headers */, 1B835B33142CBA2200FC004C /* JFFAsyncOperationsPredefinedBlocks.h in Headers */, 1B9528FC1500E67900C9B979 /* NSError+ResultOwnerships.h in Headers */, - 1B3474551502469800973C6B /* NSArray+AsyncMap.h in Headers */, - 1B34746115024EAA00973C6B /* NSDictionary+AsyncMap.h in Headers */, 1B0FB887150604860056F14E /* JFFAsyncOperationHelpers.h in Headers */, 1B0D88C31519F81F00EC4A92 /* JFFAsyncOperationBuilder.h in Headers */, 1B0E83A91563954B00825E3C /* JFFAsyncOperationAdapter.h in Headers */, - CE90A694162C346C00428011 /* NSThread+AsyncPropertyReader.h in Headers */, CE4031CC163D266B00FE6427 /* JFFLimitedLoadersQueue.h in Headers */, - CE7787E8163D2DBE009473A1 /* JFFBaseLoaderOwner.h in Headers */, 7E79064D16E4981700CFC696 /* JFFStrategyFifo.h in Headers */, 7E79065516E4984400CFC696 /* JFFQueueState.h in Headers */, 7E79065D16E49DD900CFC696 /* JFFQueueStrategyFactory.h in Headers */, 7E79066516E49F8000CFC696 /* JFFStrategyStack.h in Headers */, 7E79066D16E4A49B00CFC696 /* JFFStrategyRandom.h in Headers */, + 4CBBDCC0171741DB004D670D /* JFFAsyncOperationLoadBalancerContexts.h in Headers */, + 4C6DFB0E1718446600D86975 /* JFFBaseStrategy.h in Headers */, + 4CB5CDE7174F54E200F2B600 /* NSArray+AsyncMap.h in Headers */, + 4CB5CDEB174F551300F2B600 /* NSDictionary+AsyncMap.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -654,7 +607,6 @@ buildRules = ( ); dependencies = ( - 5391035414A88BB5007315A3 /* PBXTargetDependency */, ); name = "JFFAsyncOperations-clang"; productName = JFFAsyncOperations; @@ -693,7 +645,6 @@ buildRules = ( ); dependencies = ( - 1B90273A143F36FA00D3B0A0 /* PBXTargetDependency */, ); name = JFFAsyncOperations; productName = JFFAsyncOperations; @@ -706,7 +657,7 @@ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0500; }; buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "JFFAsyncOperations" */; compatibilityVersion = "Xcode 3.2"; @@ -722,12 +673,6 @@ mainGroup = 0867D691FE84028FC02AAC07 /* JFFAsyncOperations */; productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 1B9026D0143F368B00D3B0A0 /* Products */; - ProjectRef = 1B9026CF143F368B00D3B0A0 /* JFFAsyncOpNoARC.xcodeproj */; - }, - ); projectRoot = ""; targets = ( D2AAC07D0554694100DB518D /* JFFAsyncOperations */, @@ -737,16 +682,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 1B9026D7143F368B00D3B0A0 /* libJFFAsyncOpNoARC.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFAsyncOpNoARC.a; - remoteRef = 1B9026D6143F368B00D3B0A0 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ 7E8F20C514F94BDF00588C7D /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -814,11 +749,18 @@ 5391037214A88BB5007315A3 /* JFFAsyncOperationProgressBlockHolder.m in Sources */, 5391037314A88BB5007315A3 /* JFFAsyncOperationContinuity.m in Sources */, 5391037414A88BB5007315A3 /* JFFCallbacksBlocksHolder.m in Sources */, + 4CF62FCD16FDBA3800DAE2BB /* JFFAsyncOperationLoadBalancer.m in Sources */, 7E79065116E4981700CFC696 /* JFFStrategyFifo.m in Sources */, 7E79065916E4984400CFC696 /* JFFQueueState.m in Sources */, 7E79066116E49DD900CFC696 /* JFFQueueStrategyFactory.m in Sources */, 7E79066916E49F8000CFC696 /* JFFStrategyStack.m in Sources */, 7E79067116E4A49B00CFC696 /* JFFStrategyRandom.mm in Sources */, + 4CBBDBED17173B36004D670D /* JFFBaseLoaderOwner.m in Sources */, + 4CBBDCC317174217004D670D /* JFFLimitedLoadersQueue.m in Sources */, + 4CBBDCC617174222004D670D /* JFFActiveLoaderData.m in Sources */, + 4CBBDCC917174226004D670D /* JFFAsyncOperationLoadBalancerContexts.m in Sources */, + 4CBBDCCC1717422A004D670D /* JFFContextLoaders.m in Sources */, + 4CBBDCCF1717422E004D670D /* JFFPedingLoaderData.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -837,11 +779,18 @@ 7E8F20F614F94C3100588C7D /* JFFBlockOperation.mm in Sources */, 7E8F20F814F94C3100588C7D /* NSObject+AutoCancelAsyncOperation.m in Sources */, 7E8F20FC14F94C3100588C7D /* JFFAsyncOperationContinuity.m in Sources */, + 4CF62FCE16FDBA3800DAE2BB /* JFFAsyncOperationLoadBalancer.m in Sources */, 7E79065216E4981700CFC696 /* JFFStrategyFifo.m in Sources */, 7E79065A16E4984400CFC696 /* JFFQueueState.m in Sources */, 7E79066216E49DD900CFC696 /* JFFQueueStrategyFactory.m in Sources */, 7E79066A16E49F8000CFC696 /* JFFStrategyStack.m in Sources */, 7E79067216E4A49B00CFC696 /* JFFStrategyRandom.mm in Sources */, + 4CBBDBEE17173B37004D670D /* JFFBaseLoaderOwner.m in Sources */, + 4CBBDCC417174217004D670D /* JFFLimitedLoadersQueue.m in Sources */, + 4CBBDCC717174223004D670D /* JFFActiveLoaderData.m in Sources */, + 4CBBDCCA17174227004D670D /* JFFAsyncOperationLoadBalancerContexts.m in Sources */, + 4CBBDCCD1717422A004D670D /* JFFContextLoaders.m in Sources */, + 4CBBDCD01717422E004D670D /* JFFPedingLoaderData.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -863,38 +812,30 @@ 65BA0A4E14A7821200EB2AAB /* JFFAsyncOperationsPredefinedBlocks.m in Sources */, 65462C9514D8811100685ED8 /* JFFBlockOperation.mm in Sources */, 1B9528FD1500E67900C9B979 /* NSError+ResultOwnerships.m in Sources */, - 1B3474561502469800973C6B /* NSArray+AsyncMap.m in Sources */, - 1B34746215024EAA00973C6B /* NSDictionary+AsyncMap.m in Sources */, 1B0FB888150604860056F14E /* JFFAsyncOperationHelpers.m in Sources */, 1B0D88C41519F81F00EC4A92 /* JFFAsyncOperationBuilder.m in Sources */, 1B0E83A51563953300825E3C /* JFFAsyncOperationUtils.mm in Sources */, 1B0E83AA1563954B00825E3C /* JFFAsyncOperationAdapter.mm in Sources */, - CE90A695162C346C00428011 /* NSThread+AsyncPropertyReader.m in Sources */, CE4031CD163D266B00FE6427 /* JFFLimitedLoadersQueue.m in Sources */, - CE7787E9163D2DBE009473A1 /* JFFBaseLoaderOwner.m in Sources */, 7E79065016E4981700CFC696 /* JFFStrategyFifo.m in Sources */, 7E79065816E4984400CFC696 /* JFFQueueState.m in Sources */, 7E79066016E49DD900CFC696 /* JFFQueueStrategyFactory.m in Sources */, 7E79066816E49F8000CFC696 /* JFFStrategyStack.m in Sources */, 7E79067016E4A49B00CFC696 /* JFFStrategyRandom.mm in Sources */, + 4CBBDBEC17173B36004D670D /* JFFBaseLoaderOwner.m in Sources */, + 4CBBDCBF171741C8004D670D /* JFFAsyncOperationLoadBalancer.m in Sources */, + 4CBBDCC517174222004D670D /* JFFActiveLoaderData.m in Sources */, + 4CBBDCC817174226004D670D /* JFFAsyncOperationLoadBalancerContexts.m in Sources */, + 4CBBDCCB17174229004D670D /* JFFContextLoaders.m in Sources */, + 4CBBDCCE1717422D004D670D /* JFFPedingLoaderData.m in Sources */, + 4C6DFB0F1718446600D86975 /* JFFBaseStrategy.m in Sources */, + 4CB5CDE8174F54E200F2B600 /* NSArray+AsyncMap.m in Sources */, + 4CB5CDEC174F551300F2B600 /* NSDictionary+AsyncMap.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - 1B90273A143F36FA00D3B0A0 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFAsyncOpNoARC; - targetProxy = 1B902739143F36FA00D3B0A0 /* PBXContainerItemProxy */; - }; - 5391035414A88BB5007315A3 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFAsyncOpNoARC; - targetProxy = 5391035514A88BB5007315A3 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin PBXVariantGroup section */ 7E8F20CE14F94BDF00588C7D /* InfoPlist.strings */ = { isa = PBXVariantGroup; @@ -911,7 +852,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; COPY_PHASE_STRIP = NO; DSTROOT = /tmp/JFFAsyncOperations.dst; GCC_DYNAMIC_NO_PIC = NO; @@ -920,6 +860,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = JFFAsyncOperations_Prefix.pch; INSTALL_PATH = /usr/local/lib; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = JFFAsyncOperations; SKIP_INSTALL = YES; }; @@ -929,12 +870,12 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; DSTROOT = /tmp/JFFAsyncOperations.dst; GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = JFFAsyncOperations_Prefix.pch; INSTALL_PATH = /usr/local/lib; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = JFFAsyncOperations; SKIP_INSTALL = YES; }; @@ -943,14 +884,17 @@ 1DEB922308733DC00010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; @@ -959,13 +903,16 @@ 1DEB922408733DC00010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; diff --git a/lib/JFFAsyncOperations/JFFBlockOperation.h b/lib/JFFAsyncOperations/JFFBlockOperation.h index ed232ae..aae400f 100644 --- a/lib/JFFAsyncOperations/JFFBlockOperation.h +++ b/lib/JFFAsyncOperations/JFFBlockOperation.h @@ -4,16 +4,17 @@ @interface JFFBlockOperation : NSObject -+ (id)performOperationWithQueueName:(const char*)queueName - loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock - didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock - progressBlock:(JFFAsyncOperationProgressHandler)progressBlock - barrier:(BOOL)barrier - serialOrConcurrent:( dispatch_queue_attr_t )serialOrConcurrent_; ++ (instancetype)performOperationWithQueueName:(const char*)queueName + loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock + didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock + progressBlock:(JFFAsyncOperationProgressHandler)progressBlock + barrier:(BOOL)barrier + currentQueue:(dispatch_queue_t)currentQueue + serialOrConcurrent:(dispatch_queue_attr_t)serialOrConcurrent; -+ (id)performOperationWithQueueName:(const char*)queueName - loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock - didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock; ++ (instancetype)performOperationWithQueueName:(const char*)queueName + loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock + didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock; - (void)cancel; diff --git a/lib/JFFAsyncOperations/JFFBlockOperation.mm b/lib/JFFAsyncOperations/JFFBlockOperation.mm index 516f0ed..ac5c302 100644 --- a/lib/JFFAsyncOperations/JFFBlockOperation.mm +++ b/lib/JFFAsyncOperations/JFFBlockOperation.mm @@ -22,16 +22,14 @@ - (void)dealloc NSAssert(!_didLoadDataBlock, @"should be nil"); NSAssert(!_progressBlock , @"should be nil"); NSAssert(!_loadDataBlock , @"should be nil"); - - dispatch_release(_currentQueue); - _currentQueue = NULL; } -- (id)initWithLoadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock - didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock - progressBlock:(JFFAsyncOperationProgressHandler)progressBlock - currentQueue:(dispatch_queue_t)currentQueue - barrier:(BOOL)barrier +- (instancetype)initWithLoadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock + didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock + progressBlock:(JFFAsyncOperationProgressHandler)progressBlock + currentQueue:(dispatch_queue_t)currentQueue + barrier:(BOOL)barrier + serialOrConcurrent:(dispatch_queue_attr_t)serialOrConcurrent { self = [super init]; @@ -41,15 +39,13 @@ - (id)initWithLoadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock self.progressBlock = progressBlock; _currentQueue = currentQueue; - dispatch_retain(_currentQueue); - _barrier = barrier; } return self; } --(void)finalizeOperations +- (void)finalizeOperations { _finishedOrCanceled = YES; @@ -64,7 +60,7 @@ - (void)didFinishOperationWithResult:(id)result if (self.finishedOrCanceled) return; - self.didLoadDataBlock(result, error); + _didLoadDataBlock(result, error); [self finalizeOperations]; } @@ -80,9 +76,6 @@ - (void)cancel if (self.finishedOrCanceled) return; - dispatch_queue_t currentQueue = dispatch_get_current_queue(); - NSAssert(currentQueue == _currentQueue, @"Invalid current queue queue"); - [self finalizeOperations]; } @@ -93,8 +86,6 @@ - (void)performBackgroundOperationInQueue:(dispatch_queue_t)queue ?&dispatch_barrier_async :&dispatch_async; -// static int val; -// NSLog(@"dispatchAsyncMethod+: %d", ++val); dispatchAsyncMethod(queue, ^{ if (self.finishedOrCanceled) return; @@ -109,7 +100,9 @@ - (void)performBackgroundOperationInQueue:(dispatch_queue_t)queue }); }; @autoreleasepool { + opResult = loadDataBlock(&error, progressCallback); + NSAssert(((opResult != nil) ^ (error != nil)), @"result xor error should be loaded"); } } @catch (NSException *ex) { @@ -122,28 +115,26 @@ - (void)performBackgroundOperationInQueue:(dispatch_queue_t)queue } dispatch_async(_currentQueue, ^ { -// NSLog(@"dispatchAsyncMethod+: %d", --val); [self didFinishOperationWithResult:opResult error:error]; }); }); } -+ (id)performOperationWithQueueName:(const char*)queueName - loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock - didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock - progressBlock:(JFFAsyncOperationProgressHandler)progressBlock - barrier:(BOOL)barrier - serialOrConcurrent:( dispatch_queue_attr_t )serialOrConcurrent_; ++ (instancetype)performOperationWithQueueName:(const char*)queueName + loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock + didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock + progressBlock:(JFFAsyncOperationProgressHandler)progressBlock + barrier:(BOOL)barrier + currentQueue:(dispatch_queue_t)currentQueue + serialOrConcurrent:(dispatch_queue_attr_t)serialOrConcurrent { NSParameterAssert(loadDataBlock ); NSParameterAssert(didLoadDataBlock); - - dispatch_queue_t currentQueue = dispatch_get_current_queue(); + NSParameterAssert(currentQueue ); dispatch_queue_t queue = NULL; if (queueName != NULL && strlen(queueName) != 0) { - queue = dispatch_queue_get_or_create(queueName, - serialOrConcurrent_); + queue = dispatch_queue_get_or_create(queueName, serialOrConcurrent); } else { queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); } @@ -154,7 +145,8 @@ + (id)performOperationWithQueueName:(const char*)queueName didLoadDataBlock:didLoadDataBlock progressBlock:progressBlock currentQueue:currentQueue - barrier:barrier]; + barrier:barrier + serialOrConcurrent:serialOrConcurrent]; [result performBackgroundOperationInQueue:queue loadDataBlock:loadDataBlock]; @@ -162,16 +154,18 @@ + (id)performOperationWithQueueName:(const char*)queueName return result; } -+ (id)performOperationWithQueueName:(const char *)queueName - loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock - didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock ++ (instancetype)performOperationWithQueueName:(const char *)queueName + loadDataBlock:(JFFSyncOperationWithProgress)loadDataBlock + didLoadDataBlock:(JFFDidFinishAsyncOperationHandler)didLoadDataBlock { + NSParameterAssert([NSThread isMainThread]); return [self performOperationWithQueueName:queueName loadDataBlock:loadDataBlock didLoadDataBlock:didLoadDataBlock progressBlock:nil barrier:NO - serialOrConcurrent:DISPATCH_QUEUE_CONCURRENT ]; + currentQueue:dispatch_get_main_queue() + serialOrConcurrent:DISPATCH_QUEUE_CONCURRENT]; } @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.h b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.h index 3e5d733..d1e4a7e 100755 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.h +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.h @@ -4,7 +4,7 @@ @interface JFFActiveLoaderData : NSObject -@property ( nonatomic, copy ) JFFAsyncOperation nativeLoader; -@property ( nonatomic, copy ) JFFCancelAsyncOperation wrappedCancel; +@property (nonatomic, copy) JFFAsyncOperation nativeLoader; +@property (nonatomic, copy) JFFCancelAsyncOperation wrappedCancel; @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.m b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.m index 8970481..e965da1 100755 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.m +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFActiveLoaderData.m @@ -1,13 +1,4 @@ #import "JFFActiveLoaderData.h" @implementation JFFActiveLoaderData - --(void)dealloc -{ - [_nativeLoader release]; - [_wrappedCancel release]; - - [super dealloc]; -} - @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.h b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.h index d95b86a..fbb327d 100755 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.h +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.h @@ -6,11 +6,11 @@ @interface JFFAsyncOperationLoadBalancerContexts : NSObject -@property ( nonatomic, retain ) NSString* currentContextName; -@property ( nonatomic, retain ) NSString* activeContextName; -@property ( nonatomic, retain, readonly ) NSMutableDictionary* contextLoadersByName; +@property (nonatomic) NSString *currentContextName; +@property (nonatomic) NSString *activeContextName; +@property (nonatomic, readonly) NSMutableDictionary *contextLoadersByName; -+(id)sharedBalancer; ++ (instancetype)sharedBalancer; - (JFFContextLoaders *)activeContextLoaders; - (JFFContextLoaders *)currentContextLoaders; diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.m b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.m index 85fdea0..c52c3ce 100755 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.m +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFAsyncOperationLoadBalancerContexts.m @@ -4,21 +4,12 @@ @implementation JFFAsyncOperationLoadBalancerContexts { - NSMutableDictionary* _contextLoadersByName; + NSMutableDictionary *_contextLoadersByName; } --(void)dealloc ++ (instancetype)sharedBalancer { - [_currentContextName release]; - [_activeContextName release]; - [_contextLoadersByName release]; - - [super dealloc]; -} - -+ (id)sharedBalancer -{ - [NSThread assertMainThread]; + NSParameterAssert([NSThread isMainThread]); static JFFAsyncOperationLoadBalancerContexts *instance; if (!instance) { @@ -28,23 +19,23 @@ + (id)sharedBalancer return instance; } --(NSString*)currentContextName +- (NSString *)currentContextName { if (!_currentContextName) { - _currentContextName = [self.activeContextName retain]; + _currentContextName = self.activeContextName; } return _currentContextName; } --(NSString*)activeContextName +- (NSString *)activeContextName { if (!_activeContextName ) { - _activeContextName = [@"default" retain]; + _activeContextName = @"default"; } return _activeContextName; } --(NSMutableDictionary*)contextLoadersByName +- (NSMutableDictionary *)contextLoadersByName { if (!_contextLoadersByName) { _contextLoadersByName = [NSMutableDictionary new]; @@ -54,14 +45,12 @@ -(NSMutableDictionary*)contextLoadersByName - (JFFContextLoaders *)contextLoadersForName:(NSString *)name { - JFFContextLoaders* contextLoaders = self.contextLoadersByName[name]; + JFFContextLoaders *contextLoaders = _contextLoadersByName[name]; if (!contextLoaders) { contextLoaders = [JFFContextLoaders new]; contextLoaders.name = name; self.contextLoadersByName[name] = contextLoaders; - - [contextLoaders release]; } return contextLoaders; } diff --git a/lib/JFFAsyncOperations/LoadBalancer/Details2/JFFBaseLoaderOwner.h b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFBaseLoaderOwner.h similarity index 82% rename from lib/JFFAsyncOperations/LoadBalancer/Details2/JFFBaseLoaderOwner.h rename to lib/JFFAsyncOperations/LoadBalancer/Detail/JFFBaseLoaderOwner.h index f7a8353..1067bdc 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/Details2/JFFBaseLoaderOwner.h +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFBaseLoaderOwner.h @@ -16,8 +16,8 @@ @property (nonatomic, copy) JFFCancelAsyncOperationHandler cancelCallback; @property (nonatomic, copy) JFFDidFinishAsyncOperationHandler doneCallback; -+ (id)newLoaderOwnerWithLoader:(JFFAsyncOperation)loader - queue:(JFFLimitedLoadersQueue *)queue; ++ (instancetype)newLoaderOwnerWithLoader:(JFFAsyncOperation)loader + queue:(JFFLimitedLoadersQueue *)queue; - (void)performLoader; diff --git a/lib/JFFAsyncOperations/LoadBalancer/Details2/JFFBaseLoaderOwner.m b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFBaseLoaderOwner.m similarity index 71% rename from lib/JFFAsyncOperations/LoadBalancer/Details2/JFFBaseLoaderOwner.m rename to lib/JFFAsyncOperations/LoadBalancer/Detail/JFFBaseLoaderOwner.m index c33c555..df8be16 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/Details2/JFFBaseLoaderOwner.m +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFBaseLoaderOwner.m @@ -5,20 +5,20 @@ @interface JFFLimitedLoadersQueue (JFFBaseLoaderOwner) - (void)performPendingLoaders; -- (void)didFinishedActiveLoader:(JFFBaseLoaderOwner *)activeLoader; +- (void)didFinishActiveLoader:(JFFBaseLoaderOwner *)activeLoader; @end @implementation JFFBaseLoaderOwner -+ (id)newLoaderOwnerWithLoader:(JFFAsyncOperation)loader - queue:(JFFLimitedLoadersQueue *)queue ++ (instancetype)newLoaderOwnerWithLoader:(JFFAsyncOperation)loader + queue:(JFFLimitedLoadersQueue *)queue { JFFBaseLoaderOwner *result = [self new]; if (result) { - result.loader = loader; - result.queue = queue; + result->_loader = [loader copy]; + result->_queue = queue; } return result; @@ -47,17 +47,13 @@ - (void)performLoader JFFCancelAsyncOperationHandler cancelCallback = ^(BOOL canceled) { if (canceled) { - [_queue didFinishedActiveLoader:self]; + [_queue didFinishActiveLoader:self]; } if (_cancelCallback) { - JFFCancelAsyncOperationHandler cancelCallback = _cancelLoader; - _cancelLoader = nil; - - if ( cancelCallback ) - { - cancelCallback(canceled); - } + JFFCancelAsyncOperationHandler cancelCallback = _cancelCallback; + _cancelCallback = nil; + cancelCallback(canceled); } [self clear]; @@ -65,7 +61,7 @@ - (void)performLoader JFFDidFinishAsyncOperationHandler doneCallback = ^(id result, NSError *error) { - [_queue didFinishedActiveLoader:self]; + [_queue didFinishActiveLoader:self]; if (_doneCallback) _doneCallback(result, error); diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.h b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.h index 4a9af3c..b085540 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.h +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.h @@ -4,20 +4,20 @@ @interface JFFContextLoaders : NSObject -@property ( nonatomic, retain ) NSString* name; +@property (nonatomic) NSString *name; @end @interface JFFContextLoaders ( ActiveLoaders ) -@property ( nonatomic, readonly ) NSUInteger activeLoadersNumber; +@property (nonatomic, readonly) NSUInteger activeLoadersNumber; - (void)addActiveNativeLoader:(JFFAsyncOperation)nativeLoader - wrappedCancel:( JFFCancelAsyncOperation )cancel_; + wrappedCancel:(JFFCancelAsyncOperation)cancel; -- (BOOL)removeActiveNativeLoader:( JFFAsyncOperation )nativeLoader; +- (BOOL)removeActiveNativeLoader:(JFFAsyncOperation)nativeLoader; -- (void)cancelActiveNativeLoader:( JFFAsyncOperation )nativeLoader cancel:( BOOL )canceled; +- (void)cancelActiveNativeLoader:(JFFAsyncOperation)nativeLoader cancel:(BOOL)canceled; @end @@ -25,9 +25,9 @@ @interface JFFContextLoaders ( PendingLoaders ) -@property ( nonatomic, readonly ) NSUInteger pendingLoadersNumber; +@property (nonatomic, readonly) NSUInteger pendingLoadersNumber; --(JFFPedingLoaderData*)popPendingLoaderData; +- (JFFPedingLoaderData *)popPendingLoaderData; - (void)addPendingNativeLoader:(JFFAsyncOperation)nativeLoader progressCallback:(JFFAsyncOperationProgressHandler)progressCallback diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.m b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.m index 807320e..f3aba91 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.m +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFContextLoaders.m @@ -3,26 +3,13 @@ #import "JFFActiveLoaderData.h" #import "JFFPedingLoaderData.h" -@interface JFFContextLoaders () - -//JTODO move to ARC and remove inner properties -@property ( nonatomic, retain ) NSMutableArray* activeLoadersData; -@property ( nonatomic, retain ) NSMutableArray* pendingLoadersData; - -@end - @implementation JFFContextLoaders - --(void)dealloc { - [_activeLoadersData release]; - [_pendingLoadersData release]; - [_name release]; - - [super dealloc]; + NSMutableArray *_activeLoadersData; + NSMutableArray *_pendingLoadersData; } --(NSMutableArray*)activeLoadersData +- (NSMutableArray *)activeLoadersData { if (!_activeLoadersData) { _activeLoadersData = [NSMutableArray new]; @@ -30,7 +17,7 @@ -(NSMutableArray*)activeLoadersData return _activeLoadersData; } --(NSMutableArray*)pendingLoadersData +- (NSMutableArray *)pendingLoadersData { if (!_pendingLoadersData) { _pendingLoadersData = [NSMutableArray new]; @@ -40,22 +27,21 @@ -(NSMutableArray*)pendingLoadersData @end -@implementation JFFContextLoaders ( ActiveLoaders ) +@implementation JFFContextLoaders (ActiveLoaders) -- (NSUInteger)activeLoadersNumber { +- (NSUInteger)activeLoadersNumber +{ return [_activeLoadersData count]; } - (void)addActiveNativeLoader:(JFFAsyncOperation)nativeLoader - wrappedCancel:(JFFCancelAsyncOperation)cancel_ + wrappedCancel:(JFFCancelAsyncOperation)cancel { JFFActiveLoaderData *data = [JFFActiveLoaderData new]; data.nativeLoader = nativeLoader; - data.wrappedCancel = cancel_; + data.wrappedCancel = cancel; [self.activeLoadersData addObject:data]; - - [data release]; } - (JFFActiveLoaderData*)activeLoaderDataForNativeLoader:(JFFAsyncOperation)nativeLoader @@ -66,20 +52,20 @@ - (JFFActiveLoaderData*)activeLoaderDataForNativeLoader:(JFFAsyncOperation)nativ }]; } -- (void)cancelActiveNativeLoader:(JFFAsyncOperation)nativeLoader cancel:( BOOL )canceled_ +- (void)cancelActiveNativeLoader:(JFFAsyncOperation)nativeLoader cancel:(BOOL)canceled { - JFFActiveLoaderData* data_ = [self activeLoaderDataForNativeLoader:nativeLoader]; + JFFActiveLoaderData *data = [self activeLoaderDataForNativeLoader:nativeLoader]; - if ( data_ ) - data_.wrappedCancel( canceled_ ); + if (data) + data.wrappedCancel(canceled); } - (BOOL)removeActiveNativeLoader:(JFFAsyncOperation)nativeLoader { JFFActiveLoaderData *data = [self activeLoaderDataForNativeLoader:nativeLoader]; - if ( data ) { - [ self.activeLoadersData removeObject: data ]; + if (data) { + [self.activeLoadersData removeObject:data]; return YES; } @@ -92,64 +78,63 @@ @implementation JFFContextLoaders ( PendingLoaders ) - (NSUInteger)pendingLoadersNumber { - return [ self.pendingLoadersData count ]; + return [_pendingLoadersData count]; } -- (JFFPedingLoaderData*)popPendingLoaderData +- (JFFPedingLoaderData *)popPendingLoaderData { - JFFPedingLoaderData* data_ = [ self.pendingLoadersData[ 0 ] retain ]; - [ self.pendingLoadersData removeObjectAtIndex: 0 ]; - if ( [ self.pendingLoadersData count ] == 0 ) - { - self.pendingLoadersData = nil; + JFFPedingLoaderData *data = _pendingLoadersData[0]; + [_pendingLoadersData removeObjectAtIndex:0]; + if ([_pendingLoadersData count] == 0) { + + _pendingLoadersData = nil; } - return [ data_ autorelease ]; + return data; } -- (void)addPendingNativeLoader:( JFFAsyncOperation )native_loader_ - progressCallback:( JFFAsyncOperationProgressHandler )progress_callback_ - cancelCallback:( JFFCancelAsyncOperationHandler )cancel_callback_ - doneCallback:( JFFDidFinishAsyncOperationHandler )done_callback_ +- (void)addPendingNativeLoader:(JFFAsyncOperation)nativeLoader + progressCallback:(JFFAsyncOperationProgressHandler)progressCallback + cancelCallback:(JFFCancelAsyncOperationHandler)cancelCallback + doneCallback:(JFFDidFinishAsyncOperationHandler)doneCallback { - JFFPedingLoaderData* data_ = [ JFFPedingLoaderData new ]; - data_.nativeLoader = native_loader_; - data_.progressCallback = progress_callback_; - data_.cancelCallback = cancel_callback_; - data_.doneCallback = done_callback_; - - [ self.pendingLoadersData addObject: data_ ]; - - [ data_ release ]; + JFFPedingLoaderData *data = [JFFPedingLoaderData new]; + data.nativeLoader = nativeLoader; + data.progressCallback = progressCallback; + data.cancelCallback = cancelCallback; + data.doneCallback = doneCallback; + + [self.pendingLoadersData addObject:data]; } -- (JFFPedingLoaderData*)pendingLoaderDataForNativeLoader:( JFFAsyncOperation )native_loader_ +- (JFFPedingLoaderData*)pendingLoaderDataForNativeLoader:(JFFAsyncOperation)nativeLoader { - return [ self.pendingLoadersData firstMatch: ^BOOL( id object_ ) { - JFFPedingLoaderData* loaderData_ = object_; - return loaderData_.nativeLoader == native_loader_; - } ]; + return [self.pendingLoadersData firstMatch:^BOOL(id object) { + + JFFPedingLoaderData *loaderData = object; + return loaderData.nativeLoader == nativeLoader; + }]; } -- (BOOL)containsPendingNativeLoader:( JFFAsyncOperation )native_loader_ +- (BOOL)containsPendingNativeLoader:(JFFAsyncOperation)nativeLoader { - return [ self pendingLoaderDataForNativeLoader: native_loader_ ] != nil; + return [self pendingLoaderDataForNativeLoader:nativeLoader] != nil; } -- (void)removePendingNativeLoader:( JFFAsyncOperation )native_loader_ +- (void)removePendingNativeLoader:(JFFAsyncOperation)nativeLoader { - JFFPedingLoaderData* data_ = [ self pendingLoaderDataForNativeLoader: native_loader_ ]; - - [ self.pendingLoadersData removeObject: data_ ]; + JFFPedingLoaderData *data = [self pendingLoaderDataForNativeLoader:nativeLoader]; + + [_pendingLoadersData removeObject:data]; } - (void)unsubscribePendingNativeLoader:(JFFAsyncOperation)nativeLoader { - JFFPedingLoaderData* data_ = [self pendingLoaderDataForNativeLoader:nativeLoader]; - NSAssert( data_, @"pending loader data should exist" ); + JFFPedingLoaderData *data = [self pendingLoaderDataForNativeLoader:nativeLoader]; + NSAssert(data, @"pending loader data should exist" ); - data_.progressCallback = nil; - data_.cancelCallback = nil; - data_.doneCallback = nil; + data.progressCallback = nil; + data.cancelCallback = nil; + data.doneCallback = nil; } @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.h b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.h index b2449e4..4c5f1df 100755 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.h +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.h @@ -4,9 +4,9 @@ @interface JFFPedingLoaderData : NSObject -@property ( nonatomic, copy ) JFFAsyncOperation nativeLoader; -@property ( nonatomic, copy ) JFFAsyncOperationProgressHandler progressCallback; -@property ( nonatomic, copy ) JFFCancelAsyncOperationHandler cancelCallback; -@property ( nonatomic, copy ) JFFDidFinishAsyncOperationHandler doneCallback; +@property (nonatomic, copy) JFFAsyncOperation nativeLoader; +@property (nonatomic, copy) JFFAsyncOperationProgressHandler progressCallback; +@property (nonatomic, copy) JFFCancelAsyncOperationHandler cancelCallback; +@property (nonatomic, copy) JFFDidFinishAsyncOperationHandler doneCallback; @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.m b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.m index 6ad37a6..fa8460f 100755 --- a/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.m +++ b/lib/JFFAsyncOperations/LoadBalancer/Detail/JFFPedingLoaderData.m @@ -1,15 +1,4 @@ #import "JFFPedingLoaderData.h" @implementation JFFPedingLoaderData - --(void)dealloc -{ - [_nativeLoader release]; - [_progressCallback release]; - [_cancelCallback release]; - [_doneCallback release]; - - [super dealloc]; -} - @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.h b/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.h index 2ee1aef..ac8c10e 100755 --- a/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.h +++ b/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.h @@ -3,10 +3,8 @@ #import void setBalancerActiveContextName(NSString *contextName); -NSString * balancerActiveContextName (void); -NSString * balancerCurrentContextName(void); - -//TODO20 immediately cancel callback +NSString *balancerActiveContextName (void); +NSString *balancerCurrentContextName(void); //dont balance the same loader twice JFFAsyncOperation balancedAsyncOperation(JFFAsyncOperation loader); diff --git a/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.m b/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.m index 0bc1ddb..b8d7cab 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.m +++ b/lib/JFFAsyncOperations/LoadBalancer/JFFAsyncOperationLoadBalancer.m @@ -13,8 +13,6 @@ static NSUInteger totalActiveNumber = 0; -//JTODO test this - static JFFAsyncOperationLoadBalancerContexts *sharedBalancer() { return [JFFAsyncOperationLoadBalancerContexts sharedBalancer]; @@ -115,8 +113,8 @@ static void logBalancerState(JFFContextLoaders* originContextLoaders) JFFAsyncOperationLoadBalancerContexts *balancer = sharedBalancer(); JFFContextLoaders* activeLoaders = [balancer activeContextLoaders]; NSLog(@"Active context name: %@", activeLoaders.name); - NSLog(@"pending count: %d", activeLoaders.pendingLoadersNumber); - NSLog(@"active count: %d", activeLoaders.activeLoadersNumber); + NSLog(@"pending count: %lu", (unsigned long)activeLoaders.pendingLoadersNumber); + NSLog(@"active count: %lu", (unsigned long)activeLoaders.activeLoadersNumber); [balancer.contextLoadersByName enumerateKeysAndObjectsUsingBlock:^(id name, JFFContextLoaders *contextLoaders, @@ -124,8 +122,8 @@ static void logBalancerState(JFFContextLoaders* originContextLoaders) if (activeLoaders != contextLoaders) { NSLog(@"context name: %@", contextLoaders.name ); - NSLog(@"pending count: %d", contextLoaders.pendingLoadersNumber ); - NSLog(@"active count: %d", contextLoaders.activeLoadersNumber ); + NSLog(@"pending count: %lu", (unsigned long)contextLoaders.pendingLoadersNumber ); + NSLog(@"active count: %lu", (unsigned long)contextLoaders.activeLoadersNumber ); } }]; NSLog(@"|||||END LOG|||||"); @@ -141,20 +139,18 @@ static void finishExecuteOfNativeLoader( JFFAsyncOperation nativeLoader } static JFFCancelAsyncOperationHandler cancelCallbackWrapper(JFFCancelAsyncOperationHandler nativeCancelCallback, - JFFAsyncOperation native_loader_, + JFFAsyncOperation nativeLoader, JFFContextLoaders *contextLoaders) { - nativeCancelCallback = [[nativeCancelCallback copy] autorelease]; - return [[^void(BOOL canceled) { + nativeCancelCallback = [nativeCancelCallback copy]; + return ^void(BOOL canceled) { if (!canceled) { - assert(NO);// @"balanced loaders should not be unsubscribed from native loader not supported yet" + NSCAssert(NO, @"balanced loaders should not be unsubscribed from native loader not supported yet"); return; } - [[nativeCancelCallback copy] autorelease]; - - finishExecuteOfNativeLoader(native_loader_, contextLoaders); + finishExecuteOfNativeLoader(nativeLoader, contextLoaders); if (nativeCancelCallback) { peformBlockWithinContext(^{ @@ -163,40 +159,43 @@ static JFFCancelAsyncOperationHandler cancelCallbackWrapper(JFFCancelAsyncOperat } findAndTryToPerformNextNativeLoader(); - } copy] autorelease]; + }; } -static JFFDidFinishAsyncOperationHandler doneCallbackWrapper( JFFDidFinishAsyncOperationHandler native_done_callback_ - , JFFAsyncOperation native_loader_ - , JFFContextLoaders* context_loaders_ ) +static JFFDidFinishAsyncOperationHandler doneCallbackWrapper(JFFDidFinishAsyncOperationHandler nativeDoneCallback, + JFFAsyncOperation nativeLoader, + JFFContextLoaders* contextLoaders) { - native_done_callback_ = [ [ native_done_callback_ copy ] autorelease ]; - return [ [ ^void(id result, NSError *error) { - [ [ native_done_callback_ copy ] autorelease ]; + nativeDoneCallback = [nativeDoneCallback copy]; + + return ^void(id result, NSError *error) { - finishExecuteOfNativeLoader( native_loader_, context_loaders_ ); + finishExecuteOfNativeLoader(nativeLoader, contextLoaders); - if ( native_done_callback_ ) - { - peformBlockWithinContext( ^ { - native_done_callback_(result, error); - }, context_loaders_ ); + if (nativeDoneCallback) { + + peformBlockWithinContext(^{ + + nativeDoneCallback(result, error); + }, contextLoaders); } - + findAndTryToPerformNextNativeLoader(); - } copy ] autorelease ]; + }; } -static JFFAsyncOperation wrappedAsyncOperationWithContext( JFFAsyncOperation nativeLoader - , JFFContextLoaders* contextLoaders ) +static JFFAsyncOperation wrappedAsyncOperationWithContext(JFFAsyncOperation nativeLoader, + JFFContextLoaders *contextLoaders) { - nativeLoader = [[nativeLoader copy] autorelease]; - return [[^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler nativeProgressCallback, - JFFCancelAsyncOperationHandler nativeCancelCallback, - JFFDidFinishAsyncOperationHandler nativeDoneCallback) { + NSCParameterAssert(nativeLoader); + nativeLoader = [nativeLoader copy]; + + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler nativeProgressCallback, + JFFCancelAsyncOperationHandler nativeCancelCallback, + JFFDidFinishAsyncOperationHandler nativeDoneCallback) { //progress holder for unsubscribe - JFFAsyncOperationProgressBlockHolder *progressBlockHolder = [[JFFAsyncOperationProgressBlockHolder new] autorelease]; + JFFAsyncOperationProgressBlockHolder *progressBlockHolder = [JFFAsyncOperationProgressBlockHolder new]; progressBlockHolder.progressBlock = nativeProgressCallback; JFFAsyncOperationProgressHandler wrappedProgressCallback = ^void(id progressInfo) { peformBlockWithinContext( ^ { @@ -207,7 +206,7 @@ static JFFAsyncOperation wrappedAsyncOperationWithContext( JFFAsyncOperation nat __block BOOL done = NO; //cancel holder for unsubscribe - JFFCancelAsyncOperationBlockHolder *cancelCallbackBlockHolder = [[JFFCancelAsyncOperationBlockHolder new] autorelease]; + JFFCancelAsyncOperationBlockHolder *cancelCallbackBlockHolder = [JFFCancelAsyncOperationBlockHolder new]; cancelCallbackBlockHolder.cancelBlock = nativeCancelCallback; JFFCancelAsyncOperation wrappedCancelCallback = ^void(BOOL canceled) { done = YES; @@ -215,7 +214,7 @@ static JFFAsyncOperation wrappedAsyncOperationWithContext( JFFAsyncOperation nat }; //finish holder for unsubscribe - JFFDidFinishAsyncOperationBlockHolder *finishBlockHolder = [[JFFDidFinishAsyncOperationBlockHolder new] autorelease]; + JFFDidFinishAsyncOperationBlockHolder *finishBlockHolder = [JFFDidFinishAsyncOperationBlockHolder new]; finishBlockHolder.didFinishBlock = nativeDoneCallback; JFFDidFinishAsyncOperationHandler wrappedDoneCallback = ^void(id result, NSError *error) { done = YES; @@ -232,8 +231,8 @@ static JFFAsyncOperation wrappedAsyncOperationWithContext( JFFAsyncOperation nat // JTODO check native loader no within balancer !!! JFFCancelAsyncOperation cancelBlock = nativeLoader(wrappedProgressCallback, - wrappedCancelCallback, - wrappedDoneCallback); + wrappedCancelCallback, + wrappedDoneCallback); if (done) { return JFFStubCancelAsyncOperationBlock; @@ -241,23 +240,23 @@ static JFFAsyncOperation wrappedAsyncOperationWithContext( JFFAsyncOperation nat ++totalActiveNumber; - JFFCancelAsyncOperation wrappedCancelBlock = [[^void(BOOL canceled) { + JFFCancelAsyncOperation wrappedCancelBlock = [^void(BOOL canceled) { if (canceled) { - cancelBlock( YES ); + cancelBlock(YES); } else { cancelCallbackBlockHolder.onceCancelBlock(NO); progressBlockHolder.progressBlock = nil; finishBlockHolder.didFinishBlock = nil; } - } copy] autorelease]; + } copy]; [contextLoaders addActiveNativeLoader:nativeLoader wrappedCancel:wrappedCancelBlock]; logBalancerState(contextLoaders); return wrappedCancelBlock; - } copy] autorelease]; + }; } static BOOL canPeformAsyncOperationForContext(JFFContextLoaders *contextLoaders) @@ -284,10 +283,12 @@ JFFAsyncOperation balancedAsyncOperation(JFFAsyncOperation nativeLoader) JFFAsyncOperation balancedAsyncOperationInContext(JFFAsyncOperation nativeLoader, NSString *contextName) { - nativeLoader = [[nativeLoader copy] autorelease]; - return [[^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, - JFFCancelAsyncOperationHandler cancelCallback, - JFFDidFinishAsyncOperationHandler doneCallback) { + NSCParameterAssert(nativeLoader); + nativeLoader = [nativeLoader copy]; + + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { JFFContextLoaders *contextLoaders = [sharedBalancer() contextLoadersForName:contextName]; @@ -298,7 +299,7 @@ JFFAsyncOperation balancedAsyncOperationInContext(JFFAsyncOperation nativeLoader return contextLoader(progressCallback, cancelCallback, doneCallback); } - cancelCallback = [[cancelCallback copy] autorelease]; + cancelCallback = [cancelCallback copy]; [contextLoaders addPendingNativeLoader:nativeLoader progressCallback:progressCallback cancelCallback:cancelCallback @@ -306,7 +307,8 @@ JFFAsyncOperation balancedAsyncOperationInContext(JFFAsyncOperation nativeLoader logBalancerState(contextLoaders); - JFFCancelAsyncOperation cancel = [[^void(BOOL canceled) { + JFFCancelAsyncOperation cancel = ^void(BOOL canceled) { + if (![contextLoaders containsPendingNativeLoader:nativeLoader]) { //cancel only wrapped cancel block [contextLoaders cancelActiveNativeLoader:nativeLoader cancel:canceled]; @@ -321,8 +323,8 @@ JFFAsyncOperation balancedAsyncOperationInContext(JFFAsyncOperation nativeLoader [contextLoaders unsubscribePendingNativeLoader:nativeLoader]; } - }copy]autorelease]; + }; return cancel; - }copy]autorelease]; + }; } diff --git a/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.h b/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.h index 0e60951..2e78884 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.h +++ b/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.h @@ -5,7 +5,7 @@ @interface JFFLimitedLoadersQueue : NSObject --(id)initWithExecutionOrder:( JFFQueueExecutionOrder )orderStrategyId; +- (instancetype)initWithExecutionOrder:(JFFQueueExecutionOrder)orderStrategyId; //default value is 10 @property (nonatomic) NSUInteger limitCount; diff --git a/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.m b/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.m index cc281d7..aa58dc8 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.m +++ b/lib/JFFAsyncOperations/LoadBalancer/JFFLimitedLoadersQueue.m @@ -5,7 +5,6 @@ #import "JFFQueueStrategyFactory.h" #import "JFFQueueState.h" - @implementation JFFLimitedLoadersQueue { NSMutableArray *_activeLoaders; @@ -14,40 +13,37 @@ @implementation JFFLimitedLoadersQueue id _orderStrategy; } --(id)initWithExecutionOrder:( JFFQueueExecutionOrder )orderStrategyId +- (instancetype)initWithExecutionOrder:(JFFQueueExecutionOrder)orderStrategyId { self = [super init]; if (self) { - self->_limitCount = 10; - self->_activeLoaders = [NSMutableArray new]; - self->_pendingLoaders = [NSMutableArray new]; - JFFQueueState* state = [ JFFQueueState new ]; - state.activeLoaders = self->_activeLoaders; - state.pendingLoaders = self->_pendingLoaders; + _limitCount = 10; + _activeLoaders = [NSMutableArray new]; + _pendingLoaders = [NSMutableArray new]; + + JFFQueueState *state = [JFFQueueState new]; + state->_activeLoaders = _activeLoaders ; + state->_pendingLoaders = _pendingLoaders; - self->_orderStrategy = [ JFFQueueStrategyFactory queueStrategyWithId: orderStrategyId - queueState: state ]; + _orderStrategy = [JFFQueueStrategyFactory queueStrategyWithId:orderStrategyId + queueState:state]; } - + return self; } --(id)init +- (instancetype)init { - return [ self initWithExecutionOrder: JQOrderFifo ]; + return [self initWithExecutionOrder:JQOrderFifo]; } -- (BOOL)hasLoadersReadyToStart +- (BOOL)hasLoadersReadyToStartForPendingLoader:(JFFBaseLoaderOwner *)pendingLoader { - if ([_pendingLoaders count] > 0) { + if (pendingLoader.barrier) { - JFFBaseLoaderOwner *pendingLoader = _pendingLoaders[0]; - if (pendingLoader.barrier) { - - return [_activeLoaders count] == 0; - } + return [_activeLoaders count] == 0; } BOOL result = _limitCount > [_activeLoaders count] && [_pendingLoaders count] > 0; @@ -62,10 +58,23 @@ - (BOOL)hasLoadersReadyToStart return result; } +- (JFFBaseLoaderOwner *)nextPendingLoader +{ + JFFBaseLoaderOwner *result = ([_pendingLoaders count] > 0) + ?[_orderStrategy firstPendingLoader] + :nil; + + return result; +} + - (void)performPendingLoaders { - while ([self hasLoadersReadyToStart]) { - [self->_orderStrategy executePendingLoader]; + JFFBaseLoaderOwner *pendingLoader = [self nextPendingLoader]; + + while (pendingLoader && [self hasLoadersReadyToStartForPendingLoader:pendingLoader]) { + + [_orderStrategy executePendingLoader:pendingLoader]; + pendingLoader = [self nextPendingLoader]; } } @@ -100,24 +109,28 @@ - (JFFAsyncOperation)balancedLoaderWithLoader:(JFFAsyncOperation)loader __weak JFFBaseLoaderOwner *weakLoaderHolder = loaderHolder; return ^(BOOL canceled) { - if (weakLoaderHolder) { - - JFFCancelAsyncOperationHandler cancelCallback = weakLoaderHolder.cancelCallback; - - if (canceled) { - if (!weakLoaderHolder.cancelLoader) - [_pendingLoaders removeObject:weakLoaderHolder]; - } else { - weakLoaderHolder.progressCallback = nil; - weakLoaderHolder.cancelCallback = nil; - weakLoaderHolder.doneCallback = nil; - } - - if (weakLoaderHolder.cancelLoader) { - weakLoaderHolder.cancelLoader(YES); - } else if (cancelCallback) { - cancelCallback(canceled); + + JFFBaseLoaderOwner *loaderHolder = weakLoaderHolder; + if (!loaderHolder) + return; + + JFFCancelAsyncOperationHandler cancelCallback = loaderHolder.cancelCallback; + + if (canceled) { + if (!loaderHolder.cancelLoader) { + //TODO self owning here fix? + [_pendingLoaders removeObject:loaderHolder]; } + } else { + loaderHolder.progressCallback = nil; + loaderHolder.cancelCallback = nil; + loaderHolder.doneCallback = nil; + } + + if (loaderHolder.cancelLoader) { + loaderHolder.cancelLoader(YES); + } else if (cancelCallback) { + cancelCallback(canceled); } }; }; @@ -133,7 +146,7 @@ - (JFFAsyncOperation)barrierBalancedLoaderWithLoader:(JFFAsyncOperation)loader return [self balancedLoaderWithLoader:loader barrier:YES]; } -- (void)didFinishedActiveLoader:(JFFBaseLoaderOwner *)activeLoader +- (void)didFinishActiveLoader:(JFFBaseLoaderOwner *)activeLoader { [_activeLoaders removeObject:activeLoader]; [self performPendingLoaders]; diff --git a/lib/JFFAsyncOperations/LoadBalancer/JFFQueueExecutionOrder.h b/lib/JFFAsyncOperations/LoadBalancer/JFFQueueExecutionOrder.h index 137a68b..f80dbcc 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/JFFQueueExecutionOrder.h +++ b/lib/JFFAsyncOperations/LoadBalancer/JFFQueueExecutionOrder.h @@ -3,7 +3,7 @@ #import -typedef NS_ENUM( NSInteger, JFFQueueExecutionOrder ) +typedef NS_ENUM(NSInteger, JFFQueueExecutionOrder) { JQOrderFifo = 0, JQOrderStack = 1, diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFBaseStrategy.h b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFBaseStrategy.h new file mode 100644 index 0000000..c062143 --- /dev/null +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFBaseStrategy.h @@ -0,0 +1,17 @@ +#import + +@class +JFFQueueState, +JFFBaseLoaderOwner; + +@interface JFFBaseStrategy : NSObject +{ +@protected + JFFQueueState *_queueState; +} + +- (void)executePendingLoader:(JFFBaseLoaderOwner *)pendingLoader; + +- (instancetype)initWithQueueState:(JFFQueueState *)queueState; + +@end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFBaseStrategy.m b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFBaseStrategy.m new file mode 100644 index 0000000..fae7b99 --- /dev/null +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFBaseStrategy.m @@ -0,0 +1,43 @@ +#import "JFFBaseStrategy.h" + +#import "JFFQueueState.h" +#import "JFFBaseLoaderOwner.h" + +@implementation JFFBaseStrategy + +- (instancetype)init +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (instancetype)initWithQueueState:(JFFQueueState *)queueState +{ + self = [super init]; + + if (self) { + _queueState = queueState; + } + + return self; +} + +- (void)executePendingLoader:(JFFBaseLoaderOwner *)pendingLoader +{ + [_queueState->_pendingLoaders removeObject:pendingLoader]; + [_queueState->_activeLoaders addObject:pendingLoader]; + +#ifdef DEBUG + NSUInteger pendingLoadersCount = [_queueState->_pendingLoaders count]; + NSUInteger activeLoadersCount = [_queueState->_activeLoaders count]; +#endif //DEBUG + + [pendingLoader performLoader]; + +#ifdef DEBUG + NSParameterAssert(pendingLoadersCount >= [_queueState->_pendingLoaders count]); + NSParameterAssert(activeLoadersCount >= [_queueState->_activeLoaders count]); +#endif //DEBUG +} + +@end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.h b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.h index f5baadc..83f3942 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.h +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.h @@ -1,8 +1,10 @@ #import @interface JFFQueueState : NSObject - -@property ( nonatomic ) NSMutableArray* activeLoaders; -@property ( nonatomic ) NSMutableArray* pendingLoaders; +{ +@public + NSMutableArray *_activeLoaders; + NSMutableArray *_pendingLoaders; +} @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.m b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.m index bc01354..363ee12 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.m +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueState.m @@ -1,5 +1,4 @@ #import "JFFQueueState.h" @implementation JFFQueueState - @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategy.h b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategy.h index fa1c718..9ca1ec0 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategy.h +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategy.h @@ -1,13 +1,10 @@ #import @class JFFBaseLoaderOwner; -@class JFFQueueState; @protocol JFFQueueStrategy --(void)executePendingLoader; - --(id)initWithQueueState:( JFFQueueState* )queueState_; --(JFFQueueState*)queueState; +- (JFFBaseLoaderOwner *)firstPendingLoader; +- (void)executePendingLoader:(JFFBaseLoaderOwner *)pendingLoader; @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.h b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.h index 9c4b4fe..2f20992 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.h +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.h @@ -6,7 +6,7 @@ @interface JFFQueueStrategyFactory : NSObject -+(id)queueStrategyWithId:( JFFQueueExecutionOrder )strategyId - queueState:( JFFQueueState* )state; ++ (id)queueStrategyWithId:(JFFQueueExecutionOrder)strategyId + queueState:(JFFQueueState *)state; @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.m b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.m index e78bdf6..3f213cf 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.m +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFQueueStrategyFactory.m @@ -9,22 +9,22 @@ @implementation JFFQueueStrategyFactory -+(id)queueStrategyWithId:( JFFQueueExecutionOrder )strategyId - queueState:( JFFQueueState* )state ++ (id)queueStrategyWithId:(JFFQueueExecutionOrder)strategyId + queueState:(JFFQueueState *)state { - NSParameterAssert( strategyId >= 0 ); - NSParameterAssert( strategyId <= 2 ); - + NSParameterAssert(strategyId >= 0); + NSParameterAssert(strategyId <= 2); + static Class strategies[3] = {0}; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - strategies[0] = [ JFFStrategyFifo class ]; - strategies[1] = [ JFFStrategyStack class ]; - strategies[2] = [ JFFStrategyRandom class ]; + strategies[0] = [JFFStrategyFifo class]; + strategies[1] = [JFFStrategyStack class]; + strategies[2] = [JFFStrategyRandom class]; }); - + Class StrategyClass = strategies[ strategyId ]; - return [ [ StrategyClass alloc ] initWithQueueState: state ]; + return [[StrategyClass alloc] initWithQueueState:state]; } @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.h b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.h index 72eedfa..248e930 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.h +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.h @@ -1,5 +1,7 @@ +#import "JFFBaseStrategy.h" #import "JFFQueueStrategy.h" + #import -@interface JFFStrategyFifo : NSObject< JFFQueueStrategy > +@interface JFFStrategyFifo : JFFBaseStrategy @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.m b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.m index d082a2d..44836a2 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.m +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyFifo.m @@ -3,38 +3,12 @@ #import "JFFQueueState.h" #import "JFFBaseLoaderOwner.h" -@interface JFFStrategyFifo() -@property ( nonatomic ) JFFQueueState* queueState; -@end - @implementation JFFStrategyFifo --(id)init -{ - [ self doesNotRecognizeSelector: _cmd ]; - return nil; -} - --(void)executePendingLoader -{ - JFFBaseLoaderOwner *pendingLoader = self->_queueState.pendingLoaders[0]; - [self->_queueState.pendingLoaders removeObjectAtIndex:0]; - [self->_queueState.activeLoaders addObject:pendingLoader]; - - [pendingLoader performLoader]; -} - --(id)initWithQueueState:( JFFQueueState* )queueState_ +- (JFFBaseLoaderOwner *)firstPendingLoader { - self = [ super init ]; - if ( nil == self ) - { - return nil; - } - - self->_queueState = queueState_; - - return self; + JFFBaseLoaderOwner *result = _queueState->_pendingLoaders[0]; + return result; } @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.h b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.h index dd3f392..e413bbc 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.h +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.h @@ -1,5 +1,7 @@ +#import "JFFBaseStrategy.h" #import "JFFQueueStrategy.h" + #import -@interface JFFStrategyRandom : NSObject< JFFQueueStrategy > +@interface JFFStrategyRandom : JFFBaseStrategy @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.mm b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.mm index a5ed6ef..98b7a38 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.mm +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyRandom.mm @@ -3,43 +3,15 @@ #import "JFFQueueState.h" #import "JFFBaseLoaderOwner.h" -@interface JFFStrategyRandom() -@property ( nonatomic ) JFFQueueState* queueState; -@end - - - @implementation JFFStrategyRandom --(id)init -{ - [ self doesNotRecognizeSelector: _cmd ]; - return nil; -} - --(void)executePendingLoader +- (JFFBaseLoaderOwner *)firstPendingLoader { - int index = rand() % [ self->_queueState.pendingLoaders count ]; + int index = rand() % [_queueState->_pendingLoaders count]; NSUInteger castedIndex = static_cast(index); - JFFBaseLoaderOwner *pendingLoader = self->_queueState.pendingLoaders[castedIndex]; - [self->_queueState.pendingLoaders removeObjectAtIndex:castedIndex]; - [self->_queueState.activeLoaders addObject:pendingLoader]; - - [pendingLoader performLoader]; -} - --(id)initWithQueueState:( JFFQueueState* )queueState_ -{ - self = [ super init ]; - if ( nil == self ) - { - return nil; - } - - self->_queueState = queueState_; - - return self; + JFFBaseLoaderOwner *result = _queueState->_pendingLoaders[castedIndex]; + return result; } @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.h b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.h index e262fe3..85a1a96 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.h +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.h @@ -1,5 +1,7 @@ +#import "JFFBaseStrategy.h" #import "JFFQueueStrategy.h" + #import -@interface JFFStrategyStack : NSObject< JFFQueueStrategy > +@interface JFFStrategyStack : JFFBaseStrategy< JFFQueueStrategy > @end diff --git a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.m b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.m index e31243c..e41469f 100644 --- a/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.m +++ b/lib/JFFAsyncOperations/LoadBalancer/QueueStrategies/JFFStrategyStack.m @@ -3,39 +3,12 @@ #import "JFFQueueState.h" #import "JFFBaseLoaderOwner.h" -@interface JFFStrategyStack() -@property ( nonatomic ) JFFQueueState* queueState; -@end - - @implementation JFFStrategyStack --(id)init -{ - [ self doesNotRecognizeSelector: _cmd ]; - return nil; -} - --(void)executePendingLoader -{ - JFFBaseLoaderOwner *pendingLoader = [ self->_queueState.pendingLoaders lastObject ]; - [self->_queueState.pendingLoaders removeLastObject]; - [self->_queueState.activeLoaders addObject:pendingLoader]; - - [pendingLoader performLoader]; -} - --(id)initWithQueueState:( JFFQueueState* )queueState_ +- (JFFBaseLoaderOwner *)firstPendingLoader { - self = [ super init ]; - if ( nil == self ) - { - return nil; - } - - self->_queueState = queueState_; - - return self; + JFFBaseLoaderOwner *result = [_queueState->_pendingLoaders lastObject]; + return result; } @end diff --git a/lib/JFFAsyncOperations/NSObject+AutoCancelAsyncOperation.m b/lib/JFFAsyncOperations/NSObject+AutoCancelAsyncOperation.m index 01e21c2..0f157b3 100755 --- a/lib/JFFAsyncOperations/NSObject+AutoCancelAsyncOperation.m +++ b/lib/JFFAsyncOperations/NSObject+AutoCancelAsyncOperation.m @@ -18,7 +18,9 @@ - (JFFAsyncOperation)autoUnsibscribeOrCancelAsyncOperation:(JFFAsyncOperation)na JFFCancelAsyncOperationHandler cancelCallback, JFFDidFinishAsyncOperationHandler doneCallback) { - if (weakSelf == nil) { + id self_ = weakSelf; + + if (self_ == nil) { if (cancelCallback) { cancelCallback(cancelNativeAsyncOp); @@ -72,7 +74,7 @@ - (JFFAsyncOperation)autoUnsibscribeOrCancelAsyncOperation:(JFFAsyncOperation)na }; //try assert retain count - [weakSelf addOnDeallocBlock:ondeallocBlockHolder.onceSimpleBlock]; + [self_ addOnDeallocBlock:ondeallocBlockHolder.onceSimpleBlock]; __block JFFCancelAsyncOperation cancelBlockHolder = [^void(BOOL canceled) { cancel(canceled); diff --git a/lib/JFFCache/JFFCache.xcodeproj/project.pbxproj b/lib/JFFCache/JFFCache.xcodeproj/project.pbxproj index f5fe13e..c785d6f 100644 --- a/lib/JFFCache/JFFCache.xcodeproj/project.pbxproj +++ b/lib/JFFCache/JFFCache.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 4C0D56E617E70F4A001F0944 /* JFFCacheLoadImageError.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C0D56E417E70F4A001F0944 /* JFFCacheLoadImageError.h */; }; + 4C0D56E717E70F4A001F0944 /* JFFCacheLoadImageError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0D56E517E70F4A001F0944 /* JFFCacheLoadImageError.m */; }; 4CA0CAA816CE864C0007A85D /* JFFCacheError.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA0CAA616CE864C0007A85D /* JFFCacheError.h */; }; 4CA0CAA916CE864C0007A85D /* JFFCacheError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA0CAA716CE864C0007A85D /* JFFCacheError.m */; }; 4CA0CAC116CE86B90007A85D /* NSDictionary+DBInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA0CAAB16CE86B80007A85D /* NSDictionary+DBInfo.h */; }; @@ -33,10 +35,14 @@ 4CA0CAD616CE86B90007A85D /* JFFThumbnailStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA0CAC016CE86B90007A85D /* JFFThumbnailStorage.m */; }; 4CA0CAD916CE86F70007A85D /* JFFCacheNoURLError.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA0CAD716CE86F70007A85D /* JFFCacheNoURLError.h */; }; 4CA0CADA16CE86F70007A85D /* JFFCacheNoURLError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA0CAD816CE86F70007A85D /* JFFCacheNoURLError.m */; }; + 4CB92AE516FA02E600471165 /* UIImageView+CachedAsyncImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB92AE316FA02E600471165 /* UIImageView+CachedAsyncImageLoader.h */; }; + 4CB92AE616FA02E600471165 /* UIImageView+CachedAsyncImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB92AE416FA02E600471165 /* UIImageView+CachedAsyncImageLoader.m */; }; 6516847B144F4ECD0014670E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6516847A144F4ECD0014670E /* Foundation.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4C0D56E417E70F4A001F0944 /* JFFCacheLoadImageError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCacheLoadImageError.h; sourceTree = ""; }; + 4C0D56E517E70F4A001F0944 /* JFFCacheLoadImageError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCacheLoadImageError.m; sourceTree = ""; }; 4CA0CAA616CE864C0007A85D /* JFFCacheError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCacheError.h; sourceTree = ""; }; 4CA0CAA716CE864C0007A85D /* JFFCacheError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCacheError.m; sourceTree = ""; }; 4CA0CAAB16CE86B80007A85D /* NSDictionary+DBInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+DBInfo.h"; sourceTree = ""; }; @@ -63,6 +69,8 @@ 4CA0CAC016CE86B90007A85D /* JFFThumbnailStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFThumbnailStorage.m; sourceTree = ""; }; 4CA0CAD716CE86F70007A85D /* JFFCacheNoURLError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCacheNoURLError.h; sourceTree = ""; }; 4CA0CAD816CE86F70007A85D /* JFFCacheNoURLError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCacheNoURLError.m; sourceTree = ""; }; + 4CB92AE316FA02E600471165 /* UIImageView+CachedAsyncImageLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+CachedAsyncImageLoader.h"; sourceTree = ""; }; + 4CB92AE416FA02E600471165 /* UIImageView+CachedAsyncImageLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+CachedAsyncImageLoader.m"; sourceTree = ""; }; 65168477144F4ECD0014670E /* libJFFCache.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFCache.a; sourceTree = BUILT_PRODUCTS_DIR; }; 6516847A144F4ECD0014670E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 6516847E144F4ECD0014670E /* JFFCache-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JFFCache-Prefix.pch"; sourceTree = ""; }; @@ -88,6 +96,8 @@ 4CA0CAA716CE864C0007A85D /* JFFCacheError.m */, 4CA0CAD716CE86F70007A85D /* JFFCacheNoURLError.h */, 4CA0CAD816CE86F70007A85D /* JFFCacheNoURLError.m */, + 4C0D56E417E70F4A001F0944 /* JFFCacheLoadImageError.h */, + 4C0D56E517E70F4A001F0944 /* JFFCacheLoadImageError.m */, ); path = Errors; sourceTree = ""; @@ -107,6 +117,15 @@ path = Details; sourceTree = ""; }; + 4CB92AE216FA02E600471165 /* Categories */ = { + isa = PBXGroup; + children = ( + 4CB92AE316FA02E600471165 /* UIImageView+CachedAsyncImageLoader.h */, + 4CB92AE416FA02E600471165 /* UIImageView+CachedAsyncImageLoader.m */, + ); + path = Categories; + sourceTree = ""; + }; 6516846C144F4ECD0014670E = { isa = PBXGroup; children = ( @@ -135,6 +154,7 @@ 6516847C144F4ECD0014670E /* JFFCache */ = { isa = PBXGroup; children = ( + 4CB92AE216FA02E600471165 /* Categories */, 4CA0CAA516CE86320007A85D /* Errors */, 4CA0CAAA16CE86B80007A85D /* Details */, 4CA0CAB316CE86B80007A85D /* JFFBaseDB.h */, @@ -194,6 +214,8 @@ 4CA0CAD316CE86B90007A85D /* JFFDBManager.h in Headers */, 4CA0CAD516CE86B90007A85D /* JFFThumbnailStorage.h in Headers */, 4CA0CAD916CE86F70007A85D /* JFFCacheNoURLError.h in Headers */, + 4C0D56E617E70F4A001F0944 /* JFFCacheLoadImageError.h in Headers */, + 4CB92AE516FA02E600471165 /* UIImageView+CachedAsyncImageLoader.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -223,7 +245,7 @@ 6516846E144F4ECD0014670E /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0500; }; buildConfigurationList = 65168471144F4ECD0014670E /* Build configuration list for PBXProject "JFFCache" */; compatibilityVersion = "Xcode 3.2"; @@ -252,6 +274,7 @@ 4CA0CAC416CE86B90007A85D /* NSObject+CompositeKey.m in Sources */, 4CA0CAC616CE86B90007A85D /* NSString+CacheFSManager.m in Sources */, 4CA0CAC816CE86B90007A85D /* NSString+CompositeKey.m in Sources */, + 4C0D56E717E70F4A001F0944 /* JFFCacheLoadImageError.m in Sources */, 4CA0CACA16CE86B90007A85D /* JFFBaseDB.m in Sources */, 4CA0CACE16CE86B90007A85D /* JFFCaches.m in Sources */, 4CA0CAD016CE86B90007A85D /* JFFDBCompositeKey.m in Sources */, @@ -259,6 +282,7 @@ 4CA0CAD416CE86B90007A85D /* JFFDBManager.m in Sources */, 4CA0CAD616CE86B90007A85D /* JFFThumbnailStorage.m in Sources */, 4CA0CADA16CE86F70007A85D /* JFFCacheNoURLError.m in Sources */, + 4CB92AE616FA02E600471165 /* UIImageView+CachedAsyncImageLoader.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -269,9 +293,9 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -281,13 +305,15 @@ GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ../JFFRestKit, ., ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; }; name = Debug; @@ -296,18 +322,20 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ../JFFRestKit, ., ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -320,6 +348,7 @@ DSTROOT = /tmp/JFFCache.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFCache/JFFCache-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -333,6 +362,7 @@ DSTROOT = /tmp/JFFCache.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFCache/JFFCache-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/lib/JFFUI/Extensions/UIImageView+CachedAsyncImageLoader.h b/lib/JFFCache/JFFCache/Categories/UIImageView+CachedAsyncImageLoader.h similarity index 85% rename from lib/JFFUI/Extensions/UIImageView+CachedAsyncImageLoader.h rename to lib/JFFCache/JFFCache/Categories/UIImageView+CachedAsyncImageLoader.h index 8f67f32..32bf85b 100644 --- a/lib/JFFUI/Extensions/UIImageView+CachedAsyncImageLoader.h +++ b/lib/JFFCache/JFFCache/Categories/UIImageView+CachedAsyncImageLoader.h @@ -1,7 +1,5 @@ #import -#include - @interface UIImageView (CachedAsyncImageLoader) - (void)setImageWithURL:(NSURL *)url andPlaceholder:(UIImage *)placeholder; diff --git a/lib/JFFUI/Extensions/UIImageView+CachedAsyncImageLoader.m b/lib/JFFCache/JFFCache/Categories/UIImageView+CachedAsyncImageLoader.m similarity index 56% rename from lib/JFFUI/Extensions/UIImageView+CachedAsyncImageLoader.m rename to lib/JFFCache/JFFCache/Categories/UIImageView+CachedAsyncImageLoader.m index 1b8ae85..858e68e 100644 --- a/lib/JFFUI/Extensions/UIImageView+CachedAsyncImageLoader.m +++ b/lib/JFFCache/JFFCache/Categories/UIImageView+CachedAsyncImageLoader.m @@ -1,36 +1,44 @@ #import "UIImageView+CachedAsyncImageLoader.h" -#import +#import "JFFThumbnailStorage.h" -#include +@interface UIImageView (CachedAsyncImageLoaderInternal) -static char imageURLKey; +@property (nonatomic) NSURL *jffAsycImageURL; +@property (nonatomic) NSURL *jffAsycLoadedImageURL; -@implementation UIImageView (CachedAsyncImageLoader) +@end -- (NSURL *)jffAsycImageURL -{ - return objc_getAssociatedObject(self, &imageURLKey); -} +@implementation UIImageView (CachedAsyncImageLoaderInternal) + +@dynamic +jffAsycImageURL, +jffAsycLoadedImageURL; -- (void)setJffAsycImageURL:(NSURL *)url ++ (void)load { - objc_setAssociatedObject(self, - &imageURLKey, - url, - OBJC_ASSOCIATION_RETAIN_NONATOMIC); + jClass_implementProperty(self, NSStringFromSelector(@selector(jffAsycImageURL ))); + jClass_implementProperty(self, NSStringFromSelector(@selector(jffAsycLoadedImageURL))); } +@end + +@implementation UIImageView (CachedAsyncImageLoader) + - (void)jffSetImage:(UIImage *)image URL:(NSURL *)url { if (!image || self.jffAsycImageURL != url) return; + self.jffAsycLoadedImageURL = url; self.image = image; } - (void)setImageWithURL:(NSURL *)url andPlaceholder:(UIImage *)placeholder { + if ([self.jffAsycLoadedImageURL isEqual:url]) + return; + self.image = placeholder; self.jffAsycImageURL = url; diff --git a/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.h b/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.h index 3ccf78a..4fb6fcb 100644 --- a/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.h +++ b/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.h @@ -3,7 +3,7 @@ @interface NSDictionary (DBInfo) - (NSNumber *)timeToLiveInHoursForDBWithName:(NSString *)name; -- (NSDictionary *)autoRemoveProperiesForDBWithName:(NSString *)name; +- (instancetype)autoRemoveProperiesForDBWithName:(NSString *)name; - (NSString *)fileNameForDBWithName:(NSString *)name; - (NSUInteger)versionForDBWithName:(NSString *)name; diff --git a/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.m b/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.m index 82270ef..b9f5fcd 100644 --- a/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.m +++ b/lib/JFFCache/JFFCache/Details/NSDictionary+DBInfo.m @@ -13,7 +13,7 @@ - (NSNumber *)timeToLiveInHoursForDBWithName:(NSString *)name return result; } -- (NSDictionary *)autoRemoveProperiesForDBWithName:(NSString *)name +- (instancetype)autoRemoveProperiesForDBWithName:(NSString *)name { return self[name][@"autoRemove"]; } diff --git a/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.h b/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.h index 73901d6..db6d4fb 100644 --- a/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.h +++ b/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.h @@ -2,6 +2,6 @@ @interface NSObject (CompositeKey) --(NSString*)toCompositeKey; +- (NSString *)toCompositeKey; @end diff --git a/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.m b/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.m index 0795555..a492d6e 100644 --- a/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.m +++ b/lib/JFFCache/JFFCache/Details/NSObject+CompositeKey.m @@ -2,7 +2,7 @@ @implementation NSObject (CompositeKey) --(NSString*)toCompositeKey +- (NSString *)toCompositeKey { NSAssert(NO, @"Don't support this method.\n"); return nil; diff --git a/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.h b/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.h index f0e7a1c..b192659 100644 --- a/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.h +++ b/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.h @@ -2,7 +2,7 @@ @interface NSString (CacheFSManager) -- (NSString *)cacheDBFileLinkPathWithFolder:(NSString *)folder; +- (instancetype)cacheDBFileLinkPathWithFolder:(NSString *)folder; - (void)cacheDBFileLinkRemoveFileWithFolder:(NSString *)folder; diff --git a/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.m b/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.m index d69a383..fe42f31 100644 --- a/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.m +++ b/lib/JFFCache/JFFCache/Details/NSString+CacheFSManager.m @@ -2,7 +2,7 @@ @implementation NSString (CacheFSManager) -- (NSString *)cacheDBFileLinkPathWithFolder:(NSString *)folder +- (instancetype)cacheDBFileLinkPathWithFolder:(NSString *)folder { NSString *result = [folder stringByAppendingPathComponent:self]; return result; diff --git a/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.h b/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.h index 14f64e9..e71f3f7 100644 --- a/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.h +++ b/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.h @@ -2,6 +2,6 @@ @interface NSString (CompositeKey) -- (NSString *)toCompositeKey; +- (instancetype)toCompositeKey; @end diff --git a/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.m b/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.m index b34982f..1d0b5a6 100644 --- a/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.m +++ b/lib/JFFCache/JFFCache/Details/NSString+CompositeKey.m @@ -2,7 +2,7 @@ @implementation NSString (CompositeKey) -- (NSString *)toCompositeKey +- (instancetype)toCompositeKey { return self; } diff --git a/lib/JFFCache/JFFCache/Errors/JFFCacheError.h b/lib/JFFCache/JFFCache/Errors/JFFCacheError.h index 3cd58fd..fa288b5 100644 --- a/lib/JFFCache/JFFCache/Errors/JFFCacheError.h +++ b/lib/JFFCache/JFFCache/Errors/JFFCacheError.h @@ -1,4 +1,4 @@ -#import +#import @interface JFFCacheError : JFFError @end diff --git a/lib/JFFCache/JFFCache/Errors/JFFCacheLoadImageError.h b/lib/JFFCache/JFFCache/Errors/JFFCacheLoadImageError.h new file mode 100644 index 0000000..beca7a4 --- /dev/null +++ b/lib/JFFCache/JFFCache/Errors/JFFCacheLoadImageError.h @@ -0,0 +1,7 @@ +#import + +@interface JFFCacheLoadImageError : JFFCacheError + +@property (nonatomic) NSError *nativeError; + +@end diff --git a/lib/JFFCache/JFFCache/Errors/JFFCacheLoadImageError.m b/lib/JFFCache/JFFCache/Errors/JFFCacheLoadImageError.m new file mode 100644 index 0000000..265b1dd --- /dev/null +++ b/lib/JFFCache/JFFCache/Errors/JFFCacheLoadImageError.m @@ -0,0 +1,36 @@ +#import "JFFCacheLoadImageError.h" + +@implementation JFFCacheLoadImageError + +- (instancetype)init +{ + return [self initWithDescription:NSLocalizedString(@"JFF_CACHE_LOAD_IMAGE_ERROR", nil)]; +} + +- (instancetype)copyWithZone:(NSZone *)zone +{ + JFFCacheLoadImageError *copy = [super copyWithZone:zone]; + + if (copy) { + copy->_nativeError = [_nativeError copyWithZone:zone]; + } + + return copy; +} + +- (NSString *)errorLogDescription +{ + return [[NSString alloc] initWithFormat:@"%@ : %@, domain : %@ code : %ld nativeError: %@", + [self class], + [self localizedDescription], + [self domain], + (long)[self code], + [_nativeError errorLogDescription]]; +} + +- (void)writeErrorWithJFFLogger +{ + [JFFLogger logInfoWithFormat:@"%@", [self errorLogDescription]]; +} + +@end diff --git a/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.h b/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.h index dde4f6f..89b2eae 100644 --- a/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.h +++ b/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.h @@ -1,5 +1,4 @@ #import @interface JFFCacheNoURLError : JFFCacheError - @end diff --git a/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.m b/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.m index f7b9e30..92571b4 100644 --- a/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.m +++ b/lib/JFFCache/JFFCache/Errors/JFFCacheNoURLError.m @@ -2,7 +2,7 @@ @implementation JFFCacheNoURLError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"JFF_CACHE_NO_URL_ERROR", nil)]; } diff --git a/lib/JFFCache/JFFCache/JFFBaseDB.h b/lib/JFFCache/JFFCache/JFFBaseDB.h index 6f85b50..5275cae 100644 --- a/lib/JFFCache/JFFCache/JFFBaseDB.h +++ b/lib/JFFCache/JFFCache/JFFBaseDB.h @@ -4,11 +4,10 @@ @interface JFFBaseDB : NSObject -- (id)initWithCacheFileName:(NSString *)cacheName; +- (instancetype)initWithCacheFileName:(NSString *)cacheName; - (NSData *)dataForKey:(id)key; - (NSData *)dataForKey:(id)key lastUpdateTime:(NSDate **)date; -- (NSDate *)lastUpdateTimeForKey:(id)key; - (void)setData:(NSData *)data forKey:(id)key; diff --git a/lib/JFFCache/JFFCache/JFFBaseDB.m b/lib/JFFCache/JFFCache/JFFBaseDB.m index 236f812..73080d7 100644 --- a/lib/JFFCache/JFFCache/JFFBaseDB.m +++ b/lib/JFFCache/JFFCache/JFFBaseDB.m @@ -19,7 +19,7 @@ static dispatch_queue_t getOrCreateDispatchQueueForFile(NSString *file) NSString *queueName = [[NSString alloc] initWithFormat:@"com.jff.embedded_sources.dynamic.%@", file]; const char *queueNameCStr = [queueName cStringUsingEncoding:NSUTF8StringEncoding]; dispatch_queue_t result = dispatch_queue_get_or_create(queueNameCStr, - DISPATCH_QUEUE_SERIAL); + DISPATCH_QUEUE_CONCURRENT); return result; } @@ -33,7 +33,7 @@ @interface JFFSQLiteDB : NSObject @property (nonatomic, readonly) dispatch_queue_t queue; @property (nonatomic, readonly) NSString *folder; -- (id)initWithDBName:(NSString *)dbName; +- (instancetype)initWithDBName:(NSString *)dbName; - (BOOL)prepareQuery:(NSString *)sql statement:(sqlite3_stmt **)statement; @@ -49,17 +49,15 @@ @implementation JFFSQLiteDB - (void)dealloc { sqlite3_close(_db); - dispatch_release(_dispatchQueue); } -- (id)initWithDBName:(NSString *)dbName +- (instancetype)initWithDBName:(NSString *)dbName { self = [super init]; if (self) { _dispatchQueue = getOrCreateDispatchQueueForFile(dbName); - dispatch_retain(_dispatchQueue); NSString *const dbPath = [NSString documentsPathByAppendingPathComponent:dbName]; @@ -67,7 +65,7 @@ - (id)initWithDBName:(NSString *)dbName __block BOOL ok = NO; - safe_dispatch_barrier_sync(self.queue, ^{ + dispatch_barrier_sync(self.queue, ^{ BOOL created = [[NSFileManager defaultManager] createDirectoryAtPath:_folder withIntermediateDirectories:YES @@ -76,7 +74,7 @@ - (id)initWithDBName:(NSString *)dbName NSParameterAssert(created); - if (sqlite3_open([dbPath UTF8String], &self->_db) != SQLITE_OK) { + if (sqlite3_open([dbPath UTF8String], &_db) != SQLITE_OK) { NSLog(@"open - %@ path: %@", [self errorMessage], dbPath); return; }; @@ -85,10 +83,10 @@ - (id)initWithDBName:(NSString *)dbName const char *cacheSizePragma = "PRAGMA cache_size = 1000"; - if (sqlite3_exec(self->_db, cacheSizePragma, 0, 0, 0) != SQLITE_OK) { + if (sqlite3_exec(_db, cacheSizePragma, 0, 0, 0) != SQLITE_OK) { NSAssert1(0, @"Error: failed to execute pragma statement with message '%s'.", - sqlite3_errmsg(self->_db)); + sqlite3_errmsg(_db)); } ok = YES; }); @@ -108,7 +106,7 @@ - (dispatch_queue_t)queue - (BOOL)prepareQuery:(NSString *)sql statement:(sqlite3_stmt **)statement { - return sqlite3_prepare_v2(self->_db, + return sqlite3_prepare_v2(_db, [sql UTF8String], -1, statement, @@ -118,7 +116,8 @@ - (BOOL)prepareQuery:(NSString *)sql - (BOOL)execQuery:(NSString *)sql { char *errorMessage = 0; - if (sqlite3_exec(self->_db, [sql UTF8String], 0, 0, &errorMessage) != SQLITE_OK) { + if (sqlite3_exec(_db, [sql UTF8String], 0, 0, &errorMessage) != SQLITE_OK) { + NSLog(@"%@ error: %s", sql, errorMessage); sqlite3_free(errorMessage); @@ -130,7 +129,7 @@ - (BOOL)execQuery:(NSString *)sql - (NSString *)errorMessage { - return @(sqlite3_errmsg(self->_db)); + return @(sqlite3_errmsg(_db)); } @end @@ -148,7 +147,7 @@ @implementation JFFBaseDB JFFSQLiteDB *_db; } -- (id)initWithCacheFileName:(NSString *)cacheName +- (instancetype)initWithCacheFileName:(NSString *)cacheName { NSParameterAssert(cacheName); @@ -213,7 +212,7 @@ - (NSString *)fileLinkForRecordId:(NSString *)recordId __block NSString *result; - safe_dispatch_sync([self db].queue, ^{ + dispatch_sync([self db].queue, ^{ sqlite3_stmt *statement = 0; if ([[self db] prepareQuery:query statement:&statement]) { @@ -286,7 +285,7 @@ - (void)updateData:(NSData *)data - (void)addData:(NSData *)data forRecord:(NSString *)recordId { - NSString *fileLink = [NSString createUuid]; + NSString *fileLink = [[NSUUID new] UUIDString]; static NSString *const addQueryFormat = @"INSERT INTO records (record_id, file_link, update_time, access_time) VALUES ('%@', '%@', '%f', '%f');"; NSString *addQuery = [[NSString alloc] initWithFormat:addQueryFormat, @@ -473,7 +472,7 @@ - (NSData *)dataForKey:(id)key lastUpdateTime:(NSDate *__autoreleasing *)date __block NSData *recordData; - safe_dispatch_sync([self db].queue, ^ { + dispatch_sync([self db].queue, ^ { sqlite3_stmt *statement = 0; if ([self.db prepareQuery:query statement:&statement]) { @@ -498,32 +497,6 @@ - (NSData *)dataForKey:(id)key lastUpdateTime:(NSDate *__autoreleasing *)date return recordData; } -- (NSDate *)lastUpdateTimeForKey:(id)key -{ - NSString *recordId = [key toCompositeKey]; - - static const NSUInteger dateIndex = 0; - - static NSString *const queryFormat = @"SELECT update_time FROM records WHERE record_id='%@';"; - NSString *query = [[NSString alloc]initWithFormat:queryFormat, recordId]; - - __block NSDate *result; - - safe_dispatch_sync([self db].queue, ^ { - - sqlite3_stmt *statement = 0; - if ([self.db prepareQuery:query statement:&statement]) { - if (sqlite3_step(statement) == SQLITE_ROW) { - NSTimeInterval dateInetrval = sqlite3_column_double(statement, dateIndex); - result = [[NSDate alloc] initWithTimeIntervalSince1970:dateInetrval]; - } - sqlite3_finalize(statement); - } - }); - - return result; -} - - (void)removeAllRecordsWithCallback:(JFFSimpleBlock)callback { callback = [callback copy]; diff --git a/lib/JFFCache/JFFCache/JFFCache.h b/lib/JFFCache/JFFCache/JFFCache.h index 1760d72..9584cfb 100644 --- a/lib/JFFCache/JFFCache/JFFCache.h +++ b/lib/JFFCache/JFFCache/JFFCache.h @@ -3,9 +3,12 @@ #import #import +#import #import //Errors #import +#import + #endif //JFF_CACHE_HEADER_FILE_INCLUDED diff --git a/lib/JFFCache/JFFCache/JFFCacheDB.h b/lib/JFFCache/JFFCache/JFFCacheDB.h index df2fc35..c28342a 100644 --- a/lib/JFFCache/JFFCache/JFFCacheDB.h +++ b/lib/JFFCache/JFFCache/JFFCacheDB.h @@ -2,13 +2,12 @@ #import -@protocol JFFCacheDB < NSObject > +@protocol JFFCacheDB @required - (NSData *)dataForKey:(id)key; - (NSData *)dataForKey:(id)key lastUpdateTime:(NSDate **)date; -- (NSDate *)lastUpdateTimeForKey:(id)key; - (void)setData:(NSData *)data forKey:(id)key; @@ -17,6 +16,6 @@ - (void)migrateDB; -- (NSNumber*)timeToLiveInHours; +- (NSNumber *)timeToLiveInHours; @end diff --git a/lib/JFFCache/JFFCache/JFFCaches.h b/lib/JFFCache/JFFCache/JFFCaches.h index 6f20aae..7ba667d 100644 --- a/lib/JFFCache/JFFCache/JFFCaches.h +++ b/lib/JFFCache/JFFCache/JFFCaches.h @@ -9,7 +9,7 @@ + (JFFCaches *)sharedCaches; + (void)setSharedCaches:(JFFCaches *)caches; -- (id)initWithDBInfoDictionary:(NSDictionary *)cachesInfo; +- (instancetype)initWithDBInfoDictionary:(NSDictionary *)cachesInfo; + (id< JFFCacheDB >)createCacheForName:(NSString *)name; diff --git a/lib/JFFCache/JFFCache/JFFCaches.m b/lib/JFFCache/JFFCache/JFFCaches.m index a5a1c47..ac67c8b 100644 --- a/lib/JFFCache/JFFCache/JFFCaches.m +++ b/lib/JFFCache/JFFCache/JFFCaches.m @@ -86,7 +86,7 @@ + (void)runAutoremoveDataSchedulerWithName:(NSString *)dbPropertyName }; block(nil); - [scheduler addBlock:block duration:3600.]; + [scheduler addBlock:block duration:3600. leeway:1800.]; } } @@ -105,8 +105,8 @@ + (void)runAutoremoveDataSchedulerIfNeedsWithName:(NSString *)dbPropertyName } } -- (id)initWithCacheDBWithName:(NSString *)dbPropertyName - dbInfo:(JFFDBInfo *)dbInfo +- (instancetype)initWithCacheDBWithName:(NSString *)dbPropertyName + dbInfo:(JFFDBInfo *)dbInfo { NSString *filePath = [[dbInfo dbInfo] fileNameForDBWithName:dbPropertyName]; @@ -137,7 +137,7 @@ - (void)migrateDB } } -- (NSNumber*)timeToLiveInHours +- (NSNumber *)timeToLiveInHours { NSDictionary *dbInfo = [[JFFDBInfo sharedDBInfo] currentDbInfo]; NSNumber *result = [dbInfo timeToLiveInHoursForDBWithName:_configPropertyName]; @@ -179,13 +179,13 @@ - (void)setupCachesWithDBInfo:(JFFDBInfo *)dbInfo }]; } -- (id)initWithDBInfoDictionary:(NSDictionary *)cachesInfo +- (instancetype)initWithDBInfoDictionary:(NSDictionary *)cachesInfo { JFFDBInfo *dbInfo = [[JFFDBInfo alloc]initWithInfoDictionary:cachesInfo]; return [self initWithDBInfo:dbInfo]; } -- (id)initWithDBInfo:(JFFDBInfo *)dbInfo +- (instancetype)initWithDBInfo:(JFFDBInfo *)dbInfo { self = [super init]; diff --git a/lib/JFFCache/JFFCache/JFFDBCompositeKey.h b/lib/JFFCache/JFFCache/JFFDBCompositeKey.h index 8441661..c25dd38 100644 --- a/lib/JFFCache/JFFCache/JFFDBCompositeKey.h +++ b/lib/JFFCache/JFFCache/JFFDBCompositeKey.h @@ -1,9 +1,9 @@ #import -@interface JFFDBCompositeKey : NSObject +@interface JFFDBCompositeKey : NSObject -+ (id)compositeKeyWithKeys:(NSString *)key, ...; -+ (id)compositeKeyWithKey:(JFFDBCompositeKey *)compositeKey forIndexes:(NSIndexSet *)indexes; ++ (instancetype)compositeKeyWithKeys:(NSString *)key, ... NS_REQUIRES_NIL_TERMINATION; ++ (instancetype)compositeKeyWithKey:(JFFDBCompositeKey *)compositeKey forIndexes:(NSIndexSet *)indexes; - (NSString *)toCompositeKey; diff --git a/lib/JFFCache/JFFCache/JFFDBCompositeKey.m b/lib/JFFCache/JFFCache/JFFDBCompositeKey.m index d730908..13576f3 100644 --- a/lib/JFFCache/JFFCache/JFFDBCompositeKey.m +++ b/lib/JFFCache/JFFCache/JFFDBCompositeKey.m @@ -10,7 +10,7 @@ @interface JFFDBCompositeKey () @implementation JFFDBCompositeKey -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFDBCompositeKey *copy = [[[self class] allocWithZone:zone] init]; @@ -23,16 +23,16 @@ - (id)copyWithZone:(NSZone *)zone - (NSUInteger)hash { - return [self.keys hash]; + return [_keys hash]; } - (BOOL)isEqual:(id)object { JFFDBCompositeKey *otherObject = object; - return [otherObject.keys isEqual:self.keys]; + return [otherObject.keys isEqual:_keys]; } -- (id)initWithKeys:(NSArray *)keys +- (instancetype)initWithKeys:(NSArray *)keys { NSParameterAssert([keys isKindOfClass:[NSArray class]]); @@ -45,7 +45,7 @@ - (id)initWithKeys:(NSArray *)keys return self; } -+ (id)compositeKeyWithKeys:(NSString *)key, ... ++ (instancetype)compositeKeyWithKeys:(NSString *)key, ... { NSMutableArray *keys = [NSMutableArray new]; va_list args; @@ -58,7 +58,7 @@ + (id)compositeKeyWithKeys:(NSString *)key, ... return [[self alloc] initWithKeys:keys]; } -+ (id)compositeKeyWithKey:(JFFDBCompositeKey *)compositeKey forIndexes:(NSIndexSet *)indexes ++ (instancetype)compositeKeyWithKey:(JFFDBCompositeKey *)compositeKey forIndexes:(NSIndexSet *)indexes { NSUInteger size = [compositeKey.keys count]; NSArray *newKeys = [NSArray arrayWithSize:size producer:^id(NSUInteger index) { @@ -72,7 +72,7 @@ + (id)compositeKeyWithKey:(JFFDBCompositeKey *)compositeKey forIndexes:(NSIndexS - (NSString *)toCompositeKey { - return [self.keys componentsJoinedByString:@"_"]; + return [_keys componentsJoinedByString:@"_"]; } @end diff --git a/lib/JFFCache/JFFCache/JFFDBInfo.h b/lib/JFFCache/JFFCache/JFFDBInfo.h index 031ccc4..ba52a0f 100644 --- a/lib/JFFCache/JFFCache/JFFDBInfo.h +++ b/lib/JFFCache/JFFCache/JFFDBInfo.h @@ -5,10 +5,10 @@ @property (atomic, readonly) NSDictionary *dbInfo; @property (atomic) NSDictionary *currentDbInfo; -- (id)initWithInfoPath:(NSString *)infoPath; -- (id)initWithInfoDictionary:(NSDictionary *)infoDictionry; +- (instancetype)initWithInfoPath:(NSString *)infoPath; +- (instancetype)initWithInfoDictionary:(NSDictionary *)infoDictionry; + (void)setSharedDBInfo:(JFFDBInfo *)dbInfo; -+ (JFFDBInfo*)sharedDBInfo; ++ (JFFDBInfo *)sharedDBInfo; @end diff --git a/lib/JFFCache/JFFCache/JFFDBInfo.m b/lib/JFFCache/JFFCache/JFFDBInfo.m index 752a719..6264561 100644 --- a/lib/JFFCache/JFFCache/JFFDBInfo.m +++ b/lib/JFFCache/JFFCache/JFFDBInfo.m @@ -14,7 +14,7 @@ @implementation JFFDBInfo NSDictionary *_dbInfo; } -- (id)initWithInfoPath:(NSString *)infoPath +- (instancetype)initWithInfoPath:(NSString *)infoPath { self = [super init]; @@ -25,7 +25,7 @@ - (id)initWithInfoPath:(NSString *)infoPath return self; } -- (id)initWithInfoDictionary:(NSDictionary *)infoDictionry +- (instancetype)initWithInfoDictionary:(NSDictionary *)infoDictionry { self = [super init]; diff --git a/lib/JFFCache/JFFCache/JFFThumbnailStorage.h b/lib/JFFCache/JFFCache/JFFThumbnailStorage.h index 22428fb..820fd42 100644 --- a/lib/JFFCache/JFFCache/JFFThumbnailStorage.h +++ b/lib/JFFCache/JFFCache/JFFThumbnailStorage.h @@ -1,17 +1,17 @@ #import -#import +#import + +extern NSString *JFFNoImageDataURLString; @interface JFFThumbnailStorage : NSObject -+ (JFFThumbnailStorage *)sharedStorage; ++ (instancetype)sharedStorage; + (void)setSharedStorage:(JFFThumbnailStorage *)storage; - (JFFAsyncOperation)thumbnailLoaderForUrl:(NSURL *)url; -- (JFFAsyncOperation)thumbnailLoaderForUrl:(NSURL *)url - scaledToSize:(CGSize)scaleSize - contentMode:(UIViewContentMode)contentMode; +- (JFFAsyncOperation)tryThumbnailLoaderForUrls:(NSArray *)urls; - (void)resetCache; diff --git a/lib/JFFCache/JFFCache/JFFThumbnailStorage.m b/lib/JFFCache/JFFCache/JFFThumbnailStorage.m index 59f0ef4..f0b7a7b 100644 --- a/lib/JFFCache/JFFCache/JFFThumbnailStorage.m +++ b/lib/JFFCache/JFFCache/JFFThumbnailStorage.m @@ -4,21 +4,31 @@ #import "JFFCaches.h" #import "JFFCacheNoURLError.h" +#import "JFFCacheLoadImageError.h" #import #import -#import - static NSString *const cacheQueueName = @"com.embedded_sources.jffcache.thumbnail_storage.cache"; +NSString *JFFNoImageDataURLString = @"nodata://jff.cache.com"; + +@implementation NSURL (IsURLToIMageData) + +- (BOOL)isURLToImageData +{ + return ![[self description] isEqualToString:JFFNoImageDataURLString]; +} + +@end + @interface JFFCanNotCreateImageError : JFFError @end @implementation JFFCanNotCreateImageError -- (id)init +- (instancetype)init { return [self initWithDescription:@"can not create image with given data"]; } @@ -78,7 +88,7 @@ @interface JFFImageCacheAdapter : JFFCacheAdapter @implementation JFFImageCacheAdapter -+ (id)new ++ (instancetype)new { return [self newCacheAdapterWithCacheFactory:^id{return [JFFCaches createThumbnailDB];} cacheQueueName:cacheQueueName]; @@ -113,7 +123,7 @@ - (void)dealloc [[NSNotificationCenter defaultCenter] removeObserver:self]; } -- (id)init +- (instancetype)init { self = [super init]; @@ -136,7 +146,7 @@ - (NSCache *)imagesByUrl { return _imagesByUrl; } -+ (JFFThumbnailStorage *)sharedStorage ++ (instancetype)sharedStorage { if (!glStorageInstance) { glStorageInstance = [self new]; @@ -167,9 +177,9 @@ + (JFFAsyncOperation)onThreadLoadUrl:(NSURL *)url { return asyncOperationWithSyncOperation(^id(NSError *__autoreleasing *outError) { - NSData *imageData = [NSData dataWithContentsOfURL:url - options:NSDataReadingUncached - error:outError]; + NSData *imageData = [[NSData alloc] initWithContentsOfURL:url + options:NSDataReadingUncached + error:outError]; return imageData; }); } @@ -184,7 +194,11 @@ - (JFFAsyncOperation)cachedInDBImageDataLoaderForUrl:(NSURL *)url args.cache = [self imageCacheAdapter]; args.dataLoaderForIdentifier = ^JFFAsyncOperation(id identifier) { - assert([identifier isKindOfClass:[NSURL class]]); + + { + NSString *errorDescription = [[NSString alloc] initWithFormat:@"identifier:%@ is not a NSURL", identifier]; + NSCAssert([identifier isKindOfClass:[NSURL class]], errorDescription); + } JFFAsyncOperation dataLoader = //liveDataURLResponseLoader(identifier, nil, nil); dataURLResponseLoader(identifier, nil, nil); @@ -197,71 +211,13 @@ - (JFFAsyncOperation)cachedInDBImageDataLoaderForUrl:(NSURL *)url JFFAsyncOperation loader = jSmartDataLoaderWithCache(args); - return loader; -} - -static id cacheKeyForURLScaleSizeAndContentMode(NSURL *url, - CGSize scaleSize, - UIViewContentMode contentMode) -{ - return [[NSString alloc] initWithFormat:@"resized_image_key:%@<->%@<->%d", - url, - NSStringFromCGSize(scaleSize), - contentMode]; -} - -- (JFFAsyncOperation)cachedScaleImageForSize:(CGSize)scaleSize - contentMode:(UIViewContentMode)contentMode - url:(NSURL *)url - dataToResizeLoader:(JFFAsyncOperation)dataToResizeLoader -{ - dataToResizeLoader = [dataToResizeLoader copy]; - - JFFSmartUrlDataLoaderFields *args = [JFFSmartUrlDataLoaderFields new]; - args.loadDataIdentifier = ^id() { return url; }; - args.cacheDataLifeTimeInSeconds = [[self class] cacheDataLifeTimeInSeconds]; - args.cache = [self imageCacheAdapter]; - - args.dataLoaderForIdentifier = ^JFFAsyncOperation(NSURL *url) { - JFFAsyncOperationBinder scaledImageBinder = ^JFFAsyncOperation(UIImage *image) { - JFFSyncOperation loadDataBlock = ^(NSError *__autoreleasing *outError) { - //TODO check error if can not resize - //TODO try to reuse created here resized image for result - UIImage *scaledImage = [image imageScaledToSize:scaleSize - contentMode:contentMode]; - - NSData *result = UIImagePNGRepresentation(scaledImage); - return result; - }; - - return asyncOperationWithSyncOperationAndQueue(loadDataBlock, - "com.embedded_sources.jffcache.thumbnail_storage.cache.resize"); - }; + loader = bindTrySequenceOfAsyncOperations(loader, ^JFFAsyncOperation(NSError *error) { - return bindSequenceOfAsyncOperations(dataToResizeLoader, - scaledImageBinder, - nil); - }; - //Do not cache invalid data here (may be no needs) - args.analyzerForData = imageDataToUIImageBinder(); - - args.cacheKeyForIdentifier = ^id(NSURL *url) { - return cacheKeyForURLScaleSizeAndContentMode(url, scaleSize, contentMode); - }; - - args.lastUpdateDateForKey = ^JFFAsyncOperation(NSURL *url) { - JFFAsyncOperation loader = asyncOperationWithSyncOperationAndQueue(^id(NSError *__autoreleasing *outError) { - - id< JFFCacheDB > thumbnailDB = [JFFCaches createThumbnailDB]; - NSDate *result = [thumbnailDB lastUpdateTimeForKey:[url description]]; - //TODO wich date pass when no date, maybe 1907 year???? - return result; - }, [cacheQueueName cStringUsingEncoding:NSUTF8StringEncoding]); + JFFCacheLoadImageError *resultError = [JFFCacheLoadImageError new]; + resultError.nativeError = error; - return balanced(loader); - }; - - JFFAsyncOperation loader = jSmartDataLoaderWithCache(args); + return asyncOperationWithError(resultError); + }, nil); return loader; } @@ -269,9 +225,9 @@ - (JFFAsyncOperation)cachedScaleImageForSize:(CGSize)scaleSize //TODO add load balancer here - (JFFAsyncOperation)thumbnailLoaderForUrl:(NSURL *)url { - if (url) { - assert([url isKindOfClass:[NSURL class]]); - } else { + NSParameterAssert(!url || [url isKindOfClass:[NSURL class]]); + + if (![url isURLToImageData]) { return asyncOperationWithError([JFFCacheNoURLError new]); } @@ -283,7 +239,7 @@ - (JFFAsyncOperation)thumbnailLoaderForUrl:(NSURL *)url ignoreFreshDataLoadFail:YES]; //TODO: also check the last update date here - JFFPropertyPath* propertyPath = [[JFFPropertyPath alloc] initWithName:@"imagesByUrl" + JFFPropertyPath* propertyPath = [[JFFPropertyPath alloc] initWithName:NSStringFromSelector(@selector(imagesByUrl)) key:url]; loader = [self asyncOperationForPropertyWithPath:propertyPath @@ -295,42 +251,19 @@ - (JFFAsyncOperation)thumbnailLoaderForUrl:(NSURL *)url }; } -//It is slow, at least add 1 sec to wait -- (JFFAsyncOperation)thumbnailLoaderForUrl:(NSURL *)url - scaledToSize:(CGSize)scaleSize - contentMode:(UIViewContentMode)contentMode +- (JFFAsyncOperation)tryThumbnailLoaderForUrls:(NSArray *)urls { - if (url) { - assert([url isKindOfClass:[NSURL class]]); - } else { + urls = [urls toURLsSkippingNils]; + + if ([urls count] == 0) return asyncOperationWithError([JFFCacheNoURLError new]); - } - return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, - JFFCancelAsyncOperationHandler cancelCallback, - JFFDidFinishAsyncOperationHandler doneCallback) { + NSArray *loaders = [urls map:^id(NSURL *url) { - JFFAsyncOperation loader = [self cachedInDBImageDataLoaderForUrl:url - ignoreFreshDataLoadFail:NO]; - - loader = [self cachedScaleImageForSize:scaleSize - contentMode:contentMode - url:url - dataToResizeLoader:loader]; - - id key = cacheKeyForURLScaleSizeAndContentMode(url, scaleSize, contentMode); - - //TODO: also check the last update date here - JFFPropertyPath *propertyPath = [[JFFPropertyPath alloc] initWithName:@"imagesByUrl" - key:key]; - - loader = [self asyncOperationForPropertyWithPath:propertyPath - asyncOperation:loader]; - - return loader(progressCallback, - cancelCallback, - doneCallback); - }; + return [self thumbnailLoaderForUrl:url]; + }]; + + return trySequenceOfAsyncOperationsArray(loaders); } #pragma Memory warning diff --git a/lib/JFFCache/JFFCache/Resources/JFFCacheDBInfo.plist b/lib/JFFCache/JFFCache/Resources/JFFCacheDBInfo.plist index fbb1e99..4ac153a 100644 --- a/lib/JFFCache/JFFCache/Resources/JFFCacheDBInfo.plist +++ b/lib/JFFCache/JFFCache/Resources/JFFCacheDBInfo.plist @@ -2,18 +2,23 @@ - ES_THUMBNAIL_DB + JFF_THUMBNAIL_DB fileName - WDThumbnails.sqlite + images/JFFThumbnails.sqlite maxItems 0 version - 1 + 2 timeToLiveInHours - 24 - autoRemoveByLastAccessDateInHours - 72 + 168 + autoRemove + + lastAccessDateInHours + 320 + maxSizeInMB + 100 + diff --git a/lib/JFFContacts/JFFContacts.xcodeproj/project.pbxproj b/lib/JFFContacts/JFFContacts.xcodeproj/project.pbxproj index ad295df..a380a70 100644 --- a/lib/JFFContacts/JFFContacts.xcodeproj/project.pbxproj +++ b/lib/JFFContacts/JFFContacts.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ CE29B80C15F60083000A05B8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE29B80B15F60083000A05B8 /* Foundation.framework */; }; CE29B81115F60083000A05B8 /* JFFContacts.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = CE29B81015F60083000A05B8 /* JFFContacts.h */; }; CE29B81B15F60084000A05B8 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE29B81A15F60084000A05B8 /* SenTestingKit.framework */; }; - CE29B81D15F60084000A05B8 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE29B81C15F60084000A05B8 /* UIKit.framework */; }; CE29B81E15F60084000A05B8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE29B80B15F60083000A05B8 /* Foundation.framework */; }; CE29B82115F60084000A05B8 /* libJFFContacts.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE29B80815F60083000A05B8 /* libJFFContacts.a */; }; CE29B82715F60084000A05B8 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CE29B82515F60084000A05B8 /* InfoPlist.strings */; }; @@ -103,7 +102,6 @@ CE29B81015F60083000A05B8 /* JFFContacts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFContacts.h; sourceTree = ""; }; CE29B81915F60084000A05B8 /* JFFContactsTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JFFContactsTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; CE29B81A15F60084000A05B8 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; - CE29B81C15F60084000A05B8 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; CE29B82415F60084000A05B8 /* JFFContactsTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JFFContactsTests-Info.plist"; sourceTree = ""; }; CE29B82615F60084000A05B8 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; CE29B82815F60084000A05B8 /* JFFContactsTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFContactsTests.h; sourceTree = ""; }; @@ -155,7 +153,6 @@ buildActionMask = 2147483647; files = ( CE29B81B15F60084000A05B8 /* SenTestingKit.framework in Frameworks */, - CE29B81D15F60084000A05B8 /* UIKit.framework in Frameworks */, CE29B81E15F60084000A05B8 /* Foundation.framework in Frameworks */, CE29B82115F60084000A05B8 /* libJFFContacts.a in Frameworks */, ); @@ -189,7 +186,6 @@ CE29B85815F60330000A05B8 /* JFFUtils.xcodeproj */, CE29B80B15F60083000A05B8 /* Foundation.framework */, CE29B81A15F60084000A05B8 /* SenTestingKit.framework */, - CE29B81C15F60084000A05B8 /* UIKit.framework */, ); name = Frameworks; sourceTree = ""; @@ -345,7 +341,7 @@ CE29B7FF15F60083000A05B8 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = EmbeddedSources; }; buildConfigurationList = CE29B80215F60083000A05B8 /* Build configuration list for PBXProject "JFFContacts" */; @@ -496,15 +492,16 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -512,15 +509,18 @@ "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; }; name = Debug; @@ -529,24 +529,28 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -558,6 +562,7 @@ DSTROOT = /tmp/JFFContacts.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFContacts/JFFContacts-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -570,6 +575,7 @@ DSTROOT = /tmp/JFFContacts.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFContacts/JFFContacts-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/lib/JFFContacts/JFFContacts/Async/JFFAsyncContacts.m b/lib/JFFContacts/JFFContacts/Async/JFFAsyncContacts.m index fe49741..7db19d3 100644 --- a/lib/JFFContacts/JFFContacts/Async/JFFAsyncContacts.m +++ b/lib/JFFContacts/JFFContacts/Async/JFFAsyncContacts.m @@ -5,41 +5,52 @@ #import -@interface JFFAsyncRequestAccessToContactsLoader : NSObject < JFFAsyncOperationInterface > +@interface JFFAsyncRequestAccessToContactsLoader : NSObject @end @implementation JFFAsyncRequestAccessToContactsLoader +{ + JFFAsyncOperationInterfaceResultHandler _handler; +} + +- (void)notifyHandlerWithResult:(id)result error:(NSError *)error +{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + _handler(result, error); + }); +} - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { NSParameterAssert(handler); - handler = [handler copy]; + _handler = handler; + + __weak JFFAsyncRequestAccessToContactsLoader *weakSelf = self; JFFAddressBookSuccessCallback onSuccess = ^(JFFAddressBook *book) { - handler(book, nil); + [weakSelf notifyHandlerWithResult:book error:nil]; }; JFFAddressBookErrorCallback onFailure = ^(ABAuthorizationStatus status, NSError *error) { - if (handler) { - - handler(nil, error); - } + + [weakSelf notifyHandlerWithResult:nil error:error]; }; [JFFAddressBookFactory asyncAddressBookWithSuccessBlock:onSuccess errorCallback:onFailure]; } -- (void)cancel:(BOOL)canceled +- (BOOL)isForeignThreadResultCallback { + return YES; } @end -JFFAsyncOperation asyncAllContactsLoader( void ) +JFFAsyncOperation asyncAllContactsLoader() { JFFAsyncOperationBinder contacts = ^JFFAsyncOperation(JFFAddressBook *book) { @@ -53,7 +64,7 @@ JFFAsyncOperation asyncAllContactsLoader( void ) JFFAsyncOperation requestAccessToContactsLoader() { - JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + JFFAsyncOperationInstanceBuilder factory = ^id() { return [JFFAsyncRequestAccessToContactsLoader new]; }; return buildAsyncOperationWithAdapterFactory(factory); diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactDateField.m b/lib/JFFContacts/JFFContacts/Details/JFFContactDateField.m index 14ede61..3025f6b 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactDateField.m +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactDateField.m @@ -2,25 +2,25 @@ @implementation JFFContactDateField --(void)readPropertyFromRecord:( ABRecordRef )record_ +- (id)readProperty { - CFStringRef value_ = ABRecordCopyValue( record_, self.propertyID ); - self.value = ( __bridge_transfer NSDate* )value_; + CFStringRef value = ABRecordCopyValue(self.record, self.propertyID); + self.value = ( __bridge_transfer NSDate* )value; + return self.value; } -- (void)setPropertyFromValue:(id)value_ - toRecord:(ABRecordRef)record_ +- (void)setPropertyFromValue:(id)value { - NSParameterAssert([value_ isKindOfClass:[NSString class]]); - - NSTimeInterval timeInterval_ = [ value_ longLongValue ] / 1000.; + NSParameterAssert([value isKindOfClass:[NSString class]]); + + NSTimeInterval timeInterval_ = [value longLongValue] / 1000.; self.value = timeInterval_ == 0. ? nil : [ NSDate dateWithTimeIntervalSince1970: timeInterval_ ]; - + CFErrorRef error = NULL; - bool didSet = ABRecordSetValue( record_ - , self.propertyID - , (__bridge CFTypeRef)self.value - , &error); + bool didSet = ABRecordSetValue(self.record, + self.propertyID, + (__bridge CFTypeRef)self.value, + &error); if (!didSet) { NSLog( @"can not set %@", self.name ); } } diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.h b/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.h index 96cec55..49f43e7 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.h +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.h @@ -2,8 +2,9 @@ @interface JFFContactDictionaryArrayField : JFFContactField -+(id)contactFieldWithName:( NSString* )name_ - propertyID:( ABPropertyID )propertyID_ - labels:( NSArray* )labels_; ++ (instancetype)newContactFieldWithName:(NSString *)name + propertyID:(ABPropertyID)propertyID + labels:(NSArray *)labels + record:(ABRecordRef)record; @end diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.m b/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.m index 2871229..e9041eb 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.m +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactDictionaryArrayField.m @@ -3,23 +3,22 @@ #import "NSArray+kABMultiValue.h" #import "NSArray+ContactsDataFilters.h" -//STODO remove duplicates -static ABMutableMultiValueRef createMutableMultiValueWithArray( NSArray* elements - , NSArray* labels_ ) +static ABMutableMultiValueRef createMutableMultiValueWithArray(NSArray *elements, + NSArray *labels) { ABMutableMultiValueRef result = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); NSUInteger index = 0; - for (NSDictionary *element in elements) - { - id label_ = [ labels_ noThrowObjectAtIndex: index ]; - if ( ![ label_ isKindOfClass: [ NSDictionary class ] ] ) - label_ = nil; + for (NSDictionary *element in elements) { - ABMultiValueAddValueAndLabel( result - , (__bridge CFTypeRef)element - , (__bridge CFTypeRef)label_ - , NULL ); + id label = [labels noThrowObjectAtIndex:index]; + if (![label isKindOfClass:[NSDictionary class]]) + label = nil; + + ABMultiValueAddValueAndLabel(result, + (__bridge CFTypeRef)element, + (__bridge CFTypeRef)label, + NULL); ++index; } @@ -34,50 +33,55 @@ @implementation JFFContactDictionaryArrayField NSArray* _labels; } -+(id)contactFieldWithName:( NSString* )name_ - propertyID:( ABPropertyID )propertyID_ - labels:( NSArray* )labels_ ++ (instancetype)newContactFieldWithName:(NSString *)name + propertyID:(ABPropertyID)propertyID + labels:(NSArray *)labels + record:(ABRecordRef)record { - JFFContactDictionaryArrayField* result_ = [ self contactFieldWithName: name_ - propertyID: propertyID_ ]; - - result_->_labels = labels_; - - return result_; + JFFContactDictionaryArrayField *result = [self newContactFieldWithName:name + propertyID:propertyID + record:record]; + + if (result) { + result->_labels = labels; + } + + return result; } --(void)readPropertyFromRecord:( ABRecordRef )record_ +- (id)readProperty { - CFTypeRef value_ = ABRecordCopyValue( record_, self.propertyID ); - NSArray* address_ = [ NSArray arrayWithMultyValue: value_ ]; - + CFTypeRef value = ABRecordCopyValue(self.record, self.propertyID); + NSArray *address_ = [ NSArray arrayWithMultyValue:value]; + self.value = address_; - - if ( value_ ) - CFRelease( value_ ); + + if (value) + CFRelease(value); + + return self.value; } --(NSArray*)filteredValues:( NSArray* )values_ +- (NSArray *)filteredValues:(NSArray *)values { - return [ values_ jffContactsSelectNotEmptyStrings ]; + return [values jffContactsSelectNotEmptyStrings]; } -- (void)setPropertyFromValue:( id )value_ - toRecord:( ABRecordRef )record_ +- (void)setPropertyFromValue:(id)value { - NSParameterAssert([value_ isKindOfClass:[NSArray class]]); + NSParameterAssert([value isKindOfClass:[NSArray class]]); - self.value = value_; + self.value = value; CFErrorRef error = NULL; - ABMutableMultiValueRef values_ = createMutableMultiValueWithArray( value_, _labels ); - BOOL didSet = ABRecordSetValue( record_ - , self.propertyID - , values_ - , &error ); + ABMutableMultiValueRef values = createMutableMultiValueWithArray(value, _labels); + BOOL didSet = ABRecordSetValue(self.record, + self.propertyID, + values, + &error); if (!didSet) { NSLog( @"can not set %@", self.name ); } - if ( values_ ) - CFRelease( values_ ); + if (values) + CFRelease(values); } @end diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactEmailsField.m b/lib/JFFContacts/JFFContacts/Details/JFFContactEmailsField.m index 3a26476..d44cf28 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactEmailsField.m +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactEmailsField.m @@ -4,9 +4,9 @@ @implementation JFFContactEmailsField --(NSArray*)filteredValues:( NSArray* )values_ +- (NSArray *)filteredValues:(NSArray *)values_ { - return [ values_ jffContactsSelectWithEmailOnly ]; + return [values_ jffContactsSelectWithEmailOnly]; } @end diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactField.h b/lib/JFFContacts/JFFContacts/Details/JFFContactField.h index 7fa5971..fa0fd64 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactField.h +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactField.h @@ -4,16 +4,16 @@ @interface JFFContactField : NSObject -@property ( nonatomic, readonly ) NSString* name; -@property ( nonatomic, readonly ) ABPropertyID propertyID; +@property (nonatomic, readonly) NSString *name; +@property (nonatomic, readonly) ABPropertyID propertyID; +@property (nonatomic, readonly) ABRecordRef record; -@property ( nonatomic ) id value; +@property (nonatomic) id value; -+(id)contactFieldWithName:( NSString* )name_ - propertyID:( ABPropertyID )propertyID_; ++ (instancetype)newContactFieldWithName:(NSString *)name + propertyID:(ABPropertyID)propertyID + record:(ABRecordRef)record; --(void)readPropertyFromRecord:( ABRecordRef )record_; --(void)setPropertyFromValue:( id )value_ - toRecord:( ABRecordRef )record_; +- (void)setPropertyFromValue:(id)value; @end diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactField.m b/lib/JFFContacts/JFFContacts/Details/JFFContactField.m index cd8a54e..f74cf65 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactField.m +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactField.m @@ -4,59 +4,65 @@ @interface JFFContactField () -@property ( nonatomic ) NSString* name; -@property ( nonatomic ) ABPropertyID propertyID; +@property (nonatomic) NSString *name; +@property (nonatomic) ABPropertyID propertyID; @end @implementation JFFContactField --(id)init +- (instancetype)init { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; return self; } --(id)initWithName:( NSString* )name_ - propertyID:( ABPropertyID )propertyID_ +- (instancetype)initWithName:(NSString *)name + propertyID:(ABPropertyID)propertyID + record:(ABRecordRef)record { - self = [ super init ]; - - if ( !self ) - { + self = [super init]; + + if (!self) { + return nil; } - - NSParameterAssert( [ name_ length ] > 0 ); - self.name = name_; - self.propertyID = propertyID_; - - [ [ self class ] addInstanceMethodIfNeedWithSelector: @selector( value ) - toClass: [ self class ] - newMethodSelector: NSSelectorFromString( self.name ) ]; - [ [ self class ] addInstanceMethodIfNeedWithSelector: @selector( setValue: ) - toClass: [ self class ] - newMethodSelector: NSSelectorFromString( [ self.name propertySetNameForPropertyName ] ) ]; - + + NSParameterAssert([name length] > 0); + NSParameterAssert(record != NULL); + + _name = name; + _propertyID = propertyID; + _record = record; + + [[self class] addInstanceMethodIfNeedWithSelector:@selector(readProperty) + toClass:[self class] + newMethodSelector:NSSelectorFromString(self.name)]; + [[self class] addInstanceMethodIfNeedWithSelector:@selector(setPropertyFromValue:) + toClass:[self class] + newMethodSelector:NSSelectorFromString([self.name propertySetNameForPropertyName])]; + return self; } -+(id)contactFieldWithName:( NSString* )name_ - propertyID:( ABPropertyID )propertyID_ ++ (instancetype)newContactFieldWithName:(NSString *)name + propertyID:(ABPropertyID)propertyID + record:(ABRecordRef)record { - return [ [ self alloc ] initWithName: name_ - propertyID: propertyID_ ]; + return [[self alloc] initWithName:name + propertyID:propertyID + record:record]; } --(void)readPropertyFromRecord:( ABRecordRef )record_ +- (id)readProperty { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; + return nil; } --(void)setPropertyFromValue:( id )value_ - toRecord:( ABRecordRef )record_ +- (void)setPropertyFromValue:(id)value { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; } @end diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.h b/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.h index 1ba3254..04dffc7 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.h +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.h @@ -2,6 +2,7 @@ @interface JFFContactPhotoField : JFFContactField -+(id)contactFieldWithName:( NSString* )name_; ++ (instancetype)newContactFieldWithName:(NSString *)name + record:(ABRecordRef)record; @end diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.m b/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.m index 88be023..6a512d4 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.m +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactPhotoField.m @@ -2,50 +2,52 @@ @implementation JFFContactPhotoField -+(id)contactFieldWithName:( NSString* )name_ ++ (instancetype)newContactFieldWithName:(NSString *)name + record:(ABRecordRef)record { - return [ self contactFieldWithName: name_ - propertyID: 0 ]; + return [self newContactFieldWithName:name + propertyID:0 + record:record]; } --(void)readPropertyFromRecord:( ABRecordRef )record_ +- (id)readProperty { - CFDataRef dataRef_ = ABPersonCopyImageData( record_ ); - if ( dataRef_ ) - { - NSData* data_ = ( __bridge_transfer NSData* )dataRef_; - self.value = [ UIImage imageWithData: data_ ]; + CFDataRef dataRef = ABPersonCopyImageData(self.record); + if (dataRef != NULL) { + + NSData *data = (__bridge_transfer NSData *)dataRef; + self.value = [UIImage imageWithData:data]; } + return self.value; } --(void)setPropertyFromValue:( id )value_ - toRecord:( ABRecordRef )record_ +- (void)setPropertyFromValue:(id)value { - NSParameterAssert( [ value_ isKindOfClass: [ UIImage class ] ] - || [ value_ isKindOfClass: [ NSData class ] ] - || [ value_ isKindOfClass: [ NSNull class ] ] ); - - if ( [ value_ isKindOfClass: [ NSNull class ] ] ) + NSParameterAssert( [value isKindOfClass:[UIImage class]] + || [value isKindOfClass:[NSData class]] + || [value isKindOfClass:[NSNull class]]); + + if ([value isKindOfClass:[NSNull class]]) { - if ( ABPersonHasImageData( record_ ) ) - { + if (ABPersonHasImageData(self.record)) { + CFErrorRef error = NULL; - ABPersonRemoveImageData( record_, &error ); + ABPersonRemoveImageData(self.record, &error); } return; } - - NSData* data_ = value_; - if ( [ value_ isKindOfClass: [ UIImage class ] ] ) - { - data_ = UIImagePNGRepresentation( value_ ); + + NSData *data = value; + if ([value isKindOfClass:[UIImage class]]) { + + data = UIImagePNGRepresentation(value); } - - if ( data_ ) - { + + if (data) { + CFErrorRef error = NULL; - bool didSet = ABPersonSetImageData( record_, ( __bridge CFDataRef )data_, &error ); + bool didSet = ABPersonSetImageData(self.record, (__bridge CFDataRef)data, &error); if (!didSet) { NSLog( @"can not set %@", self.name ); } } } diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.h b/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.h index 95dfa9f..2aea56d 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.h +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.h @@ -2,8 +2,9 @@ @interface JFFContactStringArrayField : JFFContactField -+(id)contactFieldWithName:( NSString* )name_ - propertyID:( ABPropertyID )propertyID_ - labels:( NSArray* )labels_; ++ (instancetype)newContactFieldWithName:(NSString *)name + propertyID:(ABPropertyID)propertyID + labels:(NSArray *)labels + record:(ABRecordRef)record; @end diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.m b/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.m index 9d131cc..17282a7 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.m +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactStringArrayField.m @@ -3,25 +3,25 @@ #import "NSArray+kABMultiValue.h" #import "NSArray+ContactsDataFilters.h" -static ABMutableMultiValueRef createMutableMultiValueWithArray( NSArray* elements_ - , NSArray* labels_ ) +static ABMutableMultiValueRef createMutableMultiValueWithArray(NSArray *elements, + NSArray *labels) { - ABMutableMultiValueRef result = ABMultiValueCreateMutable( kABMultiStringPropertyType ); - - NSUInteger index_ = 0; - for ( NSString* element_ in elements_ ) - { - id label_ = [ labels_ noThrowObjectAtIndex: index_ ]; - if ( ![ label_ isKindOfClass: [ NSString class ] ] ) - label_ = nil; - - ABMultiValueAddValueAndLabel( result - , (__bridge CFTypeRef)element_ - , (__bridge CFTypeRef)label_ - , NULL ); - ++index_; + ABMutableMultiValueRef result = ABMultiValueCreateMutable(kABMultiStringPropertyType); + + NSUInteger index = 0; + for (NSString *element in elements) { + + id label = [labels noThrowObjectAtIndex:index]; + if (![label isKindOfClass:[NSString class]]) + label = nil; + + ABMultiValueAddValueAndLabel(result, + (__bridge CFTypeRef)element, + (__bridge CFTypeRef)label, + NULL); + ++index; } - + return result; } @@ -30,46 +30,53 @@ @interface JFFContactStringArrayField () @implementation JFFContactStringArrayField { - NSArray* _labels; + NSArray *_labels; } -+(id)contactFieldWithName:( NSString* )name_ - propertyID:( ABPropertyID )propertyID_ - labels:( NSArray* )labels_ ++ (instancetype)newContactFieldWithName:(NSString *)name + propertyID:(ABPropertyID)propertyID + labels:(NSArray *)labels + record:(ABRecordRef)record { - JFFContactStringArrayField* result_ = [ self contactFieldWithName: name_ - propertyID: propertyID_ ]; - - result_->_labels = labels_; - - return result_; + JFFContactStringArrayField *result = [self newContactFieldWithName:name + propertyID:propertyID + record:record]; + + if (result) { + result->_labels = labels; + } + + return result; } --(void)readPropertyFromRecord:( ABRecordRef )record_ +- (id)readProperty { - CFTypeRef value_ = ABRecordCopyValue( record_, self.propertyID ); - self.value = [ NSArray arrayWithMultyValue: value_ ]; - if ( value_ ) - CFRelease( value_ ); + CFTypeRef value = ABRecordCopyValue(self.record, self.propertyID); + + self.value = [NSArray arrayWithMultyValue:value]; + + if (value) + CFRelease(value); + + return self.value; } --(NSArray*)filteredValues:( NSArray* )values_ +- (NSArray *)filteredValues:(NSArray *)values { - return [ values_ jffContactsSelectNotEmptyStrings ]; + return [values jffContactsSelectNotEmptyStrings]; } -- (void)setPropertyFromValue:(id)value_ - toRecord:(ABRecordRef)record_ +- (void)setPropertyFromValue:(id)value { - NSParameterAssert([value_ isKindOfClass:[NSArray class]]); - self.value = [ self filteredValues: value_ ]; - + NSParameterAssert([value isKindOfClass:[NSArray class]]); + self.value = [self filteredValues:value]; + CFErrorRef error = NULL; - ABMutableMultiValueRef values_ = createMutableMultiValueWithArray( self.value, _labels ); - BOOL didSet = ABRecordSetValue( record_ - , self.propertyID - , values_ - , &error); + ABMutableMultiValueRef values_ = createMutableMultiValueWithArray(self.value, _labels); + BOOL didSet = ABRecordSetValue(self.record, + self.propertyID, + values_, + &error); if (!didSet) { NSLog( @"can not set %@", self.name ); } if ( values_ ) CFRelease( values_ ); diff --git a/lib/JFFContacts/JFFContacts/Details/JFFContactStringField.m b/lib/JFFContacts/JFFContacts/Details/JFFContactStringField.m index 0b8d77b..357d2fa 100644 --- a/lib/JFFContacts/JFFContacts/Details/JFFContactStringField.m +++ b/lib/JFFContacts/JFFContacts/Details/JFFContactStringField.m @@ -2,23 +2,24 @@ @implementation JFFContactStringField --(void)readPropertyFromRecord:( ABRecordRef )record_ +- (id)readProperty { - CFStringRef value_ = ABRecordCopyValue( record_, self.propertyID ); - self.value = ( __bridge_transfer NSString* )value_; + CFStringRef value = ABRecordCopyValue(self.record, self.propertyID); + self.value = (__bridge_transfer NSString *)value; + + return self.value; } - (void)setPropertyFromValue:(id)value - toRecord:(ABRecordRef)record_ { NSParameterAssert(value); self.value = value; - + CFErrorRef error = NULL; - bool didSet = ABRecordSetValue( record_ - , self.propertyID - , (__bridge CFTypeRef)self.value - , &error); + bool didSet = ABRecordSetValue(self.record, + self.propertyID, + (__bridge CFTypeRef)self.value, + &error); if (!didSet) { NSLog( @"can not set %@", self.name ); } } diff --git a/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.h b/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.h index 8e50e25..228a355 100644 --- a/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.h +++ b/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.h @@ -2,7 +2,7 @@ @interface NSArray (ContactsDataFilters) --(id)jffContactsSelectNotEmptyStrings; --(id)jffContactsSelectWithEmailOnly; +- (instancetype)jffContactsSelectNotEmptyStrings; +- (instancetype)jffContactsSelectWithEmailOnly; @end diff --git a/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.m b/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.m index 621bab7..72ba29d 100644 --- a/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.m +++ b/lib/JFFContacts/JFFContacts/Details/NSArray+ContactsDataFilters.m @@ -2,24 +2,24 @@ @implementation NSArray (ContactsDataFilters) -- (id)jffContactsSelectNotEmptyStrings +- (instancetype)jffContactsSelectNotEmptyStrings { NSArray *result = [self map:^id(NSString *str) { return [str stringByTrimmingWhitespaces]; }]; result = [result select:^BOOL(NSString *str) { - return [str length ] != 0; + return [str length] != 0; }]; return result; } -- (id)jffContactsSelectWithEmailOnly +- (instancetype)jffContactsSelectWithEmailOnly { NSArray *result = [self map:^id(NSString *str) { return [str stringByTrimmingWhitespaces]; - } ]; + }]; result = [result select:^BOOL(NSString *str) { return [str isEmailValid]; diff --git a/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.h b/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.h index b0b9f00..fdd69f1 100644 --- a/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.h +++ b/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.h @@ -4,6 +4,6 @@ @interface NSArray (kABMultiValue) -+(id)arrayWithMultyValue:( ABMutableMultiValueRef )multyValue_; ++ (instancetype)arrayWithMultyValue:(ABMutableMultiValueRef)multyValue; @end diff --git a/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.m b/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.m index 43da03a..25a8c99 100644 --- a/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.m +++ b/lib/JFFContacts/JFFContacts/Details/NSArray+kABMultiValue.m @@ -2,24 +2,24 @@ @implementation NSArray (kABMultiValue) -+(id)arrayWithMultyValue:( ABMutableMultiValueRef )multyValue_ ++ (instancetype)arrayWithMultyValue:(ABMutableMultiValueRef)multyValue { - CFIndex count_ = multyValue_ - ? ABMultiValueGetCount( multyValue_ ) + CFIndex count = multyValue + ? ABMultiValueGetCount(multyValue) : 0; - - if ( 0 == count_ ) + + if (0 == count) return nil; - NSArray* result_ = [ NSArray arrayWithCapacity: count_ - ignoringNilsProducer: ^id( NSUInteger index_ ) - { - CFTypeRef value_ = ABMultiValueCopyValueAtIndex( multyValue_, index_ ); - - return ( __bridge_transfer NSString* )value_; - } ]; + NSArray *result = [NSArray arrayWithCapacity:count + ignoringNilsProducer:^id(NSUInteger index) { + + CFTypeRef value = ABMultiValueCopyValueAtIndex(multyValue, index); - return result_; + return (__bridge_transfer NSString *)value; + }]; + + return result; } @end diff --git a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.h b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.h index 67d53c1..fdd7a45 100644 --- a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.h +++ b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.h @@ -1,5 +1,4 @@ #import @interface JFFAddressBookAccessError : JFFAddressBookWrapperError - @end diff --git a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.m b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.m index 34c2ff2..a011660 100644 --- a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.m +++ b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookAccessError.m @@ -2,6 +2,11 @@ @implementation JFFAddressBookAccessError +- (instancetype)init +{ + return [self initWithDescription:NSLocalizedString(@"ADDRESS_BOOK_ACCESS_ERROR", nil)]; +} + - (void)writeErrorWithJFFLogger { } diff --git a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookError.h b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookError.h index 419c335..4e739a6 100644 --- a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookError.h +++ b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookError.h @@ -1,4 +1,4 @@ -#import +#import @interface JFFAddressBookError : JFFError @end diff --git a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.h b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.h index 613e629..52512f8 100644 --- a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.h +++ b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.h @@ -4,6 +4,6 @@ @property (nonatomic) NSError *nativeError; -+ (id)newAddressBookWrapperErrorWithNativeError:(NSError *)nativeError; ++ (instancetype)newAddressBookWrapperErrorWithNativeError:(NSError *)nativeError; @end diff --git a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.m b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.m index d57cda3..1cd838a 100644 --- a/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.m +++ b/lib/JFFContacts/JFFContacts/Errors/JFFAddressBookWrapperError.m @@ -6,12 +6,12 @@ @implementation JFFAddressBookWrapperError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"ADDRESS_BOOK_WRAPPER_ERROR", nil)]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFAddressBookWrapperError *copy = [super copyWithZone:zone]; @@ -22,7 +22,7 @@ - (id)copyWithZone:(NSZone *)zone return copy; } -+ (id)newAddressBookWrapperErrorWithNativeError:(NSError *)nativeError ++ (instancetype)newAddressBookWrapperErrorWithNativeError:(NSError *)nativeError { Class class = Nil; @@ -45,9 +45,11 @@ + (id)newAddressBookWrapperErrorWithNativeError:(NSError *)nativeError return error; } -- (void)writeErrorWithJFFLogger +- (NSString *)errorLogDescription { - [JFFLogger logErrorWithFormat:@"%@ nativeError:%@", [self localizedDescription], _nativeError]; + return [[NSString alloc] initWithFormat:@"%@ nativeError:%@", + [self localizedDescription], + _nativeError]; } @end diff --git a/lib/JFFContacts/JFFContacts/JFFAddressBook.h b/lib/JFFContacts/JFFContacts/JFFAddressBook.h index 20eab31..6ad787d 100755 --- a/lib/JFFContacts/JFFContacts/JFFAddressBook.h +++ b/lib/JFFContacts/JFFContacts/JFFAddressBook.h @@ -5,7 +5,7 @@ @property (nonatomic, readonly) CF_RETURNS_NOT_RETAINED ABAddressBookRef rawBook; -- (id)initWithRawBook:(ABAddressBookRef)CF_CONSUMED rawBook; +- (instancetype)initWithRawBook:(ABAddressBookRef)CF_CONSUMED rawBook; - (BOOL)removeAllContactsWithError:(NSError **)error; diff --git a/lib/JFFContacts/JFFContacts/JFFAddressBook.m b/lib/JFFContacts/JFFContacts/JFFAddressBook.m index 141cb4d..1266215 100755 --- a/lib/JFFContacts/JFFContacts/JFFAddressBook.m +++ b/lib/JFFContacts/JFFContacts/JFFAddressBook.m @@ -12,46 +12,45 @@ - (void)dealloc CFRelease(_rawBook); } -- (id)init +- (instancetype)init { [self doesNotRecognizeSelector:_cmd]; return nil; } -- (id)initWithRawBook:(ABAddressBookRef)rawBook_ +- (instancetype)initWithRawBook:(ABAddressBookRef)rawBook { - NSParameterAssert(NULL != rawBook_); + NSParameterAssert(NULL != rawBook); self = [super init]; if (nil == self) { return nil; } - _rawBook = rawBook_; + _rawBook = rawBook; return self; } - (BOOL)removeAllContactsWithError:(NSError **)error { - ABAddressBookRef rawBook_ = self.rawBook; - CFErrorRef rawError_ = NULL; - NSArray* contacts_ = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(rawBook_); + ABAddressBookRef rawBook = self.rawBook; + CFErrorRef rawError = NULL; + NSArray *contacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(rawBook); - for ( id record_ in contacts_ ) + for (id record in contacts) { - ABRecordRef rawRecord_ = (__bridge ABRecordRef)record_; - ABAddressBookRemoveRecord( rawBook_, rawRecord_, &rawError_ ); - if ( NULL != rawError_ ) - { - [ (__bridge NSError*)rawError_ setToPointer:error]; + ABRecordRef rawRecord = (__bridge ABRecordRef)record; + ABAddressBookRemoveRecord(rawBook, rawRecord, &rawError); + if (NULL != rawError) { + [(__bridge NSError *)rawError setToPointer:error]; return NO; } } - ABAddressBookSave( rawBook_, &rawError_ ); - if ( NULL != rawError_ ) { - [ (__bridge NSError*)rawError_ setToPointer:error]; + ABAddressBookSave( rawBook, &rawError ); + if (NULL != rawError) { + [(__bridge NSError *)rawError setToPointer:error]; return NO; } diff --git a/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.h b/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.h index c8a223c..1802e30 100755 --- a/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.h +++ b/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.h @@ -1,23 +1,11 @@ #import #include -#ifndef __IPHONE_6_0 - enum ABAuthorizationStatusEnum - { - kABAuthorizationStatusNotDetermined = 0, - kABAuthorizationStatusRestricted, - kABAuthorizationStatusDenied, - kABAuthorizationStatusAuthorized - }; - typedef CFIndex ABAuthorizationStatus; -#endif //__IPHONE_6_ - - @protocol JFFAddressBookOwner; @class JFFAddressBook; -typedef void(^JFFAddressBookOnCreated)(JFFAddressBook *book, ABAuthorizationStatus status, NSError *error); -typedef void(^JFFAddressBookSuccessCallback)(JFFAddressBook *book); +typedef void(^JFFAddressBookOnCreated)(JFFAddressBook *addressBook, ABAuthorizationStatus status, NSError *error); +typedef void(^JFFAddressBookSuccessCallback)(JFFAddressBook *addressBook); typedef void(^JFFAddressBookErrorCallback)(ABAuthorizationStatus status, NSError *error); @interface JFFAddressBookFactory : NSObject diff --git a/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.mm b/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.mm index c80948d..146c6f3 100755 --- a/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.mm +++ b/lib/JFFContacts/JFFContacts/JFFAddressBookFactory.mm @@ -2,12 +2,13 @@ #import "JFFAddressBook.h" +#import "JFFAddressBookAccessError.h" #import "JFFAddressBookWrapperError.h" static NSError *convertErrorType(NSError *error) { if (!error) - return nil; + return [JFFAddressBookAccessError new]; JFFAddressBookWrapperError *result = [JFFAddressBookWrapperError newAddressBookWrapperErrorWithNativeError:error]; result.nativeError = error; @@ -18,21 +19,13 @@ @implementation JFFAddressBookFactory + (void)asyncAddressBookWithOnCreatedBlock:(JFFAddressBookOnCreated)callback { - NSParameterAssert(nil!=callback); - -#ifdef kCFCoreFoundationVersionNumber_iOS_5_1 - if (kCFCoreFoundationVersionNumber <= kCFCoreFoundationVersionNumber_iOS_5_1) { -#endif - [self asyncLegacyAddressBookWithOnCreatedBlock:callback]; - return; -#ifdef kCFCoreFoundationVersionNumber_iOS_5_1 - } + NSParameterAssert(callback); CFErrorRef error = NULL; ABAddressBookRef result = ABAddressBookCreateWithOptions(0, &error); if (NULL != error) { - NSError *retError = (__bridge NSError*)error; + NSError *retError = (__bridge NSError *)error; if (result) CFRelease(result); if (callback) { @@ -49,21 +42,10 @@ + (void)asyncAddressBookWithOnCreatedBlock:(JFFAddressBookOnCreated)callback NSError *retError = (__bridge NSError *)(blockError); JFFAddressBook *bookWrapper = [[JFFAddressBook alloc] initWithRawBook:result]; - callback(bookWrapper, ::ABAddressBookGetAuthorizationStatus(), convertErrorType(retError)); + callback(bookWrapper, ::ABAddressBookGetAuthorizationStatus(), blockGranted?nil:convertErrorType(retError)); }; ABAddressBookRequestAccessWithCompletion(result, onAddressBookAccess); -#endif -} - -+ (void)asyncLegacyAddressBookWithOnCreatedBlock:(JFFAddressBookOnCreated)callback -{ - NSParameterAssert(nil!=callback); - - ABAddressBookRef result = ::ABAddressBookCreate(); - JFFAddressBook *bookWrapper = [[JFFAddressBook alloc] initWithRawBook:result]; - - callback(bookWrapper, kABAuthorizationStatusAuthorized, nil); } + (NSString *)bookStatusToString:(ABAuthorizationStatus)status diff --git a/lib/JFFContacts/JFFContacts/JFFContact.h b/lib/JFFContacts/JFFContacts/JFFContact.h index 2be160c..d85f700 100644 --- a/lib/JFFContacts/JFFContacts/JFFContact.h +++ b/lib/JFFContacts/JFFContacts/JFFContact.h @@ -8,33 +8,33 @@ @interface JFFContact : NSObject -@property ( nonatomic ) NSString* firstName; -@property ( nonatomic ) NSString* lastName; -@property ( nonatomic ) NSString* company; -@property ( nonatomic ) NSDate * birthday; -@property ( nonatomic ) NSArray * emails; -@property ( nonatomic ) NSArray * phones; -@property ( nonatomic ) NSArray * sites; -@property ( nonatomic ) UIImage * photo; -@property ( nonatomic ) NSArray * addresses; -@property ( nonatomic ) ABRecordID contactInternalId; - -@property ( nonatomic, readonly ) ABRecordRef person; -@property ( nonatomic, readonly ) ABAddressBookRef addressBook; -@property ( nonatomic, readonly ) BOOL newContact; - -- (id)initWithPerson:(ABRecordRef)person - addressBook:(JFFAddressBook *)addressBook; - -- (id)initWithFieldsDict:(NSDictionary *)args - addressBook:(JFFAddressBook *)addressBook; +@property (nonatomic) NSString *firstName; +@property (nonatomic) NSString *lastName; +@property (nonatomic) NSString *company; +@property (nonatomic) NSDate *birthday; +@property (nonatomic) NSArray *emails; +@property (nonatomic) NSArray *phones; +@property (nonatomic) NSArray *sites; +@property (nonatomic) UIImage *photo; +@property (nonatomic) NSArray *addresses; +@property (nonatomic) ABRecordID contactInternalId; + +@property (nonatomic, readonly) ABRecordRef person; +@property (nonatomic, readonly) ABAddressBookRef addressBook; +@property (nonatomic, readonly) BOOL newContact; + +- (instancetype)initWithPerson:(ABRecordRef)person + addressBook:(JFFAddressBook *)addressBook; + +- (instancetype)initWithFieldsDict:(NSDictionary *)args + addressBook:(JFFAddressBook *)addressBook; - (BOOL)save; - (BOOL)remove; -+ (id)findContactWithContactInternalId:(ABRecordID)contactInternalId - addressBook:(JFFAddressBook *)addressBook; ++ (instancetype)findContactWithContactInternalId:(ABRecordID)contactInternalId + addressBook:(JFFAddressBook *)addressBook; -+ (id)allContactsAddressBook:(JFFAddressBook *)addressBook; ++ (NSArray *)allContactsAddressBook:(JFFAddressBook *)addressBook; @end diff --git a/lib/JFFContacts/JFFContacts/JFFContact.m b/lib/JFFContacts/JFFContacts/JFFContact.m index 07dbb91..045d191 100644 --- a/lib/JFFContacts/JFFContacts/JFFContact.m +++ b/lib/JFFContacts/JFFContacts/JFFContact.m @@ -13,97 +13,109 @@ #import -static ABRecordRef createOrGetContactPerson( ABRecordID contactInternalId_ - , ABAddressBookRef addressBook_ ) +static ABRecordRef createOrGetContactPerson(ABRecordID contactInternalId, + ABAddressBookRef addressBook) { - if ( contactInternalId_ != 0 ) - { - ABRecordRef result_ = ABAddressBookGetPersonWithRecordID( addressBook_ - , contactInternalId_ ); - - if ( result_ ) - { - CFRetain( result_ ); - return result_; + if (contactInternalId != 0) { + + ABRecordRef result = ABAddressBookGetPersonWithRecordID(addressBook, + contactInternalId); + + if (result) { + CFRetain(result); + return result; } } - + return ABPersonCreate(); } @interface JFFContact () -@property ( nonatomic ) BOOL newContact; --(ABRecordRef)rawPerson CF_RETURNS_NOT_RETAINED; --(void)setRawPerson:( ABRecordRef )person_; +@property (nonatomic) BOOL newContact; +- (ABRecordRef)rawPerson CF_RETURNS_NOT_RETAINED; +- (void)setRawPerson:(ABRecordRef)person_; @end @implementation JFFContact { - NSMutableDictionary* _fieldByName; - JFFAddressBook* _addressBookWrapper; + NSMutableDictionary *_fieldByName; + JFFAddressBook *_addressBookWrapper; ABRecordRef _person; } @dynamic addressBook; -@dynamic firstName -, lastName -, company -, emails -, phones -, sites -, birthday -, photo -, addresses; +@dynamic firstName, +lastName, +company, +emails, +phones, +sites, +birthday, +photo, +addresses; + +- (instancetype)init +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} --(id)forwardingTargetForSelector:( SEL )selector_ +- (id)forwardingTargetForSelector:(SEL)selector { - NSString* selectorName_ = NSStringFromSelector( selector_ ); - JFFContactField* field_ = _fieldByName[ selectorName_ ]; - if ( !field_ ) - { - field_ = _fieldByName[ [ selectorName_ propertyGetNameFromPropertyName ] ]; + NSString *propertyName = NSStringFromSelector(selector); + JFFContactField *field = _fieldByName[propertyName]; + if (!field) { + + propertyName = [propertyName propertyGetNameFromPropertyName]; + field = _fieldByName[propertyName]; } - return field_ ?: self; + return field?:self; } --(void)dealloc +- (void)dealloc { self.rawPerson = nil; } --(void)addField:( JFFContactField* )field_ +- (void)addField:(JFFContactField *)field { - _fieldByName[ field_.name ] = field_; + _fieldByName[field.name] = field; } --(void)initializeDynamicFields +- (void)initializeDynamicFields { - _fieldByName = [ NSMutableDictionary new ]; - + _fieldByName = [NSMutableDictionary new]; + NSDictionary* fieldNameByPropertyId_ = @{ @(kABPersonFirstNameProperty) : JFFContactFirstName, @(kABPersonLastNameProperty) : JFFContactLastName , @(kABPersonOrganizationProperty) : JFFContactCompany , @(kABPersonBirthdayProperty) : JFFContactBirthday , }; - - [ fieldNameByPropertyId_ enumerateKeysAndObjectsUsingBlock: ^( NSNumber* propertyID_, id fieldName_, BOOL* stop_ ) - { - [ self addField: [ JFFContactStringField contactFieldWithName: fieldName_ - propertyID: [ propertyID_ longLongValue ] ] ]; - } ]; - - [ self addField: [ JFFContactPhotoField contactFieldWithName: JFFContactPhoto ] ]; - + + ABRecordRef person = self.person; + + [fieldNameByPropertyId_ enumerateKeysAndObjectsUsingBlock:^(NSNumber *propertyID, id fieldName, BOOL *stop) { + + JFFContactStringField *field = [JFFContactStringField newContactFieldWithName:fieldName + propertyID:(ABPropertyID)[propertyID longLongValue] + record:person]; + + [self addField:field]; + }]; + + [self addField:[JFFContactPhotoField newContactFieldWithName:JFFContactPhoto record:person]]; + //JTODO localize all labels NSArray *labels = @[@"home", @"work"]; - [self addField:[JFFContactEmailsField contactFieldWithName:JFFContactEmails - propertyID:kABPersonEmailProperty - labels:labels]]; + [self addField:[JFFContactEmailsField newContactFieldWithName:JFFContactEmails + propertyID:kABPersonEmailProperty + labels:labels + record:person]]; labels = @[ @"mobile", @@ -117,216 +129,200 @@ -(void)initializeDynamicFields @"pager", @"other", ]; - [ self addField: [ JFFContactStringArrayField contactFieldWithName:JFFContactPhones + [self addField:[JFFContactStringArrayField newContactFieldWithName:JFFContactPhones propertyID:kABPersonPhoneProperty - labels:labels]]; - + labels:labels + record:person]]; + labels = @[ @"home page", @"home", @"work", @"other" ]; - [ self addField: [ JFFContactStringArrayField contactFieldWithName:JFFContactWebsites + [self addField:[JFFContactStringArrayField newContactFieldWithName:JFFContactWebsites propertyID:kABPersonURLProperty - labels:labels]]; - + labels:labels + record:person]]; + labels = @[ @"home", @"work", @"other", ]; - [ self addField: [ JFFContactDictionaryArrayField contactFieldWithName:JFFContactAddresses + [self addField:[JFFContactDictionaryArrayField newContactFieldWithName:JFFContactAddresses propertyID:kABPersonAddressProperty - labels:labels]]; + labels:labels + record:person]]; } --(id)initWithPerson:( ABRecordRef )person_ - addressBook:( JFFAddressBook* )addressBook_ +- (instancetype)initWithPerson:(ABRecordRef)person + addressBook:(JFFAddressBook *)addressBook { - self = [ super init ]; - - if ( !self ) - { + self = [super init]; + + if (!self) { return nil; } - - NSParameterAssert(person_); - NSParameterAssert(nil!=addressBook_); - _addressBookWrapper = addressBook_; - [ self initializeDynamicFields ]; - - _contactInternalId = ABRecordGetRecordID( person_ ); - - [ _fieldByName enumerateKeysAndObjectsUsingBlock: ^( id key, JFFContactField* field_, BOOL* stop ) - { - [ field_ readPropertyFromRecord: person_ ]; - } ]; - - self.rawPerson = person_; - + NSParameterAssert(person); + NSParameterAssert(nil!=addressBook); + _addressBookWrapper = addressBook; + + _contactInternalId = ABRecordGetRecordID(person); + + [self initializeDynamicFields]; + return self; } --(id)initWithFieldsDict:( NSDictionary* )args_ - addressBook:( JFFAddressBook* )addressBook_ +- (instancetype)initWithFieldsDict:(NSDictionary *)args + addressBook:(JFFAddressBook *)addressBook { - self = [ super init ]; - - NSParameterAssert( nil != addressBook_ ); - - if ( !self ) - { + self = [super init]; + + NSParameterAssert(nil != addressBook); + + if (!self) { return nil; } - - _addressBookWrapper = addressBook_; - - [ self initializeDynamicFields ]; - - NSString* contactInternalId_ = args_[ @"contactInternalId" ]; - _contactInternalId = [ contactInternalId_ longLongValue ]; - self.newContact = contactInternalId_ == nil; - - ABRecordRef person_ = self.person; - [ args_ enumerateKeysAndObjectsUsingBlock: ^( id fieldName_, id value_, BOOL* stop ) + + _addressBookWrapper = addressBook; + + NSString *contactInternalId = args[@"contactInternalId"]; + _contactInternalId = (ABRecordID)[contactInternalId longLongValue]; + self.newContact = contactInternalId == nil; + + [self initializeDynamicFields]; + + [args enumerateKeysAndObjectsUsingBlock:^(id fieldName, id value, BOOL *stop) { - JFFContactField* field_ = _fieldByName[ fieldName_ ]; - if ( !field_ ) - { - NSLog( @"!!!WARNING!!! unsupported field name: %@", fieldName_ ); + JFFContactField *field = _fieldByName[fieldName]; + if (!field) { + NSLog( @"!!!WARNING!!! unsupported field name: %@", fieldName); } - [ field_ setPropertyFromValue: value_ - toRecord: person_ ]; - } ]; - + [field setPropertyFromValue:value]; + }]; + return self; } --(ABAddressBookRef)addressBook +- (ABAddressBookRef)addressBook { return _addressBookWrapper.rawBook; } --(ABRecordRef)person +- (ABRecordRef)person { - if ( !_person ) - { - _person = createOrGetContactPerson( self.contactInternalId, self.addressBook ); + if (!_person) { + + _person = createOrGetContactPerson(self.contactInternalId, self.addressBook); } return _person; } --(ABRecordRef)rawPerson +- (ABRecordRef)rawPerson { return _person; } --(void)setRawPerson:( ABRecordRef )person_ +- (void)setRawPerson:(ABRecordRef)person { - if ( person_ == _person ) - { + if (person == _person) { return; } - - if ( NULL != _person ) - { - CFRelease( _person ); + + if (NULL != _person) { + + CFRelease(_person); } _person = NULL; - - if ( NULL != person_ ) - { - _person = CFRetain( person_ ); + + if (NULL != person) { + + _person = CFRetain(person); } } --(BOOL)save +- (BOOL)save { CFErrorRef error = NULL; - bool result_ = false; - if ( self.newContact ) - { - result_ = ABAddressBookAddRecord( self.addressBook, self.person, &error ); - if ( !result_ ) - { - NSLog( @"can not add Person" ); + bool result = false; + if (self.newContact) { + result = ABAddressBookAddRecord(self.addressBook, self.person, &error); + if (!result) { + NSLog(@"can not add Person"); return NO; } } - - result_ = ABAddressBookSave( self.addressBook, &error ); - if ( !result_ ) - { - NSLog( @"can not save Person" ); + + result = ABAddressBookSave(self.addressBook, &error); + if (!result) { + NSLog(@"can not save Person"); return NO; } - - _contactInternalId = ABRecordGetRecordID( self.person ); - + + _contactInternalId = ABRecordGetRecordID(self.person); + return YES; } --(BOOL)remove +- (BOOL)remove { - if ( 0 == _contactInternalId || NULL == self.rawPerson ) - { + if (0 == _contactInternalId || NULL == self.rawPerson) { NSLog( @"record has no id" ); return NO; } - + CFErrorRef error = NULL; - bool result_ = ABAddressBookRemoveRecord( self.addressBook, self.rawPerson, &error ); - if ( !result_ ) - { - NSLog( @"can not remove record from AddressBook" ); + bool result = ABAddressBookRemoveRecord( self.addressBook, self.rawPerson, &error ); + if (!result) { + + NSLog(@"can not remove record from AddressBook"); return NO; } - + error = NULL; - result_ = ABAddressBookSave( self.addressBook, &error ); - if ( !result_ ) - { - NSLog( @"can not save AddressBook" ); + result = ABAddressBookSave(self.addressBook, &error); + if (!result) { + + NSLog(@"can not save AddressBook"); return NO; } - + return YES; } -+(id)findContactWithContactInternalId:( ABRecordID )contactInternalId_ - addressBook:( JFFAddressBook* )addressBook_ ++ (instancetype)findContactWithContactInternalId:(ABRecordID)contactInternalId + addressBook:(JFFAddressBook *)addressBook { - ABAddressBookRef addressBookRef_ = addressBook_.rawBook; - - ABRecordRef record_ = ABAddressBookGetPersonWithRecordID( addressBookRef_ - , contactInternalId_ ); - - if ( NULL == record_ ) - { + ABAddressBookRef addressBookRef = addressBook.rawBook; + + ABRecordRef record = ABAddressBookGetPersonWithRecordID(addressBookRef, + contactInternalId); + + if (NULL == record) { return nil; } - - return [ [ self alloc ] initWithPerson: record_ - addressBook: addressBook_ ]; + + return [[self alloc] initWithPerson:record + addressBook:addressBook]; } -+(id)allContactsAddressBook:( JFFAddressBook* )addressBook_ ++ (NSArray *)allContactsAddressBook:(JFFAddressBook *)addressBook { - ABAddressBookRef addressBookRef_ = addressBook_.rawBook; - - NSArray* result_ = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople( addressBookRef_ ); - - result_ = [ result_ map: ^id( id object_ ) - { - ABRecordRef person_ = ( __bridge ABRecordRef )object_; - return [ [ JFFContact alloc ] initWithPerson: person_ - addressBook: addressBook_ ]; - } ]; - - return result_; + ABAddressBookRef addressBookRef = addressBook.rawBook; + + NSArray *result = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef); + + result = [result map:^id(id object) { + ABRecordRef person = (__bridge ABRecordRef)object; + return [[JFFContact alloc] initWithPerson:person + addressBook:addressBook]; + }]; + + return result; } @end diff --git a/lib/JFFCoreData/JFFCoreData.xcodeproj/project.pbxproj b/lib/JFFCoreData/JFFCoreData.xcodeproj/project.pbxproj deleted file mode 100644 index e269ab4..0000000 --- a/lib/JFFCoreData/JFFCoreData.xcodeproj/project.pbxproj +++ /dev/null @@ -1,694 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - CE025685162B08E100481461 /* NSOrderedSet+ObjectInManagedObjectContext.m in Sources */ = {isa = PBXBuildFile; fileRef = CE025684162B08E100481461 /* NSOrderedSet+ObjectInManagedObjectContext.m */; }; - CE11ADEF168C806C00D35C5C /* NSManagedObject+SaveAsyncOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CE11ADEE168C806C00D35C5C /* NSManagedObject+SaveAsyncOperation.m */; }; - CE8C6D151696D6A900B06045 /* JFFCoreDataError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE8C6D141696D6A900B06045 /* JFFCoreDataError.m */; }; - CE8C6D181696D6ED00B06045 /* JFFNoManagedObjectError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE8C6D171696D6ED00B06045 /* JFFNoManagedObjectError.m */; }; - CEA097ED16216ED1005820FA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA097EC16216ED1005820FA /* Foundation.framework */; }; - CEA097F216216ED1005820FA /* JFFCoreData.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = CEA097F116216ED1005820FA /* JFFCoreData.h */; }; - CEA097FC16216ED1005820FA /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA097FB16216ED1005820FA /* SenTestingKit.framework */; }; - CEA097FE16216ED1005820FA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA097FD16216ED1005820FA /* UIKit.framework */; }; - CEA097FF16216ED1005820FA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA097EC16216ED1005820FA /* Foundation.framework */; }; - CEA0980216216ED1005820FA /* libJFFCoreData.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA097E916216ED1005820FA /* libJFFCoreData.a */; }; - CEA0980816216ED1005820FA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CEA0980616216ED1005820FA /* InfoPlist.strings */; }; - CEA0980B16216ED1005820FA /* JFFCoreDataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA0980A16216ED1005820FA /* JFFCoreDataTests.m */; }; - CEA0981616216EE7005820FA /* JFFCoreDataProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA0981516216EE7005820FA /* JFFCoreDataProvider.m */; }; - CEA0982E16217259005820FA /* JFFCoreDataAsyncOperationAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA0982D16217259005820FA /* JFFCoreDataAsyncOperationAdapter.m */; }; - CECEFBE416217FB0007A61C9 /* NSArray+ObjectInManagedObjectContext.m in Sources */ = {isa = PBXBuildFile; fileRef = CECEFBE316217FB0007A61C9 /* NSArray+ObjectInManagedObjectContext.m */; }; - CECEFBE716217FC7007A61C9 /* NSDictionary+ObjectInManagedObjectContext.m in Sources */ = {isa = PBXBuildFile; fileRef = CECEFBE616217FC7007A61C9 /* NSDictionary+ObjectInManagedObjectContext.m */; }; - CECEFBEA16218008007A61C9 /* NSManagedObject+ObjectInManagedObjectContext.m in Sources */ = {isa = PBXBuildFile; fileRef = CECEFBE916218008007A61C9 /* NSManagedObject+ObjectInManagedObjectContext.m */; }; - CEF5A018168DA81200393AC0 /* JFFCoreDataAsyncOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CEF5A017168DA81200393AC0 /* JFFCoreDataAsyncOperation.m */; }; - CEF9F26516662A7A008310DA /* NSManagedObject+JSONParser.m in Sources */ = {isa = PBXBuildFile; fileRef = CEF9F26416662A7A008310DA /* NSManagedObject+JSONParser.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - CEA0980016216ED1005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA097E016216ED1005820FA /* Project object */; - proxyType = 1; - remoteGlobalIDString = CEA097E816216ED1005820FA; - remoteInfo = JFFCoreData; - }; - CEA0983C16217633005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0983416217632005820FA /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2AAC07E0554694100DB518D; - remoteInfo = JFFUtils; - }; - CEA0983E16217633005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0983416217632005820FA /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 65802A5B148BF2930040A93A; - remoteInfo = JFFUtilsMacOS; - }; - CEA0984016217633005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0983416217632005820FA /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 5391044314A88C04007315A3; - remoteInfo = "JFFUtils-clang"; - }; - CEA0984216217633005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0983416217632005820FA /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7E57F42414F93738002D139B; - remoteInfo = JFFUtilsFW; - }; - CEA0984416217633005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0983416217632005820FA /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = CE444A1C1608609100DD85B0; - remoteInfo = JFFUtilsTest; - }; - CEA0984C16217638005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0984616217638005820FA /* JFFAsyncOperations.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2AAC07E0554694100DB518D; - remoteInfo = JFFAsyncOperations; - }; - CEA0984E16217638005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0984616217638005820FA /* JFFAsyncOperations.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 5391037B14A88BB5007315A3; - remoteInfo = "JFFAsyncOperations-clang"; - }; - CEA0985016217638005820FA /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEA0984616217638005820FA /* JFFAsyncOperations.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7E8F20C914F94BDF00588C7D; - remoteInfo = JFFAsyncOperationsFW; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXCopyFilesBuildPhase section */ - CEA097E716216ED1005820FA /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = "include/${PRODUCT_NAME}"; - dstSubfolderSpec = 16; - files = ( - CEA097F216216ED1005820FA /* JFFCoreData.h in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - CE025683162B08E100481461 /* NSOrderedSet+ObjectInManagedObjectContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSOrderedSet+ObjectInManagedObjectContext.h"; sourceTree = ""; }; - CE025684162B08E100481461 /* NSOrderedSet+ObjectInManagedObjectContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSOrderedSet+ObjectInManagedObjectContext.m"; sourceTree = ""; }; - CE11ADED168C806C00D35C5C /* NSManagedObject+SaveAsyncOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObject+SaveAsyncOperation.h"; sourceTree = ""; }; - CE11ADEE168C806C00D35C5C /* NSManagedObject+SaveAsyncOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObject+SaveAsyncOperation.m"; sourceTree = ""; }; - CE8C6D131696D6A900B06045 /* JFFCoreDataError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCoreDataError.h; sourceTree = ""; }; - CE8C6D141696D6A900B06045 /* JFFCoreDataError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCoreDataError.m; sourceTree = ""; }; - CE8C6D161696D6ED00B06045 /* JFFNoManagedObjectError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFNoManagedObjectError.h; sourceTree = ""; }; - CE8C6D171696D6ED00B06045 /* JFFNoManagedObjectError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFNoManagedObjectError.m; sourceTree = ""; }; - CEA097E916216ED1005820FA /* libJFFCoreData.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFCoreData.a; sourceTree = BUILT_PRODUCTS_DIR; }; - CEA097EC16216ED1005820FA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - CEA097F016216ED1005820FA /* JFFCoreData-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JFFCoreData-Prefix.pch"; sourceTree = ""; }; - CEA097F116216ED1005820FA /* JFFCoreData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFCoreData.h; sourceTree = ""; }; - CEA097FA16216ED1005820FA /* JFFCoreDataTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JFFCoreDataTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; - CEA097FB16216ED1005820FA /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; - CEA097FD16216ED1005820FA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; - CEA0980516216ED1005820FA /* JFFCoreDataTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JFFCoreDataTests-Info.plist"; sourceTree = ""; }; - CEA0980716216ED1005820FA /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - CEA0980916216ED1005820FA /* JFFCoreDataTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFCoreDataTests.h; sourceTree = ""; }; - CEA0980A16216ED1005820FA /* JFFCoreDataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JFFCoreDataTests.m; sourceTree = ""; }; - CEA0981416216EE7005820FA /* JFFCoreDataProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCoreDataProvider.h; sourceTree = ""; }; - CEA0981516216EE7005820FA /* JFFCoreDataProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCoreDataProvider.m; sourceTree = ""; }; - CEA0982C16217259005820FA /* JFFCoreDataAsyncOperationAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCoreDataAsyncOperationAdapter.h; sourceTree = ""; }; - CEA0982D16217259005820FA /* JFFCoreDataAsyncOperationAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCoreDataAsyncOperationAdapter.m; sourceTree = ""; }; - CEA0983416217632005820FA /* JFFUtils.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFUtils.xcodeproj; path = ../JFFUtils/JFFUtils.xcodeproj; sourceTree = ""; }; - CEA0984616217638005820FA /* JFFAsyncOperations.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFAsyncOperations.xcodeproj; path = ../JFFAsyncOperations/JFFAsyncOperations.xcodeproj; sourceTree = ""; }; - CECEFBE216217FB0007A61C9 /* NSArray+ObjectInManagedObjectContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+ObjectInManagedObjectContext.h"; sourceTree = ""; }; - CECEFBE316217FB0007A61C9 /* NSArray+ObjectInManagedObjectContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+ObjectInManagedObjectContext.m"; sourceTree = ""; }; - CECEFBE516217FC7007A61C9 /* NSDictionary+ObjectInManagedObjectContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+ObjectInManagedObjectContext.h"; sourceTree = ""; }; - CECEFBE616217FC7007A61C9 /* NSDictionary+ObjectInManagedObjectContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+ObjectInManagedObjectContext.m"; sourceTree = ""; }; - CECEFBE816218008007A61C9 /* NSManagedObject+ObjectInManagedObjectContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObject+ObjectInManagedObjectContext.h"; sourceTree = ""; }; - CECEFBE916218008007A61C9 /* NSManagedObject+ObjectInManagedObjectContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObject+ObjectInManagedObjectContext.m"; sourceTree = ""; }; - CECEFBEB16218094007A61C9 /* JFFObjectInManagedObjectContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFObjectInManagedObjectContext.h; sourceTree = ""; }; - CEF5A013168DA6FB00393AC0 /* JFFCDReadWriteLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFCDReadWriteLock.h; sourceTree = ""; }; - CEF5A015168DA79400393AC0 /* JFFCoreDataAsyncBlocks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFCoreDataAsyncBlocks.h; sourceTree = ""; }; - CEF5A016168DA81200393AC0 /* JFFCoreDataAsyncOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCoreDataAsyncOperation.h; sourceTree = ""; }; - CEF5A017168DA81200393AC0 /* JFFCoreDataAsyncOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFCoreDataAsyncOperation.m; sourceTree = ""; }; - CEF9F26316662A7A008310DA /* NSManagedObject+JSONParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObject+JSONParser.h"; sourceTree = ""; }; - CEF9F26416662A7A008310DA /* NSManagedObject+JSONParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObject+JSONParser.m"; sourceTree = ""; }; - CEF9F26616662D5F008310DA /* JSONParserDefinitions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSONParserDefinitions.h; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - CEA097E616216ED1005820FA /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - CEA097ED16216ED1005820FA /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - CEA097F616216ED1005820FA /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - CEA097FC16216ED1005820FA /* SenTestingKit.framework in Frameworks */, - CEA097FE16216ED1005820FA /* UIKit.framework in Frameworks */, - CEA097FF16216ED1005820FA /* Foundation.framework in Frameworks */, - CEA0980216216ED1005820FA /* libJFFCoreData.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - CE11ADEC168C805500D35C5C /* Extensions */ = { - isa = PBXGroup; - children = ( - CE11ADED168C806C00D35C5C /* NSManagedObject+SaveAsyncOperation.h */, - CE11ADEE168C806C00D35C5C /* NSManagedObject+SaveAsyncOperation.m */, - ); - path = Extensions; - sourceTree = ""; - }; - CE8C6D091696D67C00B06045 /* Errors */ = { - isa = PBXGroup; - children = ( - CE8C6D131696D6A900B06045 /* JFFCoreDataError.h */, - CE8C6D141696D6A900B06045 /* JFFCoreDataError.m */, - CE8C6D161696D6ED00B06045 /* JFFNoManagedObjectError.h */, - CE8C6D171696D6ED00B06045 /* JFFNoManagedObjectError.m */, - ); - path = Errors; - sourceTree = ""; - }; - CEA097DE16216ED1005820FA = { - isa = PBXGroup; - children = ( - CEA097EE16216ED1005820FA /* JFFCoreData */, - CEA0983316217616005820FA /* Dependencies */, - CEA0980316216ED1005820FA /* JFFCoreDataTests */, - CEA097EB16216ED1005820FA /* Frameworks */, - CEA097EA16216ED1005820FA /* Products */, - ); - sourceTree = ""; - }; - CEA097EA16216ED1005820FA /* Products */ = { - isa = PBXGroup; - children = ( - CEA097E916216ED1005820FA /* libJFFCoreData.a */, - CEA097FA16216ED1005820FA /* JFFCoreDataTests.octest */, - ); - name = Products; - sourceTree = ""; - }; - CEA097EB16216ED1005820FA /* Frameworks */ = { - isa = PBXGroup; - children = ( - CEA097EC16216ED1005820FA /* Foundation.framework */, - CEA097FB16216ED1005820FA /* SenTestingKit.framework */, - CEA097FD16216ED1005820FA /* UIKit.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - CEA097EE16216ED1005820FA /* JFFCoreData */ = { - isa = PBXGroup; - children = ( - CE8C6D091696D67C00B06045 /* Errors */, - CEF5A009168DA6C400393AC0 /* AsyncCoreData */, - CE11ADEC168C805500D35C5C /* Extensions */, - CEF9F26216662A7A008310DA /* JSONParser */, - CECEFBE116217FA7007A61C9 /* ObjectInManagedObjectContext */, - CEA097EF16216ED1005820FA /* Supporting Files */, - CEA0981416216EE7005820FA /* JFFCoreDataProvider.h */, - CEA0981516216EE7005820FA /* JFFCoreDataProvider.m */, - CEA0982C16217259005820FA /* JFFCoreDataAsyncOperationAdapter.h */, - CEA0982D16217259005820FA /* JFFCoreDataAsyncOperationAdapter.m */, - CEA097F116216ED1005820FA /* JFFCoreData.h */, - ); - path = JFFCoreData; - sourceTree = ""; - }; - CEA097EF16216ED1005820FA /* Supporting Files */ = { - isa = PBXGroup; - children = ( - CEA097F016216ED1005820FA /* JFFCoreData-Prefix.pch */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - CEA0980316216ED1005820FA /* JFFCoreDataTests */ = { - isa = PBXGroup; - children = ( - CEA0980916216ED1005820FA /* JFFCoreDataTests.h */, - CEA0980A16216ED1005820FA /* JFFCoreDataTests.m */, - CEA0980416216ED1005820FA /* Supporting Files */, - ); - path = JFFCoreDataTests; - sourceTree = ""; - }; - CEA0980416216ED1005820FA /* Supporting Files */ = { - isa = PBXGroup; - children = ( - CEA0980516216ED1005820FA /* JFFCoreDataTests-Info.plist */, - CEA0980616216ED1005820FA /* InfoPlist.strings */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - CEA0983316217616005820FA /* Dependencies */ = { - isa = PBXGroup; - children = ( - CEA0984616217638005820FA /* JFFAsyncOperations.xcodeproj */, - CEA0983416217632005820FA /* JFFUtils.xcodeproj */, - ); - name = Dependencies; - sourceTree = ""; - }; - CEA0983516217632005820FA /* Products */ = { - isa = PBXGroup; - children = ( - CEA0983D16217633005820FA /* libJFFUtils.a */, - CEA0983F16217633005820FA /* libJFFUtilsMacOS.a */, - CEA0984116217633005820FA /* libJFFUtils-clang.a */, - CEA0984316217633005820FA /* JFFUtilsFW.framework */, - CEA0984516217633005820FA /* JFFUtilsTest.octest */, - ); - name = Products; - sourceTree = ""; - }; - CEA0984716217638005820FA /* Products */ = { - isa = PBXGroup; - children = ( - CEA0984D16217638005820FA /* libJFFAsyncOperations.a */, - CEA0984F16217638005820FA /* libJFFAsyncOperations-clang.a */, - CEA0985116217638005820FA /* JFFAsyncOperationsFW.framework */, - ); - name = Products; - sourceTree = ""; - }; - CECEFBE116217FA7007A61C9 /* ObjectInManagedObjectContext */ = { - isa = PBXGroup; - children = ( - CECEFBEB16218094007A61C9 /* JFFObjectInManagedObjectContext.h */, - CECEFBE216217FB0007A61C9 /* NSArray+ObjectInManagedObjectContext.h */, - CECEFBE316217FB0007A61C9 /* NSArray+ObjectInManagedObjectContext.m */, - CECEFBE516217FC7007A61C9 /* NSDictionary+ObjectInManagedObjectContext.h */, - CECEFBE616217FC7007A61C9 /* NSDictionary+ObjectInManagedObjectContext.m */, - CE025683162B08E100481461 /* NSOrderedSet+ObjectInManagedObjectContext.h */, - CE025684162B08E100481461 /* NSOrderedSet+ObjectInManagedObjectContext.m */, - CECEFBE816218008007A61C9 /* NSManagedObject+ObjectInManagedObjectContext.h */, - CECEFBE916218008007A61C9 /* NSManagedObject+ObjectInManagedObjectContext.m */, - ); - path = ObjectInManagedObjectContext; - sourceTree = ""; - }; - CEF5A009168DA6C400393AC0 /* AsyncCoreData */ = { - isa = PBXGroup; - children = ( - CEF5A013168DA6FB00393AC0 /* JFFCDReadWriteLock.h */, - CEF5A015168DA79400393AC0 /* JFFCoreDataAsyncBlocks.h */, - CEF5A016168DA81200393AC0 /* JFFCoreDataAsyncOperation.h */, - CEF5A017168DA81200393AC0 /* JFFCoreDataAsyncOperation.m */, - ); - path = AsyncCoreData; - sourceTree = ""; - }; - CEF9F26216662A7A008310DA /* JSONParser */ = { - isa = PBXGroup; - children = ( - CEF9F26616662D5F008310DA /* JSONParserDefinitions.h */, - CEF9F26316662A7A008310DA /* NSManagedObject+JSONParser.h */, - CEF9F26416662A7A008310DA /* NSManagedObject+JSONParser.m */, - ); - path = JSONParser; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - CEA097E816216ED1005820FA /* JFFCoreData */ = { - isa = PBXNativeTarget; - buildConfigurationList = CEA0980E16216ED1005820FA /* Build configuration list for PBXNativeTarget "JFFCoreData" */; - buildPhases = ( - CEA097E516216ED1005820FA /* Sources */, - CEA097E616216ED1005820FA /* Frameworks */, - CEA097E716216ED1005820FA /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = JFFCoreData; - productName = JFFCoreData; - productReference = CEA097E916216ED1005820FA /* libJFFCoreData.a */; - productType = "com.apple.product-type.library.static"; - }; - CEA097F916216ED1005820FA /* JFFCoreDataTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = CEA0981116216ED1005820FA /* Build configuration list for PBXNativeTarget "JFFCoreDataTests" */; - buildPhases = ( - CEA097F516216ED1005820FA /* Sources */, - CEA097F616216ED1005820FA /* Frameworks */, - CEA097F716216ED1005820FA /* Resources */, - CEA097F816216ED1005820FA /* ShellScript */, - ); - buildRules = ( - ); - dependencies = ( - CEA0980116216ED1005820FA /* PBXTargetDependency */, - ); - name = JFFCoreDataTests; - productName = JFFCoreDataTests; - productReference = CEA097FA16216ED1005820FA /* JFFCoreDataTests.octest */; - productType = "com.apple.product-type.bundle"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - CEA097E016216ED1005820FA /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0450; - ORGANIZATIONNAME = EmbeddedSources; - }; - buildConfigurationList = CEA097E316216ED1005820FA /* Build configuration list for PBXProject "JFFCoreData" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = CEA097DE16216ED1005820FA; - productRefGroup = CEA097EA16216ED1005820FA /* Products */; - projectDirPath = ""; - projectReferences = ( - { - ProductGroup = CEA0984716217638005820FA /* Products */; - ProjectRef = CEA0984616217638005820FA /* JFFAsyncOperations.xcodeproj */; - }, - { - ProductGroup = CEA0983516217632005820FA /* Products */; - ProjectRef = CEA0983416217632005820FA /* JFFUtils.xcodeproj */; - }, - ); - projectRoot = ""; - targets = ( - CEA097E816216ED1005820FA /* JFFCoreData */, - CEA097F916216ED1005820FA /* JFFCoreDataTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXReferenceProxy section */ - CEA0983D16217633005820FA /* libJFFUtils.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFUtils.a; - remoteRef = CEA0983C16217633005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEA0983F16217633005820FA /* libJFFUtilsMacOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFUtilsMacOS.a; - remoteRef = CEA0983E16217633005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEA0984116217633005820FA /* libJFFUtils-clang.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libJFFUtils-clang.a"; - remoteRef = CEA0984016217633005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEA0984316217633005820FA /* JFFUtilsFW.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework.static; - path = JFFUtilsFW.framework; - remoteRef = CEA0984216217633005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEA0984516217633005820FA /* JFFUtilsTest.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = JFFUtilsTest.octest; - remoteRef = CEA0984416217633005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEA0984D16217638005820FA /* libJFFAsyncOperations.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFAsyncOperations.a; - remoteRef = CEA0984C16217638005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEA0984F16217638005820FA /* libJFFAsyncOperations-clang.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libJFFAsyncOperations-clang.a"; - remoteRef = CEA0984E16217638005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEA0985116217638005820FA /* JFFAsyncOperationsFW.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework.static; - path = JFFAsyncOperationsFW.framework; - remoteRef = CEA0985016217638005820FA /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - -/* Begin PBXResourcesBuildPhase section */ - CEA097F716216ED1005820FA /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - CEA0980816216ED1005820FA /* InfoPlist.strings in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - CEA097F816216ED1005820FA /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - CEA097E516216ED1005820FA /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - CEA0981616216EE7005820FA /* JFFCoreDataProvider.m in Sources */, - CEA0982E16217259005820FA /* JFFCoreDataAsyncOperationAdapter.m in Sources */, - CECEFBE416217FB0007A61C9 /* NSArray+ObjectInManagedObjectContext.m in Sources */, - CECEFBE716217FC7007A61C9 /* NSDictionary+ObjectInManagedObjectContext.m in Sources */, - CECEFBEA16218008007A61C9 /* NSManagedObject+ObjectInManagedObjectContext.m in Sources */, - CE025685162B08E100481461 /* NSOrderedSet+ObjectInManagedObjectContext.m in Sources */, - CEF9F26516662A7A008310DA /* NSManagedObject+JSONParser.m in Sources */, - CE11ADEF168C806C00D35C5C /* NSManagedObject+SaveAsyncOperation.m in Sources */, - CEF5A018168DA81200393AC0 /* JFFCoreDataAsyncOperation.m in Sources */, - CE8C6D151696D6A900B06045 /* JFFCoreDataError.m in Sources */, - CE8C6D181696D6ED00B06045 /* JFFNoManagedObjectError.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - CEA097F516216ED1005820FA /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - CEA0980B16216ED1005820FA /* JFFCoreDataTests.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - CEA0980116216ED1005820FA /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = CEA097E816216ED1005820FA /* JFFCoreData */; - targetProxy = CEA0980016216ED1005820FA /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin PBXVariantGroup section */ - CEA0980616216ED1005820FA /* InfoPlist.strings */ = { - isa = PBXVariantGroup; - children = ( - CEA0980716216ED1005820FA /* en */, - ); - name = InfoPlist.strings; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - CEA0980C16216ED1005820FA /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ., - ../, - ); - IPHONEOS_DEPLOYMENT_TARGET = 5.1; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - CEA0980D16216ED1005820FA /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ., - ../, - ); - IPHONEOS_DEPLOYMENT_TARGET = 5.1; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - CEA0980F16216ED1005820FA /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - DSTROOT = /tmp/JFFCoreData.dst; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "JFFCoreData/JFFCoreData-Prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - CEA0981016216ED1005820FA /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - DSTROOT = /tmp/JFFCoreData.dst; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "JFFCoreData/JFFCoreData-Prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; - CEA0981216216ED1005820FA /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SDKROOT)/Developer/Library/Frameworks\"", - "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", - ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "JFFCoreData/JFFCoreData-Prefix.pch"; - INFOPLIST_FILE = "JFFCoreDataTests/JFFCoreDataTests-Info.plist"; - PRODUCT_NAME = "$(TARGET_NAME)"; - WRAPPER_EXTENSION = octest; - }; - name = Debug; - }; - CEA0981316216ED1005820FA /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SDKROOT)/Developer/Library/Frameworks\"", - "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", - ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "JFFCoreData/JFFCoreData-Prefix.pch"; - INFOPLIST_FILE = "JFFCoreDataTests/JFFCoreDataTests-Info.plist"; - PRODUCT_NAME = "$(TARGET_NAME)"; - WRAPPER_EXTENSION = octest; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - CEA097E316216ED1005820FA /* Build configuration list for PBXProject "JFFCoreData" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - CEA0980C16216ED1005820FA /* Debug */, - CEA0980D16216ED1005820FA /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - CEA0980E16216ED1005820FA /* Build configuration list for PBXNativeTarget "JFFCoreData" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - CEA0980F16216ED1005820FA /* Debug */, - CEA0981016216ED1005820FA /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - CEA0981116216ED1005820FA /* Build configuration list for PBXNativeTarget "JFFCoreDataTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - CEA0981216216ED1005820FA /* Debug */, - CEA0981316216ED1005820FA /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = CEA097E016216ED1005820FA /* Project object */; -} diff --git a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCDReadWriteLock.h b/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCDReadWriteLock.h deleted file mode 100644 index 7de2438..0000000 --- a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCDReadWriteLock.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef JFFCoreData_JFFCDReadWriteLock_h -#define JFFCoreData_JFFCDReadWriteLock_h - -typedef enum { - - JFFCDReadLock, - JFFCDWriteLock -} JFFCDReadWriteLock; - -#endif diff --git a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncBlocks.h b/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncBlocks.h deleted file mode 100644 index b69573d..0000000 --- a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncBlocks.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef JFFCoreData_JFFCoreDataAsyncBlocks_h -#define JFFCoreData_JFFCoreDataAsyncBlocks_h - -@class NSError; -@class NSManagedObjectContext; - -@protocol JFFObjectInManagedObjectContext; - -typedef id (^JFFCoreDataSyncOperation)(NSError *__autoreleasing *outError); - -typedef id (^JFFCoreDataSyncOperationWithObject)(id managedObject, NSError *__autoreleasing *outError); - -typedef JFFCoreDataSyncOperation (^JFFCoreDataSyncOperationFactory)(NSManagedObjectContext *context); -typedef JFFCoreDataSyncOperationWithObject (^JFFCoreDataSyncOperationWithObjectFactory)(NSManagedObjectContext *context); - -#endif diff --git a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncOperation.h b/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncOperation.h deleted file mode 100644 index 3d3c6f2..0000000 --- a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncOperation.h +++ /dev/null @@ -1,21 +0,0 @@ -#import - -#import - -#include -#include - -@class NSManagedObject; - -@protocol JFFObjectInManagedObjectContext; - -@interface JFFCoreDataAsyncOperation : NSObject - -+ (JFFAsyncOperation)operationWithBlock2:(JFFCoreDataSyncOperationFactory)block - readWrite:(JFFCDReadWriteLock)readWrite; - -+ (JFFAsyncOperation)operationWithRootObject2:(NSManagedObject *)managedObject - block:(JFFCoreDataSyncOperationWithObjectFactory)block - readWrite:(JFFCDReadWriteLock)readWrite; - -@end diff --git a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncOperation.m b/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncOperation.m deleted file mode 100644 index aba10a4..0000000 --- a/lib/JFFCoreData/JFFCoreData/AsyncCoreData/JFFCoreDataAsyncOperation.m +++ /dev/null @@ -1,130 +0,0 @@ -#import "JFFCoreDataAsyncOperation.h" - -#import "JFFCoreDataProvider.h" -#import "JFFObjectInManagedObjectContext.h" -#import "JFFNoManagedObjectError.h" - -#import - -@interface JFFCoreDataAsyncOperation () - -@property (copy, nonatomic) JFFCoreDataSyncOperation operationBlock; -@property (nonatomic) JFFCDReadWriteLock readWrite; -@property (nonatomic) NSManagedObjectContext *context; - -+ (dispatch_queue_t)coreDataQueue; - -@end - -@implementation JFFCoreDataAsyncOperation - -+ (dispatch_queue_t)coreDataQueue -{ - static dispatch_queue_t _coreDataQueue = nil; - - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - _coreDataQueue = dispatch_queue_create("com.jff_core_data.worker.library", DISPATCH_QUEUE_CONCURRENT); - }); - - return _coreDataQueue; -} - -#pragma mark - JFFAsyncOperationInterface - -- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler - cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler - progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress -{ - handler = [handler copy]; - - NSManagedObjectContext *mainContext = [[JFFCoreDataProvider sharedCoreDataProvider] contextForMainThread]; - - void (*dispatchAsyncMethod)(dispatch_queue_t, dispatch_block_t) = _readWrite == JFFCDWriteLock - ?&dispatch_barrier_async - :&dispatch_async; - - NSManagedObjectContext *context = self.context; - JFFCoreDataSyncOperation operationBlock = self.operationBlock; - - //TODO1 may be use the performBlock: here, test realy it concurrent on reading - dispatchAsyncMethod([[self class] coreDataQueue], ^{ - - NSError *error = nil; - id result = operationBlock(&error); - NSParameterAssert((result || error) && !(result && error)); - - if (_readWrite == JFFCDWriteLock) { - result = [context save:&error]?result:nil; - [[JFFCoreDataProvider sharedCoreDataProvider] saveRootContext]; - } - - dispatch_async(dispatch_get_main_queue(), ^() { - - id resultInMainContext = [result objectInManagedObjectContext:mainContext]; - //TODO try to avoid this call - [resultInMainContext updateManagedObjectFromContext]; - handler(resultInMainContext, error); - }); - }); -} - -- (void)cancel:(BOOL)canceled -{ -} - -+ (JFFAsyncOperation)operationWithBlock2:(JFFCoreDataSyncOperationFactory)block - readWrite:(JFFCDReadWriteLock)readWrite -{ - NSParameterAssert(block); - - block = [block copy]; - - JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { - - JFFCoreDataAsyncOperation *adapter = [self new]; - - NSManagedObjectContext *context = [[JFFCoreDataProvider sharedCoreDataProvider] newPrivateQueueConcurrentContext]; - - adapter.readWrite = readWrite; - adapter.context = context; - adapter.operationBlock = block(context); - - return adapter; - }; - - return buildAsyncOperationWithAdapterFactory(factory); -} - -+ (JFFAsyncOperation)operationWithRootObject2:(NSManagedObject *)managedObject - block:(JFFCoreDataSyncOperationWithObjectFactory)block - readWrite:(JFFCDReadWriteLock)readWrite -{ - block = [block copy]; - - JFFCoreDataSyncOperationFactory tmpBlock = ^(NSManagedObjectContext *context) { - - NSManagedObjectID *objectID = [managedObject objectID]; - - return ^id(NSError *__autoreleasing *outError) { - - NSError *error; - NSManagedObject *currManagedObject = [context existingObjectWithID:objectID error:&error]; - - [error writeErrorWithJFFLogger]; - if (!currManagedObject) { - - if (outError) { - *outError = [JFFNoManagedObjectError new]; - } - return nil; - } - - return block(context)(currManagedObject, outError); - }; - }; - - return [self operationWithBlock2:tmpBlock readWrite:readWrite]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/Errors/JFFCoreDataError.h b/lib/JFFCoreData/JFFCoreData/Errors/JFFCoreDataError.h deleted file mode 100644 index 15b5169..0000000 --- a/lib/JFFCoreData/JFFCoreData/Errors/JFFCoreDataError.h +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface JFFCoreDataError : JFFError -@end diff --git a/lib/JFFCoreData/JFFCoreData/Errors/JFFCoreDataError.m b/lib/JFFCoreData/JFFCoreData/Errors/JFFCoreDataError.m deleted file mode 100644 index a4166d6..0000000 --- a/lib/JFFCoreData/JFFCoreData/Errors/JFFCoreDataError.m +++ /dev/null @@ -1,10 +0,0 @@ -#import "JFFCoreDataError.h" - -@implementation JFFCoreDataError - -+ (NSString *)jffErrorsDomain -{ - return @"com.just_for_fun.core_data.library"; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/Errors/JFFNoManagedObjectError.h b/lib/JFFCoreData/JFFCoreData/Errors/JFFNoManagedObjectError.h deleted file mode 100644 index 50463b5..0000000 --- a/lib/JFFCoreData/JFFCoreData/Errors/JFFNoManagedObjectError.h +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface JFFNoManagedObjectError : JFFCoreDataError -@end diff --git a/lib/JFFCoreData/JFFCoreData/Errors/JFFNoManagedObjectError.m b/lib/JFFCoreData/JFFCoreData/Errors/JFFNoManagedObjectError.m deleted file mode 100644 index e3e6298..0000000 --- a/lib/JFFCoreData/JFFCoreData/Errors/JFFNoManagedObjectError.m +++ /dev/null @@ -1,10 +0,0 @@ -#import "JFFNoManagedObjectError.h" - -@implementation JFFNoManagedObjectError - -- (id)init -{ - return [self initWithDescription:NSLocalizedString(@"JFF_MANAGED_OBJECT_WAS_DELETED", nil)]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/Extensions/NSManagedObject+SaveAsyncOperation.h b/lib/JFFCoreData/JFFCoreData/Extensions/NSManagedObject+SaveAsyncOperation.h deleted file mode 100644 index 2c141ba..0000000 --- a/lib/JFFCoreData/JFFCoreData/Extensions/NSManagedObject+SaveAsyncOperation.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -#import - -@interface NSManagedObject (SaveAsyncOperation) - -- (JFFAsyncOperation)saveObjectLoader; - -- (JFFAsyncOperation)saveObjectLoaderWithChanges:(JFFAnalyzer)changes; - -@end diff --git a/lib/JFFCoreData/JFFCoreData/Extensions/NSManagedObject+SaveAsyncOperation.m b/lib/JFFCoreData/JFFCoreData/Extensions/NSManagedObject+SaveAsyncOperation.m deleted file mode 100644 index 17b24a6..0000000 --- a/lib/JFFCoreData/JFFCoreData/Extensions/NSManagedObject+SaveAsyncOperation.m +++ /dev/null @@ -1,79 +0,0 @@ -#import "NSManagedObject+SaveAsyncOperation.h" - -#import "JFFCoreDataAsyncOperationAdapter.h" - -#import "NSManagedObject+ObjectInManagedObjectContext.h" -#import "NSArray+ObjectInManagedObjectContext.h" - -#import - -#import "JFFCoreDataProvider.h" - -@implementation NSManagedObject (SaveAsyncOperation) - -- (JFFAsyncOperation)saveObjectLoader -{ - return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, - JFFCancelAsyncOperationHandler cancelCallback, - JFFDidFinishAsyncOperationHandler doneCallback) { - - //TODO12 refactor this - NSError *error; - BOOL saved = [self.managedObjectContext save:&error]; - - if (!saved) { - - [error writeErrorWithJFFLogger]; - if (doneCallback) - doneCallback(nil, error); - return JFFStubCancelAsyncOperationBlock; - } - - __block BOOL canceledOrFinishedFlag = NO; - - [[[JFFCoreDataProvider sharedCoreDataProvider] mediateRootContext] performBlock:^{ - - NSError *error; - [[[JFFCoreDataProvider sharedCoreDataProvider] mediateRootContext] save:&error]; - - dispatch_async(dispatch_get_main_queue(), ^{ - - if (!canceledOrFinishedFlag) { - canceledOrFinishedFlag = YES; - - //TODO weak self - if (doneCallback) - doneCallback(error?nil:self, error); - } - }); - }]; - - return ^(BOOL canceled) { - - if (!canceledOrFinishedFlag) { - - canceledOrFinishedFlag = YES; - if (cancelCallback) - cancelCallback(canceled); - } - }; - }; -} - -- (JFFAsyncOperation)saveObjectLoaderWithChanges:(JFFAnalyzer)changes -{ - JFFCoreDataSyncOperationWithObjectFactory block = ^JFFCoreDataSyncOperationWithObject(NSManagedObjectContext *context) { - - return ^id(NSManagedObjectID *object, NSError **outError) { - - NSManagedObject *result = changes(object, outError); - return result; - }; - }; - - return [JFFCoreDataAsyncOperationAdapter operationWithRootObject:self - block:block - readWrite:(JFFCDWriteLock)]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/JFFCoreData-Prefix.pch b/lib/JFFCoreData/JFFCoreData/JFFCoreData-Prefix.pch deleted file mode 100644 index 8165bd7..0000000 --- a/lib/JFFCoreData/JFFCoreData/JFFCoreData-Prefix.pch +++ /dev/null @@ -1,10 +0,0 @@ -// -// Prefix header for all source files of the 'JFFCoreData' target in the 'JFFCoreData' project -// - -#ifdef __OBJC__ - #import - - #import - #import -#endif diff --git a/lib/JFFCoreData/JFFCoreData/JFFCoreData.h b/lib/JFFCoreData/JFFCoreData/JFFCoreData.h deleted file mode 100644 index d3dfafc..0000000 --- a/lib/JFFCoreData/JFFCoreData/JFFCoreData.h +++ /dev/null @@ -1,17 +0,0 @@ - -#import -#import - -#import - -#import -#import -#import -#import - -#import - -#include -#include - -#import diff --git a/lib/JFFCoreData/JFFCoreData/JFFCoreDataAsyncOperationAdapter.h b/lib/JFFCoreData/JFFCoreData/JFFCoreDataAsyncOperationAdapter.h deleted file mode 100644 index 82a9e8a..0000000 --- a/lib/JFFCoreData/JFFCoreData/JFFCoreDataAsyncOperationAdapter.h +++ /dev/null @@ -1,22 +0,0 @@ -#import - -#import - -#include -#include - -@class NSManagedObject; - -@protocol JFFObjectInManagedObjectContext; - -@interface JFFCoreDataAsyncOperationAdapter : NSObject - -//TODO1 remove -+ (JFFAsyncOperation)operationWithBlock:(JFFCoreDataSyncOperationFactory)block - readWrite:(JFFCDReadWriteLock)readWrite; - -+ (JFFAsyncOperation)operationWithRootObject:(NSManagedObject *)managedObject - block:(JFFCoreDataSyncOperationWithObjectFactory)block - readWrite:(JFFCDReadWriteLock)readWrite; - -@end diff --git a/lib/JFFCoreData/JFFCoreData/JFFCoreDataAsyncOperationAdapter.m b/lib/JFFCoreData/JFFCoreData/JFFCoreDataAsyncOperationAdapter.m deleted file mode 100644 index a8e257a..0000000 --- a/lib/JFFCoreData/JFFCoreData/JFFCoreDataAsyncOperationAdapter.m +++ /dev/null @@ -1,155 +0,0 @@ -#import "JFFCoreDataAsyncOperationAdapter.h" - -#import "JFFCoreDataProvider.h" -#import "JFFObjectInManagedObjectContext.h" -#import "JFFNoManagedObjectError.h" - -#import - -@interface JFFCoreDataAsyncOperationAdapter () - -@property (copy, nonatomic) JFFCoreDataSyncOperation operationBlock; -@property (nonatomic) JFFCDReadWriteLock readWrite; -@property (nonatomic) NSManagedObjectContext *context; - -+ (dispatch_queue_t)coreDataQueue; - -@end - -@implementation JFFCoreDataAsyncOperationAdapter - -+ (dispatch_queue_t)coreDataQueue -{ - static dispatch_queue_t _coreDataQueue = nil; - - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - _coreDataQueue = dispatch_queue_create("com.jff_core_data.worker.library", DISPATCH_QUEUE_CONCURRENT); - }); - - return _coreDataQueue; -} - -#pragma mark - JFFAsyncOperationInterface - -- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler - cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler - progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress -{ - handler = [handler copy]; - - NSManagedObjectContext *mainContext = [[JFFCoreDataProvider sharedCoreDataProvider] contextForMainThread]; - - void (*dispatchAsyncMethod)(dispatch_queue_t, dispatch_block_t) = _readWrite == JFFCDWriteLock - ?&dispatch_barrier_async - :&dispatch_async; - - NSManagedObjectContext *context = self.context; - JFFCoreDataSyncOperation operationBlock = self.operationBlock; - - //TODO1 may be use the performBlock: here, test realy it concurrent on reading - dispatchAsyncMethod([[self class] coreDataQueue], ^{ - - NSError *error; - id result = operationBlock(&error); - NSParameterAssert((result || error) && !(result && error)); - - float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; - - if (_readWrite == JFFCDWriteLock) { - result = [context save:&error]?result:nil; - [[JFFCoreDataProvider sharedCoreDataProvider] saveRootContext]; - - if (osVersion >= 6.0) { - BOOL obtained = [result obtainPermanentIDsIfNeedsWithError:&error]; - result = obtained?result:nil; - } - } - - dispatch_async(dispatch_get_main_queue(), ^() { - - if (error) { - - handler(nil, error); - return; - } - - id resultInMainContext = [result objectInManagedObjectContext:mainContext]; - - if (osVersion >= 6.0) { - NSError *error; - BOOL obtained = [resultInMainContext obtainPermanentIDsIfNeedsWithError:&error]; - if (!obtained) { - - handler(nil, error); - return; - } - } - - //TODO try to avoid this call - [resultInMainContext updateManagedObjectFromContext]; - handler(resultInMainContext, error); - }); - }); -} - -- (void)cancel:(BOOL)canceled -{ -} - -+ (JFFAsyncOperation)operationWithBlock:(JFFCoreDataSyncOperationFactory)block - readWrite:(JFFCDReadWriteLock)readWrite -{ - NSParameterAssert(block); - - block = [block copy]; - - JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { - - JFFCoreDataAsyncOperationAdapter *adapter = [self new]; - - NSManagedObjectContext *context = [[JFFCoreDataProvider sharedCoreDataProvider] newPrivateQueueConcurrentContext]; - - adapter.readWrite = readWrite; - adapter.context = context; - adapter.operationBlock = block(context); - - return adapter; - }; - - return buildAsyncOperationWithAdapterFactory(factory); -} - -+ (JFFAsyncOperation)operationWithRootObject:(NSManagedObject *)managedObject - block:(JFFCoreDataSyncOperationWithObjectFactory)block - readWrite:(JFFCDReadWriteLock)readWrite -{ - block = [block copy]; - - NSManagedObjectID *objectID = managedObject.objectID; - NSParameterAssert(objectID && ![objectID isTemporaryID]); - - JFFCoreDataSyncOperationFactory tmpBlock = ^(NSManagedObjectContext *context) { - - return ^id(NSError *__autoreleasing *outError) { - - NSError *error; - NSManagedObject *currManagedObject = [context existingObjectWithID:objectID error:&error]; - - [error writeErrorWithJFFLogger]; - if (!currManagedObject) { - - if (outError) { - *outError = [JFFNoManagedObjectError new]; - } - return nil; - } - - return block(context)(currManagedObject, outError); - }; - }; - - return [self operationWithBlock:tmpBlock readWrite:readWrite]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/JFFCoreDataProvider.h b/lib/JFFCoreData/JFFCoreData/JFFCoreDataProvider.h deleted file mode 100644 index 1949764..0000000 --- a/lib/JFFCoreData/JFFCoreData/JFFCoreDataProvider.h +++ /dev/null @@ -1,19 +0,0 @@ -#import - -@class NSManagedObjectContext; - -@interface JFFCoreDataProvider : NSObject - -- (NSManagedObjectContext *)contextForMainThread; -- (NSManagedObjectContext *)newPrivateQueueConcurrentContext; -- (NSManagedObjectContext *)mediateRootContext; - -- (void)resetMainThreadContext; - -+ (id)sharedCoreDataProvider; - -- (void)saveRootContext; - -- (BOOL)removeDatabaseFile:(NSError **)outError; - -@end diff --git a/lib/JFFCoreData/JFFCoreData/JFFCoreDataProvider.m b/lib/JFFCoreData/JFFCoreData/JFFCoreDataProvider.m deleted file mode 100644 index 767b9e5..0000000 --- a/lib/JFFCoreData/JFFCoreData/JFFCoreDataProvider.m +++ /dev/null @@ -1,211 +0,0 @@ -#import "JFFCoreDataProvider.h" - -@interface JFFCoreDataProvider () - -@property (nonatomic) NSManagedObjectContext *mediateRootContext; - -@property (readonly) NSManagedObjectModel *managedObjectModel; -@property (readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; - -@end - -@implementation JFFCoreDataProvider -{ - NSManagedObjectContext *_contextForMainThread; -} - -+ (id)sharedCoreDataProvider -{ - static dispatch_once_t once; - static id sharedInstance; - dispatch_once(&once, ^{ - sharedInstance = [self new]; - }); - return sharedInstance; -} - -@synthesize managedObjectModel = _managedObjectModel; -@synthesize persistentStoreCoordinator = _persistentStoreCoordinator; - -- (NSManagedObjectContext *)newPrivateQueueConcurrentContext -{ - //TODO1 may be use NSConfinementConcurrencyType - NSManagedObjectContext *result = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; - result.parentContext = self.mediateRootContext; - return result; -} - -- (NSManagedObjectContext *)contextForMainThread -{ - if (_contextForMainThread != nil) - return _contextForMainThread; - - _contextForMainThread = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; - _contextForMainThread.parentContext = self.mediateRootContext; - - NSMergePolicy *mergePolicy = [[NSMergePolicy alloc] initWithMergeType:NSMergeByPropertyObjectTrumpMergePolicyType]; - [_contextForMainThread setMergePolicy:mergePolicy]; - - _contextForMainThread.undoManager = [NSUndoManager new]; - [_contextForMainThread.undoManager disableUndoRegistration]; - - return _contextForMainThread; -} - -- (void)resetMainThreadContext -{ - _contextForMainThread = nil; -} - -+ (NSManagedObjectModel *)newManagedObjectModelNamed:(NSString *)modelFileName -{ - NSString *path = [[NSBundle mainBundle] pathForResource:[modelFileName stringByDeletingPathExtension] - ofType:[modelFileName pathExtension]]; - NSURL *momURL = [NSURL fileURLWithPath:path]; - - NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL]; - return model; -} - -+ (NSManagedObjectModel *)managedObjectModelNamed:(NSString *)modelFileName -{ - return [self newManagedObjectModelNamed:modelFileName]; -} - -- (NSManagedObjectModel *)managedObjectModel -{ - if (_managedObjectModel != nil) - return _managedObjectModel; - - _managedObjectModel = [[self class] managedObjectModelNamed:@"Wishdates.momd"]; - - return _managedObjectModel; -} - -- (NSPersistentStoreCoordinator *)newPersistentStoreCoordinator -{ - NSURL *documentsStoreURL = [self dataBaseFileURL]; - NSError *error; - - NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; - - if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType - configuration:nil - URL:documentsStoreURL - options:nil - error: &error]) { - NSLog(@"Unresolved error %@, %@", error, [error userInfo]); - - if (error.domain == NSCocoaErrorDomain) { - NSLog(@"Old store found"); - NSFileManager *fileManager = [NSFileManager defaultManager]; - - if ([fileManager removeItemAtURL:documentsStoreURL error:&error]) { - if ([persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType - configuration:nil - URL:documentsStoreURL - options:nil - error:&error]) { - NSLog(@" created new _persistentStoreCoordinator"); - } else { - NSLog(@"Unresolved error %@, %@", error, [error userInfo]); - abort(); - } - } else { - NSLog(@"Unresolved error %@, %@", error, [error userInfo]); - abort(); - } - } - else - abort(); - } - - [[documentsStoreURL path] addSkipBackupAttribute]; - - return persistentStoreCoordinator; -} - -- (NSURL *)dataBaseFileURL -{ - return [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Wishdates.sqlite"]; -} - -- (BOOL)removeDatabaseFile:(NSError **)outError -{ - NSURL *dbUrl = [self dataBaseFileURL]; - NSFileManager *fileManager = [NSFileManager defaultManager]; - - BOOL result = YES; - if ([fileManager fileExistsAtPath:dbUrl.path]) { - result = [fileManager removeItemAtURL:dbUrl error:outError]; - } - - _contextForMainThread = nil; - _mediateRootContext = nil; - _persistentStoreCoordinator = nil; - - return result; -} - -- (NSPersistentStoreCoordinator *)persistentStoreCoordinator -{ - if (_persistentStoreCoordinator) - return _persistentStoreCoordinator; - - @synchronized(self) { - if (_persistentStoreCoordinator) - return _persistentStoreCoordinator; - - _persistentStoreCoordinator = [self newPersistentStoreCoordinator]; - - return _persistentStoreCoordinator; - } -} - -#pragma mark - Application's Documents directory - -- (NSURL *)applicationDocumentsDirectory // returns the URL to the application's Documents directory -{ - NSArray *urls = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory - inDomains:NSUserDomainMask]; - return [urls lastObject]; -} - -#pragma mark - Mediate context - -- (NSManagedObjectContext *)mediateRootContext -{ - if (_mediateRootContext) - return _mediateRootContext; - - @synchronized(self) { - - if (_mediateRootContext) - return _mediateRootContext; - - NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; - - _mediateRootContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:(NSPrivateQueueConcurrencyType)]; - [_mediateRootContext setPersistentStoreCoordinator: coordinator]; - - NSMergePolicy *mergePolicy = [[NSMergePolicy alloc] initWithMergeType:NSMergeByPropertyStoreTrumpMergePolicyType]; - [_mediateRootContext setMergePolicy:mergePolicy]; - } - - return _mediateRootContext; -} - -- (void)saveRootContext -{ - //TODO may be performBlockAndWait should used - [self.mediateRootContext performBlock:^{ - NSError *error; - [self.mediateRootContext save:&error]; - - if (error) { - NSLog(@"Error during saving root context: %@", error); - } - }]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/JSONParser/JSONParserDefinitions.h b/lib/JFFCoreData/JFFCoreData/JSONParser/JSONParserDefinitions.h deleted file mode 100644 index c678711..0000000 --- a/lib/JFFCoreData/JFFCoreData/JSONParser/JSONParserDefinitions.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef JFFCoreData_JSONParserDefinitions_h -#define JFFCoreData_JSONParserDefinitions_h - -@class NSArray; -@class NSManagedObject; - -//this block should return object like @[key, values] -typedef NSArray*(^JFFCoreDataCachePrimaryKeys)(NSArray *jsonObject); - -typedef NSManagedObject*(^JFFCoreDataModelParser)(id jsonObject, - NSManagedObject* cachedObject, - NSError **outError); - -#endif diff --git a/lib/JFFCoreData/JFFCoreData/JSONParser/NSManagedObject+JSONParser.h b/lib/JFFCoreData/JFFCoreData/JSONParser/NSManagedObject+JSONParser.h deleted file mode 100644 index f6466bc..0000000 --- a/lib/JFFCoreData/JFFCoreData/JSONParser/NSManagedObject+JSONParser.h +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#import -#import - -@interface NSManagedObject (JSONParser) - -//TODO rename to Just data parser -+ (NSArray *)managedObjectsInContext:(NSManagedObjectContext *)context - arrayData:(NSArray *)arrayData - primaryKeys:(JFFCoreDataCachePrimaryKeys)primaryKeys - parser:(JFFCoreDataModelParser)parser - error:(NSError *__autoreleasing *)outError; - -@end diff --git a/lib/JFFCoreData/JFFCoreData/JSONParser/NSManagedObject+JSONParser.m b/lib/JFFCoreData/JFFCoreData/JSONParser/NSManagedObject+JSONParser.m deleted file mode 100644 index 0a4d1b9..0000000 --- a/lib/JFFCoreData/JFFCoreData/JSONParser/NSManagedObject+JSONParser.m +++ /dev/null @@ -1,99 +0,0 @@ -#import "NSManagedObject+JSONParser.h" - -#import "JFFCoreDataProvider.h" - -@implementation NSManagedObject (JSONParser) - -+ (NSArray *)cachedManagedObjectsInContext:(NSManagedObjectContext *)context - arrayData:(NSArray *)arrayData - primaryKeys:(JFFCoreDataCachePrimaryKeys)primaryKeysBlock -{ - if (!primaryKeysBlock || [arrayData count] == 0) - return nil; - - NSArray *primaryKeyAndValues = primaryKeysBlock(arrayData); - NSParameterAssert([primaryKeyAndValues count] == 2); - - NSString *modelKey = primaryKeyAndValues[0]; - NSArray *primaryKeyValues = primaryKeyAndValues[1]; - - NSParameterAssert([primaryKeyValues count] == [arrayData count]); - - NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:NSStringFromClass([self class])]; - request.predicate = [NSPredicate predicateWithFormat:@"%K IN (%@)", modelKey, primaryKeyValues]; - request.includesPendingChanges = YES; - request.fetchLimit = [arrayData count]; - - NSError *error; - NSArray *cachedObjects = [context executeFetchRequest:request error:&error]; - - NSParameterAssert(!error); - NSParameterAssert(cachedObjects); - - //TODO remove jffMeaningClass at all - Class anyPrimaryKeyValue = [primaryKeyValues[0] jffMeaningClass]; - - NSMutableDictionary *objectByKeys = [NSMutableDictionary new]; - for (NSManagedObject *mnObject in cachedObjects) { - - id key = [mnObject valueForKey:modelKey]; - - NSParameterAssert([key isKindOfClass:anyPrimaryKeyValue]); - - objectByKeys[key] = mnObject; - } - - return @[cachedObjects, primaryKeyValues, [objectByKeys copy]]; -} - -//TODO move to public -+ (id)createManagedObjectInContext:(NSManagedObjectContext *)context -{ - NSString *entityName = NSStringFromClass([self class]); - return [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:context]; -} - -+ (NSArray *)managedObjectsInContext:(NSManagedObjectContext *)context - arrayData:(NSArray *)arrayData - primaryKeys:(JFFCoreDataCachePrimaryKeys)primaryKeys - parser:(JFFCoreDataModelParser)parser - error:(NSError *__autoreleasing *)outError -{ - NSParameterAssert(context); - NSParameterAssert(parser); - NSParameterAssert([arrayData isKindOfClass:[NSArray class]]); - - NSArray *cachedObjectsResult = [self cachedManagedObjectsInContext:context - arrayData:arrayData - primaryKeys:primaryKeys]; - - NSArray *cachedObjects ; - NSArray *primaryKeyValues ; - NSDictionary *objectByKeys; - if (cachedObjectsResult) { - cachedObjects = cachedObjectsResult[0]; - primaryKeyValues = cachedObjectsResult[1]; - objectByKeys = cachedObjectsResult[2]; - } - - NSArray *objects = [arrayData mapWithIndex:^id(NSDictionary *jsonObject, - NSInteger idx, - NSError *__autoreleasing *outError) { - - NSManagedObject *cachedObject; - if (cachedObjectsResult) { - cachedObject = objectByKeys[primaryKeyValues[idx]]; - } - - cachedObject = cachedObject?:[self createManagedObjectInContext:context]; - NSManagedObject *model = parser(jsonObject, cachedObject, outError); - return model; - } error:outError]; - - if (!objects) - return nil; - - return objects; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/JFFObjectInManagedObjectContext.h b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/JFFObjectInManagedObjectContext.h deleted file mode 100644 index a3dc775..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/JFFObjectInManagedObjectContext.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -@class NSManagedObjectContext; - -@protocol JFFObjectInManagedObjectContext - -@required -- (id)objectInManagedObjectContext:(NSManagedObjectContext *)context; -- (void)updateManagedObjectFromContext; -- (BOOL)obtainPermanentIDsIfNeedsWithError:(NSError **)outError; - -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSArray+ObjectInManagedObjectContext.h b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSArray+ObjectInManagedObjectContext.h deleted file mode 100644 index 9280ef5..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSArray+ObjectInManagedObjectContext.h +++ /dev/null @@ -1,6 +0,0 @@ -#import - -#import - -@interface NSArray (ObjectInManagedObjectContext) -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSArray+ObjectInManagedObjectContext.m b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSArray+ObjectInManagedObjectContext.m deleted file mode 100644 index 2c932f7..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSArray+ObjectInManagedObjectContext.m +++ /dev/null @@ -1,45 +0,0 @@ -#import "NSArray+ObjectInManagedObjectContext.h" - -#import "NSManagedObject+ObjectInManagedObjectContext.h" - -@implementation NSArray (ObjectInManagedObjectContext) - -- (id)objectInManagedObjectContext:(NSManagedObjectContext *)context -{ - return [self map:^id(NSManagedObject *object) { - return [object objectInManagedObjectContext:context]; - }]; -} - -- (void)updateManagedObjectFromContext -{ - [self enumerateObjectsUsingBlock:^(NSManagedObject *obj, NSUInteger idx, BOOL *stop) { - [obj updateManagedObjectFromContext]; - }]; -} - -- (NSManagedObject *)managedObjectForObject -{ - [self doesNotRecognizeSelector:_cmd]; - return nil; -} - -- (BOOL)obtainPermanentIDsIfNeedsWithError:(NSError **)outError -{ - NSArray *managedObjects = [self map:^id(id object) { - - return [object managedObjectForObject]; - }]; - - NSArray *toObtain = [managedObjects select:^BOOL(NSManagedObject *object) { - return [object.objectID isTemporaryID]; - }]; - - if ([toObtain count] == 0) - return YES; - - NSManagedObjectContext *context = [toObtain[0] managedObjectContext]; - return [context obtainPermanentIDsForObjects:toObtain error:outError]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSDictionary+ObjectInManagedObjectContext.h b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSDictionary+ObjectInManagedObjectContext.h deleted file mode 100644 index 481213f..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSDictionary+ObjectInManagedObjectContext.h +++ /dev/null @@ -1,6 +0,0 @@ -#import - -#import - -@interface NSDictionary (ObjectInManagedObjectContext) -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSDictionary+ObjectInManagedObjectContext.m b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSDictionary+ObjectInManagedObjectContext.m deleted file mode 100644 index 7e3cfd6..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSDictionary+ObjectInManagedObjectContext.m +++ /dev/null @@ -1,36 +0,0 @@ -#import "NSDictionary+ObjectInManagedObjectContext.h" - -#import "NSManagedObject+ObjectInManagedObjectContext.h" - -@implementation NSDictionary (ObjectInManagedObjectContext) - -- (id)objectInManagedObjectContext:(NSManagedObjectContext *)context -{ - return [self map:^id(id key, NSManagedObject *object) { - return [object objectInManagedObjectContext:context]; - }]; -} - -- (void)updateManagedObjectFromContext -{ - [self enumerateKeysAndObjectsUsingBlock:^(id key, NSManagedObject *obj, BOOL *stop) { - [obj updateManagedObjectFromContext]; - }]; -} - -- (BOOL)obtainPermanentIDsIfNeedsWithError:(NSError **)outError -{ - NSDictionary *toObtainDict = [self select:^BOOL(id key, NSManagedObject *object) { - return object.objectID.isTemporaryID; - }]; - - if ([toObtainDict count] == 0) - return YES; - - NSArray *toObtain = [toObtainDict allValues]; - - NSManagedObjectContext *context = [toObtain[0] managedObjectContext]; - return [context obtainPermanentIDsForObjects:toObtain error:outError]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSManagedObject+ObjectInManagedObjectContext.h b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSManagedObject+ObjectInManagedObjectContext.h deleted file mode 100644 index edad5a7..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSManagedObject+ObjectInManagedObjectContext.h +++ /dev/null @@ -1,6 +0,0 @@ -#import - -#import - -@interface NSManagedObject (ObjectInManagedObjectContext) -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSManagedObject+ObjectInManagedObjectContext.m b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSManagedObject+ObjectInManagedObjectContext.m deleted file mode 100644 index 0a3780b..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSManagedObject+ObjectInManagedObjectContext.m +++ /dev/null @@ -1,31 +0,0 @@ -#import "NSManagedObject+ObjectInManagedObjectContext.h" - -@implementation NSManagedObject (ObjectInManagedObjectContext) - -- (id)objectInManagedObjectContext:(NSManagedObjectContext *)context -{ - NSParameterAssert(![context isEqual:self.managedObjectContext]); - id newObject = [context objectWithID:self.objectID]; - return newObject; -} - -- (void)updateManagedObjectFromContext -{ - [self.managedObjectContext refreshObject:self mergeChanges:YES]; -} - -- (BOOL)obtainPermanentIDsIfNeedsWithError:(NSError **)outError -{ - if (!self.objectID.isTemporaryID) - return YES; - - NSManagedObjectContext *context = [self managedObjectContext]; - return [context obtainPermanentIDsForObjects:@[self] error:outError]; -} - -- (NSManagedObject *)managedObjectForObject -{ - return self; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSOrderedSet+ObjectInManagedObjectContext.h b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSOrderedSet+ObjectInManagedObjectContext.h deleted file mode 100644 index 3242e3b..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSOrderedSet+ObjectInManagedObjectContext.h +++ /dev/null @@ -1,6 +0,0 @@ -#import - -#import - -@interface NSOrderedSet (ObjectInManagedObjectContext) -@end diff --git a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSOrderedSet+ObjectInManagedObjectContext.m b/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSOrderedSet+ObjectInManagedObjectContext.m deleted file mode 100644 index c6db26e..0000000 --- a/lib/JFFCoreData/JFFCoreData/ObjectInManagedObjectContext/NSOrderedSet+ObjectInManagedObjectContext.m +++ /dev/null @@ -1,34 +0,0 @@ -#import "NSOrderedSet+ObjectInManagedObjectContext.h" - -#import "NSManagedObject+ObjectInManagedObjectContext.h" - -@implementation NSOrderedSet (ObjectInManagedObjectContext) - -- (id)objectInManagedObjectContext:(NSManagedObjectContext *)context -{ - return [self map:^id(NSManagedObject *object) { - return [object objectInManagedObjectContext:context]; - }]; -} - -- (void)updateManagedObjectFromContext -{ - [self enumerateObjectsUsingBlock:^(NSManagedObject *obj, NSUInteger idx, BOOL *stop) { - [obj updateManagedObjectFromContext]; - }]; -} - -- (BOOL)obtainPermanentIDsIfNeedsWithError:(NSError **)outError -{ - NSOrderedSet *toObtain = [self select:^BOOL(NSManagedObject *object) { - return object.objectID.isTemporaryID; - }]; - - if ([toObtain count] == 0) - return YES; - - NSManagedObjectContext *context = [toObtain[0] managedObjectContext]; - return [context obtainPermanentIDsForObjects:[toObtain array] error:outError]; -} - -@end diff --git a/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests-Info.plist b/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests-Info.plist deleted file mode 100644 index b80638c..0000000 --- a/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests-Info.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - com.EmbeddedSources.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests.h b/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests.h deleted file mode 100644 index ed92da7..0000000 --- a/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// JFFCoreDataTests.h -// JFFCoreDataTests -// -// Created by user on 07.10.12. -// Copyright (c) 2012 EmbeddedSources. All rights reserved. -// - -#import - -@interface JFFCoreDataTests : SenTestCase - -@end diff --git a/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests.m b/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests.m deleted file mode 100644 index dbb975a..0000000 --- a/lib/JFFCoreData/JFFCoreDataTests/JFFCoreDataTests.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// JFFCoreDataTests.m -// JFFCoreDataTests -// -// Created by user on 07.10.12. -// Copyright (c) 2012 EmbeddedSources. All rights reserved. -// - -#import "JFFCoreDataTests.h" - -@implementation JFFCoreDataTests - -- (void)setUp -{ - [super setUp]; - - // Set-up code here. -} - -- (void)tearDown -{ - // Tear-down code here. - - [super tearDown]; -} - -- (void)testExample -{ - STFail(@"Unit tests are not implemented yet in JFFCoreDataTests"); -} - -@end diff --git a/lib/JFFCoreData/JFFCoreDataTests/en.lproj/InfoPlist.strings b/lib/JFFCoreData/JFFCoreDataTests/en.lproj/InfoPlist.strings deleted file mode 100644 index 477b28f..0000000 --- a/lib/JFFCoreData/JFFCoreDataTests/en.lproj/InfoPlist.strings +++ /dev/null @@ -1,2 +0,0 @@ -/* Localized versions of Info.plist keys */ - diff --git a/lib/JFFCoreLocation/JFFCoreLocation.xcodeproj/project.pbxproj b/lib/JFFCoreLocation/JFFCoreLocation.xcodeproj/project.pbxproj index 88cf99c..84f4568 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation.xcodeproj/project.pbxproj +++ b/lib/JFFCoreLocation/JFFCoreLocation.xcodeproj/project.pbxproj @@ -251,7 +251,7 @@ CE206DE716414CC2002476FD /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0450; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = EmbeddedSources; }; buildConfigurationList = CE206DEA16414CC2002476FD /* Build configuration list for PBXProject "JFFCoreLocation" */; @@ -349,13 +349,12 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -364,6 +363,7 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( @@ -371,6 +371,7 @@ ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; }; name = Debug; @@ -379,14 +380,14 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( @@ -394,6 +395,7 @@ ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -405,6 +407,7 @@ DSTROOT = /tmp/JFFCoreLocation.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFCoreLocation/JFFCoreLocation-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -417,6 +420,7 @@ DSTROOT = /tmp/JFFCoreLocation.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFCoreLocation/JFFCoreLocation-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFCoreLocationError.h b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFCoreLocationError.h index 79e592f..6b05d4f 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFCoreLocationError.h +++ b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFCoreLocationError.h @@ -1,4 +1,4 @@ -#import +#import @interface JFFCoreLocationError : JFFError @end diff --git a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFLocationServicesDisabledError.m b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFLocationServicesDisabledError.m index a935b2a..fa3509e 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFLocationServicesDisabledError.m +++ b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFLocationServicesDisabledError.m @@ -2,7 +2,7 @@ @implementation JFFLocationServicesDisabledError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"JFF_LOCALIZATION_SERVICE_NOT_ENABLED", nil)]; } diff --git a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFNoPlacemarksError.m b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFNoPlacemarksError.m index 8860b43..6e999eb 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFNoPlacemarksError.m +++ b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFNoPlacemarksError.m @@ -2,12 +2,12 @@ @implementation JFFNoPlacemarksError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"JFF_NO_PLACEMARK_FOR_LOCATION", nil)]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFNoPlacemarksError *copy = [super copyWithZone:zone]; diff --git a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFUnableToGetLocationError.m b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFUnableToGetLocationError.m index dfcc3b3..7ccad62 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFUnableToGetLocationError.m +++ b/lib/JFFCoreLocation/JFFCoreLocation/Errors/JFFUnableToGetLocationError.m @@ -2,9 +2,13 @@ @implementation JFFUnableToGetLocationError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"JFF_UNABLE_TO_GET_LOCATION_ERROR", nil)]; } +- (void)writeErrorWithJFFLogger +{ +} + @end diff --git a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.h b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.h index 27469d0..dc74136 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.h +++ b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.h @@ -13,7 +13,7 @@ @property(readonly, nonatomic) CLLocation *location; -+ (id)sharedLocationLoaderSupervisorWithAccuracy:(CLLocationAccuracy)accuracy; ++ (instancetype)sharedLocationLoaderSupervisorWithAccuracy:(CLLocationAccuracy)accuracy; - (void)addLocationObserver:(id)observer; - (void)removeLocationObserver:(id)observer; diff --git a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.m b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.m index 5192972..ccae318 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.m +++ b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/Details/JFFLocationLoaderSupervisor.m @@ -17,12 +17,12 @@ - (void)dealloc _locationManager = nil; } -- (id)initWithAccuracy:(CLLocationAccuracy)accuracy +- (instancetype)initWithAccuracy:(CLLocationAccuracy)accuracy { self = [super init]; if (self) { - _accuracy = accuracy; + _accuracy = accuracy; _observers = [JFFMutableAssignArray new]; __weak JFFLocationLoaderSupervisor *weakSelf = self; @@ -34,9 +34,9 @@ - (id)initWithAccuracy:(CLLocationAccuracy)accuracy return self; } -+ (id)sharedLocationLoaderSupervisorWithAccuracy:(CLLocationAccuracy)accuracy ++ (instancetype)sharedLocationLoaderSupervisorWithAccuracy:(CLLocationAccuracy)accuracy { - NSParameterAssert(accuracy == kCLLocationAccuracyHundredMeters); + NSParameterAssert(accuracy == kCLLocationAccuracyKilometer); __weak static id instance; diff --git a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFLocationLoader.m b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFLocationLoader.m index 129c9bc..acf3e7a 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFLocationLoader.m +++ b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFLocationLoader.m @@ -22,7 +22,7 @@ @implementation JFFCoreLocationAsyncAdapter JFFScheduler *_scheduler; } -- (id)initWithAccuracy:(CLLocationAccuracy)accuracy +- (instancetype)initWithAccuracy:(CLLocationAccuracy)accuracy { self = [super init]; @@ -33,7 +33,7 @@ - (id)initWithAccuracy:(CLLocationAccuracy)accuracy return self; } -+ (id)newCoreLocationAsyncAdapterWithAccuracy:(double)accuracyInMeters ++ (instancetype)newCoreLocationAsyncAdapterWithAccuracy:(double)accuracyInMeters { return [[self alloc] initWithAccuracy:accuracyInMeters]; } @@ -71,7 +71,7 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler cancel(); [weakSelf onSchedulerWithHandler:handler]; - } duration:1.]; + } duration:3. leeway:.5]; } - (void)onSchedulerWithHandler:(JFFAsyncOperationInterfaceResultHandler)handler @@ -108,8 +108,8 @@ - (BOOL)processLocation:(CLLocation *)location if (!location) return NO; - if (location.horizontalAccuracy <= 200. - && location.verticalAccuracy <= 200.) { + if (location.horizontalAccuracy <= 2000. + && location.verticalAccuracy <= 2000.) { [self forceProcessLocation:location]; return YES; @@ -131,7 +131,7 @@ @implementation JFFLocationLoader + (JFFAsyncOperation)locationLoaderWithAccuracy:(CLLocationAccuracy)accuracy { - NSParameterAssert(accuracy == kCLLocationAccuracyHundredMeters); + NSParameterAssert(accuracy == kCLLocationAccuracyKilometer); JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { return [JFFCoreLocationAsyncAdapter newCoreLocationAsyncAdapterWithAccuracy:accuracy]; @@ -141,7 +141,6 @@ + (JFFAsyncOperation)locationLoaderWithAccuracy:(CLLocationAccuracy)accuracy id key = @{ @"accuracy" : @(accuracy), @"method" : NSStringFromSelector(_cmd), - @"class" : [self description], }; return [self asyncOperationMergeLoaders:loader withArgument:key]; } diff --git a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFPlacemarksLoader.m b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFPlacemarksLoader.m index f9a9e11..0d35e5f 100644 --- a/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFPlacemarksLoader.m +++ b/lib/JFFCoreLocation/JFFCoreLocation/asyncAdapters/JFFPlacemarksLoader.m @@ -30,7 +30,7 @@ @implementation JFFPlacemarksAsyncAdapter CLGeocoder *_geocoder; } -- (id)initWithLocation:(CLLocation *)location +- (instancetype)initWithLocation:(CLLocation *)location { NSParameterAssert(location); @@ -43,7 +43,7 @@ - (id)initWithLocation:(CLLocation *)location return self; } -+ (id)newPlacemarksAsyncAdapterWithLocation:(CLLocation *)location ++ (instancetype)newPlacemarksAsyncAdapterWithLocation:(CLLocation *)location { return [[self alloc] initWithLocation:location]; } @@ -76,7 +76,7 @@ @implementation JFFPlacemarksLoader + (JFFAsyncOperation)placemarksLoaderForCurrentLocationWithAccuracy:(CLLocationAccuracy)accuracy { - NSParameterAssert(accuracy == kCLLocationAccuracyHundredMeters); + NSParameterAssert(accuracy == kCLLocationAccuracyKilometer); JFFAsyncOperation locationLoader = [JFFLocationLoader locationLoaderWithAccuracy:accuracy]; @@ -88,7 +88,7 @@ + (JFFAsyncOperation)placemarksLoaderForCurrentLocationWithAccuracy:(CLLocationA + (JFFAsyncOperation)placemarkLoaderForCurrentLocationWithAccuracy:(CLLocationAccuracy)accuracy { - NSParameterAssert(accuracy == kCLLocationAccuracyHundredMeters); + NSParameterAssert(accuracy == kCLLocationAccuracyKilometer); JFFAsyncOperation locationLoader = [JFFLocationLoader locationLoaderWithAccuracy:accuracy]; @@ -110,7 +110,6 @@ + (JFFAsyncOperation)placemarksLoaderForLocation:(CLLocation *)location id key = @{ @"location" : [location uniqueLocationIdentificator], @"method" : NSStringFromSelector(_cmd), - @"class" : [self description], }; return [self asyncOperationMergeLoaders:loader withArgument:key]; } diff --git a/lib/JFFJsonTools/JFFJsonTools.xcodeproj/project.pbxproj b/lib/JFFJsonTools/JFFJsonTools.xcodeproj/project.pbxproj index 9d2114d..b205dfb 100644 --- a/lib/JFFJsonTools/JFFJsonTools.xcodeproj/project.pbxproj +++ b/lib/JFFJsonTools/JFFJsonTools.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ CE532D0B160375190029920A /* JFFJsonValidationError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE532D0A160375190029920A /* JFFJsonValidationError.m */; }; CE532D12160379190029920A /* libJFFAsyncOperations.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE532C7E16036D9A0029920A /* libJFFAsyncOperations.a */; }; CE532D13160379190029920A /* libJFFScheduler.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE532C5516036D3E0029920A /* libJFFScheduler.a */; }; - CE532D14160379190029920A /* libJFFUtils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE532C4316036D380029920A /* libJFFUtils.a */; }; CE532D16160379590029920A /* libc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CE532D15160379590029920A /* libc++.dylib */; }; CE532D18160379660029920A /* libstdc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CE532D17160379660029920A /* libstdc++.dylib */; }; CE5330BF160722760029920A /* NSObject+JFFJsonObjectValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = CE5330BE160722760029920A /* NSObject+JFFJsonObjectValidator.m */; }; @@ -33,41 +32,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - CE444A681608653700DD85B0 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE532C3816036D380029920A /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = CE444A1C1608609100DD85B0; - remoteInfo = JFFUtilsTest; - }; - CE532C4216036D380029920A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE532C3816036D380029920A /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2AAC07E0554694100DB518D; - remoteInfo = JFFUtils; - }; - CE532C4416036D380029920A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE532C3816036D380029920A /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 65802A5B148BF2930040A93A; - remoteInfo = JFFUtilsMacOS; - }; - CE532C4616036D380029920A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE532C3816036D380029920A /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 5391044314A88C04007315A3; - remoteInfo = "JFFUtils-clang"; - }; - CE532C4816036D380029920A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE532C3816036D380029920A /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7E57F42414F93738002D139B; - remoteInfo = JFFUtilsFW; - }; CE532C5416036D3E0029920A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CE532C4A16036D3E0029920A /* JFFScheduler.xcodeproj */; @@ -131,13 +95,6 @@ remoteGlobalIDString = D2AAC07D0554694100DB518D; remoteInfo = JFFScheduler; }; - CE532D10160379070029920A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE532C3816036D380029920A /* JFFUtils.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = D2AAC07D0554694100DB518D; - remoteInfo = JFFUtils; - }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -166,7 +123,6 @@ CE532C2A16036CE40029920A /* JFFJsonValidatorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JFFJsonValidatorTests.m; sourceTree = ""; }; CE532C3416036D1B0029920A /* JFFJsonValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFJsonValidator.h; sourceTree = ""; }; CE532C3516036D1B0029920A /* JFFJsonValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFJsonValidator.m; sourceTree = ""; }; - CE532C3816036D380029920A /* JFFUtils.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFUtils.xcodeproj; path = ../JFFUtils/JFFUtils.xcodeproj; sourceTree = ""; }; CE532C4A16036D3E0029920A /* JFFScheduler.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFScheduler.xcodeproj; path = ../JFFScheduler/JFFScheduler.xcodeproj; sourceTree = ""; }; CE532C7016036D9A0029920A /* JFFAsyncOperations.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFAsyncOperations.xcodeproj; path = ../JFFAsyncOperations/JFFAsyncOperations.xcodeproj; sourceTree = ""; }; CE532C8416036DB90029920A /* JFFAsyncJSONParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncJSONParser.h; sourceTree = ""; }; @@ -210,7 +166,6 @@ CE532D16160379590029920A /* libc++.dylib in Frameworks */, CE532D12160379190029920A /* libJFFAsyncOperations.a in Frameworks */, CE532D13160379190029920A /* libJFFScheduler.a in Frameworks */, - CE532D14160379190029920A /* libJFFUtils.a in Frameworks */, CE532C1C16036CE40029920A /* SenTestingKit.framework in Frameworks */, CE532C1F16036CE40029920A /* Foundation.framework in Frameworks */, CE532C2216036CE40029920A /* libJFFJsonTools.a in Frameworks */, @@ -302,23 +257,10 @@ children = ( CE532C7016036D9A0029920A /* JFFAsyncOperations.xcodeproj */, CE532C4A16036D3E0029920A /* JFFScheduler.xcodeproj */, - CE532C3816036D380029920A /* JFFUtils.xcodeproj */, ); name = Dependencies; sourceTree = ""; }; - CE532C3916036D380029920A /* Products */ = { - isa = PBXGroup; - children = ( - CE532C4316036D380029920A /* libJFFUtils.a */, - CE532C4516036D380029920A /* libJFFUtilsMacOS.a */, - CE532C4716036D380029920A /* libJFFUtils-clang.a */, - CE532C4916036D380029920A /* JFFUtilsFW.framework */, - CE444A691608653700DD85B0 /* JFFUtilsTest.octest */, - ); - name = Products; - sourceTree = ""; - }; CE532C4B16036D3E0029920A /* Products */ = { isa = PBXGroup; children = ( @@ -400,7 +342,6 @@ dependencies = ( CE532D0D160379070029920A /* PBXTargetDependency */, CE532D0F160379070029920A /* PBXTargetDependency */, - CE532D11160379070029920A /* PBXTargetDependency */, ); name = JFFJsonToolsTests; productName = JFFJsonToolsTests; @@ -413,7 +354,7 @@ CE532C0016036CE40029920A /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = EmbeddedSources; }; buildConfigurationList = CE532C0316036CE40029920A /* Build configuration list for PBXProject "JFFJsonTools" */; @@ -435,10 +376,6 @@ ProductGroup = CE532C4B16036D3E0029920A /* Products */; ProjectRef = CE532C4A16036D3E0029920A /* JFFScheduler.xcodeproj */; }, - { - ProductGroup = CE532C3916036D380029920A /* Products */; - ProjectRef = CE532C3816036D380029920A /* JFFUtils.xcodeproj */; - }, ); projectRoot = ""; targets = ( @@ -449,41 +386,6 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - CE444A691608653700DD85B0 /* JFFUtilsTest.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = JFFUtilsTest.octest; - remoteRef = CE444A681608653700DD85B0 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE532C4316036D380029920A /* libJFFUtils.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFUtils.a; - remoteRef = CE532C4216036D380029920A /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE532C4516036D380029920A /* libJFFUtilsMacOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFUtilsMacOS.a; - remoteRef = CE532C4416036D380029920A /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE532C4716036D380029920A /* libJFFUtils-clang.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libJFFUtils-clang.a"; - remoteRef = CE532C4616036D380029920A /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE532C4916036D380029920A /* JFFUtilsFW.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework.static; - path = JFFUtilsFW.framework; - remoteRef = CE532C4816036D380029920A /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE532C5516036D3E0029920A /* libJFFScheduler.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -600,11 +502,6 @@ name = JFFScheduler; targetProxy = CE532D0E160379070029920A /* PBXContainerItemProxy */; }; - CE532D11160379070029920A /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFUtils; - targetProxy = CE532D10160379070029920A /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -623,15 +520,16 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -639,15 +537,18 @@ "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; @@ -657,24 +558,28 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -687,6 +592,7 @@ DSTROOT = /tmp/JFFJsonTools.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFJsonTools/JFFJsonTools-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; @@ -698,6 +604,7 @@ DSTROOT = /tmp/JFFJsonTools.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFJsonTools/JFFJsonTools-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; diff --git a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.h b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.h index 8b285e5..31f8c94 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.h +++ b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.h @@ -4,7 +4,7 @@ @property (nonatomic, readonly, copy) id fieldKey; -+ (id)newOptionalObjectFieldWithFieldKey:(id)fieldKey; ++ (instancetype)newOptionalObjectFieldWithFieldKey:(id)fieldKey; @end diff --git a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.m b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.m index 0f8cfa9..58f0b3b 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.m +++ b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldKey.m @@ -2,7 +2,7 @@ @implementation JFFOptionalObjectFieldKey : NSObject -+ (id)newOptionalObjectFieldWithFieldKey:(id)fieldKey ++ (instancetype)newOptionalObjectFieldWithFieldKey:(id)fieldKey { JFFOptionalObjectFieldKey *result = [self new]; @@ -13,7 +13,7 @@ + (id)newOptionalObjectFieldWithFieldKey:(id)fieldKey return result; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFOptionalObjectFieldKey *copy = [[[self class] allocWithZone:zone] init]; diff --git a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.h b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.h index 6fff9aa..baae17d 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.h +++ b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.h @@ -4,7 +4,7 @@ @property (nonatomic, readonly) id fieldValue; -+ (id)newOptionalObjectFieldWithFieldValue:(id)fieldValue; ++ (instancetype)newOptionalObjectFieldWithFieldValue:(id)fieldValue; @end diff --git a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.m b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.m index 4cfed1d..847f5b3 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.m +++ b/lib/JFFJsonTools/JFFJsonTools/Details/JFFOptionalObjectFieldValue.m @@ -2,7 +2,7 @@ @implementation JFFOptionalObjectFieldValue : NSObject -+ (id)newOptionalObjectFieldWithFieldValue:(id)fieldValue ++ (instancetype)newOptionalObjectFieldWithFieldValue:(id)fieldValue { JFFOptionalObjectFieldValue *result = [self new]; diff --git a/lib/JFFJsonTools/JFFJsonTools/Details/NSObject+JFFJsonObjectValidator.m b/lib/JFFJsonTools/JFFJsonTools/Details/NSObject+JFFJsonObjectValidator.m index d409f01..7c1bbce 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Details/NSObject+JFFJsonObjectValidator.m +++ b/lib/JFFJsonTools/JFFJsonTools/Details/NSObject+JFFJsonObjectValidator.m @@ -4,7 +4,6 @@ #import "JFFOptionalObjectFieldKey.h" #import "JFFOptionalObjectFieldValue.h" -#include #include static BOOL isClass(id object) @@ -76,24 +75,10 @@ - (BOOL)validateWithJsonPattern:(id)jsonPattern rootJsonObject:rootJsonObject rootJsonPattern:rootJsonPattern error:outError]) { + return NO; } - - return [self validateWithJsonPatternValue:jsonPattern - rootJsonObject:rootJsonObject - rootJsonPattern:rootJsonPattern - error:outError]; -} - -@end - -@implementation NSNull (JFFJsonObjectValidator) - -- (BOOL)validateWithJsonPattern:(id)jsonPattern - rootJsonObject:(id)rootJsonObject - rootJsonPattern:(id)rootJsonPattern - error:(NSError *__autoreleasing *)outError -{ + return [self validateWithJsonPatternValue:jsonPattern rootJsonObject:rootJsonObject rootJsonPattern:rootJsonPattern diff --git a/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonToolsError.h b/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonToolsError.h index b413dd7..840e8ef 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonToolsError.h +++ b/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonToolsError.h @@ -1,4 +1,4 @@ -#import +#import @interface JFFJsonToolsError : JFFError @end diff --git a/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonValidationError.m b/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonValidationError.m index 1a288f0..0bf5709 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonValidationError.m +++ b/lib/JFFJsonTools/JFFJsonTools/Errors/JFFJsonValidationError.m @@ -2,12 +2,12 @@ @implementation JFFJsonValidationError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"JSON_VALIDATION_ERROR", nil)]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFJsonValidationError *copy = [super copyWithZone:zone]; @@ -20,9 +20,13 @@ - (id)copyWithZone:(NSZone *)zone return copy; } -- (void)writeErrorWithJFFLogger +- (NSString *)errorLogDescription { - [JFFLogger logErrorWithFormat:@"%@ jsonObject:%@ jsonPattern:%@ message:%@", [self localizedDescription], _jsonObject, _jsonPattern, _message]; + return [[NSString alloc] initWithFormat:@"%@ jsonObject:%@ jsonPattern:%@ message:%@", + [self localizedDescription], + _jsonObject, + _jsonPattern, + _message]; } @end diff --git a/lib/JFFJsonTools/JFFJsonTools/Errors/JFFParseJsonError.m b/lib/JFFJsonTools/JFFJsonTools/Errors/JFFParseJsonError.m index 950a9fa..792b7b6 100644 --- a/lib/JFFJsonTools/JFFJsonTools/Errors/JFFParseJsonError.m +++ b/lib/JFFJsonTools/JFFJsonTools/Errors/JFFParseJsonError.m @@ -2,12 +2,12 @@ @implementation JFFParseJsonError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"PARSE_JSON_ERROR", nil)]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFParseJsonError *copy = [super copyWithZone:zone]; @@ -20,9 +20,12 @@ - (id)copyWithZone:(NSZone *)zone return copy; } -- (void)writeErrorWithJFFLogger +- (NSString *)errorLogDescription { - [JFFLogger logErrorWithFormat:@"%@ context: %@ data: %@", [self localizedDescription], _context, [_data toString]]; + return [[NSString alloc] initWithFormat:@"%@ context: %@ data: %@", + [self localizedDescription], + _context, + [_data toString]]; } @end diff --git a/lib/JFFJsonTools/JFFJsonTools/JFFAsyncJSONParser.m b/lib/JFFJsonTools/JFFJsonTools/JFFAsyncJSONParser.m index 4af166f..4409b48 100644 --- a/lib/JFFJsonTools/JFFJsonTools/JFFAsyncJSONParser.m +++ b/lib/JFFJsonTools/JFFJsonTools/JFFAsyncJSONParser.m @@ -4,7 +4,7 @@ JFFAsyncOperation asyncOperationJsonDataParserWithContext(NSData *data, id context) { - assert([data isKindOfClass:[NSData class]]); + NSCParameterAssert([data isKindOfClass:[NSData class]]); JFFSyncOperation loadDataBlock = ^id(NSError **outError) { NSError *jsonError; @@ -26,7 +26,7 @@ JFFAsyncOperation asyncOperationJsonDataParserWithContext(NSData *data, id + +@interface NSData (DataForHTTPPost) + ++ (instancetype)dataForHTTPPostWithData:(NSData *)data + andFileName:(NSString *)fileName + andParameterName:(NSString *)parameter + boundary:(NSString *)boundary; + +@end + +@interface NSMutableData (DataForHTTPPost) + +- (void)appendHTTPParameters:(NSDictionary *)parameters + boundary:(NSString *)boundary; + +@end diff --git a/lib/JFFNetwork/Categories/NSData+DataForHTTPPost.m b/lib/JFFNetwork/Categories/NSData+DataForHTTPPost.m new file mode 100644 index 0000000..a78e454 --- /dev/null +++ b/lib/JFFNetwork/Categories/NSData+DataForHTTPPost.m @@ -0,0 +1,43 @@ +#import "NSData+DataForHTTPPost.h" + +@implementation NSData (DataForHTTPPost) + ++ (instancetype)dataForHTTPPostWithData:(NSData *)data + andFileName:(NSString *)fileName + andParameterName:(NSString *)parameter + boundary:(NSString *)boundary +{ + NSMutableData *result = [[self alloc] initWithCapacity:[data length] + 512]; + [result appendData:[[[NSString alloc] initWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + [result appendData:[[[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", parameter, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; + + [result appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; + + [result appendData:data]; + + [result appendData:[[[NSString alloc] initWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + + return result; +} + +@end + +@implementation NSMutableData (DataForHTTPPost) + +- (void)appendHTTPParameters:(NSDictionary *)parameters + boundary:(NSString *)boundary +{ + if (!parameters) { + return; + } + + [parameters enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { + + [self appendData:[[[NSString alloc] initWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + [self appendData:[[[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]]; + [self appendData:[[obj description] dataUsingEncoding:NSUTF8StringEncoding]]; + [self appendData:[[[NSString alloc] initWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + }]; +} + +@end diff --git a/lib/JFFNetwork/Categories/NSDictionary+JHTTPHeaders.h b/lib/JFFNetwork/Categories/NSDictionary+JHTTPHeaders.h new file mode 100644 index 0000000..6260406 --- /dev/null +++ b/lib/JFFNetwork/Categories/NSDictionary+JHTTPHeaders.h @@ -0,0 +1,11 @@ +#import + +@interface NSDictionary (JHTTPHeaders) + +- (instancetype)initWithContentType:(NSString *)contentType; ++ (instancetype)headersDictionadyWithUploadContentType; + ++ (NSString *)utf8XmlContentType; ++ (instancetype)headersDictionadyWithUtf8XmlContentType; + +@end diff --git a/lib/JFFNetwork/Categories/NSDictionary+JHTTPHeaders.m b/lib/JFFNetwork/Categories/NSDictionary+JHTTPHeaders.m new file mode 100644 index 0000000..f2651c0 --- /dev/null +++ b/lib/JFFNetwork/Categories/NSDictionary+JHTTPHeaders.m @@ -0,0 +1,32 @@ +#import "NSDictionary+JHTTPHeaders.h" + +@implementation NSDictionary (JHTTPHeaders) + +- (instancetype)initWithContentType:( NSString* )contentType +{ + NSParameterAssert(contentType); + + id objects[] = {contentType }; + id keys [] = {@"Content-Type"}; + + return [self initWithObjects:objects forKeys:keys count:1]; +} + ++ (instancetype)headersDictionadyWithUploadContentType +{ + return [[self alloc] initWithContentType:@"application/x-www-form-urlencoded"]; +} + +#pragma mark - +#pragma mark UTF8 xml ++ (NSString *)utf8XmlContentType +{ + return @"application/xml;charset=utf-8"; +} + ++ (instancetype)headersDictionadyWithUtf8XmlContentType +{ + return [[self alloc] initWithContentType:[self utf8XmlContentType]]; +} + +@end diff --git a/lib/JFFNetwork/CookiesStorage/Details/NSHTTPCookie+matchesURL.h b/lib/JFFNetwork/Categories/NSHTTPCookie+MatchesURL.h old mode 100755 new mode 100644 similarity index 69% rename from lib/JFFNetwork/CookiesStorage/Details/NSHTTPCookie+matchesURL.h rename to lib/JFFNetwork/Categories/NSHTTPCookie+MatchesURL.h index 7ba9dd6..a8a10f9 --- a/lib/JFFNetwork/CookiesStorage/Details/NSHTTPCookie+matchesURL.h +++ b/lib/JFFNetwork/Categories/NSHTTPCookie+MatchesURL.h @@ -2,6 +2,6 @@ @interface NSHTTPCookie (matchesURL) --(BOOL)matchesURL:( NSURL* )url_; +- (BOOL)matchesURL:(NSURL *)url; @end diff --git a/lib/JFFNetwork/Categories/NSHTTPCookie+MatchesURL.m b/lib/JFFNetwork/Categories/NSHTTPCookie+MatchesURL.m new file mode 100644 index 0000000..85a8c82 --- /dev/null +++ b/lib/JFFNetwork/Categories/NSHTTPCookie+MatchesURL.m @@ -0,0 +1,13 @@ +#import "NSHTTPCookie+matchesURL.h" + +#import "NSString+RFC_2965.h" + +@implementation NSHTTPCookie (matchesURL) + +- (BOOL)matchesURL:(NSURL *)url +{ + return [url.host domainMatchesCookiesDomain:self.domain] + && [url.path pathMatchesCookiesPath:self.path]; +} + +@end diff --git a/lib/JFFNetwork/Extensions/NSMutableURLRequest+CreateRequestWithURLParams.h b/lib/JFFNetwork/Categories/NSMutableURLRequest+CreateRequestWithURLParams.h old mode 100755 new mode 100644 similarity index 63% rename from lib/JFFNetwork/Extensions/NSMutableURLRequest+CreateRequestWithURLParams.h rename to lib/JFFNetwork/Categories/NSMutableURLRequest+CreateRequestWithURLParams.h index 9f27259..831e16c --- a/lib/JFFNetwork/Extensions/NSMutableURLRequest+CreateRequestWithURLParams.h +++ b/lib/JFFNetwork/Categories/NSMutableURLRequest+CreateRequestWithURLParams.h @@ -4,6 +4,6 @@ @interface NSMutableURLRequest (CreateRequestWithURLParams) -+ (id)mutableURLRequestWithParams:(JFFURLConnectionParams *)params; ++ (instancetype)mutableURLRequestWithParams:(JFFURLConnectionParams *)params; @end diff --git a/lib/JFFNetwork/Extensions/NSMutableURLRequest+CreateRequestWithURLParams.m b/lib/JFFNetwork/Categories/NSMutableURLRequest+CreateRequestWithURLParams.m old mode 100755 new mode 100644 similarity index 58% rename from lib/JFFNetwork/Extensions/NSMutableURLRequest+CreateRequestWithURLParams.m rename to lib/JFFNetwork/Categories/NSMutableURLRequest+CreateRequestWithURLParams.m index 06ced96..de1084c --- a/lib/JFFNetwork/Extensions/NSMutableURLRequest+CreateRequestWithURLParams.m +++ b/lib/JFFNetwork/Categories/NSMutableURLRequest+CreateRequestWithURLParams.m @@ -5,9 +5,11 @@ @implementation NSMutableURLRequest (CreateRequestWithURLParams) -+ (id)mutableURLRequestWithParams:(JFFURLConnectionParams *)params ++ (instancetype)mutableURLRequestWithParams:(JFFURLConnectionParams *)params { - NSParameterAssert((!params.httpBody && !params.httpBodyStream) || !(params.httpBody && params.httpBodyStream)); + NSInputStream *inputStream = params.httpBodyStreamBuilder?params.httpBodyStreamBuilder():nil; + + NSParameterAssert((!params.httpBody && !inputStream) || !(params.httpBody && inputStream)); static const NSTimeInterval timeout = 60.; NSMutableURLRequest *request = [self requestWithURL:params.url @@ -15,16 +17,16 @@ + (id)mutableURLRequestWithParams:(JFFURLConnectionParams *)params timeoutInterval:timeout]; NSString *httpMethod = params.httpMethod ?: @"GET"; - if (!params.httpMethod && (params.httpBody || params.httpBodyStream)) { + if (!params.httpMethod && (params.httpBody || inputStream)) { httpMethod = @"POST"; } - [request setHTTPBodyStream:params.httpBodyStream]; + [request setHTTPBodyStream:inputStream]; if (params.httpBody) [request setHTTPBody:params.httpBody]; - [request setAllHTTPHeaderFields:params.headers ]; - [request setHTTPMethod :httpMethod ]; + [request setAllHTTPHeaderFields:params.headers]; + [request setHTTPMethod :httpMethod ]; return request; } diff --git a/lib/JFFNetwork/Extensions/NSURL+Cookies.h b/lib/JFFNetwork/Categories/NSURL+Cookies.h old mode 100755 new mode 100644 similarity index 61% rename from lib/JFFNetwork/Extensions/NSURL+Cookies.h rename to lib/JFFNetwork/Categories/NSURL+Cookies.h index 7d31744..b2e382c --- a/lib/JFFNetwork/Extensions/NSURL+Cookies.h +++ b/lib/JFFNetwork/Categories/NSURL+Cookies.h @@ -2,7 +2,7 @@ @interface NSURL (Cookies) --(void)logCookies; --(void)removeCookies; +- (void)logCookies; +- (void)removeCookies; @end diff --git a/lib/JFFNetwork/Categories/NSURL+Cookies.m b/lib/JFFNetwork/Categories/NSURL+Cookies.m new file mode 100644 index 0000000..ee1ac09 --- /dev/null +++ b/lib/JFFNetwork/Categories/NSURL+Cookies.m @@ -0,0 +1,27 @@ +#import "NSURL+Cookies.h" + +@implementation NSURL (Cookies) + +- (void)logCookies +{ + NSMutableString *cookiesLog = [[NSMutableString alloc] initWithFormat:@"Cookies for url: %@\n", self]; + + NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:self]; + for (NSHTTPCookie *cookie in cookies) { + + [cookiesLog appendFormat:@"Name: '%@'; Value: '%@'\n", cookie.name, cookie.value]; + } + + NSLog(@"%@", cookiesLog); +} + +- (void)removeCookies +{ + NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:self]; + for (NSHTTPCookie *cookie in cookies) { + + [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; + } +} + +@end diff --git a/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.h b/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.h index fcb842f..acc39d9 100755 --- a/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.h +++ b/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.h @@ -6,9 +6,11 @@ @interface JNConnectionsFactory : NSObject --(id)initWithURLConnectionParams:( JFFURLConnectionParams* )params_; +- (instancetype)initWithURLConnectionParams:(JFFURLConnectionParams *)params; --(id< JNUrlConnection >)createFastConnection; --(id< JNUrlConnection >)createStandardConnection; +- (id< JNUrlConnection >)createFastConnection; +- (id< JNUrlConnection >)createStandardConnection; + +- (id< JNUrlConnection >)createConnection; @end diff --git a/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.m b/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.m index dc7814e..f476a30 100755 --- a/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.m +++ b/lib/JFFNetwork/ConnectionsFactory/JNConnectionsFactory.m @@ -11,13 +11,13 @@ @implementation JNConnectionsFactory #pragma mark - #pragma mark Constructor --(id)init +- (instancetype)init { [ self doesNotRecognizeSelector: _cmd ]; return nil; } -- (id)initWithURLConnectionParams:(JFFURLConnectionParams *)params +- (instancetype)initWithURLConnectionParams:(JFFURLConnectionParams *)params { NSParameterAssert(params.url); @@ -32,14 +32,30 @@ - (id)initWithURLConnectionParams:(JFFURLConnectionParams *)params #pragma mark - #pragma mark Factory --(id< JNUrlConnection >)createFastConnection +- (id< JNUrlConnection >)createFastConnection { return [[JFFURLConnection alloc] initWithURLConnectionParams:_params]; } --(id< JNUrlConnection >)createStandardConnection +- (id< JNUrlConnection >)createStandardConnection { return [[JNNsUrlConnection alloc] initWithURLConnectionParams:_params]; } +- (id< JNUrlConnection >)createConnection +{ + if (nil == _params) { + + return nil; + } + else if (_params.useLiveConnection) { + + return [self createFastConnection]; + } + else { + + return [self createStandardConnection]; + } +} + @end diff --git a/lib/JFFNetwork/ContentEncodings/JNGzipCustomErrors.h b/lib/JFFNetwork/ContentEncodings/JNGzipCustomErrors.h index a9e88d8..880d968 100755 --- a/lib/JFFNetwork/ContentEncodings/JNGzipCustomErrors.h +++ b/lib/JFFNetwork/ContentEncodings/JNGzipCustomErrors.h @@ -3,12 +3,12 @@ @class NSString; -extern NSString* kGzipErrorDomain; +extern NSString *kGzipErrorDomain; -enum JNCustomGzipErrorsEnum +typedef NS_ENUM(NSInteger, JNCustomGzipErrorsEnum) { - kJNGzipInitFailed = -100 - , kJNGzipUnexpectedEOF = -101 + kJNGzipInitFailed = -100, + kJNGzipUnexpectedEOF = -101 }; #endif diff --git a/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.h b/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.h index f31bb21..8d94343 100755 --- a/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.h +++ b/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.h @@ -2,8 +2,8 @@ #import -@interface JNGzipDecoder : NSObject < JNHttpDecoder > +@interface JNGzipDecoder : NSObject --(id)initWithContentLength:( unsigned long long )contentLength_; +- (instancetype)initWithContentLength:(unsigned long long)contentLength; @end diff --git a/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.m b/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.m index 1268470..fb02639 100755 --- a/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.m +++ b/lib/JFFNetwork/ContentEncodings/JNGzipDecoder.m @@ -15,48 +15,46 @@ @implementation JNGzipDecoder unsigned long long _contentLength; } --(id)init +- (instancetype)init { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; return nil; } --(id)initWithContentLength:( unsigned long long )contentLength_ +- (instancetype)initWithContentLength:(unsigned long long)contentLength { - self = [ super init ]; - if ( nil == self ) - { + self = [super init]; + if (nil == self) { return nil; } - self->_contentLength = contentLength_; + _contentLength = contentLength; return self; } --(BOOL)openZipStreamWithError:( NSError** )outError +- (BOOL)openZipStreamWithError:(NSError **)outError { - if ( self->_isOpen ) - { + if (_isOpen) { + return YES; } - - self->_strm.total_out = 0; - self->_strm.zalloc = Z_NULL; - self->_strm.zfree = Z_NULL; - - + + _strm.total_out = 0; + _strm.zalloc = Z_NULL; + _strm.zfree = Z_NULL; + //!! dodikk -- WTF Magic - int initResult = inflateInit2( &self->_strm, (15+32) ); - BOOL result = ( Z_OK == initResult ); - - if ( !result ) - { - [ JFFLogger logErrorWithFormat:@"JNGzipDecoder -- inflateInit2 failed" ]; - NSError* gzipError = [ NSError errorWithDomain: kGzipErrorDomain - code: kJNGzipInitFailed - userInfo: nil ]; - [ gzipError setToPointer: outError ]; + int initResult = inflateInit2(&_strm, (15+32)); + BOOL result = (Z_OK == initResult); + + if (!result) { + + [JFFLogger logErrorWithFormat:@"JNGzipDecoder -- inflateInit2 failed"]; + NSError *gzipError = [NSError errorWithDomain:kGzipErrorDomain + code:kJNGzipInitFailed + userInfo:nil]; + [gzipError setToPointer:outError]; return NO; } @@ -64,146 +62,120 @@ -(BOOL)openZipStreamWithError:( NSError** )outError return YES; } - - -- (NSData*)decodeData:(NSData *)encodedData_ - error:(NSError **)outError -{ - @synchronized( self ) - { - return [ self threadUnsafeDecodeData: encodedData_ - error: outError ]; - } -} - - //http://www.cocoadev.com/index.pl?NSDataCategory -- (NSData*)threadUnsafeDecodeData:(NSData *)encodedData_ - error:(NSError **)outError +- (NSData *)decodeData:(NSData *)encodedData + error:(NSError **)outError { NSParameterAssert(outError); *outError = nil; - - if ( 0 == [ encodedData_ length ] ) - { - return encodedData_; + + if (0 == [encodedData length]) { + return encodedData; } - - NSUInteger full_length_ = [ encodedData_ length ]; - + + NSUInteger fullLength = [encodedData length]; + static const NSUInteger SCALE_TO_GET_ENOUGH_MEMORY = 3; - NSUInteger bufferLength_ = SCALE_TO_GET_ENOUGH_MEMORY * full_length_; + NSUInteger bufferLength_ = SCALE_TO_GET_ENOUGH_MEMORY * fullLength; - NSMutableData* decompressed_ = [ NSMutableData dataWithLength: bufferLength_ ]; - int status_ = 0 ; - - self->_strm.next_in = (Bytef*)[ encodedData_ bytes ]; - self->_strm.avail_in = (uInt )[ encodedData_ length ]; + NSMutableData* decompressed = [NSMutableData dataWithLength:bufferLength_]; + int status = 0 ; - + _strm.next_in = (Bytef*)[ encodedData bytes ]; + _strm.avail_in = (uInt )[ encodedData length ]; - self->_isOpen = [ self openZipStreamWithError: outError ]; - if ( !self->_isOpen ) - { + _isOpen = [ self openZipStreamWithError: outError ]; + if (!_isOpen) { return nil; } - else if ( self->_done ) - { - [ self closeZipStreamWithError: outError ]; + else if (_done) { + [self closeZipStreamWithError:outError]; } - - NSUInteger decompressedThisTime = 0; - uLong oldTotalOut = self->_strm.total_out; + uLong oldTotalOut = _strm.total_out; uLong totalCountDiff = 0; - while ( 0 != self->_strm.avail_in ) - { + while (0 != _strm.avail_in) { + // Make sure we have enough room and reset the lengths. - NSUInteger decompressedDataLength_ = [ decompressed_ length ]; + NSUInteger decompressedDataLength = [decompressed length]; - if ( self->_strm.total_out >= decompressedDataLength_) - { - [ decompressed_ increaseLengthBy: decompressedDataLength_ ]; + if (_strm.total_out >= decompressedDataLength) { + [ decompressed increaseLengthBy: decompressedDataLength ]; } - self->_strm.next_out = [decompressed_ mutableBytes] + decompressedThisTime; - self->_strm.avail_out = (uInt)( [decompressed_ length] - decompressedThisTime ); - - // Inflate another chunk. - status_ = inflate (&self->_strm, Z_SYNC_FLUSH); + _strm.next_out = [decompressed mutableBytes] + decompressedThisTime; + _strm.avail_out = (uInt)( [decompressed length] - decompressedThisTime ); + // Inflate another chunk. + status = inflate (&_strm, Z_SYNC_FLUSH); - totalCountDiff = self->_strm.total_out - oldTotalOut; - oldTotalOut = self->_strm.total_out; + totalCountDiff = _strm.total_out - oldTotalOut; + oldTotalOut = _strm.total_out; decompressedThisTime += totalCountDiff; - - if (status_ == Z_STREAM_END) - { - self->_done = YES; + if (status == Z_STREAM_END) { + + _done = YES; break; } - else if (status_ != Z_OK) - { - NSLog( @"[!!! WARNING !!!] JNZipDecoder -- unzip action has failed.\n Zip error code -- %d\n Zip error -- %@" - , status_ - , [ JNGzipErrorsLogger zipErrorMessageFromCode: status_ ] ); + else if (status != Z_OK) { + + NSLog(@"[!!! WARNING !!!] JNZipDecoder -- unzip action has failed.\n Zip error code -- %d\n Zip error -- %@", + status, + [JNGzipErrorsLogger zipErrorMessageFromCode:status]); - NSError* gzipError = [ NSError errorWithDomain: kGzipErrorDomain - code: status_ - userInfo: nil ]; - [ gzipError setToPointer: outError ]; + NSError *gzipError = [NSError errorWithDomain:kGzipErrorDomain + code:status + userInfo:nil]; + [gzipError setToPointer:outError]; - inflateEnd(&self->_strm); + inflateEnd(&_strm); return nil; } } - - BOOL isEndingSignatureAvailable = ( self->_strm.avail_in > 0 ); - if ( self->_done ) - { - if ( isEndingSignatureAvailable ) - { - [ self closeZipStreamWithError: outError ]; + BOOL isEndingSignatureAvailable = (_strm.avail_in > 0); + + if (_done) { + + if ( isEndingSignatureAvailable ) { + + [self closeZipStreamWithError:outError]; } - } - + } + // Set real length. - [ decompressed_ setLength: decompressedThisTime ]; - return [ NSData dataWithData: decompressed_ ]; + [decompressed setLength:decompressedThisTime]; + return [[NSData alloc] initWithData:decompressed]; } --(BOOL)closeWithError:( NSError ** )outError +- (BOOL)closeWithError:(NSError **)outError { - return [ self closeZipStreamWithError: outError ]; + return [self closeZipStreamWithError:outError]; } --(BOOL)closeZipStreamWithError:( NSError ** )outError +- (BOOL)closeZipStreamWithError:(NSError **)outError { - if ( !self->_isOpen ) - { + if (!_isOpen) { return YES; } + int inflateEndResultCode = inflateEnd(&_strm); + _isOpen = NO; - int inflateEndResultCode_ = inflateEnd (&self->_strm); - self->_isOpen = NO; - - if ( inflateEndResultCode_ != Z_OK) - { + if (inflateEndResultCode != Z_OK) { NSLog( @"[!!! WARNING !!!] JNZipDecoder -- unexpected EOF" ); - NSError* gzipError = - [ NSError errorWithDomain: kGzipErrorDomain - code: kJNGzipUnexpectedEOF - userInfo: nil ]; + NSError *gzipError = + [[NSError alloc] initWithDomain:kGzipErrorDomain + code:kJNGzipUnexpectedEOF + userInfo:nil]; - [ gzipError setToPointer: outError ]; + [gzipError setToPointer:outError]; return NO; } diff --git a/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.h b/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.h index 15c284a..e1a737d 100755 --- a/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.h +++ b/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.h @@ -2,6 +2,6 @@ @interface JNGzipErrorsLogger : NSObject -+(NSString*)zipErrorMessageFromCode:(int)errorCode; ++ (NSString *)zipErrorMessageFromCode:(int)errorCode; @end diff --git a/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.m b/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.m index 0525021..ba87278 100755 --- a/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.m +++ b/lib/JFFNetwork/ContentEncodings/JNGzipErrorsLogger.m @@ -2,28 +2,26 @@ @implementation JNGzipErrorsLogger -+(NSString*)zipErrorMessageFromCode:(int)errorCode ++ (NSString *)zipErrorMessageFromCode:(int)errorCode { - static NSString* zip_errors_[] = - { - @"Z_VERSION_ERROR" - , @"Z_BUF_ERROR" - , @"Z_MEM_ERROR" - , @"Z_DATA_ERROR" - , @"Z_STREAM_ERROR" - , @"Z_ERRNO" - }; - + static NSString *zipErrors[] = + { + @"Z_VERSION_ERROR", + @"Z_BUF_ERROR", + @"Z_MEM_ERROR", + @"Z_DATA_ERROR", + @"Z_STREAM_ERROR", + @"Z_ERRNO" + }; - int error_index_ = errorCode + abs( Z_VERSION_ERROR ); - int max_error_index_ = Z_ERRNO + abs( Z_VERSION_ERROR ); - - if ( error_index_ > max_error_index_ || error_index_ < 0 ) - { - return @"Z_UnknownError"; - } - - return zip_errors_[ error_index_ ]; + NSUInteger errorIndex = errorCode + abs(Z_VERSION_ERROR); + NSUInteger maxErrorIndex = Z_ERRNO + abs(Z_VERSION_ERROR); + + if (errorIndex > maxErrorIndex) { + return @"Z_UnknownError"; + } + + return zipErrors[errorIndex]; } @end diff --git a/lib/JFFNetwork/ContentEncodings/JNHttpDecoder.h b/lib/JFFNetwork/ContentEncodings/JNHttpDecoder.h index f01c986..c5c5c6f 100644 --- a/lib/JFFNetwork/ContentEncodings/JNHttpDecoder.h +++ b/lib/JFFNetwork/ContentEncodings/JNHttpDecoder.h @@ -1,10 +1,10 @@ #import -@protocol JNHttpDecoder < NSObject > +@protocol JNHttpDecoder --(NSData*)decodeData:( NSData* )encodedData - error:(NSError ** )outError; +- (NSData *)decodeData:(NSData *)encodedData + error:(NSError **)outError; --(BOOL)closeWithError:( NSError ** )outError; +- (BOOL)closeWithError:(NSError **)outError; @end diff --git a/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.h b/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.h index a55e6f0..f0873a3 100755 --- a/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.h +++ b/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.h @@ -4,12 +4,12 @@ @interface JNHttpEncodingsFactory : NSObject --(id)initWithContentLength:( unsigned long long )contentLength; +- (instancetype)initWithContentLength:(unsigned long long)contentLength; @property (nonatomic, readonly) unsigned long long contentLength; --(id)decoderForHeaderString:( NSString* )header_string_; --(id)gzipDecoder; --(id)stubDecoder; +- (id)decoderForHeaderString:(NSString *)headerString; +- (id)gzipDecoder; +- (id)stubDecoder; @end diff --git a/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.m b/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.m index a3c74b4..4fd7349 100755 --- a/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.m +++ b/lib/JFFNetwork/ContentEncodings/JNHttpEncodingsFactory.m @@ -11,7 +11,7 @@ @interface JNHttpEncodingsFactory() @implementation JNHttpEncodingsFactory --(id)initWithContentLength:( unsigned long long )contentLength +- (instancetype)initWithContentLength:( unsigned long long )contentLength { self = [ super init ]; self.contentLength = contentLength; @@ -19,11 +19,11 @@ -(id)initWithContentLength:( unsigned long long )contentLength return self; } --(id)decoderForHeaderString:( NSString* )headerString_ +- (id)decoderForHeaderString:(NSString *)headerString { NSDictionary* decoderClasses_ = @{ @"gzip": [ JNGzipDecoder class ] }; - Class decoderClass_ = decoderClasses_[ headerString_ ]; + Class decoderClass_ = decoderClasses_[headerString]; if ( Nil == decoderClass_ ) { return [ self stubDecoder ]; @@ -32,13 +32,12 @@ -(id)initWithContentLength:( unsigned long long )contentLength return [ [ decoderClass_ alloc ] initWithContentLength: self.contentLength ]; } --(id)gzipDecoder +- (id)gzipDecoder { return [ [ JNGzipDecoder alloc ] initWithContentLength: self.contentLength ]; } - --(id)stubDecoder +- (id)stubDecoder { return [ JNStubDecoder new ]; } diff --git a/lib/JFFNetwork/ContentEncodings/JNStubDecoder.m b/lib/JFFNetwork/ContentEncodings/JNStubDecoder.m index fca1059..83e6231 100644 --- a/lib/JFFNetwork/ContentEncodings/JNStubDecoder.m +++ b/lib/JFFNetwork/ContentEncodings/JNStubDecoder.m @@ -2,16 +2,16 @@ @implementation JNStubDecoder --(NSData*)decodeData:( NSData* )encoded_data_ - error:( NSError** )outError +- (NSData *)decodeData:(NSData *)encodedData + error:(NSError **)outError { - NSParameterAssert( outError ); + NSParameterAssert(outError); *outError = nil; - return encoded_data_; + return encodedData; } --(BOOL)closeWithError:( NSError ** )outError +- (BOOL)closeWithError:(NSError **)outError { return YES; } diff --git a/lib/JFFNetwork/ContentEncodings/JNZipDecoder.m b/lib/JFFNetwork/ContentEncodings/JNZipDecoder.m index 206dd5a..86f3b65 100644 --- a/lib/JFFNetwork/ContentEncodings/JNZipDecoder.m +++ b/lib/JFFNetwork/ContentEncodings/JNZipDecoder.m @@ -8,40 +8,40 @@ @implementation JNZipDecoder --(NSData*)decodeData:( NSData* )encoded_data_ - error:( NSError** )outError +- (NSData *)decodeData:(NSData *)encodedData + error:(NSError **)outError { NSParameterAssert( outError ); *outError = nil; - if (nil == encoded_data_) { + if (nil == encodedData) { return nil; } - Bytef decoded_buffer_[ kJNMaxBufferSize ] = {0}; - uLongf decoded_size_ = kJNMaxBufferSize; + Bytef decodedBuffer[ kJNMaxBufferSize ] = {0}; + uLongf decodedSize = kJNMaxBufferSize; - int uncompress_result_ = uncompress( decoded_buffer_ , &decoded_size_ , - encoded_data_.bytes, encoded_data_.length ); + int uncompressResult = uncompress(decodedBuffer , &decodedSize , + encodedData.bytes, encodedData.length ); - if ( Z_OK != uncompress_result_ ) { - NSLog( @"[!!! WARNING !!!] JNZipDecoder -- unzip action has failed.\n Zip error code -- %d\n Zip error -- %@" - , uncompress_result_ - , [ JNGzipErrorsLogger zipErrorMessageFromCode: uncompress_result_ ] ); - - *outError = [NSError errorWithDomain:kGzipErrorDomain - code:uncompress_result_ - userInfo:nil]; + if (Z_OK != uncompressResult) { + NSLog(@"[!!! WARNING !!!] JNZipDecoder -- unzip action has failed.\n Zip error code -- %d\n Zip error -- %@", + uncompressResult, + [JNGzipErrorsLogger zipErrorMessageFromCode:uncompressResult]); + + *outError = [[NSError alloc] initWithDomain:kGzipErrorDomain + code:uncompressResult + userInfo:nil]; return nil; } - - NSData* result_ = [ NSData dataWithBytes: decoded_buffer_ - length: decoded_size_ ]; - - return result_; + + NSData *result = [[NSData alloc] initWithBytes:decodedBuffer + length:decodedSize]; + + return result; } --(BOOL)closeWithError:( NSError** )error +- (BOOL)closeWithError:(NSError **)error { return YES; } diff --git a/lib/JFFNetwork/CookiesStorage/Details/NSHTTPCookie+matchesURL.m b/lib/JFFNetwork/CookiesStorage/Details/NSHTTPCookie+matchesURL.m deleted file mode 100755 index 29cddfe..0000000 --- a/lib/JFFNetwork/CookiesStorage/Details/NSHTTPCookie+matchesURL.m +++ /dev/null @@ -1,13 +0,0 @@ -#import "NSHTTPCookie+matchesURL.h" - -#import "NSString+RFC_2965.h" - -@implementation NSHTTPCookie (matchesURL) - --(BOOL)matchesURL:( NSURL* )url_ -{ - return [ url_.host domainMatchesCookiesDomain: self.domain ] - && [ url_.path pathMatchesCookiesPath : self.path ]; -} - -@end diff --git a/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.h b/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.h index 089a025..7e80261 100755 --- a/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.h +++ b/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.h @@ -2,7 +2,7 @@ @interface NSString (RFC_2965) --(BOOL)domainMatchesCookiesDomain:( NSString* )cookiesDomain_; --(BOOL)pathMatchesCookiesPath:( NSString* )cookiesPath_; +- (BOOL)domainMatchesCookiesDomain:(NSString *)cookiesDomain; +- (BOOL)pathMatchesCookiesPath:(NSString *)cookiesPath; @end diff --git a/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.m b/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.m index f8c7834..d6cc4d7 100755 --- a/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.m +++ b/lib/JFFNetwork/CookiesStorage/Details/NSString+RFC_2965.m @@ -13,22 +13,22 @@ @implementation NSString (RFC_2965) restrictions are valid. See RFC 2965 for more detail. @result The domain of the receiver. */ --(BOOL)domainMatchesCookiesDomain:( NSString* )cookiesDomain_ +- (BOOL)domainMatchesCookiesDomain:(NSString *)cookiesDomain { - NSString* domain_ = [ self lowercaseString ]; - cookiesDomain_ = [ cookiesDomain_ lowercaseString ]; - - if ( [ cookiesDomain_ length ] == 0 ) + NSString* domain = [self lowercaseString]; + cookiesDomain = [cookiesDomain lowercaseString]; + + if ([cookiesDomain length] == 0) return NO; - - if ( [ cookiesDomain_ hasPrefix: @"." ] ) - { - return [ domain_ hasSuffix: cookiesDomain_ ] - || ( ( [ cookiesDomain_ length ] - [ domain_ length ] ) == 1 - && [ cookiesDomain_ hasSuffix: domain_ ] ); + + if ([cookiesDomain hasPrefix:@"."]) { + + return [domain hasSuffix: cookiesDomain] + || (([cookiesDomain length] - [domain length]) == 1 + && [cookiesDomain hasSuffix:domain]); } - - return [ domain_ isEqualToString: cookiesDomain_ ]; + + return [domain isEqualToString:cookiesDomain]; } /*! @@ -39,18 +39,18 @@ -(BOOL)domainMatchesCookiesDomain:( NSString* )cookiesDomain_ be sent for children of that path, so "/" is the most general. @result The path of the receiver. */ --(BOOL)pathMatchesCookiesPath:( NSString* )cookiesPath_ +- (BOOL)pathMatchesCookiesPath:(NSString *)cookiesPath { - if ( [ cookiesPath_ length ] == 0 ) + if ([cookiesPath length] == 0) return NO; - - if ( [ cookiesPath_ isEqualToString: @"/" ] ) + + if ([cookiesPath isEqualToString:@"/"]) return YES; - - NSString* path_ = [ self lowercaseString ]; - cookiesPath_ = [ cookiesPath_ lowercaseString ]; - - return [ path_ hasPrefix: cookiesPath_ ]; + + NSString *path = [self lowercaseString]; + cookiesPath = [cookiesPath lowercaseString]; + + return [path hasPrefix:cookiesPath]; } @end diff --git a/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.h b/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.h index 9b04db7..3be947b 100755 --- a/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.h +++ b/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.h @@ -2,7 +2,7 @@ @interface JFFLocalCookiesStorage : NSObject --(void)setCookie:( NSHTTPCookie* )cookie_; --(NSArray*)cookiesForURL:( NSURL* )url_; +- (void)setCookie:(NSHTTPCookie *)cookie; +- (NSArray *)cookiesForURL:(NSURL *)url; @end diff --git a/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.m b/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.m index 4bce38d..4317f04 100644 --- a/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.m +++ b/lib/JFFNetwork/CookiesStorage/JFFLocalCookiesStorage.m @@ -4,39 +4,38 @@ @implementation JFFLocalCookiesStorage { - NSMutableSet* _allCookies; + NSMutableSet *_allCookies; } --(id)init +- (instancetype)init { - self = [ super init ]; - - if ( self ) - { - _allCookies = [ NSMutableSet new ]; + self = [super init]; + + if (self) { + _allCookies = [NSMutableSet new]; } - + return self; } --(void)setCookie:( NSHTTPCookie* )cookie_ +- (void)setCookie:(NSHTTPCookie *)cookie { - [ _allCookies addObject: cookie_ ]; + [_allCookies addObject:cookie]; } --(NSArray*)cookiesForURL:( NSURL* )url_ +- (NSArray *)cookiesForURL:(NSURL *)url { - NSArray* result_ = [ _allCookies selectArray: ^BOOL( NSHTTPCookie* cookie_ ) + NSArray *result = [_allCookies selectArray:^BOOL(NSHTTPCookie *cookie) { - BOOL result_ = [ cookie_ matchesURL: url_ ]; - - result_ &= cookie_.expiresDate == nil - || [ cookie_.expiresDate compare: [ NSDate new ] ] == NSOrderedDescending; - - return result_; - } ]; - - return result_; + BOOL result = [cookie matchesURL:url]; + + result &= cookie.expiresDate == nil + || [cookie.expiresDate compare:[NSDate new]] == NSOrderedDescending; + + return result; + }]; + + return result; } @end diff --git a/lib/JFFNetwork/Detail/JFFAsyncOperationNetwork.h b/lib/JFFNetwork/Detail/JFFAsyncOperationNetwork.h deleted file mode 100644 index 73b51e0..0000000 --- a/lib/JFFNetwork/Detail/JFFAsyncOperationNetwork.h +++ /dev/null @@ -1,15 +0,0 @@ -#import -#import - -#import - -@class JFFURLConnectionParams; -@protocol JNUrlConnection; - -@interface JFFAsyncOperationNetwork : NSObject < JFFAsyncOperationInterface > - -@property ( nonatomic ) JFFURLConnectionParams* params; -@property ( nonatomic ) id< JNUrlConnection > connection; -@property ( nonatomic ) id resultContext; - -@end diff --git a/lib/JFFNetwork/Detail/JFFAsyncOperationNetwork.m b/lib/JFFNetwork/Detail/JFFAsyncOperationNetwork.m deleted file mode 100644 index fc23c27..0000000 --- a/lib/JFFNetwork/Detail/JFFAsyncOperationNetwork.m +++ /dev/null @@ -1,77 +0,0 @@ -#import "JFFAsyncOperationNetwork.h" - -#import "JFFURLConnectionParams.h" -#import "JNConnectionsFactory.h" -#import "JNUrlConnection.h" -#import "JHttpFlagChecker.h" -#import "JHttpError.h" - -#import - -@implementation JFFAsyncOperationNetwork - --(void)asyncOperationWithResultHandler:( void (^)( id, NSError* ) )handler_ - progressHandler:( void (^)( id ) )progress_ -{ - { - JNConnectionsFactory* factory_ = - [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: self.params ]; - - self.connection = [ factory_ createConnection ]; - } - - self.connection.shouldAcceptCertificateBlock = self.params.certificateCallback; - - __weak JFFAsyncOperationNetwork* self_ = self; - - progress_ = [ progress_ copy ]; - self.connection.didReceiveDataBlock = ^( NSData* data_ ) - { - if ( progress_ ) - progress_( data_ ); - }; - - handler_ = [ handler_ copy ]; - JFFDidFinishLoadingHandler finish_ = ^( NSError* error_ ) - { - if ( handler_ ) - handler_( error_ ? nil : self_.resultContext, error_ ); - }; - - finish_ = [ finish_ copy ]; - self.connection.didFinishLoadingBlock = finish_; - - - self.connection.didReceiveResponseBlock = ^void( id< JNUrlResponse > response_ ) - { - self_.resultContext = response_; - - NSInteger statusCode_ = [ response_ statusCode ]; - - if ( [ JHttpFlagChecker isDownloadErrorFlag : statusCode_ ] ) - { - JHttpError* httpError_ = [ [ JHttpError alloc ] initWithHttpCode: statusCode_ ]; - finish_( httpError_ ); - - [ self_ forceCancel ]; - } - }; - - [ self.connection start ]; -} - --(void)forceCancel -{ - [ self cancel: YES ]; -} - --(void)cancel:( BOOL )canceled_ -{ - if ( canceled_ ) - { - [ self.connection cancel ]; - self.connection = nil; - } -} - -@end diff --git a/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.h b/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.h index 667a2a7..49d0d11 100644 --- a/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.h +++ b/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.h @@ -7,10 +7,13 @@ @class JFFURLConnectionParams; @protocol JNUrlConnection; +typedef NSError *(^JFFNetworkErrorTransformer)(NSError *error); + @interface JFFNetworkAsyncOperation : NSObject @property (nonatomic) JFFURLConnectionParams *params; -@property (nonatomic) id< JNUrlConnection > connection; +@property (nonatomic) id connection; @property (nonatomic, copy) JFFAnalyzer responseAnalyzer; +@property (nonatomic, copy) JFFNetworkErrorTransformer errorTransformer; @end diff --git a/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.m b/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.m index 1d3cfff..a33009e 100644 --- a/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.m +++ b/lib/JFFNetwork/Detail/JFFNetworkAsyncOperation.m @@ -20,33 +20,30 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler { JNConnectionsFactory *factory = - [[JNConnectionsFactory alloc]initWithURLConnectionParams:self.params]; + [[JNConnectionsFactory alloc] initWithURLConnectionParams:self.params]; - self.connection = self.params.useLiveConnection - ?[factory createFastConnection ] - :[factory createStandardConnection]; + _connection = [factory createConnection]; } - self.connection.shouldAcceptCertificateBlock = self.params.certificateCallback; + _connection.shouldAcceptCertificateBlock = self.params.certificateCallback; __unsafe_unretained JFFNetworkAsyncOperation *unretainedSelf = self; - id< JNUrlConnection > connection = self.connection; - + id connection = self.connection; progress = [progress copy]; - self.connection.didReceiveDataBlock = ^(NSData *dataChunk) { + _connection.didReceiveDataBlock = ^(NSData *dataChunk) { JFFNetworkResponseDataCallback *progressData = [JFFNetworkResponseDataCallback new]; { progressData.dataChunk = dataChunk; - progressData.totalBytesCount = [ connection totalBytesCount ]; - progressData.downloadedBytesCount = [ connection downloadedBytesCount ]; + progressData.totalBytesCount = [connection totalBytesCount ]; + progressData.downloadedBytesCount = [connection downloadedBytesCount]; } progress(progressData); }; - self.connection.didUploadDataBlock = ^(NSNumber *progressNum) { + _connection.didUploadDataBlock = ^(NSNumber *progressNum) { JFFNetworkUploadProgressCallback *uploadProgress = [JFFNetworkUploadProgressCallback new]; uploadProgress.progress = progressNum; @@ -56,15 +53,26 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler __block id resultHolder; + JFFNetworkErrorTransformer errorTransformer = _errorTransformer; + handler = [handler copy]; JFFDidFinishLoadingHandler finish = [^(NSError *error) { - handler(error?nil:resultHolder, error); + + if (error) { + + handler(nil, errorTransformer?errorTransformer(error):error); + return; + } + + handler(resultHolder, nil); + } copy]; - self.connection.didFinishLoadingBlock = finish; + finish = [finish copy]; + _connection.didFinishLoadingBlock = finish; - self.connection.didReceiveResponseBlock = ^void(id response) - { + _connection.didReceiveResponseBlock = ^void(id response) { + if (!unretainedSelf->_responseAnalyzer) { resultHolder = response; return; @@ -79,26 +87,26 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler } }; - [self.connection start]; + [_connection start]; } --(void)forceCancel +- (void)forceCancel { [self cancel:YES]; } - (void)cancel:(BOOL)canceled { - self.connection.didReceiveDataBlock = nil; - self.connection.didFinishLoadingBlock = nil; - self.connection.didReceiveResponseBlock = nil; - self.connection.didUploadDataBlock = nil; - self.connection.shouldAcceptCertificateBlock = nil; + _connection.didReceiveDataBlock = nil; + _connection.didFinishLoadingBlock = nil; + _connection.didReceiveResponseBlock = nil; + _connection.didUploadDataBlock = nil; + _connection.shouldAcceptCertificateBlock = nil; //TODO maybe always cancel? if (canceled) { - [self.connection cancel]; - self.connection = nil; + [_connection cancel]; + _connection = nil; } } diff --git a/lib/JFFNetwork/Detail/NSURL+URLWithLocation.h b/lib/JFFNetwork/Detail/NSURL+URLWithLocation.h index a88e5a5..1bbf538 100644 --- a/lib/JFFNetwork/Detail/NSURL+URLWithLocation.h +++ b/lib/JFFNetwork/Detail/NSURL+URLWithLocation.h @@ -2,6 +2,6 @@ @interface NSURL (URLWithLocation) -- (id)URLWithLocation:(NSString *)location; +- (instancetype)URLWithLocation:(NSString *)location; @end diff --git a/lib/JFFNetwork/Detail/NSURL+URLWithLocation.m b/lib/JFFNetwork/Detail/NSURL+URLWithLocation.m index f731ee5..c3cc2b3 100644 --- a/lib/JFFNetwork/Detail/NSURL+URLWithLocation.m +++ b/lib/JFFNetwork/Detail/NSURL+URLWithLocation.m @@ -23,7 +23,7 @@ @implementation NSURL (URLWithLocation) -- (id)URLWithLocation:(NSString *)location +- (instancetype)URLWithLocation:(NSString *)location { NSParameterAssert([location hasPrefix:@"/"]); diff --git a/lib/JFFNetwork/Detail/NSUrlLocationValidator.h b/lib/JFFNetwork/Detail/NSUrlLocationValidator.h index 5e4d8a5..795ada5 100644 --- a/lib/JFFNetwork/Detail/NSUrlLocationValidator.h +++ b/lib/JFFNetwork/Detail/NSUrlLocationValidator.h @@ -2,6 +2,6 @@ @interface NSUrlLocationValidator : NSObject -+(BOOL)isValidLocation:( NSString* )location_; ++ (BOOL)isValidLocation:(NSString *)location; @end diff --git a/lib/JFFNetwork/Detail/NSUrlLocationValidator.m b/lib/JFFNetwork/Detail/NSUrlLocationValidator.m index 0d6fc8a..2dfae6f 100644 --- a/lib/JFFNetwork/Detail/NSUrlLocationValidator.m +++ b/lib/JFFNetwork/Detail/NSUrlLocationValidator.m @@ -2,21 +2,21 @@ @implementation NSUrlLocationValidator -+(BOOL)isValidLocation:( NSString* )location_ ++ (BOOL)isValidLocation:(NSString *)location { - if ( nil == location_ ) + if ( nil == location ) { return NO; } - else if ( [ location_ isEqualToString: @"" ] ) + else if ( [ location isEqualToString: @"" ] ) { return NO; } - else if ( [ location_ hasPrefix: @"/" ] ) + else if ( [ location hasPrefix: @"/" ] ) { return YES; } - else if ( [ self isLocationValidURL: location_ ] ) + else if ( [ self isLocationValidURL: location ] ) { return NO; } @@ -24,10 +24,10 @@ +(BOOL)isValidLocation:( NSString* )location_ return NO; } -+(BOOL)isLocationValidURL:( NSString* )location_ ++ (BOOL)isLocationValidURL:(NSString *)location { - NSURL* url_ = [ NSURL URLWithString: location_ ]; - return ( nil != url_ ); + NSURL *url = [NSURL URLWithString:location]; + return (nil != url); } @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/JFFFileManager.h b/lib/JFFNetwork/DownloadManager/Detail/JFFFileManager.h index 97e148e..d37a2df 100755 --- a/lib/JFFNetwork/DownloadManager/Detail/JFFFileManager.h +++ b/lib/JFFNetwork/DownloadManager/Detail/JFFFileManager.h @@ -2,8 +2,8 @@ @interface JFFFileManager : NSObject -+(FILE*)createFileForPath:( NSString* )path_; ++ (FILE *)createFileForPath:(NSString *)path; -+(BOOL)removeFileForPath:( NSString* )path_; ++ (BOOL)removeFileForPath:(NSString *)path; @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.h b/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.h index 5d86129..2450397 100755 --- a/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.h +++ b/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.h @@ -2,16 +2,16 @@ @protocol JFFTrafficCalculatorDelegate; -typedef void (^RICancelCalculateSpeed) ( void ); +typedef void (^RICancelCalculateSpeed) (void); @interface JFFTrafficCalculator : NSObject --(id)initWithDelegate:( id< JFFTrafficCalculatorDelegate > )delegate_; +- (instancetype)initWithDelegate:(id)delegate; --(void)startLoading; +- (void)startLoading; --(void)stop; +- (void)stop; --(void)bytesReceived:( NSUInteger )bytes_count_; +- (void)bytesReceived:(NSUInteger)bytesCount; @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.m b/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.m index 15c1363..9b4d64a 100644 --- a/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.m +++ b/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculator.m @@ -13,13 +13,13 @@ @interface JFFDownloadedBytesPerDate : NSObject @implementation JFFDownloadedBytesPerDate --(id)initWithBytesCount:( NSUInteger )bytesCount_ +- (instancetype)initWithBytesCount:( NSUInteger )bytesCount_ { - self = [ super init ]; - - if ( self ) - { - _date = [ NSDate new ]; + self = [super init]; + + if (self) { + + _date = [NSDate new]; _bytesCount = bytesCount_; } @@ -36,7 +36,7 @@ @implementation JFFTrafficCalculator JFFScheduler* _scheduler; } --(id)initWithDelegate:( id< JFFTrafficCalculatorDelegate > )delegate_ +- (instancetype)initWithDelegate:(id)delegate_ { self = [ super init ]; @@ -49,7 +49,7 @@ -(id)initWithDelegate:( id< JFFTrafficCalculatorDelegate > )delegate_ return self; } --(void)removeOldItemsFromDownloadingSpeedInfo +- (void)removeOldItemsFromDownloadingSpeedInfo { static NSTimeInterval average_speed_duration_ = 3.0; @@ -62,65 +62,63 @@ -(void)removeOldItemsFromDownloadingSpeedInfo } } --(void)calculateDownloadSpeed +- (void)calculateDownloadSpeed { - [ self removeOldItemsFromDownloadingSpeedInfo ]; - - float speed_ = 0.f; - - if ( [ _downloadingSpeedInfo count ] > 1 ) - { - NSRange range_ = { 0, [ _downloadingSpeedInfo count ] - 1 }; - NSArray* arrayExcludeLast_ = [ _downloadingSpeedInfo subarrayWithRange: range_ ]; + [self removeOldItemsFromDownloadingSpeedInfo]; + + float speed = 0.f; + + if ([_downloadingSpeedInfo count] > 1) { + + NSRange range = {0, [_downloadingSpeedInfo count] - 1}; + NSArray *arrayExcludeLast = [_downloadingSpeedInfo subarrayWithRange:range]; - NSUInteger donloadedBytes_ = 0; - for ( JFFDownloadedBytesPerDate* item_ in arrayExcludeLast_ ) - { - donloadedBytes_ += item_.bytesCount; + NSUInteger donloadedBytes = 0; + for (JFFDownloadedBytesPerDate *item in arrayExcludeLast) { + + donloadedBytes += item.bytesCount; } - - JFFDownloadedBytesPerDate* firstItem_ = arrayExcludeLast_[ 0 ]; - NSDate* lastDate_ = ( [ arrayExcludeLast_ count ] == 1 ) ? [ NSDate new ] : firstItem_.date; - - JFFDownloadedBytesPerDate* lastItem_ = [ arrayExcludeLast_ lastObject ]; - NSTimeInterval timeDiff = ( [ lastDate_ timeIntervalSince1970 ] - [ lastItem_.date timeIntervalSince1970 ] ); - NSTimeInterval result = donloadedBytes_ / timeDiff; + JFFDownloadedBytesPerDate *firstItem = arrayExcludeLast[ 0 ]; + NSDate *lastDate = ([arrayExcludeLast count] == 1)?[NSDate new]:firstItem.date; - speed_ = (float)result; + JFFDownloadedBytesPerDate* lastItem_ = [ arrayExcludeLast lastObject ]; + + NSTimeInterval timeDiff = ([lastDate timeIntervalSince1970] - [lastItem_.date timeIntervalSince1970]); + NSTimeInterval result = donloadedBytes / timeDiff; + + speed = (float)result; } - - [ _delegate trafficCalculator: self didChangeDownloadSpeed: speed_ ]; + + [_delegate trafficCalculator:self didChangeDownloadSpeed:speed]; } --(void)stop +- (void)stop { _scheduler = nil; - _downloadingSpeedInfo = [ NSMutableArray new ]; - [ self calculateDownloadSpeed ]; + _downloadingSpeedInfo = [NSMutableArray new]; + [self calculateDownloadSpeed]; } --(void)bytesReceived:( NSUInteger )bytesCount_ +- (void)bytesReceived:(NSUInteger)bytesCount { - JFFDownloadedBytesPerDate* item_ = [ [ JFFDownloadedBytesPerDate alloc ] initWithBytesCount: bytesCount_ ]; - [ _downloadingSpeedInfo insertObject: item_ atIndex: 0 ]; - - [ self removeOldItemsFromDownloadingSpeedInfo ]; + JFFDownloadedBytesPerDate *item = [[JFFDownloadedBytesPerDate alloc] initWithBytesCount:bytesCount]; + [_downloadingSpeedInfo insertObject:item atIndex:0]; + + [self removeOldItemsFromDownloadingSpeedInfo]; } --(void)startLoading +- (void)startLoading { - static NSTimeInterval calculateSpeedInterval_ = 1.0; - - __unsafe_unretained JFFTrafficCalculator* self_ = self; - JFFScheduledBlock block_ = ^void( JFFCancelScheduledBlock cancel_ ) - { - [ self_ calculateDownloadSpeed ]; + __unsafe_unretained JFFTrafficCalculator* weakSelf = self; + JFFScheduledBlock block = ^void(JFFCancelScheduledBlock cancel) { + + [weakSelf calculateDownloadSpeed]; }; - - _scheduler = [ JFFScheduler new ]; - [ _scheduler addBlock: block_ duration: calculateSpeedInterval_ ]; + + _scheduler = [JFFScheduler new]; + [_scheduler addBlock:block duration:1. leeway:.2]; } @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculatorDelegate.h b/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculatorDelegate.h index eaf2352..80783d6 100755 --- a/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculatorDelegate.h +++ b/lib/JFFNetwork/DownloadManager/Detail/JFFTrafficCalculatorDelegate.h @@ -2,9 +2,9 @@ @class JFFTrafficCalculator; -@protocol JFFTrafficCalculatorDelegate < NSObject > +@protocol JFFTrafficCalculatorDelegate --(void)trafficCalculator:( JFFTrafficCalculator* )traffic_calculator_ - didChangeDownloadSpeed:( float )speed_; +- (void)trafficCalculator:(JFFTrafficCalculator *)trafficCalculator + didChangeDownloadSpeed:(float)speed; @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.h b/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.h index 5a8e00c..276c1f5 100755 --- a/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.h +++ b/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.h @@ -2,9 +2,9 @@ @interface NSMutableDictionary (DownloadingFileInfo) -+(unsigned long long)fileLengthForDestinationURL:( NSURL* )url_; ++ (unsigned long long)fileLengthForDestinationURL:(NSURL *)url; -+(void)setFileLength:( unsigned long long )file_length_ - forDestinationURL:( NSURL* )url_; ++ (void)setFileLength:(unsigned long long)fileLength + forDestinationURL:(NSURL *)url; @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.m b/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.m index f3e8de6..c511db4 100755 --- a/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.m +++ b/lib/JFFNetwork/DownloadManager/Detail/NSMutableDictionary+DownloadingFileInfo.m @@ -4,43 +4,42 @@ @implementation NSMutableDictionary (DownloadingFileInfo) -+(NSString*)storePathForDownloadFilesInfo ++ (NSString *)storePathForDownloadFilesInfo { - return [ NSString documentsPathByAppendingPathComponent: @"JFFDownloadFilesInfo.data" ]; + return [NSString documentsPathByAppendingPathComponent:@"JFFDownloadFilesInfo.data"]; } -+(NSMutableDictionary*)dictionaryWithDownloadFilesInfo ++ (NSMutableDictionary *)dictionaryWithDownloadFilesInfo { - NSMutableDictionary* result_ = [ NSMutableDictionary dictionaryWithContentsOfFile: [ self storePathForDownloadFilesInfo ] ]; - return result_ ?: [ NSMutableDictionary new ]; + NSMutableDictionary *result = [NSMutableDictionary dictionaryWithContentsOfFile:[self storePathForDownloadFilesInfo]]; + return result?:[NSMutableDictionary new]; } --(void)writeToFileDownloadFilesInfo +- (void)writeToFileDownloadFilesInfo { - [ self writeToFile: [ [ self class ] storePathForDownloadFilesInfo ] atomically: NO ]; + [self writeToFile:[[self class] storePathForDownloadFilesInfo] atomically:NO]; } -+(unsigned long long)fileLengthForDestinationURL:( NSURL* )url_ ++ (unsigned long long)fileLengthForDestinationURL:(NSURL *)url { - NSMutableDictionary* dict_ = [ self dictionaryWithDownloadFilesInfo ]; - - NSNumber* fileLength_ = dict_[ [ url_ absoluteString ] ]; - if ( fileLength_ ) - { - return [ fileLength_ unsignedLongLongValue ]; - } + NSMutableDictionary *dict = [self dictionaryWithDownloadFilesInfo]; - return (unsigned long long)NSURLResponseUnknownLength; + NSNumber *fileLength = dict[[url absoluteString]]; + if (fileLength) { + + return [fileLength unsignedLongLongValue]; + } + return NSURLResponseUnknownLength; } -+(void)setFileLength:( unsigned long long )fileLength_ - forDestinationURL:( NSURL* )url_ ++ (void)setFileLength:(unsigned long long)fileLength + forDestinationURL:(NSURL *)url { - NSMutableDictionary* dict_ = [ self dictionaryWithDownloadFilesInfo ]; - - dict_[ [ url_ absoluteString ] ] = @( fileLength_ ); - - [ dict_ writeToFileDownloadFilesInfo ]; + NSMutableDictionary *dict = [self dictionaryWithDownloadFilesInfo]; + + dict[[url absoluteString]] = @(fileLength); + + [dict writeToFileDownloadFilesInfo]; } @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.h b/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.h index 9312d9f..8d65ebf 100755 --- a/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.h +++ b/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.h @@ -2,9 +2,9 @@ @interface NSMutableSet (DownloadManager) -+(void)addDownloadedFileWithPath:( NSString* )path_; ++ (void)addDownloadedFileWithPath:(NSString *)path; -+(BOOL)containsDownloadedFileWithPath:( NSString* )file_path_; -+(void)removeDownloadedFileWithPath:( NSString* )path_; ++ (BOOL)containsDownloadedFileWithPath:(NSString *)filePath; ++ (void)removeDownloadedFileWithPath:(NSString *)path; @end diff --git a/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.m b/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.m index 5e8cc7b..350d823 100755 --- a/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.m +++ b/lib/JFFNetwork/DownloadManager/Detail/NSMutableSet+DownloadManager.m @@ -4,12 +4,12 @@ @implementation NSMutableSet (DownloadManager) -+(NSString*)storePathForDownloadedFiles ++ (NSString *)storePathForDownloadedFiles { return [ NSString documentsPathByAppendingPathComponent: @"JFFDownloadedFiles.data" ]; } -+ (id)setWithDownloadedFiles ++ (instancetype)setWithDownloadedFiles { NSString *storePathForDownloadedFiles = [self storePathForDownloadedFiles]; NSArray *downloadedItems = [[NSArray alloc] initWithContentsOfFile:storePathForDownloadedFiles]; @@ -35,30 +35,29 @@ - (void)removeDownloadedFileWithPath:(NSString *)filePath [self writeToFileDownloadedFiles]; } --(BOOL)containsDownloadedFileWithPath:( NSString* )filePath_ +- (BOOL)containsDownloadedFileWithPath:(NSString *)filePath { - BOOL result_ = [ self containsObject: filePath_ ]; - if ( result_ && ![ [ NSFileManager defaultManager ] fileExistsAtPath: filePath_ ] ) - { - [ self removeDownloadedFileWithPath: filePath_ ]; + BOOL result = [self containsObject:filePath]; + if (result && ![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { + [self removeDownloadedFileWithPath:filePath]; return NO; } - return result_; + return result; } -+(void)addDownloadedFileWithPath:( NSString* )filePath_ ++ (void)addDownloadedFileWithPath:(NSString *)filePath { - [ [ self setWithDownloadedFiles ] addDownloadedFileWithPath: filePath_ ]; + [[self setWithDownloadedFiles] addDownloadedFileWithPath:filePath]; } -+(BOOL)containsDownloadedFileWithPath:( NSString* )filePath_ ++ (BOOL)containsDownloadedFileWithPath:(NSString *)filePath { - return [ [ self setWithDownloadedFiles ] containsDownloadedFileWithPath: filePath_ ]; + return [[self setWithDownloadedFiles] containsDownloadedFileWithPath:filePath]; } -+(void)removeDownloadedFileWithPath:( NSString* )filePath_ ++ (void)removeDownloadedFileWithPath:(NSString *)filePath { - [ [ self setWithDownloadedFiles ] removeDownloadedFileWithPath: filePath_ ]; + [[self setWithDownloadedFiles] removeDownloadedFileWithPath:filePath]; } @end diff --git a/lib/JFFNetwork/DownloadManager/JFFDownloadItem.h b/lib/JFFNetwork/DownloadManager/JFFDownloadItem.h index 75a842d..b63a96a 100644 --- a/lib/JFFNetwork/DownloadManager/JFFDownloadItem.h +++ b/lib/JFFNetwork/DownloadManager/JFFDownloadItem.h @@ -8,32 +8,32 @@ extern long long JFFUnknownFileLength; @interface JFFDownloadItem : NSObject -@property ( nonatomic, readonly ) NSURL* url; -@property ( nonatomic, readonly ) NSString* localFilePath; +@property (nonatomic, readonly) NSURL *url; +@property (nonatomic, readonly) NSString *localFilePath; -@property ( nonatomic, readonly ) unsigned long long fileLength; -@property ( nonatomic, readonly ) unsigned long long downloadedFileLength; -@property ( nonatomic, readonly ) BOOL downloaded; -@property ( nonatomic, readonly ) float progress; -@property ( nonatomic, readonly ) BOOL activeDownload; -@property ( nonatomic, readonly ) float downlodingSpeed; +@property (nonatomic, readonly) unsigned long long fileLength; +@property (nonatomic, readonly) unsigned long long downloadedFileLength; +@property (nonatomic, readonly) BOOL downloaded; +@property (nonatomic, readonly) float progress; +@property (nonatomic, readonly) BOOL activeDownload; +@property (nonatomic, readonly) float downlodingSpeed; //can return existing download item -+(id)downloadItemWithURL:( NSURL* )url_ - localFilePath:( NSString* )localFilePath_ - error:(NSError **)outError; ++ (instancetype)downloadItemWithURL:(NSURL *)url + localFilePath:(NSString *)localFilePath + error:(NSError **)outError; -+(BOOL)removeDownloadForURL:( NSURL* )url_ - localFilePath:( NSString* )localFilePath_ - error:(NSError **)outError; ++ (BOOL)removeDownloadForURL:(NSURL *)url + localFilePath:(NSString *)localFilePath + error:(NSError **)outError; --(void)start; --(void)stop; --(void)removeDownload; +- (void)start; +- (void)stop; +- (void)removeDownload; --(void)addDelegate:( id< JFFDownloadItemDelegate > )delegate_; --(void)removeDelegate:( id< JFFDownloadItemDelegate > )delegate_; +- (void)addDelegate:(id)delegate; +- (void)removeDelegate:(id)delegate; --(JFFAsyncOperation)fileLoader; +- (JFFAsyncOperation)fileLoader; @end diff --git a/lib/JFFNetwork/DownloadManager/JFFDownloadItem.m b/lib/JFFNetwork/DownloadManager/JFFDownloadItem.m index 48559b5..6316229 100644 --- a/lib/JFFNetwork/DownloadManager/JFFDownloadItem.m +++ b/lib/JFFNetwork/DownloadManager/JFFDownloadItem.m @@ -15,102 +15,97 @@ #import #import -static JFFMutableAssignArray* downloadItems_ = nil; +static JFFMutableAssignArray *downloadItems = nil; long long JFFUnknownFileLength = NSURLResponseUnknownLength; -//TODO move library to separate repository @interface JFFDownloadItem () -@property (nonatomic) NSURL* url; -@property (nonatomic) NSString* localFilePath; +@property (nonatomic) NSURL *url; +@property (nonatomic) NSString *localFilePath; @property (nonatomic) float downlodingSpeed; @property (nonatomic) unsigned long long fileLength; @property (nonatomic) unsigned long long downloadedFileLength; -@property (nonatomic) NSNull* downloadedFlag; +@property (nonatomic) NSNull *downloadedFlag; @property (nonatomic, copy) JFFCancelAsyncOperation stopBlock; @end @implementation JFFDownloadItem { - JFFTrafficCalculator* _trafficCalculator; - FILE* _file; + JFFTrafficCalculator *_trafficCalculator; + FILE *_file; float _previousProgress; - JFFMulticastDelegate< JFFDownloadItemDelegate >* _multicastDelegate; + JFFMulticastDelegate< JFFDownloadItemDelegate > *_multicastDelegate; } @dynamic downloadedFlag; @dynamic downloaded; @dynamic activeDownload; --(void)dealloc +- (void)dealloc { - [ self closeFile ]; + [self closeFile]; } --(unsigned long long)fileSizeForURL:( NSURL* )url_ +- (unsigned long long)fileSizeForPath:(NSString *)filePath { - NSDictionary* dict_ = [ [ NSFileManager defaultManager ] attributesOfItemAtPath: self.localFilePath error: nil ]; - return [ dict_ fileSize ]; + NSDictionary *dict = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; + return [dict fileSize]; } --(id)initWithURL:( NSURL* )url_ - localFilePath:( NSString* )local_file_path_ +- (instancetype)initWithURL:(NSURL *)url + localFilePath:(NSString *)localFilePath { - self = [ super init ]; - - if ( self ) - { - self.url = url_; - self.localFilePath = local_file_path_; - self.downloadedFileLength = [ self fileSizeForURL: url_ ]; - _multicastDelegate = (JFFMulticastDelegate< JFFDownloadItemDelegate >*)[ JFFMulticastDelegate new ]; - - if ( self.downloaded ) - { + self = [super init]; + + if (self) { + self.url = url; + self.localFilePath = localFilePath; + self.downloadedFileLength = [self fileSizeForPath:localFilePath]; + _multicastDelegate = (JFFMulticastDelegate< JFFDownloadItemDelegate >*)[JFFMulticastDelegate new]; + + if (self.downloaded) { + self.fileLength = self.downloadedFileLength; - } - else - { - self.fileLength = [ NSMutableDictionary fileLengthForDestinationURL: url_ ]; + } else { + self.fileLength = [NSMutableDictionary fileLengthForDestinationURL:url]; } } - + return self; } --(JFFTrafficCalculator*)trafficCalculator +- (JFFTrafficCalculator *)trafficCalculator { - if ( !_trafficCalculator ) - { - _trafficCalculator = [ [ JFFTrafficCalculator alloc ] initWithDelegate: self ]; + if (!_trafficCalculator) { + _trafficCalculator = [[JFFTrafficCalculator alloc] initWithDelegate:self]; } return _trafficCalculator; } --(void)closeFile +- (void)closeFile { - if ( _file ) - { - fclose( _file ); + if (_file) { + + fclose(_file); _file = 0; } } --(NSNull*)downloadedFlag +- (NSNull *)downloadedFlag { - BOOL downloded_ = [ NSMutableSet containsDownloadedFileWithPath: self.localFilePath ]; - return downloded_ ? [ NSNull null ] : nil; + BOOL downloded_ = [NSMutableSet containsDownloadedFileWithPath:self.localFilePath]; + return downloded_ ? [NSNull new] : nil; } --(void)setDownloadedFlag:( NSNull* )downloaded_flag_ +- (void)setDownloadedFlag:(NSNull *)downloadedFlag { - if ( downloaded_flag_ ) - [ NSMutableSet addDownloadedFileWithPath: self.localFilePath ]; + if (downloadedFlag) + [NSMutableSet addDownloadedFileWithPath:self.localFilePath]; } --(float)progress +- (float)progress { unsigned long long fileLength = self.fileLength; static const unsigned long long castecUnknownLength = (unsigned long long)NSURLResponseUnknownLength; @@ -118,12 +113,10 @@ -(float)progress BOOL isUnknownLength = ( fileLength == castecUnknownLength ); BOOL isZeroLength = ( 0.f == fileLength ); - if ( isUnknownLength ) - { + if (isUnknownLength) { return 0.f; } - else if ( isZeroLength ) - { + else if (isZeroLength) { return 1.f; } @@ -138,7 +131,7 @@ + (BOOL)checkNotAlreadyUsedLocalPath:(NSString *)localFilePath url:(NSURL *)url error:(NSError **)outError { - BOOL result = ![downloadItems_ any:^BOOL(id object) { + BOOL result = ![downloadItems any:^BOOL(id object) { JFFDownloadItem *item_ = object; return ![item_.url isEqual:url] && [ item_.localFilePath isEqualToString:localFilePath]; @@ -146,7 +139,6 @@ + (BOOL)checkNotAlreadyUsedLocalPath:(NSString *)localFilePath if (!result && outError) { - //TODO use NSLocalizedString here static NSString *const errorDescription = @"Invalid arguments. This \"local path\" used for another url"; *outError = [JFFError newErrorWithDescription:errorDescription]; } @@ -154,43 +146,42 @@ + (BOOL)checkNotAlreadyUsedLocalPath:(NSString *)localFilePath return result; } -+(id)downloadItemWithURL:( NSURL* )url_ - localFilePath:( NSString* )local_file_path_ - error:( NSError** )outError ++ (instancetype)downloadItemWithURL:(NSURL *)url + localFilePath:(NSString *)localFilePath + error:(NSError **)outError { - if ( ![ self checkNotAlreadyUsedLocalPath: local_file_path_ url: url_ error: outError ] ) + if (![self checkNotAlreadyUsedLocalPath:localFilePath url:url error:outError]) return nil; - id result = [ downloadItems_ firstMatch: ^BOOL(id object) { - JFFDownloadItem* item_ = object; - return [ item_.url isEqual: url_ ] - && [ item_.localFilePath isEqualToString: local_file_path_ ]; + id result = [downloadItems firstMatch: ^BOOL(id object) { + JFFDownloadItem *item = object; + return [item.url isEqual:url] + && [item.localFilePath isEqualToString:localFilePath]; } ]; - if ( !result ) - { - result = [ [ self alloc ] initWithURL: url_ localFilePath: local_file_path_ ]; - if ( !downloadItems_ ) - { - downloadItems_ = [ JFFMutableAssignArray new ]; + if (!result) { + + result = [[self alloc] initWithURL:url localFilePath:localFilePath]; + if (!downloadItems) { + downloadItems = [JFFMutableAssignArray new]; } - [ downloadItems_ addObject: result ]; + [downloadItems addObject:result]; } return result; } --(BOOL)downloaded +- (BOOL)downloaded { return self.downloadedFlag != nil; } --(BOOL)activeDownload +- (BOOL)activeDownload { return self.stopBlock != nil; } --(void)start +- (void)start { if (self.stopBlock) return; @@ -201,128 +192,126 @@ -(void)start }); } --(void)stop +- (void)stop { - if ( self.stopBlock ) - { - JFFCancelAsyncOperation stop_block_ = [ self.stopBlock copy ]; + JFFCancelAsyncOperation stopBlock = [self.stopBlock copy]; + if (stopBlock) { self.stopBlock = nil; - stop_block_( YES ); + stopBlock(YES); } } --(void)removeDownload +- (void)removeDownload { - [ self stop ]; - [ NSMutableSet removeDownloadedFileWithPath: self.localFilePath ]; + [self stop]; + [NSMutableSet removeDownloadedFileWithPath:self.localFilePath]; } -+(BOOL)removeDownloadForURL:( NSURL* )url_ - localFilePath:( NSString* )local_file_path_ - error:( NSError** )outError ++ (BOOL)removeDownloadForURL:(NSURL *)url + localFilePath:(NSString *)localFilePath + error:(NSError **)outError { @autoreleasepool { - JFFDownloadItem* item_ = [ self downloadItemWithURL: url_ localFilePath: local_file_path_ error: outError ]; - [ item_ removeDownload ]; - return item_ != nil; + JFFDownloadItem *item = [self downloadItemWithURL:url localFilePath:localFilePath error:outError]; + [item removeDownload]; + return item != nil; } - + return NO; } --(void)addDelegate:( id< JFFDownloadItemDelegate > )delegate_ +- (void)addDelegate:(id)delegate { - [ _multicastDelegate addDelegate: delegate_ ]; + [_multicastDelegate addDelegate:delegate]; } --(void)removeDelegate:( id< JFFDownloadItemDelegate > )delegate_ +- (void)removeDelegate:(id)delegate { - [ _multicastDelegate removeDelegate: delegate_ ]; + [_multicastDelegate removeDelegate:delegate]; } #pragma mark JFFURLConnection callbacks --(void)finalizeLoading +- (void)finalizeLoading { self.stopBlock = nil; - [ self closeFile ]; - [ _trafficCalculator stop ]; + [self closeFile]; + [_trafficCalculator stop]; _trafficCalculator = nil; } --(void)notifyFinishWithError:( NSError* )error +- (void)notifyFinishWithError:(NSError *)error { - if ( error ) - [ _multicastDelegate didFailLoadingOfDownloadItem: self error: error ]; + if (error) + [_multicastDelegate didFailLoadingOfDownloadItem:self error:error]; else - [ _multicastDelegate didFinishLoadingOfDownloadItem: self ]; + [_multicastDelegate didFinishLoadingOfDownloadItem:self]; } --(void)didFinishLoadedWithError:( NSError* )error_ +- (void)didFinishLoadedWithError:(NSError *)error { - id downloaded_flag_ = error_ ? nil : [ NSNull null ]; - self.downloadedFlag = downloaded_flag_; - - [ self finalizeLoading ]; + id downloadedFlag = error ? nil : [NSNull new]; + self.downloadedFlag = downloadedFlag; + + [self finalizeLoading]; } -- (void)didCancelWithFlag:( BOOL )canceled - cancelCallback:( JFFCancelAsyncOperationHandler )cancelCallback +- (void)didCancelWithFlag:(BOOL)canceled + cancelCallback:(JFFCancelAsyncOperationHandler)cancelCallback { NSParameterAssert(canceled); [self finalizeLoading]; - + [_multicastDelegate didCancelLoadingOfDownloadItem:self]; - + if (cancelCallback) cancelCallback(canceled); } --(void)didReceiveData:( NSData* )data_ - progressHandler:( JFFAsyncOperationProgressHandler )progress_callback_ +- (void)didReceiveData:(NSData *)data + progressHandler:(JFFAsyncOperationProgressHandler)progressCallback { - if ( !_trafficCalculator ) - [ self.trafficCalculator startLoading ]; - - if ( !_file ) - _file = [ JFFFileManager createFileForPath: self.localFilePath ]; - - fwrite([ data_ bytes ], 1, [ data_ length ], _file ); + if (!_trafficCalculator) + [self.trafficCalculator startLoading]; + + if (!_file) + _file = [JFFFileManager createFileForPath:self.localFilePath]; + + fwrite([data bytes], 1, [data length], _file); fflush(_file ); - [self.trafficCalculator bytesReceived:data_.length]; + [self.trafficCalculator bytesReceived:data.length]; - self.downloadedFileLength += data_.length; + self.downloadedFileLength += data.length; - if ((self.progress - _previousProgress) > 0.005f) - { + if ((self.progress - _previousProgress) > 0.005f) { _previousProgress = self.progress; - [ _multicastDelegate didProgressChangeForDownloadItem: self ]; + [_multicastDelegate didProgressChangeForDownloadItem:self]; } - if ( progress_callback_ ) - progress_callback_( self ); + if (progressCallback) + progressCallback(self); } --(void)didReceiveResponse:( JFFURLResponse* )response_ +- (void)didReceiveResponse:(JFFURLResponse *)response { - self.fileLength = self.downloadedFileLength + response_.expectedContentLength; + self.fileLength = self.downloadedFileLength + response.expectedContentLength; } --(JFFAsyncOperation)fileLoader +- (JFFAsyncOperation)fileLoader { JFFAsyncOperation loader = ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, JFFCancelAsyncOperationHandler cancelCallback, JFFDidFinishAsyncOperationHandler doneCallback) { - NSString *range_ = [[NSString alloc] initWithFormat:@"bytes=%qu-", self.downloadedFileLength]; - NSDictionary *headers_ = @{ @"Range" : range_ }; + NSString *range = [[NSString alloc] initWithFormat:@"bytes=%qu-", self.downloadedFileLength]; + NSDictionary *headers = @{ @"Range" : range }; - JFFURLConnectionParams* params = [ JFFURLConnectionParams new ]; + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; params.url = self.url; - params.headers = headers_; - JFFURLConnection* connection = [[JFFURLConnection alloc] initWithURLConnectionParams:params]; + params.headers = headers; + JFFURLConnection *connection = [[JFFURLConnection alloc] initWithURLConnectionParams:params]; progressCallback = [ progressCallback copy ]; connection.didReceiveDataBlock = ^(NSData *data) { @@ -343,7 +332,7 @@ -(JFFAsyncOperation)fileLoader [self didReceiveResponse:response]; }; - JFFCancelAsyncOperationBlockHolder *cancelCallbackBlockHolder = [ JFFCancelAsyncOperationBlockHolder new ]; + JFFCancelAsyncOperationBlockHolder *cancelCallbackBlockHolder = [JFFCancelAsyncOperationBlockHolder new]; cancelCallback = [cancelCallback copy]; JFFCancelAsyncOperationHandler cancelCallbackWrapper = ^(BOOL canceled) { @@ -360,14 +349,14 @@ -(JFFAsyncOperation)fileLoader if (canceled) [connection cancel]; else - assert(NO);// pass canceled as YES only + NSCAssert(NO, @"pass canceled as YES only"); cancelCallbackBlockHolder.onceCancelBlock(canceled); }; return self.stopBlock; }; - loader = [self asyncOperationForPropertyWithName:@"downloadedFlag" + loader = [self asyncOperationForPropertyWithName:NSStringFromSelector(@selector(downloadedFlag)) asyncOperation:loader]; JFFDidFinishAsyncOperationHandler didFinishOperation = ^void(id result, NSError *error) { @@ -379,11 +368,11 @@ -(JFFAsyncOperation)fileLoader #pragma mark JFFTrafficCalculatorDelegate --(void)trafficCalculator:( JFFTrafficCalculator* )traffic_calculator_ - didChangeDownloadSpeed:( float )speed_ +- (void)trafficCalculator:(JFFTrafficCalculator *)trafficCalculator + didChangeDownloadSpeed:(float)speed { - self.downlodingSpeed = speed_; - [ _multicastDelegate didProgressChangeForDownloadItem: self ]; + self.downlodingSpeed = speed; + [_multicastDelegate didProgressChangeForDownloadItem:self]; } @end diff --git a/lib/JFFNetwork/DownloadManager/JFFDownloadItemDelegate.h b/lib/JFFNetwork/DownloadManager/JFFDownloadItemDelegate.h index 8dec9fa..4ce0707 100755 --- a/lib/JFFNetwork/DownloadManager/JFFDownloadItemDelegate.h +++ b/lib/JFFNetwork/DownloadManager/JFFDownloadItemDelegate.h @@ -5,12 +5,12 @@ @protocol JFFDownloadItemDelegate @optional --(void)didProgressChangeForDownloadItem:( JFFDownloadItem* )download_item_; +- (void)didProgressChangeForDownloadItem:(JFFDownloadItem *)downloadItem; --(void)didFailLoadingOfDownloadItem:( JFFDownloadItem* )download_item_ error:( NSError* )error; +- (void)didFailLoadingOfDownloadItem:(JFFDownloadItem *)downloadItem error:(NSError *)error; --(void)didFinishLoadingOfDownloadItem:( JFFDownloadItem* )download_item_; +- (void)didFinishLoadingOfDownloadItem:(JFFDownloadItem *)downloadItem; --(void)didCancelLoadingOfDownloadItem:( JFFDownloadItem* )download_item_; +- (void)didCancelLoadingOfDownloadItem:(JFFDownloadItem *)downloadItem; @end diff --git a/lib/JFFNetwork/Errors/JHttpError.h b/lib/JFFNetwork/Errors/JHttpError.h new file mode 100644 index 0000000..4d7bf7f --- /dev/null +++ b/lib/JFFNetwork/Errors/JHttpError.h @@ -0,0 +1,15 @@ +#import + +#import + +@interface JHttpError : JNetworkError + +@property (nonatomic) id context; + +- (instancetype)initWithHttpCode:(CFIndex)statusCode; + +- (BOOL)isHttpNotChangedError; +- (BOOL)isServiceUnavailableError; +- (BOOL)isInternalServerError; + +@end diff --git a/lib/JFFNetwork/Errors/JHttpError.m b/lib/JFFNetwork/Errors/JHttpError.m new file mode 100644 index 0000000..836990c --- /dev/null +++ b/lib/JFFNetwork/Errors/JHttpError.m @@ -0,0 +1,67 @@ +#import "JHttpError.h" + +@implementation JHttpError + +- (instancetype)init +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (instancetype)initWithDescription:(NSString *)description + domain:(NSString *)domain + code:(NSInteger)code +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (instancetype)initWithDescription:(NSString *)description + code:(NSInteger)code +{ + return [super initWithDescription:description + domain:@"com.just_for_fun.library.http" + code:code]; +} + +- (instancetype)initWithHttpCode:(CFIndex)statusCode +{ + return [self initWithDescription:NSLocalizedString(@"JFF_HTTP_ERROR", nil) + code:statusCode]; +} + +- (instancetype)copyWithZone:(NSZone *)zone +{ + JHttpError *copy = [super copyWithZone:zone]; + + if (copy) { + copy->_context = [_context copyWithZone:zone]; + } + + return copy; +} + +- (NSString *)errorLogDescription +{ + return [[NSString alloc] initWithFormat:@"%@ Http code:%ld cantext:%@", + [self localizedDescription], + (long)self.code, + _context]; +} + +- (BOOL)isHttpNotChangedError +{ + return (self.code == 304); +} + +- (BOOL)isServiceUnavailableError +{ + return (self.code == 503); +} + +- (BOOL)isInternalServerError +{ + return (self.code == 500); +} + +@end diff --git a/lib/JFFNetwork/Errors/JNetworkError.h b/lib/JFFNetwork/Errors/JNetworkError.h index 9ba9633..0b76f75 100644 --- a/lib/JFFNetwork/Errors/JNetworkError.h +++ b/lib/JFFNetwork/Errors/JNetworkError.h @@ -1,4 +1,4 @@ -#import +#import @interface JNetworkError : JFFError @end diff --git a/lib/JFFNetwork/Errors/JNetworkError.m b/lib/JFFNetwork/Errors/JNetworkError.m index f9031ef..a32b560 100644 --- a/lib/JFFNetwork/Errors/JNetworkError.m +++ b/lib/JFFNetwork/Errors/JNetworkError.m @@ -1,4 +1,10 @@ #import "JNetworkError.h" @implementation JNetworkError + ++ (NSString *)jffErrorsDomain +{ + return @"com.just_for_fun.network.library"; +} + @end diff --git a/lib/JFFNetwork/Errors/JStreamError.h b/lib/JFFNetwork/Errors/JStreamError.h index 36d5102..94dc33c 100644 --- a/lib/JFFNetwork/Errors/JStreamError.h +++ b/lib/JFFNetwork/Errors/JStreamError.h @@ -1,10 +1,12 @@ #import -#import + +#import @interface JStreamError : JNetworkError --(id)initWithStreamError:( CFStreamError )rawError_; +@property (nonatomic, readonly) CFStreamError rawError; -@property ( nonatomic, assign, readonly ) CFStreamError rawError; +- (instancetype)initWithStreamError:(CFStreamError)rawError + context:(id)context; @end diff --git a/lib/JFFNetwork/Errors/JStreamError.m b/lib/JFFNetwork/Errors/JStreamError.m index f47e313..723e24e 100644 --- a/lib/JFFNetwork/Errors/JStreamError.m +++ b/lib/JFFNetwork/Errors/JStreamError.m @@ -4,40 +4,63 @@ @implementation JStreamError { @private CFStreamError _rawError; + id _context; } - --(id)init +- (instancetype)init { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; return nil; } --(id)initWithDescription:( NSString* )description_ - domain:( NSString* )domain_ - code:( NSInteger )code_ +- (instancetype)initWithDescription:(NSString *)description + domain:(NSString *)domain + code:(NSInteger)code { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; return nil; } --(id)initWithStreamError:( CFStreamError )rawError_ +- (instancetype)initWithStreamError:(CFStreamError)rawError + context:(id)context { - NSString* domain_ = [ NSString stringWithFormat: @"com.just_for_fun.library.network.CFError(%ld)", rawError_.domain ]; + NSString *domain_ = [[NSString alloc] initWithFormat: @"com.just_for_fun.library.network.CFError(%ld)", rawError.domain]; - self = [ super initWithDescription: NSLocalizedString( @"JNETWORK_CF_STREAM_ERROR", nil ) - domain: domain_ - code: rawError_.error ]; + self = [super initWithDescription:NSLocalizedString(@"JNETWORK_CF_STREAM_ERROR", nil) + domain:domain_ + code:rawError.error]; - if ( nil == self ) - { + if (nil == self) { + return nil; } - - self->_rawError = rawError_; + _rawError = rawError; + _context = context; return self; } +- (instancetype)copyWithZone:(NSZone *)zone +{ + JStreamError *copy = [super copyWithZone:zone]; + + if (copy) { + + copy->_rawError = _rawError; + copy->_context = [_context copyWithZone:zone]; + } + + return copy; +} + +- (NSString *)errorLogDescription +{ + return [[NSString alloc] initWithFormat:@"%@ nativeError domain:%ld error_code:%d context:%@", + [self localizedDescription], + _rawError.domain, + (int)_rawError.error, + _context]; +} + @end diff --git a/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNetworkError.h b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNetworkError.h new file mode 100644 index 0000000..7bfc65e --- /dev/null +++ b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNetworkError.h @@ -0,0 +1,13 @@ +#import + +#import + +@interface JNSNetworkError : JNetworkError + +@property (nonatomic, readonly) id context; +@property (nonatomic, readonly) NSError *nativeError; + ++ (instancetype)newJNSNetworkErrorWithContext:(id)context + nativeError:(NSError *)nativeError; + +@end diff --git a/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNetworkError.m b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNetworkError.m new file mode 100644 index 0000000..d0b5391 --- /dev/null +++ b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNetworkError.m @@ -0,0 +1,84 @@ +#import "JNSNetworkError.h" + +#import "JNSNoInternetNetworkError.h" + +@implementation JNSNetworkError +{ + id _context; + NSError *_nativeError; +} + +- (instancetype)init +{ + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (instancetype)initWithContext:(id)context + nativeError:(NSError *)nativeError +{ + self = [self initWithDescription:NSLocalizedString(@"JNETWORK_GENERIC_ERROR", nil)]; + + if (self) { + _context = context; + _nativeError = nativeError; + } + + return self; +} + ++ (BOOL)isMineNSNetworkError:(NSError *)error +{ + return NO; +} + ++ (instancetype)newJNSNetworkErrorWithContext:(id)context + nativeError:(NSError *)nativeError +{ + Class class = Nil; + + //select class for error + { + NSArray *errorClasses = + @[ + [JNSNoInternetNetworkError class], + ]; + + class = [errorClasses firstMatch:^BOOL(id object) { + + Class someClass = object; + return [someClass isMineNSNetworkError:nativeError]; + }]; + } + + if (class == Nil) { + + class = [JNSNetworkError class]; + } + + JNSNetworkError *result = [[class alloc] initWithContext:context nativeError:nativeError]; + return result; +} + +- (instancetype)copyWithZone:(NSZone *)zone +{ + JNSNetworkError *copy = [super copyWithZone:zone]; + + if (copy) { + + copy->_nativeError = [_nativeError copyWithZone:zone]; + copy->_context = [_context copyWithZone:zone]; + } + + return copy; +} + +- (NSString *)errorLogDescription +{ + return [[NSString alloc] initWithFormat:@"%@ nativeError:%@ context:%@", + [self localizedDescription], + _nativeError, + _context]; +} + +@end diff --git a/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNoInternetNetworkError.h b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNoInternetNetworkError.h new file mode 100644 index 0000000..0b89a88 --- /dev/null +++ b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNoInternetNetworkError.h @@ -0,0 +1,4 @@ +#import + +@interface JNSNoInternetNetworkError : JNSNetworkError +@end diff --git a/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNoInternetNetworkError.m b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNoInternetNetworkError.m new file mode 100644 index 0000000..5216c58 --- /dev/null +++ b/lib/JFFNetwork/Errors/NSNetworkErrors/JNSNoInternetNetworkError.m @@ -0,0 +1,20 @@ +#import "JNSNoInternetNetworkError.h" + +@implementation JNSNoInternetNetworkError + ++ (BOOL)isMineNSNetworkError:(NSError *)error +{ + return [error isNetworkError]; +} + +- (instancetype)init +{ + return [self initWithDescription:NSLocalizedString(@"JNETWORK_NO_INTERNET_ERROR", nil)]; +} + +- (void)writeErrorWithJFFLogger +{ + [self writeErrorToNSLog]; +} + +@end diff --git a/lib/JFFNetwork/Extensions/NSData+DataForHTTPPost.h b/lib/JFFNetwork/Extensions/NSData+DataForHTTPPost.h deleted file mode 100644 index 9ecdb71..0000000 --- a/lib/JFFNetwork/Extensions/NSData+DataForHTTPPost.h +++ /dev/null @@ -1,18 +0,0 @@ -#import - -@interface NSData (DataForHTTPPost) - -+ (NSData *)dataForHTTPPostWithData:(NSData *)data - andFileName:(NSString *)fileName - andParameterName:(NSString *)parameter - boundary:(NSString *)boundary; - -+ (NSData *)mutableDataForHTTPPostWithData:(NSData *)data - andFileName:(NSString *)fileName - andParameterName:(NSString *)parameter - boundary:(NSString *)boundary; - -- (NSData *)dataForHTTPPostByAppendingParameters:(NSDictionary *)parameters - boundary:(NSString *)boundary; - -@end diff --git a/lib/JFFNetwork/Extensions/NSData+DataForHTTPPost.m b/lib/JFFNetwork/Extensions/NSData+DataForHTTPPost.m deleted file mode 100644 index 37589c3..0000000 --- a/lib/JFFNetwork/Extensions/NSData+DataForHTTPPost.m +++ /dev/null @@ -1,56 +0,0 @@ -#import "NSData+DataForHTTPPost.h" - -@implementation NSData (DataForHTTPPost) - -+ (NSData *)dataForHTTPPostWithData:(NSData *)data - andFileName:(NSString *)fileName - andParameterName:(NSString *)parameter - boundary:(NSString *)boundary -{ - NSData *result = [self mutableDataForHTTPPostWithData:data - andFileName:fileName - andParameterName:parameter - boundary:boundary]; - return [result copy]; -} - -+ (NSData *)mutableDataForHTTPPostWithData:(NSData *)data - andFileName:(NSString *)fileName - andParameterName:(NSString *)parameter - boundary:(NSString *)boundary -{ - NSMutableData *body = [[NSMutableData alloc] initWithCapacity:[data length] + 512]; - [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", parameter, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; - - [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - - [body appendData:[NSData dataWithData:data]]; - - [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - - return [body copy]; - -} - -- (NSData *)dataForHTTPPostByAppendingParameters:(NSDictionary *)parameters - boundary:(NSString *)boundary -{ - if (!parameters) { - return self; - } - - NSMutableData *newData = [self mutableCopy]; - - [parameters enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { - - [newData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - [newData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]]; - [newData appendData:[[obj description] dataUsingEncoding:NSUTF8StringEncoding]]; - [newData appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - }]; - - return [newData copy]; -} - -@end diff --git a/lib/JFFNetwork/Extensions/NSDictionary+JHTTPHeaders.h b/lib/JFFNetwork/Extensions/NSDictionary+JHTTPHeaders.h deleted file mode 100755 index ee8a6d9..0000000 --- a/lib/JFFNetwork/Extensions/NSDictionary+JHTTPHeaders.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -@interface NSDictionary (JHTTPHeaders) - --(id)initWithContentType:( NSString* )contentType_; -+(id)headersDictionadyWithUploadContentType; - -+(NSString*)utf8XmlContentType; -+(id)headersDictionadyWithUtf8XmlContentType; - -@end diff --git a/lib/JFFNetwork/Extensions/NSDictionary+JHTTPHeaders.m b/lib/JFFNetwork/Extensions/NSDictionary+JHTTPHeaders.m deleted file mode 100755 index b9d36b7..0000000 --- a/lib/JFFNetwork/Extensions/NSDictionary+JHTTPHeaders.m +++ /dev/null @@ -1,32 +0,0 @@ -#import "NSDictionary+JHTTPHeaders.h" - -@implementation NSDictionary (JHTTPHeaders) - --(id)initWithContentType:( NSString* )contentType_ -{ - NSParameterAssert( contentType_ ); - - id objects_[] = { contentType_ }; - id keys_ [] = { @"Content-Type" }; - - return [ self initWithObjects: objects_ forKeys: keys_ count: 1 ]; -} - -+(id)headersDictionadyWithUploadContentType -{ - return [ [ self alloc ] initWithContentType: @"application/x-www-form-urlencoded" ]; -} - -#pragma mark - -#pragma mark UTF8 xml -+(NSString*)utf8XmlContentType -{ - return @"application/xml;charset=utf-8"; -} - -+(id)headersDictionadyWithUtf8XmlContentType -{ - return [ [ self alloc ] initWithContentType: [ self utf8XmlContentType ] ]; -} - -@end diff --git a/lib/JFFNetwork/Extensions/NSURL+Cookies.m b/lib/JFFNetwork/Extensions/NSURL+Cookies.m deleted file mode 100755 index 93383ba..0000000 --- a/lib/JFFNetwork/Extensions/NSURL+Cookies.m +++ /dev/null @@ -1,27 +0,0 @@ -#import "NSURL+Cookies.h" - -@implementation NSURL (Cookies) - --(void)logCookies -{ - NSMutableString* cookiesLog_ = [ [ NSMutableString alloc ] initWithFormat: @"Cookies for url: %@\n", self ]; - - NSArray* cookies_ = [ [ NSHTTPCookieStorage sharedHTTPCookieStorage ] cookiesForURL: self ]; - for ( NSHTTPCookie* cookie_ in cookies_ ) - { - [ cookiesLog_ appendFormat: @"Name: '%@'; Value: '%@'\n", cookie_.name, cookie_.value ]; - } - - NSLog( @"%@", cookiesLog_ ); -} - --(void)removeCookies -{ - NSArray* cookies_ = [ [ NSHTTPCookieStorage sharedHTTPCookieStorage ] cookiesForURL: self ]; - for ( NSHTTPCookie* cookie_ in cookies_ ) - { - [ [ NSHTTPCookieStorage sharedHTTPCookieStorage ] deleteCookie: cookie_ ]; - } -} - -@end diff --git a/lib/JFFNetwork/HttpBodyBuilder/JHttpBodyBuilder.h b/lib/JFFNetwork/HttpBodyBuilder/JHttpBodyBuilder.h new file mode 100644 index 0000000..a811e10 --- /dev/null +++ b/lib/JFFNetwork/HttpBodyBuilder/JHttpBodyBuilder.h @@ -0,0 +1,11 @@ +#import + +@interface JHttpBodyBuilder : NSObject + ++ (NSString *)tmpFileForUploadStreamWithDataForFilePath:(NSString *)dataFilePath + boundary:(NSString *)boundary + name:(NSString *)name + fileName:(NSString *)fileName + dictWithParam:(NSDictionary *)dictWithParam; + +@end diff --git a/lib/JFFNetwork/HttpBodyBuilder/JHttpBodyBuilder.m b/lib/JFFNetwork/HttpBodyBuilder/JHttpBodyBuilder.m new file mode 100644 index 0000000..837ec9e --- /dev/null +++ b/lib/JFFNetwork/HttpBodyBuilder/JHttpBodyBuilder.m @@ -0,0 +1,112 @@ +#import "JHttpBodyBuilder.h" + +@implementation JHttpBodyBuilder + ++ (NSString *)tmpFileForUploadStreamWithDataForFilePath:(NSString *)dataFilePath + boundary:(NSString *)boundary + name:(NSString *)name + fileName:(NSString *)fileName + dictWithParam:(NSDictionary *)dictWithParam +{ + NSString *filePath; + + @autoreleasepool { + + filePath = [[NSUUID new] UUIDString]; + filePath = [NSString cachesPathByAppendingPathComponent:filePath]; + const char *filePathPtr = [filePath cStringUsingEncoding:NSUTF8StringEncoding]; + + FILE *file = fopen(filePathPtr, "w+"); + + @autoreleasepool + { + { + NSString *boundaryStr = [[NSString alloc] initWithFormat:@"--%@\r\n", boundary]; + NSData *boundaryData = [boundaryStr dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([boundaryData bytes], 1, [boundaryData length], file); + } + //[result appendData:[[[NSString alloc] initWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + + { + NSString *contentDisposition = [[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName]; + NSData *contentDispositionData = [contentDisposition dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([contentDispositionData bytes], 1, [contentDispositionData length], file); + } + //[result appendData:[[[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", parameter, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; + + { + NSString *contentType = @"Content-Type: application/octet-stream\r\n\r\n"; + NSData *contentTypeData = [contentType dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([contentTypeData bytes], 1, [contentTypeData length], file); + } + //[result appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; + + { + FILE *uploadDataFile = fopen([dataFilePath cStringUsingEncoding:NSUTF8StringEncoding], + "r"); + + uint8_t buffer[10*1024]; + const size_t bufferSize = sizeof(buffer)/sizeof(buffer[0]); + + size_t readBytes = 0; + + while ((readBytes = fread((void* __restrict)&buffer[0], 1, bufferSize, uploadDataFile)) != 0) { + + fwrite(buffer, 1, readBytes, file); + } + + fclose(uploadDataFile); + } + //[result appendData:data]; + + { + NSString *boundaryStr = [[NSString alloc] initWithFormat:@"\r\n--%@\r\n", boundary]; + NSData *boundaryData = [boundaryStr dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([boundaryData bytes], 1, [boundaryData length], file); + } + //[result appendData:[[[NSString alloc] initWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + } + + { + [dictWithParam enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { + + @autoreleasepool + { + { + NSString *boundaryStr = [[NSString alloc] initWithFormat:@"--%@\r\n", boundary]; + NSData *boundaryData = [boundaryStr dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([boundaryData bytes], 1, [boundaryData length], file); + } + //[self appendData:[[[NSString alloc] initWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + + { + NSString *contentDisposition = [[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key]; + NSData *contentDispositionData = [contentDisposition dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([contentDispositionData bytes], 1, [contentDispositionData length], file); + } + //[self appendData:[[[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]]; + + { + NSString *objStr = [obj description]; + NSData *objData = [objStr dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([objData bytes], 1, [objData length], file); + } + //[self appendData:[[obj description] dataUsingEncoding:NSUTF8StringEncoding]]; + + { + NSString *boundaryStr = [[NSString alloc] initWithFormat:@"\r\n--%@\r\n", boundary]; + NSData *boundaryData = [boundaryStr dataUsingEncoding:NSUTF8StringEncoding]; + fwrite([boundaryData bytes], 1, [boundaryData length], file); + } + //[self appendData:[[[NSString alloc] initWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + } + }]; + } + + fclose(file); + } + + return filePath; +} + +@end diff --git a/lib/JFFNetwork/JFFNetwork.h b/lib/JFFNetwork/JFFNetwork.h index b6df593..27fdfda 100755 --- a/lib/JFFNetwork/JFFNetwork.h +++ b/lib/JFFNetwork/JFFNetwork.h @@ -30,11 +30,17 @@ #import #import -#import -#import -#import +#import +#import +#import +#import #import #import -#import +#import + +//Errors +#import +#import +#import diff --git a/lib/JFFNetwork/JFFNetwork/JFFNetwork-Prefix.pch b/lib/JFFNetwork/JFFNetwork/JFFNetwork-Prefix.pch index 179e20c..2bfe2ec 100644 --- a/lib/JFFNetwork/JFFNetwork/JFFNetwork-Prefix.pch +++ b/lib/JFFNetwork/JFFNetwork/JFFNetwork-Prefix.pch @@ -1,6 +1,5 @@ #ifdef __OBJC__ #import - #import #import #include diff --git a/lib/JFFNetwork/JFFNetworkBlocksFunctions.m b/lib/JFFNetwork/JFFNetworkBlocksFunctions.m index 55f5047..63680ab 100644 --- a/lib/JFFNetwork/JFFNetworkBlocksFunctions.m +++ b/lib/JFFNetwork/JFFNetworkBlocksFunctions.m @@ -1,6 +1,5 @@ #import "JFFNetworkBlocksFunctions.h" -#import "JHttpError.h" #import "JNUrlResponse.h" #import "JHttpFlagChecker.h" #import "JFFURLConnectionParams.h" @@ -8,16 +7,20 @@ #import "JFFNetworkResponseDataCallback.h" +//Errors +#import "JHttpError.h" +#import "JNSNetworkError.h" + #import "NSURL+Cookies.h" -static JFFAnalyzer downloadErrorFlagResponseAnalyzer(id context) +static JFFAnalyzer downloadStatusCodeResponseAnalyzer(id context) { return ^id(id< JNUrlResponse > response, NSError **outError) { NSInteger statusCode = [response statusCode]; if ([JHttpFlagChecker isDownloadErrorFlag:statusCode]) { if (outError) { - JHttpError *httpError = [[JHttpError alloc]initWithHttpCode:statusCode]; + JHttpError *httpError = [[JHttpError alloc] initWithHttpCode:statusCode]; httpError.context = context; *outError = httpError; } @@ -28,6 +31,20 @@ static JFFAnalyzer downloadErrorFlagResponseAnalyzer(id context) }; } +static JFFNetworkErrorTransformer networkErrorAnalyzer(id context) +{ + return ^NSError *(NSError *error) { + + if ([error isKindOfClass:[JNetworkError class]]) + return error; + + JNSNetworkError *resultError = [JNSNetworkError newJNSNetworkErrorWithContext:context + nativeError:error]; + + return resultError; + }; +} + static JFFAsyncOperation privateGenericChunkedURLResponseLoader(JFFURLConnectionParams *params, JFFAnalyzer responseAnalyzer) { @@ -37,6 +54,7 @@ static JFFAsyncOperation privateGenericChunkedURLResponseLoader(JFFURLConnection JFFNetworkAsyncOperation *asyncObj = [JFFNetworkAsyncOperation new]; asyncObj.params = params; asyncObj.responseAnalyzer = responseAnalyzer; + asyncObj.errorTransformer = networkErrorAnalyzer(params); return asyncObj; }; @@ -45,13 +63,13 @@ static JFFAsyncOperation privateGenericChunkedURLResponseLoader(JFFURLConnection JFFAsyncOperation genericChunkedURLResponseLoader(JFFURLConnectionParams* params) { - return privateGenericChunkedURLResponseLoader(params, downloadErrorFlagResponseAnalyzer(params)); + return privateGenericChunkedURLResponseLoader(params, downloadStatusCodeResponseAnalyzer(params)); } static JFFAsyncOperation privateGenericDataURLResponseLoader(JFFURLConnectionParams *params, JFFAnalyzer responseAnalyzer) { - assert([params.url isKindOfClass:[NSURL class]]); + NSCParameterAssert([params.url isKindOfClass:[NSURL class]]); params = [params copy]; return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, JFFCancelAsyncOperationHandler cancelCallback, @@ -90,7 +108,7 @@ static JFFAsyncOperation privateGenericDataURLResponseLoader(JFFURLConnectionPar JFFAsyncOperation genericDataURLResponseLoader(JFFURLConnectionParams *params) { - return privateGenericDataURLResponseLoader(params, downloadErrorFlagResponseAnalyzer(params) ); + return privateGenericDataURLResponseLoader(params, downloadStatusCodeResponseAnalyzer(params) ); } #pragma mark - @@ -105,7 +123,7 @@ JFFAsyncOperation chunkedURLResponseLoader( params.url = url; params.httpBody = postData; params.headers = headers; - return privateGenericChunkedURLResponseLoader(params, downloadErrorFlagResponseAnalyzer(params)); + return privateGenericChunkedURLResponseLoader(params, downloadStatusCodeResponseAnalyzer(params)); } JFFAsyncOperation dataURLResponseLoader(NSURL *url, @@ -116,7 +134,7 @@ JFFAsyncOperation dataURLResponseLoader(NSURL *url, params.url = url; params.httpBody = postData; params.headers = headers; - return privateGenericDataURLResponseLoader(params, downloadErrorFlagResponseAnalyzer(params)); + return privateGenericDataURLResponseLoader(params, downloadStatusCodeResponseAnalyzer(params)); } JFFAsyncOperation liveChunkedURLResponseLoader(NSURL *url, @@ -128,7 +146,7 @@ JFFAsyncOperation liveChunkedURLResponseLoader(NSURL *url, params.httpBody = postData; params.headers = headers; params.useLiveConnection = YES; - return privateGenericChunkedURLResponseLoader(params, downloadErrorFlagResponseAnalyzer(params)); + return privateGenericChunkedURLResponseLoader(params, downloadStatusCodeResponseAnalyzer(params)); } JFFAsyncOperation liveDataURLResponseLoader(NSURL* url, @@ -140,7 +158,7 @@ JFFAsyncOperation liveDataURLResponseLoader(NSURL* url, params.httpBody = postData; params.headers = headers; params.useLiveConnection = YES; - return privateGenericDataURLResponseLoader(params, downloadErrorFlagResponseAnalyzer(params)); + return privateGenericDataURLResponseLoader(params, downloadStatusCodeResponseAnalyzer(params)); } JFFAsyncOperation perkyDataURLResponseLoader(NSURL *url, diff --git a/lib/JFFNetwork/JFFURLConnection.h b/lib/JFFNetwork/JFFURLConnection.h index a98a7af..ff98b57 100755 --- a/lib/JFFNetwork/JFFURLConnection.h +++ b/lib/JFFNetwork/JFFURLConnection.h @@ -8,7 +8,7 @@ //all callbacks cleared after cancel or finish action @interface JFFURLConnection : JNAbstractConnection -- (id)initWithURLConnectionParams:(JFFURLConnectionParams *)params; +- (instancetype)initWithURLConnectionParams:(JFFURLConnectionParams *)params; - (void)start; - (void)cancel; diff --git a/lib/JFFNetwork/JFFURLConnection.m b/lib/JFFNetwork/JFFURLConnection.m index 7b6c630..08860a3 100644 --- a/lib/JFFNetwork/JFFURLConnection.m +++ b/lib/JFFNetwork/JFFURLConnection.m @@ -30,33 +30,43 @@ static const char* const ZIP_QUEUE_NAME = "org.EmbeddedSources.network.gzip"; #define ZIP_QUEUE_MODE DISPATCH_QUEUE_SERIAL +@interface JFFURLConnectionContext : NSObject + +@property (nonatomic) JFFURLConnectionParams *params; +@property (nonatomic, weak) JFFURLConnection *connection; + +@end + +@implementation JFFURLConnectionContext +@end + @interface JFFURLConnection () -@property ( nonatomic ) unsigned long long downloadedBytesCount; -@property ( nonatomic ) unsigned long long totalBytesCount; -@property ( nonatomic, unsafe_unretained ) dispatch_queue_t zipQueue; +@property (nonatomic) JFFURLConnectionContext *context; +@property (nonatomic) unsigned long long downloadedBytesCount; +@property (nonatomic) unsigned long long totalBytesCount; +@property (nonatomic) dispatch_queue_t zipQueue; +@property (nonatomic) id decoder; --(void)handleResponseForReadStream:( CFReadStreamRef )stream_; --(void)handleData:( void* )buffer_ length:( NSUInteger )length_; --(void)handleFinish:( NSError* )error; +- (void)handleResponseForReadStream:(CFReadStreamRef)stream; +- (void)handleData:(void *)buffer length:(NSUInteger)length; +- (void)handleFinish:(NSError *)error; @end static void readStreamCallback(CFReadStreamRef stream, - CFStreamEventType event_, - void* selfContext_ ) + CFStreamEventType event, + void *selfContext) { + JFFURLConnectionContext *connectionContext = (__bridge JFFURLConnectionContext *)selfContext; - __unsafe_unretained JFFURLConnection* rawSelf = (__bridge JFFURLConnection*)selfContext_; - - // @adk - it is ok to use weak since connection may be closed in data callback - __weak JFFURLConnection* weakSelf = rawSelf; - dispatch_queue_t zipQueue = [ weakSelf zipQueue ]; - - + if (!connectionContext.connection) { + NSLog(@"!!!!!! ERROR !!!!!!, readStreamCallback called after freeing JFFURLConnection instance"); + return; + } - switch( event_ ) - { + switch(event) { + case kCFStreamEventNone: { break; @@ -67,14 +77,14 @@ static void readStreamCallback(CFReadStreamRef stream, } case kCFStreamEventHasBytesAvailable: { - [ weakSelf handleResponseForReadStream: stream ]; - - UInt8 buffer[ kJNMaxBufferSize ]; - CFIndex bytesRead = CFReadStreamRead( stream, buffer, kJNMaxBufferSize ); - if ( bytesRead > 0 ) - { - [ weakSelf handleData: buffer - length: (NSUInteger)bytesRead ]; + [connectionContext.connection handleResponseForReadStream:stream]; + + UInt8 buffer[kJNMaxBufferSize]; + CFIndex bytesRead = CFReadStreamRead(stream, buffer, kJNMaxBufferSize); + if (bytesRead > 0) { + + [connectionContext.connection handleData:buffer + length:bytesRead]; } break; } @@ -84,26 +94,18 @@ static void readStreamCallback(CFReadStreamRef stream, } case kCFStreamEventErrorOccurred: { - [weakSelf handleResponseForReadStream:stream]; + [connectionContext.connection handleResponseForReadStream:stream]; CFStreamError error = CFReadStreamGetError(stream); - JStreamError* errorObject = [ [ JStreamError alloc ] initWithStreamError: error ]; - dispatch_barrier_async( zipQueue, - ^{ - [weakSelf handleFinish: errorObject]; - } ); - + JFFError *wrappedError = [[JStreamError alloc] initWithStreamError:error context:connectionContext.params]; + [connectionContext.connection handleFinish:wrappedError]; break; } case kCFStreamEventEndEncountered: { - [ weakSelf handleResponseForReadStream: stream ]; - - dispatch_barrier_async( zipQueue, - ^{ - [ weakSelf handleFinish: nil ]; - } ); + [connectionContext.connection handleResponseForReadStream:stream]; + [connectionContext.connection handleFinish:nil]; break; } } @@ -112,142 +114,145 @@ static void readStreamCallback(CFReadStreamRef stream, @implementation JFFURLConnection { CFReadStreamRef _readStream; - JFFURLConnectionParams* _params; id _cookiesStorage; BOOL _responseHandled; - JFFURLResponse* _urlResponse; - -// NSString* _previousContentEncoding; - id< JNHttpDecoder > _decoder; + JFFURLResponse *_urlResponse; + + // NSString* _previousContentEncoding; unsigned long long _downloadedBytesCount; unsigned long long _totalBytesCount; dispatch_queue_t _queueForCallbacks; + + __strong id _selfHolder; }; @synthesize downloadedBytesCount = _downloadedBytesCount; @synthesize totalBytesCount = _totalBytesCount ; --(void)dealloc +- (void)dealloc { - [ self cancel ]; + [self cancel]; } --(id)initWithURLConnectionParams:( JFFURLConnectionParams* )params_ +- (instancetype)initWithURLConnectionParams:(JFFURLConnectionParams *)params { - self = [ super init ]; - - if ( self ) - { - _params = params_; - _cookiesStorage = _params.cookiesStorage ?: [ NSHTTPCookieStorage sharedHTTPCookieStorage ]; + self = [super init]; + + if (self) { + + _context = [JFFURLConnectionContext new]; + _context.connection = self; + _context.params = params; + _cookiesStorage = _context.params.cookiesStorage?:[NSHTTPCookieStorage sharedHTTPCookieStorage]; } - + return self; } --(NSString*)zipQueueName +- (NSString *)zipQueueName { - return [ NSString stringWithFormat: @"%s-%p", ZIP_QUEUE_NAME, self ]; + return [NSString stringWithFormat:@"%s-%p", ZIP_QUEUE_NAME, self]; } --(void)start +- (void)start { - [ self startConnectionWithPostData:_params.httpBody - headers:_params.headers ]; + _selfHolder = self; + + [self startConnectionWithPostData:_context.params.httpBody + headers:_context.params.headers]; } --(void)applyCookiesForHTTPRequest:( CFHTTPMessageRef )httpRequest_ +- (void)applyCookiesForHTTPRequest:(CFHTTPMessageRef)httpRequest { - NSArray *availableCookies_ = [ _cookiesStorage cookiesForURL: _params.url ]; - - NSDictionary *headers = [ NSHTTPCookie requestHeaderFieldsWithCookies: availableCookies_ ]; - - [headers enumerateKeysAndObjectsUsingBlock: ^( id key_, id value_, BOOL *stop ) - { - - CFHTTPMessageSetHeaderFieldValue ( httpRequest_ - , (__bridge CFStringRef)key_ - , (__bridge CFStringRef)value_ ); - } ]; + NSArray *availableCookies = [_cookiesStorage cookiesForURL:_context.params.url]; + + NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:availableCookies]; + + [headers enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { + + CFHTTPMessageSetHeaderFieldValue(httpRequest, + (__bridge CFStringRef)key, + (__bridge CFStringRef)value); + }]; } //JTODO add timeout and test //JTODO test invalid url //JTODO test no internet connection --(void)startConnectionWithPostData:( NSData* )data_ - headers:( NSDictionary* )headers_ +- (void)startConnectionWithPostData:(NSData *)data + headers:(NSDictionary *)headers { - self->_queueForCallbacks = dispatch_get_current_queue(); + _queueForCallbacks = dispatch_get_current_queue(); - NSString* zipQueueName = [ self zipQueueName ]; - self->_zipQueue = dispatch_queue_create( [ zipQueueName UTF8String ], ZIP_QUEUE_MODE ); + NSString *zipQueueName = [self zipQueueName]; + _zipQueue = dispatch_queue_create([zipQueueName UTF8String], ZIP_QUEUE_MODE); - CFStringRef method = (__bridge CFStringRef)(self->_params.httpMethod?:@"GET"); - if ( !self->_params.httpMethod && data_ ) - { - method = (__bridge CFStringRef)@"POST"; + CFStringRef method = (__bridge CFStringRef)(_context.params.httpMethod?:@"GET"); + if (!_context.params.httpMethod && data) { + method = (__bridge CFStringRef)@"POST"; } - CFHTTPMessageRef httpRequest_ = CFHTTPMessageCreateRequest(NULL, - method, - (__bridge CFURLRef)_params.url, - kCFHTTPVersion1_1); - - [ self applyCookiesForHTTPRequest: httpRequest_ ]; - - if ( data_ ) - { - CFHTTPMessageSetBody ( httpRequest_, (__bridge CFDataRef)data_ ); + CFHTTPMessageRef httpRequest = CFHTTPMessageCreateRequest(NULL, + method, + (__bridge CFURLRef)_context.params.url, + kCFHTTPVersion1_1); + + [self applyCookiesForHTTPRequest:httpRequest]; + + if (data) { + + CFHTTPMessageSetBody(httpRequest, (__bridge CFDataRef)data); } - - [ headers_ enumerateKeysAndObjectsUsingBlock: ^( id header_, id headerValue_, BOOL *stop ) - { - CFHTTPMessageSetHeaderFieldValue( httpRequest_ - , (__bridge CFStringRef)header_ - , (__bridge CFStringRef)headerValue_ ); - } ]; - - [ self closeReadStream ]; + + [headers enumerateKeysAndObjectsUsingBlock:^(id header, id headerValue, BOOL *stop) { + + CFHTTPMessageSetHeaderFieldValue(httpRequest, + (__bridge CFStringRef)header, + (__bridge CFStringRef)headerValue); + }]; + + [self closeReadStream]; // CFReadStreamCreateForStreamedHTTPRequest( CFAllocatorRef alloc, // CFHTTPMessageRef requestHeaders, - // CFReadStreamRef requestBody ) - self->_readStream = CFReadStreamCreateForHTTPRequest( NULL, httpRequest_ ); - CFRelease( httpRequest_ ); - + // CFReadStreamRef requestBody ) + _readStream = CFReadStreamCreateForHTTPRequest(NULL, httpRequest); + CFRelease(httpRequest); + //Prefer using keep-alive packages - Boolean keepAliveSetResult_ = CFReadStreamSetProperty( self->_readStream - , kCFStreamPropertyHTTPAttemptPersistentConnection - , kCFBooleanTrue ); - if ( FALSE == keepAliveSetResult_ ) - { - NSLog( @"JFFURLConnection->start : unable to setup keep-alive packages" ); + Boolean keepAliveSetResult = CFReadStreamSetProperty(_readStream, + kCFStreamPropertyHTTPAttemptPersistentConnection, + kCFBooleanTrue); + if (FALSE == keepAliveSetResult) { + + NSLog(@"JFFURLConnection->start : unable to setup keep-alive packages"); } - - typedef void* (*retain)( void* info_ ); - typedef void (*release)( void* info_ ); - CFStreamClientContext streamContext_ = - { - 0 - , (__bridge void*)(self) - , (retain)CFRetain - , (release)CFRelease - , NULL - }; - - CFOptionFlags registered_events_ = kCFStreamEventHasBytesAvailable - | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered; - if ( CFReadStreamSetClient( self->_readStream, registered_events_, readStreamCallback, &streamContext_ ) ) - { - CFRunLoopRef streamRunLoop = [ self runLoopForReadStream ]; + + typedef void* (*retain)(void *info); + typedef void (*release)(void *info); + CFStreamClientContext streamContext = { + 0, + (__bridge void*)(_context), + (retain)CFRetain, + (release)CFRelease, + NULL}; + + CFOptionFlags registeredEvents = kCFStreamEventHasBytesAvailable + | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered; + if (CFReadStreamSetClient(_readStream, registeredEvents, readStreamCallback, &streamContext)) { - CFReadStreamScheduleWithRunLoop( self->_readStream, streamRunLoop, kCFRunLoopCommonModes ); + CFRunLoopRef streamRunLoop = [self runLoopForReadStream]; + CFReadStreamScheduleWithRunLoop(_readStream, streamRunLoop, kCFRunLoopCommonModes); + } + + Boolean openResult = CFReadStreamOpen(_readStream); + if (!openResult) { + + NSLog(@"Error opening a socket"); } - - CFReadStreamOpen( self->_readStream ); } --(CFRunLoopRef)runLoopForReadStream +- (CFRunLoopRef)runLoopForReadStream { CFRunLoopRef streamRunLoop = CFRunLoopGetCurrent(); @@ -259,295 +264,229 @@ -(CFRunLoopRef)runLoopForReadStream return streamRunLoop; } --(void)closeReadStream +- (void)closeReadStream { - if ( NULL != self->_readStream ) - { - CFRunLoopRef streamRunLoop = [ self runLoopForReadStream ]; + if (NULL != _readStream) { - CFReadStreamUnscheduleFromRunLoop( self->_readStream - , streamRunLoop - , kCFRunLoopCommonModes ); + CFRunLoopRef streamRunLoop = [self runLoopForReadStream]; - @synchronized( self ) - { - if ( NULL != self->_readStream ) - { - CFReadStreamClose( self->_readStream ); - CFRelease( self->_readStream ); - self->_readStream = nil; - } - } + CFReadStreamUnscheduleFromRunLoop(_readStream, + streamRunLoop, + kCFRunLoopCommonModes); + CFReadStreamClose(_readStream); + CFRelease(_readStream); + _readStream = nil; } } --(void)closeStreams -{ - [ self closeReadStream ]; -} - --(void)cancel +- (void)closeStreams { - [ self closeStreams ]; - [ self clearCallbacks ]; - [ self disposeZipQueue ]; + [self closeReadStream]; } --(void)disposeZipQueue +- (void)cancel { - // @adk - using "strong" since this code may be called from "dealloc". - // No retain cycles here - __strong JFFURLConnection* weakSelf = self; - - dispatch_block_t cleanupBlock = - ^{ - dispatch_queue_t zipQueue = [ weakSelf zipQueue ]; - if ( NULL != zipQueue ) - { - dispatch_release( zipQueue ); - } - - weakSelf.zipQueue = NULL; - }; + [self closeStreams ]; + [self clearCallbacks]; - if ( nil == self->_queueForCallbacks ) - { - cleanupBlock(); - return; - } - else - { - safe_dispatch_sync( self->_queueForCallbacks, cleanupBlock ); - return; - } + _selfHolder = nil; } --(id)getDecoder +- (id)getDecoder { - NSString* contentEncoding = self->_urlResponse.contentEncoding; - - BOOL isDecoderMissing = ( nil == self->_decoder ); + NSString *contentEncoding = _urlResponse.contentEncoding; - if ( isDecoderMissing ) - { - JNHttpEncodingsFactory* factory = [ [ JNHttpEncodingsFactory alloc ] initWithContentLength: self->_totalBytesCount ]; + BOOL isDecoderMissing = (nil == _decoder); + + if (isDecoderMissing) { + JNHttpEncodingsFactory *factory = [[JNHttpEncodingsFactory alloc] initWithContentLength:_totalBytesCount]; - id< JNHttpDecoder > decoder = [ factory decoderForHeaderString: contentEncoding ]; - self->_decoder = decoder; + id decoder = [factory decoderForHeaderString:contentEncoding]; + _decoder = decoder; } - - return self->_decoder; + return _decoder; } --(void)handleData:( void* )buffer_ - length:( NSUInteger )length_ +- (void)handleData:(void *)buffer + length:(NSUInteger)length { if (!self.didReceiveDataBlock) - { return; - } - __weak JFFURLConnection* weakSelf = self; + NSData *rawNsData = [[NSData alloc] initWithBytes:buffer + length:length]; - id< JNHttpDecoder > decoder = [ self getDecoder ]; - NSData *rawNsData = [ [ NSData alloc ] initWithBytes: buffer_ - length: length_ ]; - dispatch_queue_t zipQueue = self->_zipQueue; + __weak JFFURLConnection *weakSelf = self; - dispatch_async( zipQueue, - ^{ - NSError *decoderError = nil; + self.downloadedBytesCount += length; + BOOL isDownloadCompleted = (self.totalBytesCount == self.downloadedBytesCount); + + dispatch_queue_t queueForCallbacks = _queueForCallbacks; + + dispatch_barrier_async(_zipQueue, ^void(void) { - NSData *decodedData = [ decoder decodeData: rawNsData - error: &decoderError ]; + id decoder = [weakSelf getDecoder]; + NSError *decoderError = nil; - weakSelf.downloadedBytesCount += length_; - BOOL isDownloadCompleted = ( weakSelf.totalBytesCount == weakSelf.downloadedBytesCount ); + NSData *decodedData = [decoder decodeData:rawNsData + error:&decoderError]; - if ( nil == decodedData || isDownloadCompleted ) - { - NSError* decoderCloseError = nil; - [ decoder closeWithError: &decoderCloseError ]; - [ decoderCloseError writeErrorToNSLog ]; + BOOL finished = (nil == decodedData || isDownloadCompleted); + + if (finished) { - [ weakSelf invokeDataBlock: decodedData ]; - [ weakSelf handleFinish: decoderError ]; + NSError *decoderCloseError = nil; + [decoder closeWithError:&decoderCloseError]; + [decoderCloseError writeErrorToNSLog]; + weakSelf.decoder = nil; } - else - { - [ weakSelf invokeDataBlock: decodedData ]; - } - } ); - + + dispatch_sync(queueForCallbacks, ^void(void) { + + if (weakSelf.didReceiveDataBlock) + weakSelf.didReceiveDataBlock(decodedData); + + if (finished) { + + NSError *error = decoderError + ?decoderError + :((nil == decodedData)?decoderError:nil); + [weakSelf handleFinish:error]; + } + }); + }); } --(void)handleFinish:( NSError* )error +- (void)handleFinish:(NSError *)error { - [ self closeReadStream ]; - [ self invokeFinishBlock: error ]; - [ self clearCallbacks ]; + __weak JFFURLConnection *weakSelf = self; + + dispatch_queue_t queueForCallbacks = _queueForCallbacks; - [ self disposeZipQueue ]; + dispatch_barrier_async(_zipQueue, ^void(void) { + + dispatch_sync(queueForCallbacks, ^void(void) { + + JFFDidFinishLoadingHandler didFinishLoadingBlock = weakSelf.didFinishLoadingBlock; + + [weakSelf cancel]; + + if (didFinishLoadingBlock) + didFinishLoadingBlock(error); + }); + }); } --(void)acceptCookiesForHeaders:( NSDictionary* )headers_ +- (void)acceptCookiesForHeaders:(NSDictionary *)headers { - NSArray* cookies_ = [ NSHTTPCookie cookiesWithResponseHeaderFields: headers_ - forURL: _params.url ]; - - for ( NSHTTPCookie* cookie_ in cookies_ ) - { - [ _cookiesStorage setCookie: cookie_ ]; + NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:headers + forURL:_context.params.url]; + + for (NSHTTPCookie *cookie in cookies) { + + [_cookiesStorage setCookie:cookie]; } } --(void)handleResponseForReadStream:( CFReadStreamRef )stream_ +- (void)handleResponseForReadStream:(CFReadStreamRef)stream { - if ( self->_responseHandled ) - { + if (_responseHandled) { return; } - - NSDictionary* allHeadersDict_; + + NSDictionary* allHeadersDict; CFIndex statusCode; - + { - CFHTTPMessageRef response_ = (CFHTTPMessageRef)CFReadStreamCopyProperty( stream_, kCFStreamPropertyHTTPResponseHeader ); - - if ( !response_ ) - { + CFHTTPMessageRef response = (CFHTTPMessageRef)CFReadStreamCopyProperty(stream, kCFStreamPropertyHTTPResponseHeader); + + if (!response) return; - } - - allHeadersDict_ = (__bridge_transfer NSDictionary*)CFHTTPMessageCopyAllHeaderFields( response_ ); - statusCode = CFHTTPMessageGetResponseStatusCode( response_ ); - - CFRelease(response_); + + allHeadersDict = (__bridge_transfer NSDictionary *)CFHTTPMessageCopyAllHeaderFields(response); + statusCode = CFHTTPMessageGetResponseStatusCode(response); + + CFRelease(response); } - - [ self acceptCookiesForHeaders: allHeadersDict_ ]; - + + [self acceptCookiesForHeaders:allHeadersDict]; + //JTODO test redirects (cyclic for example) - if ([JHttpFlagChecker isRedirectFlag:statusCode]) - { - NSDebugLog( @"JConnection - creating URL..." ); - NSDebugLog( @"%@", self->_params.url ); - NSString* location_ = allHeadersDict_[ @"Location" ]; - + if ([JHttpFlagChecker isRedirectFlag:statusCode]) { + NSDebugLog(@"JConnection - creating URL..."); + NSDebugLog(@"%@", _params.url); + NSString *location = allHeadersDict[@"Location"]; + #ifdef USE_DD_URL_BUILDER - if ( ![ NSUrlLocationValidator isValidLocation: location_ ] ) - { - NSLog( @"[!!!WARNING!!!] JConnection : path for URL is invalid. Ignoring..." ); - location_ = @"/"; + if (![ NSUrlLocationValidator isValidLocation:location]) { + + NSLog(@"[!!!WARNING!!!] JConnection : path for URL is invalid. Ignoring..."); + location = @"/"; } - DDURLBuilder* urlBuilder_ = [ DDURLBuilder URLBuilderWithURL: self->_params.url ]; - urlBuilder_.shouldSkipPathPercentEncoding = YES; - urlBuilder_.path = location_; + DDURLBuilder *urlBuilder = [DDURLBuilder URLBuilderWithURL:_context.params.url]; + urlBuilder.shouldSkipPathPercentEncoding = YES; + urlBuilder.path = location; - self->_params.url = [ urlBuilder_ URL ]; + _context.params.url = [urlBuilder URL]; // To avoid HTTP 500 - self->_params.httpMethod = @"GET"; - self->_params.httpBody = nil; + _context.params.httpMethod = @"GET"; + _context.params.httpBody = nil; #else - if ( [ location_ hasPrefix: @"/" ] ) - { - self->_params.url = [ self->_params.url URLWithLocation: location_ ]; - } - else - { - self->_params.url = [location_ toURL]; - } - - if ( !self->_params.url ) - { - self->_params.url = [ self->_params.url URLWithLocation: @"/" ]; + if ([location hasPrefix:@"/"]) { + + _context.params.url = [_context.params.url URLWithLocation:location]; + } else { + + _context.params.url = [location toURL]; } - - self->_params.httpMethod = @"GET"; - self->_params.httpBody = nil; + + if (!_context.params.url) { + _context.params.url = [_context.params.url URLWithLocation:@"/"]; + } + + _context.params.httpMethod = @"GET"; + _context.params.httpBody = nil; #endif - - NSDebugLog( @"%@", _params.url ); - NSDebugLog( @"Done." ); - - [ self start ]; + + NSDebugLog(@"%@", _context.params.url); + NSDebugLog(@"Done."); + + [self start];//TODO start it later } else { - self->_responseHandled = YES; - - if ( self.didReceiveResponseBlock ) - { - JFFURLResponse* urlResponse_ = [ JFFURLResponse new ]; + _responseHandled = YES; + + JFFDidReceiveResponseHandler didReceiveResponseBlock = self.didReceiveResponseBlock; + self.didReceiveResponseBlock = nil; + + if (didReceiveResponseBlock) { - urlResponse_.statusCode = statusCode; - urlResponse_.allHeaderFields = allHeadersDict_; - urlResponse_.url = self->_params.url; + __strong JFFURLConnection *self_ = self; - [ self invokeResponseBlock: urlResponse_ ]; - self.didReceiveResponseBlock = nil; - -// self->_previousContentEncoding = self->_urlResponse.contentEncoding; - self->_decoder = nil; + JFFURLResponse *urlResponse = [JFFURLResponse new]; + + urlResponse.statusCode = statusCode; + urlResponse.allHeaderFields = allHeadersDict; + urlResponse.url = self_->_context.params.url; - self->_urlResponse = urlResponse_; + didReceiveResponseBlock(urlResponse);//here in callback connection can be cancelled - unsigned long long tmpContentLength = [ urlResponse_ expectedContentLength ]; - if ( [ urlResponse_ hasContentLength ] ) - { - self->_totalBytesCount = tmpContentLength; + // _previousContentEncoding = _urlResponse.contentEncoding; + self_->_decoder = nil; + self_->_urlResponse = urlResponse; + + unsigned long long tmpContentLength = [urlResponse expectedContentLength]; + if ([urlResponse hasContentLength]) { + + self_->_totalBytesCount = tmpContentLength; } } } } -#pragma mark - -#pragma mark Callbacks --(void)invokeResponseBlock:( id )response -{ - JFFDidReceiveResponseHandler block = self.didReceiveResponseBlock; - if ( nil == block ) - { - return; - } - - dispatch_async( self->_queueForCallbacks, - ^{ - block( response ); - } ); -} - --(void)invokeDataBlock:( NSData* )data -{ - JFFDidReceiveDataHandler block = self.didReceiveDataBlock; - if ( nil == block ) - { - return; - } - - dispatch_async( self->_queueForCallbacks, - ^{ - block( data ); - } ); -} - --(void)invokeFinishBlock:( NSError* )error -{ - JFFDidFinishLoadingHandler block = self.didFinishLoadingBlock; - if ( nil == block ) - { - return; - } - - - dispatch_async( self->_queueForCallbacks, - ^{ - block( error ); - } ); -} - @end diff --git a/lib/JFFNetwork/JFFURLConnectionParams.h b/lib/JFFNetwork/JFFURLConnectionParams.h index 9851606..4b6d6b9 100644 --- a/lib/JFFNetwork/JFFURLConnectionParams.h +++ b/lib/JFFNetwork/JFFURLConnectionParams.h @@ -2,17 +2,21 @@ #import +typedef NSInputStream *(^JFFInputStreamBuilder)(void); + @class JFFLocalCookiesStorage; -@interface JFFURLConnectionParams : NSObject< NSCopying > +@interface JFFURLConnectionParams : NSObject + +@property (nonatomic) NSURL *url; +@property (nonatomic) NSData *httpBody; +@property (nonatomic) NSString *httpMethod; +@property (nonatomic) NSDictionary *headers; +@property (nonatomic) BOOL useLiveConnection; +@property (nonatomic) long long totalBytesExpectedToWrite; +@property (nonatomic) JFFLocalCookiesStorage *cookiesStorage; -@property (nonatomic, strong) NSURL *url; -@property (nonatomic, strong) NSData *httpBody; -@property (nonatomic, strong) NSInputStream *httpBodyStream; -@property (nonatomic, strong) NSString *httpMethod; -@property (nonatomic, strong) NSDictionary *headers; -@property (nonatomic) BOOL useLiveConnection; -@property (nonatomic, strong) JFFLocalCookiesStorage* cookiesStorage; +@property (nonatomic, copy) JFFInputStreamBuilder httpBodyStreamBuilder; @property (nonatomic, copy) JFFShouldAcceptCertificateForHost certificateCallback; @end diff --git a/lib/JFFNetwork/JFFURLConnectionParams.m b/lib/JFFNetwork/JFFURLConnectionParams.m index fbdbf18..8d88cd4 100755 --- a/lib/JFFNetwork/JFFURLConnectionParams.m +++ b/lib/JFFNetwork/JFFURLConnectionParams.m @@ -2,27 +2,24 @@ @implementation JFFURLConnectionParams -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFURLConnectionParams *copy = [[[self class] allocWithZone:zone] init]; if (copy) { - copy->_url = [ self->_url copyWithZone: zone]; - copy->_httpBody = [ self->_httpBody copyWithZone: zone]; - copy->_httpMethod = [ self->_httpMethod copyWithZone: zone ]; - copy->_headers = [ self->_headers copyWithZone: zone]; - - // TODO : Make a deep copy of the stream - // @adk : Plain assignment pay lead to inproper resource management and inconsistency - copy->_httpBodyStream = _httpBodyStream; - + copy->_url = [_url copyWithZone:zone]; + copy->_httpBody = [_httpBody copyWithZone:zone]; + copy->_httpMethod = [_httpMethod copyWithZone:zone]; + copy->_headers = [_headers copyWithZone:zone]; + copy->_httpBodyStreamBuilder = [_httpBodyStreamBuilder copyWithZone:zone]; + copy->_certificateCallback = [_certificateCallback copyWithZone:zone]; - copy->_useLiveConnection = _useLiveConnection; - copy->_certificateCallback = [ _certificateCallback copy ]; + copy->_totalBytesExpectedToWrite = _totalBytesExpectedToWrite; + copy->_useLiveConnection = _useLiveConnection; //cookie storage is common object for different connections //do not copy it - copy->_cookiesStorage = _cookiesStorage; + copy->_cookiesStorage = _cookiesStorage; } return copy; diff --git a/lib/JFFNetwork/JFFURLResponse.h b/lib/JFFNetwork/JFFURLResponse.h index 6f4c34d..e29ca88 100644 --- a/lib/JFFNetwork/JFFURLResponse.h +++ b/lib/JFFNetwork/JFFURLResponse.h @@ -3,13 +3,13 @@ @interface JFFURLResponse : NSObject< JNUrlResponse > -@property ( nonatomic ) NSInteger statusCode; -@property ( nonatomic, strong ) NSDictionary* allHeaderFields; -@property ( nonatomic, strong ) NSURL* url; +@property (nonatomic) NSInteger statusCode; +@property (nonatomic) NSDictionary* allHeaderFields; +@property (nonatomic) NSURL* url; @property (nonatomic, readonly) unsigned long long expectedContentLength; @property (nonatomic, readonly) BOOL hasContentLength; -@property ( nonatomic, readonly ) NSString* contentEncoding; +@property (nonatomic, readonly) NSString *contentEncoding; @end diff --git a/lib/JFFNetwork/JFFURLResponse.m b/lib/JFFNetwork/JFFURLResponse.m index 7e975c8..c834c5c 100755 --- a/lib/JFFNetwork/JFFURLResponse.m +++ b/lib/JFFNetwork/JFFURLResponse.m @@ -7,36 +7,34 @@ @implementation JFFURLResponse @dynamic expectedContentLength; @dynamic contentEncoding; - --(BOOL)hasContentLength +- (BOOL)hasContentLength { - return [ self->_allHeaderFields.allKeys containsObject: @"Content-Length" ]; + return [_allHeaderFields.allKeys containsObject:@"Content-Length"]; } - (unsigned long long)expectedContentLength { - id contentLengthObj_ = self->_allHeaderFields[@"Content-Length"]; + id contentLengthObj = _allHeaderFields[@"Content-Length"]; - SEL ulongSelector_ = @selector(unsignedLongLongValue); - if ( [ contentLengthObj_ respondsToSelector: ulongSelector_ ] ) - { - return [ contentLengthObj_ unsignedLongLongValue ]; + SEL ulongSelector = @selector(unsignedLongLongValue); + if ([contentLengthObj respondsToSelector:ulongSelector]) { + return [contentLengthObj unsignedLongLongValue]; } - - return (unsigned long long)[ contentLengthObj_ longLongValue ]; + + return (unsigned long long)[contentLengthObj longLongValue]; } #pragma mark - #pragma mark NSObject --(NSString*)description +- (NSString *)description { NSString *custom = [JFFUrlResponseLogger descriptionStringForUrlResponse:self]; return [[NSString alloc] initWithFormat:@"%@ \n %@", [super description], custom]; } --(NSString*)contentEncoding +- (NSString *)contentEncoding { - return self->_allHeaderFields[@"Content-Encoding"]; + return _allHeaderFields[@"Content-Encoding"]; } @end diff --git a/lib/JFFNetwork/JFFUrlResponseLogger.h b/lib/JFFNetwork/JFFUrlResponseLogger.h index 2c6872a..cdb7269 100755 --- a/lib/JFFNetwork/JFFUrlResponseLogger.h +++ b/lib/JFFNetwork/JFFUrlResponseLogger.h @@ -3,9 +3,9 @@ @interface JFFUrlResponseLogger : NSObject /** - @param url_response_ -- conforms to the JNUrlResponse protocol. The protocol is omitted for the NSHTTPURLResponse compatibility. + @param urlResponse -- conforms to the JNUrlResponse protocol. The protocol is omitted for the NSHTTPURLResponse compatibility. */ -+(NSString*)descriptionStringForUrlResponse:(id /*< JNUrlResponse >*/)url_response_; -+(NSString*)dumpHttpHeaderFields:(NSDictionary*)all_header_fields_; ++ (NSString *)descriptionStringForUrlResponse:(id /*< JNUrlResponse >*/)urlResponse; ++ (NSString *)dumpHttpHeaderFields:(NSDictionary *)allHeaderFields; @end diff --git a/lib/JFFNetwork/JFFUrlResponseLogger.m b/lib/JFFNetwork/JFFUrlResponseLogger.m index 4365c5c..503bb85 100755 --- a/lib/JFFNetwork/JFFUrlResponseLogger.m +++ b/lib/JFFNetwork/JFFUrlResponseLogger.m @@ -2,33 +2,32 @@ @implementation JFFUrlResponseLogger -+(NSString*)descriptionStringForUrlResponse:(id)url_response_ ++ (NSString *)descriptionStringForUrlResponse:(id)urlResponse { - NSAssert( [ url_response_ respondsToSelector: @selector( statusCode ) ], @"[!!! ERROR !!!] statusCode not supported" ); - NSAssert( [ url_response_ respondsToSelector: @selector( expectedContentLength ) ], @"[!!! ERROR !!!] expectedContentLength not supported" ); - NSAssert( [ url_response_ respondsToSelector: @selector( allHeaderFields ) ], @"[!!! ERROR !!!] allHeaderFields not supported" ); - - NSMutableString* result_ = [ [ NSMutableString alloc ] initWithFormat: @"<<< UrlResponse. HttpStatusCode = %d \n", [ url_response_ statusCode ] ] ; - [ result_ appendFormat: @"Result length = %lld \n", [ url_response_ expectedContentLength ] ]; - - NSString* headerFields_ = [ self dumpHttpHeaderFields: [ url_response_ allHeaderFields ] ]; - [ result_ appendString: headerFields_ ]; - - return [ result_ copy ]; + NSAssert([urlResponse respondsToSelector:@selector(statusCode )], @"[!!! ERROR !!!] statusCode not supported" ); + NSAssert([urlResponse respondsToSelector:@selector(expectedContentLength)], @"[!!! ERROR !!!] expectedContentLength not supported"); + NSAssert([urlResponse respondsToSelector:@selector(allHeaderFields )], @"[!!! ERROR !!!] allHeaderFields not supported" ); + + NSMutableString *result = [[NSMutableString alloc] initWithFormat:@"<<< UrlResponse. HttpStatusCode = %ld \n", (long)[ urlResponse statusCode ] ] ; + [result appendFormat: @"Result length = %lld \n", [urlResponse expectedContentLength]]; + + NSString *headerFields = [self dumpHttpHeaderFields:[urlResponse allHeaderFields]]; + [result appendString:headerFields]; + + return [result copy]; } -+(NSString*)dumpHttpHeaderFields:( NSDictionary* )allHeaderFields_ ++ (NSString *)dumpHttpHeaderFields:(NSDictionary *)allHeaderFields { - NSMutableString* result_ = [ NSMutableString new ]; - - [ result_ appendString: @"Headers : \n" ]; - - [ allHeaderFields_ enumerateKeysAndObjectsUsingBlock: ^(id key_, id obj_, BOOL* stop_) - { - [ result_ appendFormat: @"\t%@ = %@ \n", key_, obj_ ]; - } ]; - - return [ result_ copy ]; + NSMutableString *result = [NSMutableString new]; + + [result appendString:@"Headers : \n"]; + + [allHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + [result appendFormat:@"\t%@ = %@ \n", key, obj]; + }]; + + return [result copy]; } @end diff --git a/lib/JFFNetwork/JHttpError.h b/lib/JFFNetwork/JHttpError.h deleted file mode 100644 index 1c58a85..0000000 --- a/lib/JFFNetwork/JHttpError.h +++ /dev/null @@ -1,13 +0,0 @@ -#import - -@interface JHttpError : JFFError - -@property (nonatomic, strong) id context; - -- (id)initWithHttpCode:(CFIndex)statusCode; - --(BOOL)isHttpNotChangedError; --(BOOL)isServiceUnavailableError; --(BOOL)isInternalServerError; - -@end diff --git a/lib/JFFNetwork/JHttpError.m b/lib/JFFNetwork/JHttpError.m deleted file mode 100644 index 698e403..0000000 --- a/lib/JFFNetwork/JHttpError.m +++ /dev/null @@ -1,50 +0,0 @@ -#import "JHttpError.h" - -@implementation JHttpError - -- (id)initWithDescription:(NSString *)description - code:(NSInteger)code -{ - return [self initWithDescription:description - domain:@"com.just_for_fun.library.http" - code:code]; -} - -- (id)initWithHttpCode:(CFIndex)statusCode -{ - return [self initWithDescription:NSLocalizedString(@"JFF_HTTP_ERROR", nil) - code:statusCode]; -} - -- (id)copyWithZone:(NSZone *)zone -{ - JHttpError *copy = [super copyWithZone:zone]; - - if (copy) { - copy->_context = [_context copyWithZone:zone]; - } - - return copy; -} - -- (void)writeErrorWithJFFLogger -{ - [JFFLogger logErrorWithFormat:@"%@ Http code:%d cantext:%@", [self localizedDescription], self.code, _context]; -} - --(BOOL)isHttpNotChangedError -{ - return ( self.code == 304 ); -} - --(BOOL)isServiceUnavailableError -{ - return ( self.code == 503 ); -} - --(BOOL)isInternalServerError -{ - return ( self.code == 500 ); -} - -@end diff --git a/lib/JFFNetwork/JHttpFlagChecker.mm b/lib/JFFNetwork/JHttpFlagChecker.mm index 93607f0..76a0cfa 100644 --- a/lib/JFFNetwork/JHttpFlagChecker.mm +++ b/lib/JFFNetwork/JHttpFlagChecker.mm @@ -4,7 +4,7 @@ @implementation JHttpFlagChecker -+(BOOL)isDownloadErrorFlag:( CFIndex )statusCode ++ (BOOL)isDownloadErrorFlag:( CFIndex )statusCode { BOOL result = ![self isSuccessFlag :statusCode] && @@ -13,7 +13,7 @@ +(BOOL)isDownloadErrorFlag:( CFIndex )statusCode return result; } -+(BOOL)isRedirectFlag:(CFIndex)statusCode ++ (BOOL)isRedirectFlag:(CFIndex)statusCode { std::set redirectFlags; { @@ -28,7 +28,7 @@ +(BOOL)isRedirectFlag:(CFIndex)statusCode return result_; } -+(BOOL)isSuccessFlag:(CFIndex)statusCode ++ (BOOL)isSuccessFlag:(CFIndex)statusCode { return (200 == statusCode); } diff --git a/lib/JFFNetwork/JNAbstractConnection.h b/lib/JFFNetwork/JNAbstractConnection.h index c15bd9b..ff14be5 100755 --- a/lib/JFFNetwork/JNAbstractConnection.h +++ b/lib/JFFNetwork/JNAbstractConnection.h @@ -9,9 +9,9 @@ @property (nonatomic, copy) JFFDidUploadDataHandler didUploadDataBlock ; @property (nonatomic, copy) JFFShouldAcceptCertificateForHost shouldAcceptCertificateBlock; --(unsigned long long)downloadedBytesCount; --(unsigned long long)totalBytesCount; +- (unsigned long long)downloadedBytesCount; +- (unsigned long long)totalBytesCount; --(void)clearCallbacks; +- (void)clearCallbacks; @end diff --git a/lib/JFFNetwork/JNAbstractConnection.m b/lib/JFFNetwork/JNAbstractConnection.m index bbeaa3b..a2bc955 100755 --- a/lib/JFFNetwork/JNAbstractConnection.m +++ b/lib/JFFNetwork/JNAbstractConnection.m @@ -4,41 +4,40 @@ @implementation JNAbstractConnection #pragma mark - #pragma mark Not Supported --(void)start +- (void)start { - NSLog( @"[!!! ERROR !!!] : JNAbstractConnection->start is not supported. Please subclass it." ); - [ self doesNotRecognizeSelector: _cmd ]; + NSLog(@"[!!! ERROR !!!] : JNAbstractConnection->start is not supported. Please subclass it."); + [self doesNotRecognizeSelector:_cmd]; } --(void)cancel +- (void)cancel { - NSLog( @"[!!! ERROR !!!] : JNAbstractConnection->cancel is not supported. Please subclass it." ); - [ self doesNotRecognizeSelector: _cmd ]; + NSLog(@"[!!! ERROR !!!] : JNAbstractConnection->cancel is not supported. Please subclass it."); + [self doesNotRecognizeSelector:_cmd]; } --(unsigned long long)downloadedBytesCount +- (unsigned long long)downloadedBytesCount { - NSLog( @"[!!! ERROR !!!] : JNAbstractConnection->downloadedBytesCount is not supported. Please subclass it." ); - [ self doesNotRecognizeSelector: _cmd ]; + NSLog(@"[!!! ERROR !!!] : JNAbstractConnection->downloadedBytesCount is not supported. Please subclass it."); + [self doesNotRecognizeSelector:_cmd]; return 0; } --(unsigned long long)totalBytesCount +- (unsigned long long)totalBytesCount { - NSLog( @"[!!! ERROR !!!] : JNAbstractConnection->totalBytesCount is not supported. Please subclass it." ); - [ self doesNotRecognizeSelector: _cmd ]; + NSLog(@"[!!! ERROR !!!] : JNAbstractConnection->totalBytesCount is not supported. Please subclass it."); + [self doesNotRecognizeSelector:_cmd]; return 0; } - #pragma mark - #pragma mark Callbacks management --(void)clearCallbacks +- (void)clearCallbacks { - self.didReceiveResponseBlock = nil; - self.didReceiveDataBlock = nil; - self.didFinishLoadingBlock = nil; - self.shouldAcceptCertificateBlock = nil; + _didReceiveResponseBlock = nil; + _didReceiveDataBlock = nil; + _didFinishLoadingBlock = nil; + _shouldAcceptCertificateBlock = nil; } @end diff --git a/lib/JFFNetwork/JNConstants.h b/lib/JFFNetwork/JNConstants.h index 8036964..f8d8d08 100755 --- a/lib/JFFNetwork/JNConstants.h +++ b/lib/JFFNetwork/JNConstants.h @@ -1,7 +1,7 @@ #ifndef __JN_CONSTANTS_H__ #define __JN_CONSTANTS_H__ -enum JNConstantsEnum +typedef NS_ENUM(NSUInteger, JNConstantsEnum) { kJNMaxBufferSize = 4096 }; diff --git a/lib/JFFNetwork/JNNsUrlConnection.h b/lib/JFFNetwork/JNNsUrlConnection.h index da82faa..b9e01b3 100644 --- a/lib/JFFNetwork/JNNsUrlConnection.h +++ b/lib/JFFNetwork/JNNsUrlConnection.h @@ -5,7 +5,7 @@ @interface JNNsUrlConnection : JNAbstractConnection -- (id)initWithURLConnectionParams:(JFFURLConnectionParams *)params; +- (instancetype)initWithURLConnectionParams:(JFFURLConnectionParams *)params; - (void)start; - (void)cancel; diff --git a/lib/JFFNetwork/JNNsUrlConnection.m b/lib/JFFNetwork/JNNsUrlConnection.m index e750266..e511f71 100644 --- a/lib/JFFNetwork/JNNsUrlConnection.m +++ b/lib/JFFNetwork/JNNsUrlConnection.m @@ -9,29 +9,27 @@ @interface JNNsUrlConnection () -@property ( nonatomic, readonly ) unsigned long long downloadedBytesCount; -@property ( nonatomic, readonly ) unsigned long long totalBytesCount; +@property (nonatomic, readonly) unsigned long long downloadedBytesCount; +@property (nonatomic, readonly) unsigned long long totalBytesCount; @end @implementation JNNsUrlConnection { - NSURLConnection* _nativeConnection; - JFFURLConnectionParams* _params; - NSRunLoop *_connectRunLoop; + NSURLConnection *_nativeConnection; + JFFURLConnectionParams *_params; + NSRunLoop *_connectRunLoop; } @synthesize downloadedBytesCount = _downloadedBytesCount; @synthesize totalBytesCount = _totalBytesCount ; - -//TODO: Test Connection with runloops! --(void)dealloc +- (void)dealloc { [self cancel]; } -- (id)initWithURLConnectionParams:(JFFURLConnectionParams *)params +- (instancetype)initWithURLConnectionParams:(JFFURLConnectionParams *)params { NSParameterAssert(params); @@ -150,9 +148,9 @@ - (void)connection:(NSURLConnection *)connection return; } - NSString* strContentLength = response.allHeaderFields[ @"Content-Length" ]; - self->_totalBytesCount = (unsigned long long)[ strContentLength longLongValue ]; - self->_downloadedBytesCount = 0; + NSString *strContentLength = response.allHeaderFields[@"Content-Length"]; + _totalBytesCount = (unsigned long long)[strContentLength longLongValue]; + _downloadedBytesCount = 0; if (nil != self.didReceiveResponseBlock) { self.didReceiveResponseBlock(response); @@ -166,7 +164,7 @@ - (void)connection:(NSURLConnection *)connection return; } - self->_downloadedBytesCount += [ chunk length ]; + _downloadedBytesCount += [chunk length]; if (nil != self.didReceiveDataBlock) { self.didReceiveDataBlock(chunk); @@ -218,15 +216,15 @@ - (void)connection:(NSURLConnection *)connection [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; } --(NSCachedURLResponse *)connection:(NSURLConnection *)connection - willCacheResponse:(NSCachedURLResponse *)cachedResponse +- (NSCachedURLResponse *)connection:(NSURLConnection *)connection + willCacheResponse:(NSCachedURLResponse *)cachedResponse { return nil; } #pragma mark NSURLConnectionDataDelegate --(void)connectionDidFinishLoading:(NSURLConnection *)connection +- (void)connectionDidFinishLoading:(NSURLConnection *)connection { if (![self assertConnectionMismatch:connection]) { return; @@ -245,11 +243,21 @@ - (void)connection:(NSURLConnection *)connection totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { - if (self.didUploadDataBlock) { + if (!self.didUploadDataBlock) + return; + + totalBytesExpectedToWrite = (totalBytesExpectedToWrite == -1) + ?_params.totalBytesExpectedToWrite + :totalBytesExpectedToWrite; + + if (totalBytesExpectedToWrite <= 0) { - NSNumber *progress = @((float)totalBytesWritten/totalBytesExpectedToWrite); - self.didUploadDataBlock(progress); + self.didUploadDataBlock(@0); + return; } + + NSNumber *progress = @((float)totalBytesWritten/totalBytesExpectedToWrite); + self.didUploadDataBlock(progress); } @end diff --git a/lib/JFFNetwork/JNUrlConnection.h b/lib/JFFNetwork/JNUrlConnection.h index b14cff0..af0d901 100755 --- a/lib/JFFNetwork/JNUrlConnection.h +++ b/lib/JFFNetwork/JNUrlConnection.h @@ -4,20 +4,20 @@ @protocol JNUrlConnection < NSObject > @required - -(void)start; - -(void)cancel; + - (void)start; + - (void)cancel; @required - -(unsigned long long)downloadedBytesCount; - -(unsigned long long)totalBytesCount; + - (unsigned long long)downloadedBytesCount; + - (unsigned long long)totalBytesCount; @required //callbacks cleared after finish of loading - @property ( nonatomic, copy ) JFFDidReceiveResponseHandler didReceiveResponseBlock; - @property ( nonatomic, copy ) JFFDidReceiveDataHandler didReceiveDataBlock ; - @property ( nonatomic, copy ) JFFDidFinishLoadingHandler didFinishLoadingBlock ; - @property ( nonatomic, copy ) JFFDidUploadDataHandler didUploadDataBlock ; - @property ( nonatomic, copy ) JFFShouldAcceptCertificateForHost shouldAcceptCertificateBlock; + @property (nonatomic, copy) JFFDidReceiveResponseHandler didReceiveResponseBlock; + @property (nonatomic, copy) JFFDidReceiveDataHandler didReceiveDataBlock ; + @property (nonatomic, copy) JFFDidFinishLoadingHandler didFinishLoadingBlock ; + @property (nonatomic, copy) JFFDidUploadDataHandler didUploadDataBlock ; + @property (nonatomic, copy) JFFShouldAcceptCertificateForHost shouldAcceptCertificateBlock; @end diff --git a/lib/JFFNetwork/JNUrlResponse.h b/lib/JFFNetwork/JNUrlResponse.h index 05f02bf..b71ab6e 100644 --- a/lib/JFFNetwork/JNUrlResponse.h +++ b/lib/JFFNetwork/JNUrlResponse.h @@ -3,11 +3,11 @@ /** A protocol for JFFURLResponse and NSHTTPURLResponse */ -@protocol JNUrlResponse < NSObject > +@protocol JNUrlResponse --(NSInteger) statusCode; --(NSDictionary*)allHeaderFields; --(unsigned long long)expectedContentLength; --(BOOL)hasContentLength; +- (NSInteger)statusCode; +- (NSDictionary *)allHeaderFields; +- (unsigned long long)expectedContentLength; +- (BOOL)hasContentLength; @end diff --git a/lib/JFFNetwork/Mock/JNConnectionMock.h b/lib/JFFNetwork/Mock/JNConnectionMock.h index 29f665a..5bdeb59 100644 --- a/lib/JFFNetwork/Mock/JNConnectionMock.h +++ b/lib/JFFNetwork/Mock/JNConnectionMock.h @@ -3,10 +3,10 @@ @interface JNConnectionMock : NSObject< JNMock > --(id)initWithConnectionClass:( Class )connectionClass - action:( void (^)(void) )action //JFFSimpleBlock - executeOriginalImpl:( BOOL )yesNo; +- (instancetype)initWithConnectionClass:(Class )connectionClass + action:(void (^)(void))action //JFFSimpleBlock + executeOriginalImpl:(BOOL)yesNo; -@property ( nonatomic, readonly ) BOOL isMockEnabled; +@property (nonatomic, readonly) BOOL isMockEnabled; @end diff --git a/lib/JFFNetwork/Mock/JNConnectionMock.m b/lib/JFFNetwork/Mock/JNConnectionMock.m index fb90192..ba5825b 100644 --- a/lib/JFFNetwork/Mock/JNConnectionMock.m +++ b/lib/JFFNetwork/Mock/JNConnectionMock.m @@ -20,63 +20,61 @@ @implementation JNConnectionMock SEL _realSel; } --(void)dealloc +- (void)dealloc { - [ self disableMock]; + [self disableMock]; - self->_connectionClass = Nil; - self->_realImpl = NULL; - self->_mockImpl = NULL; - self->_realMethod = NULL; + _connectionClass = Nil; + _realImpl = NULL; + _mockImpl = NULL; + _realMethod = NULL; } --(id)init +- (instancetype)init { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; return nil; } --(id)initWithConnectionClass:( Class )connectionClass - action:( JFFSimpleBlock )action - executeOriginalImpl:( BOOL )executeOriginalImpl +- (instancetype)initWithConnectionClass:(Class)connectionClass + action:(JFFSimpleBlock)action + executeOriginalImpl:(BOOL)executeOriginalImpl { - self = [ super init ]; - if ( nil == self ) - { + self = [super init]; + if (nil == self) { + return nil; } - - NSParameterAssert( [ connectionClass conformsToProtocol: @protocol(JNUrlConnection) ] ); - NSParameterAssert( nil != action ); + NSParameterAssert([connectionClass conformsToProtocol:@protocol(JNUrlConnection)]); + NSParameterAssert(nil != action); - action = [ action copy ]; + action = [action copy]; //save args { - self->_shouldInvokeOriginalMethod = executeOriginalImpl; - self->_connectionClass = connectionClass; + _shouldInvokeOriginalMethod = executeOriginalImpl; + _connectionClass = connectionClass; } - //save "real" methods { - self->_realSel = @selector(start); - self->_realMethod = class_getInstanceMethod( connectionClass, self->_realSel ); - self->_realImpl = method_getImplementation( self->_realMethod ); + _realSel = @selector(start); + _realMethod = class_getInstanceMethod(connectionClass, _realSel); + _realImpl = method_getImplementation(_realMethod); } - + //create a mock { - SEL start_ = self->_realSel; + SEL start = _realSel; NSImplBlock newAction = nil; - if ( executeOriginalImpl ) + if (executeOriginalImpl) { - newAction = ^void( id connectionSelf ) + newAction = ^void(id connectionSelf) { action(); - self->_realImpl( connectionSelf, start_ ); + _realImpl(connectionSelf, start); }; } else @@ -86,34 +84,31 @@ -(id)initWithConnectionClass:( Class )connectionClass action(); }; } - self->_mockImpl = imp_implementationWithBlock( newAction ); - NSParameterAssert( NULL != self->_mockImpl ); + _mockImpl = imp_implementationWithBlock(newAction); + NSParameterAssert(NULL != _mockImpl); } - - + return self; } --(void)enableMock +- (void)enableMock { - if ( self->_isMockEnabled ) - { + if (_isMockEnabled) { return; } - method_setImplementation( self->_realMethod, self->_mockImpl ); - self->_isMockEnabled = YES; + method_setImplementation(_realMethod, _mockImpl); + _isMockEnabled = YES; } --(void)disableMock +- (void)disableMock { - if ( !self->_isMockEnabled ) - { + if (!_isMockEnabled) { return; } - - method_setImplementation( self->_realMethod, self->_realImpl ); - self->_isMockEnabled = NO; + + method_setImplementation(_realMethod, _realImpl); + _isMockEnabled = NO; } @end diff --git a/lib/JFFNetwork/Mock/JNMock.h b/lib/JFFNetwork/Mock/JNMock.h index e492e13..0225168 100644 --- a/lib/JFFNetwork/Mock/JNMock.h +++ b/lib/JFFNetwork/Mock/JNMock.h @@ -2,9 +2,9 @@ @protocol JNMock --(void)enableMock; --(void)disableMock; +- (void)enableMock; +- (void)disableMock; --(BOOL)isMockEnabled; +- (BOOL)isMockEnabled; @end diff --git a/lib/JFFNetwork/XQueryComponents/NSDictionary+XQueryComponents.m b/lib/JFFNetwork/XQueryComponents/NSDictionary+XQueryComponents.m index ca73b5f..8431111 100755 --- a/lib/JFFNetwork/XQueryComponents/NSDictionary+XQueryComponents.m +++ b/lib/JFFNetwork/XQueryComponents/NSDictionary+XQueryComponents.m @@ -7,19 +7,19 @@ @interface NSObject (XQueryComponents) -- (NSArray*)arrayOfQueryComponentsForKey:(NSString *)key; +- (NSArray *)arrayOfQueryComponentsForKey:(NSString *)key; @end @implementation NSObject (XQueryComponents) -- (NSString*)stringFromQueryComponentAndKey:(NSString *)key +- (NSString *)stringFromQueryComponentAndKey:(NSString *)key { - NSString *value = [[self description]stringByEncodingURLFormat]; - return [[NSString alloc]initWithFormat:queryComponentFormat, key, value]; + NSString *value = [[self description] stringByEncodingURLFormat]; + return [[NSString alloc] initWithFormat:queryComponentFormat, key, value]; } -- (NSArray*)arrayOfQueryComponentsForKey:(NSString *)key +- (NSArray *)arrayOfQueryComponentsForKey:(NSString *)key { NSString *component = [self stringFromQueryComponentAndKey:key]; return @[component]; @@ -29,7 +29,7 @@ - (NSArray*)arrayOfQueryComponentsForKey:(NSString *)key @implementation NSArray (XQueryComponents) -- (NSArray*)arrayOfQueryComponentsForKey:(NSString *)key +- (instancetype)arrayOfQueryComponentsForKey:(NSString *)key { return [self map:^id(id value) { return [value stringFromQueryComponentAndKey:key]; @@ -57,7 +57,7 @@ - (NSData *)dataFromQueryComponents - (NSString *)firstValueIfExsistsForKey:(NSString *)key { - return [self[key] noThrowObjectAtIndex:0]; + return [self[key] firstObject]; } @end diff --git a/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.h b/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.h index 818e95a..bef235e 100755 --- a/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.h +++ b/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.h @@ -2,8 +2,8 @@ @interface NSString (XQueryComponents) --(NSString*)stringByDecodingURLFormat; --(NSString*)stringByEncodingURLFormat; --(NSDictionary*)dictionaryFromQueryComponents; +- (instancetype)stringByDecodingURLFormat; +- (instancetype)stringByEncodingURLFormat; +- (NSDictionary *)dictionaryFromQueryComponents; @end diff --git a/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.m b/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.m index 5eebd1d..74908e4 100755 --- a/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.m +++ b/lib/JFFNetwork/XQueryComponents/NSString+XQueryComponents.m @@ -2,12 +2,12 @@ @implementation NSString (XQueryComponents) -- (NSString *)stringByDecodingURLFormat +- (instancetype)stringByDecodingURLFormat { return [self stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } -- (NSString *)stringByEncodingURLFormat +- (instancetype)stringByEncodingURLFormat { static NSString *unsafe = @" <>#%'\";?:@&=+$/,{}|\\^~[]`-*!()"; CFStringRef resultRef = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, @@ -20,17 +20,17 @@ - (NSString *)stringByEncodingURLFormat - (NSDictionary *)dictionaryFromQueryComponents { - NSMutableDictionary *queryComponents = [ NSMutableDictionary new ]; + NSMutableDictionary *queryComponents = [NSMutableDictionary new]; for (NSString *keyValuePairString in [self componentsSeparatedByString:@"&"]) { NSArray *keyValuePairArray = [keyValuePairString componentsSeparatedByString:@"="]; // Verify that there is at least one key, and at least one value. Ignore extra = signs - if ( [ keyValuePairArray count ] < 2 ) + if ([keyValuePairArray count] < 2) continue; - NSString* key = [keyValuePairArray[0]stringByDecodingURLFormat]; - NSString* value = [keyValuePairArray[1]stringByDecodingURLFormat]; + NSString *key = [keyValuePairArray[0]stringByDecodingURLFormat]; + NSString *value = [keyValuePairArray[1]stringByDecodingURLFormat]; NSMutableArray* results_ = queryComponents[ key ]; // URL spec says that multiple values are allowed per key // First object if( !results_ ) { diff --git a/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.h b/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.h index 2f8cbc6..32810cf 100755 --- a/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.h +++ b/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.h @@ -2,6 +2,6 @@ @interface NSURL (XQueryComponents) --(NSDictionary*)queryComponents; +- (NSDictionary *)queryComponents; @end diff --git a/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.m b/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.m index 5826023..7fe1e5a 100755 --- a/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.m +++ b/lib/JFFNetwork/XQueryComponents/NSURL+XQueryComponents.m @@ -4,9 +4,9 @@ @implementation NSURL (XQueryComponents) --(NSDictionary*)queryComponents +- (NSDictionary *)queryComponents { - return [ [ self query ] dictionaryFromQueryComponents ]; + return [[self query] dictionaryFromQueryComponents]; } @end diff --git a/lib/JFFRestKit/JFFRestKit.xcodeproj/project.pbxproj b/lib/JFFRestKit/JFFRestKit.xcodeproj/project.pbxproj index eabfb8c..9b0e671 100644 --- a/lib/JFFRestKit/JFFRestKit.xcodeproj/project.pbxproj +++ b/lib/JFFRestKit/JFFRestKit.xcodeproj/project.pbxproj @@ -160,7 +160,7 @@ 1B7ABA78152D9739005DD4CA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0500; }; buildConfigurationList = 1B7ABA7B152D9739005DD4CA /* Build configuration list for PBXProject "JFFRestKit" */; compatibilityVersion = "Xcode 3.2"; @@ -199,8 +199,9 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -210,6 +211,7 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( @@ -220,7 +222,8 @@ ../TouchXmlHelper, ../JFFCache, ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; }; name = Debug; @@ -229,10 +232,12 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( @@ -243,7 +248,8 @@ ../TouchXmlHelper, ../JFFCache, ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -255,7 +261,7 @@ DSTROOT = /tmp/JFFRestKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFRestKit/JFFRestKit-Prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -268,7 +274,7 @@ DSTROOT = /tmp/JFFRestKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFRestKit/JFFRestKit-Prefix.pch"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.h b/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.h index 84d0ed2..0761398 100644 --- a/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.h +++ b/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.h @@ -8,7 +8,7 @@ typedef id(^JFFCacheFactory)(void); @interface JFFCacheAdapter : NSObject -+ (id)newCacheAdapterWithCacheFactory:(JFFCacheFactory)cacheFactory - cacheQueueName:(NSString *)cacheQueueName; ++ (instancetype)newCacheAdapterWithCacheFactory:(JFFCacheFactory)cacheFactory + cacheQueueName:(NSString *)cacheQueueName; @end diff --git a/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.m b/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.m index 36e2974..863a5b5 100644 --- a/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.m +++ b/lib/JFFRestKit/JFFRestKit/CacheAdapter/JFFCacheAdapter.m @@ -10,8 +10,8 @@ @implementation JFFCacheAdapter NSString *_cacheQueueName; } -+ (id)newCacheAdapterWithCacheFactory:(JFFCacheFactory)cacheFactory - cacheQueueName:(NSString *)cacheQueueName ++ (instancetype)newCacheAdapterWithCacheFactory:(JFFCacheFactory)cacheFactory + cacheQueueName:(NSString *)cacheQueueName { NSParameterAssert(cacheFactory); @@ -19,7 +19,8 @@ + (id)newCacheAdapterWithCacheFactory:(JFFCacheFactory)cacheFactory if (result) { - result->_cacheFactory = [cacheFactory copy]; + result->_cacheQueueName = cacheQueueName; + result->_cacheFactory = [cacheFactory copy]; } return result; diff --git a/lib/JFFRestKit/JFFRestKit/Details/JFFResponseDataWithUpdateData.m b/lib/JFFRestKit/JFFRestKit/Details/JFFResponseDataWithUpdateData.m index cc6cf91..193f357 100644 --- a/lib/JFFRestKit/JFFRestKit/Details/JFFResponseDataWithUpdateData.m +++ b/lib/JFFRestKit/JFFRestKit/Details/JFFResponseDataWithUpdateData.m @@ -2,7 +2,7 @@ @implementation JFFResponseDataWithUpdateData -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFResponseDataWithUpdateData *copy = [[[self class] allocWithZone:zone] init]; diff --git a/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.h b/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.h index 3de91d7..6028599 100755 --- a/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.h +++ b/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.h @@ -6,7 +6,7 @@ extern "C" { #endif -JFFAsyncOperation jTmpFileLoaderWithChunkedDataLoader( JFFAsyncOperation chunkedDataLoader_ ); + JFFAsyncOperation jTmpFileLoaderWithChunkedDataLoader(JFFAsyncOperation chunkedDataLoader); #ifdef __cplusplus } /* closing brace for extern "C" */ diff --git a/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.m b/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.m index ee1c35d..9c92b9c 100755 --- a/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.m +++ b/lib/JFFRestKit/JFFRestKit/JFFDataLoadersTools.m @@ -3,31 +3,31 @@ #import "JFFRestKitError.h" #import - -static NSString* queueNameForFileAtPath( NSString* filePath ) +static NSString *queueNameForFileAtPath(NSString *filePath) { - NSCParameterAssert( nil != filePath ); - return [ @"org.jRestKit.tmp-file-download/path=" stringByAppendingString: filePath ]; + NSCParameterAssert(nil != filePath); + return [@"org.jRestKit.tmp-file-download/path=" stringByAppendingString:filePath]; } -static dispatch_queue_t queueForFileAtPath( NSString* filePath ) +static dispatch_queue_t queueForFileAtPath(NSString *filePath) { - NSString* queueName = queueNameForFileAtPath( filePath ); - return dispatch_queue_get_or_create( [ queueName UTF8String ], DISPATCH_QUEUE_SERIAL ); + NSString *queueName = queueNameForFileAtPath(filePath); + return dispatch_queue_get_or_create([queueName UTF8String], DISPATCH_QUEUE_SERIAL); } -static void disposeQueueForFileAtPath( NSString* filePath ) +static void disposeQueueForFileAtPath(NSString *filePath) { - NSString* queueName = queueNameForFileAtPath( filePath ); - dispatch_queue_release_by_label( [ queueName UTF8String ] ); + NSString *queueName = queueNameForFileAtPath(filePath); + dispatch_queue_release_by_label([queueName UTF8String]); } -JFFAsyncOperation jTmpFileLoaderWithChunkedDataLoader( JFFAsyncOperation chunkedDataLoader ) +JFFAsyncOperation jTmpFileLoaderWithChunkedDataLoader(JFFAsyncOperation chunkedDataLoader) { chunkedDataLoader = [chunkedDataLoader copy]; - return ^JFFCancelAsyncOperation( JFFAsyncOperationProgressHandler progressCallback - , JFFCancelAsyncOperationHandler cancelCallback - , JFFDidFinishAsyncOperationHandler doneCallback) { + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + __block NSString *fileName = nil; __block NSString *filePath = nil; __block NSFileHandle *handle = nil; @@ -55,11 +55,9 @@ __block void (^closeFile)() = ^{ __block void (^closeAndRemoveFile)() = ^{ closeFile(); - if ( filePath ) - { - [ [ NSFileManager defaultManager ] removeItemAtPath: filePath - error: nil ]; - } + if (filePath) + [[NSFileManager defaultManager] removeItemAtPath:filePath + error:nil]; }; progressCallback = [progressCallback copy]; @@ -83,9 +81,7 @@ __block void (^closeAndRemoveFile)() = ^{ } ); if (progressCallback) - { progressCallback(progressInfo); - } }; cancelCallback = [cancelCallback copy]; @@ -93,9 +89,7 @@ __block void (^closeAndRemoveFile)() = ^{ closeAndRemoveFile(); if (cancelCallback) - { cancelCallback(canceled); - } }; JFFDidFinishAsyncOperationHandler doneWrapperCallback = ^(id response, NSError *error ) { @@ -107,7 +101,7 @@ __block void (^closeAndRemoveFile)() = ^{ } if (doneCallback) { - if ( result == nil && error == nil ) { + if (result == nil && error == nil) { error = [JFFRestKitEmptyFileResponseError new]; } doneCallback(result, error); diff --git a/lib/JFFRestKit/JFFRestKit/JFFRestKitError.h b/lib/JFFRestKit/JFFRestKit/JFFRestKitError.h index 9f90ce3..a47c806 100644 --- a/lib/JFFRestKit/JFFRestKit/JFFRestKitError.h +++ b/lib/JFFRestKit/JFFRestKit/JFFRestKitError.h @@ -1,4 +1,4 @@ -#import +#import @interface JFFRestKitError : JFFError @end diff --git a/lib/JFFRestKit/JFFRestKit/JFFRestKitError.m b/lib/JFFRestKit/JFFRestKit/JFFRestKitError.m index b014a50..24973eb 100644 --- a/lib/JFFRestKit/JFFRestKit/JFFRestKitError.m +++ b/lib/JFFRestKit/JFFRestKit/JFFRestKitError.m @@ -7,7 +7,7 @@ + (NSString *)jffErrorsDomain return @"com.just_for_fun.rest_kit.library"; } -- (id)init +- (instancetype)init { return [super initWithDescription:NSLocalizedString(@"REST_KIT_BASE_ERROR", nil)]; } @@ -16,7 +16,7 @@ - (id)init @implementation JFFRestKitEmptyFileResponseError -- (id)init +- (instancetype)init { return [super initWithDescription:NSLocalizedString(@"REST_KIT_EMPTY_FILE_RESPONSE_ERROR", nil)]; } diff --git a/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.h b/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.h index a47e1e7..400da4d 100644 --- a/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.h +++ b/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.h @@ -7,7 +7,6 @@ typedef JFFAsyncOperationBinder(^JFFAsyncBinderForIdentifier)(id loadDataIdentifier); typedef id (^JFFCacheKeyForIdentifier)(id loadDataIdentifier); -typedef JFFAsyncOperation(^JFFCacheLastUpdateDateForKey)(id key); @interface JFFSmartUrlDataLoaderFields : NSObject @@ -15,9 +14,8 @@ typedef JFFAsyncOperation(^JFFCacheLastUpdateDateForKey)(id key); @property (nonatomic, copy) JFFAsyncOperationBinder dataLoaderForIdentifier; @property (nonatomic, copy) JFFAsyncBinderForIdentifier analyzerForData; @property (nonatomic, copy) JFFCacheKeyForIdentifier cacheKeyForIdentifier; -@property (nonatomic, copy) JFFCacheLastUpdateDateForKey lastUpdateDateForKey; @property (nonatomic) BOOL doesNotIgnoreFreshDataLoadFail; -@property (nonatomic) id< JFFRestKitCache > cache; +@property (nonatomic) id cache; @property (nonatomic) NSTimeInterval cacheDataLifeTimeInSeconds; @end diff --git a/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.m b/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.m index 1590333..b7fef33 100644 --- a/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.m +++ b/lib/JFFRestKit/JFFRestKit/JFFSmartUrlDataLoader.m @@ -19,7 +19,7 @@ @implementation NSData (JFFSmartDataLoaderLogResponse) - (void)logResponse { NSString *str = [[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding]; - NSLog(@"jsResponse: %@ length: %d", str, self.length); + NSLog(@"jsResponse: %@ length: %lu", str, (unsigned long)self.length); } @end @@ -40,12 +40,12 @@ + (NSString *)jffErrorsDomain return @"com.just_for_fun.rest_kit_internal.library"; } -- (id)init +- (instancetype)init { return [self initWithDescription:@"internal logic error (no fresh data)"]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFErrorNoFreshData *copy = [super copyWithZone:zone]; @@ -80,7 +80,7 @@ static JFFAsyncOperationBinder dataLoaderWithCachedResultBinder(BOOL doesNotIgno return; } - //TODO test [bindError isKindOfClass:[JFFErrorNoFreshData class]] issue, here it van got - not data in cache error !!! + //TODO test [bindError isKindOfClass:[JFFErrorNoFreshData class]] issue, here it can got - not data in cache error !!! JFFErrorNoFreshData *noFreshDataError = (JFFErrorNoFreshData *)([bindError isKindOfClass:[JFFErrorNoFreshData class]]?bindError:nil); if ([noFreshDataError.cachedData data] && !doesNotIgnoreFreshDataLoadFail) { @@ -99,26 +99,9 @@ static JFFAsyncOperationBinder dataLoaderWithCachedResultBinder(BOOL doesNotIgno }; static JFFAsyncOperation loadFreshCachedDataWithUpdateDate(id key, - JFFAsyncOperation cahcedDataLoader, - JFFCacheLastUpdateDateForKey lastUpdateDateForKey, + JFFAsyncOperation cachedDataLoader, NSTimeInterval cacheDataLifeTimeInSeconds) { - JFFAsyncOperationBinder changeCachedDateBinder = ^JFFAsyncOperation(id cachedData) { - - if (lastUpdateDateForKey) { - JFFAsyncOperationBinder binder = ^JFFAsyncOperation(NSDate *date) { - JFFResponseDataWithUpdateData *result = [JFFResponseDataWithUpdateData new]; - result.data = cachedData.data; - result.updateDate = date?:cachedData.updateDate; - return asyncOperationWithResult(result); - }; - - return bindSequenceOfAsyncOperations(lastUpdateDateForKey(key), binder, nil); - } - - return asyncOperationWithResult(cachedData); - }; - JFFAsyncOperationBinder validateByDateResultBinder = ^JFFAsyncOperation(id cachedData) { NSDate *newDate = [cachedData.updateDate dateByAddingTimeInterval:cacheDataLifeTimeInSeconds]; @@ -131,25 +114,23 @@ static JFFAsyncOperation loadFreshCachedDataWithUpdateDate(id key, return asyncOperationWithError(error); }; - return bindSequenceOfAsyncOperations(cahcedDataLoader, - changeCachedDateBinder, + return bindSequenceOfAsyncOperations(cachedDataLoader, validateByDateResultBinder, nil); } JFFAsyncOperation jSmartDataLoaderWithCache(JFFSmartUrlDataLoaderFields *args) { - id loadDataIdentifier = args.loadDataIdentifier; - JFFAsyncOperationBinder dataLoaderForIdentifier = args.dataLoaderForIdentifier; - JFFAsyncBinderForIdentifier analyzerForData = args.analyzerForData; - id< JFFRestKitCache > cache = args.cache; - JFFCacheKeyForIdentifier cacheKeyForIdentifier = args.cacheKeyForIdentifier; - JFFCacheLastUpdateDateForKey lastUpdateDateForKey = args.lastUpdateDateForKey; - NSTimeInterval cacheDataLifeTimeInSeconds = args.cacheDataLifeTimeInSeconds; - BOOL doesNotIgnoreFreshDataLoadFail = args.doesNotIgnoreFreshDataLoadFail; + id loadDataIdentifier = args.loadDataIdentifier; + JFFAsyncOperationBinder dataLoaderForIdentifier = args.dataLoaderForIdentifier; + JFFAsyncBinderForIdentifier analyzerForData = args.analyzerForData; + id< JFFRestKitCache > cache = args.cache; + JFFCacheKeyForIdentifier cacheKeyForIdentifier = args.cacheKeyForIdentifier; + NSTimeInterval cacheDataLifeTimeInSeconds = args.cacheDataLifeTimeInSeconds; + BOOL doesNotIgnoreFreshDataLoadFail = args.doesNotIgnoreFreshDataLoadFail; - assert(loadDataIdentifier ); - assert(dataLoaderForIdentifier); + NSCParameterAssert(loadDataIdentifier ); + NSCParameterAssert(dataLoaderForIdentifier); if (!analyzerForData) { analyzerForData = ^JFFAsyncOperationBinder(NSURL *url) { @@ -183,7 +164,6 @@ JFFAsyncOperation jSmartDataLoaderWithCache(JFFSmartUrlDataLoaderFields *args) JFFAsyncOperation loadChachedData = loadFreshCachedDataWithUpdateDate(key, [cache cachedDataLoaderForKey:key], - lastUpdateDateForKey, cacheDataLifeTimeInSeconds); loader = bindTrySequenceOfAsyncOperations(loadChachedData, dataLoaderBinder, nil); diff --git a/lib/JFFScheduler/JFFScheduler.h b/lib/JFFScheduler/JFFScheduler.h index df61ab5..243ed93 100755 --- a/lib/JFFScheduler/JFFScheduler.h +++ b/lib/JFFScheduler/JFFScheduler.h @@ -6,12 +6,26 @@ typedef void (^JFFScheduledBlock) (JFFCancelScheduledBlock cancel); @interface JFFScheduler : NSObject //returns the shared scheduler -+ (id)sharedByThreadScheduler; ++ (instancetype)sharedByThreadScheduler; //Add new block to scheduler which will be invoked on the current thread using the default mode after a delay, //returning the block for canceling this invocation //the invocation will be canceled at removing "scheduler" object from memory -- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)block duration:(NSTimeInterval)duration; +- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)block + duration:(NSTimeInterval)duration; + +- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)block + duration:(NSTimeInterval)duration + leeway:(NSTimeInterval)leeway; + +- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)block + duration:(NSTimeInterval)duration + dispatchQueue:(dispatch_queue_t)dispatchQueue; + +- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)block + duration:(NSTimeInterval)duration + leeway:(NSTimeInterval)leeway + dispatchQueue:(dispatch_queue_t)dispatchQueue; //cancel all delayed invocations for self - (void)cancelAllScheduledOperations; diff --git a/lib/JFFScheduler/JFFScheduler.m b/lib/JFFScheduler/JFFScheduler.m index 05a5694..b92966f 100644 --- a/lib/JFFScheduler/JFFScheduler.m +++ b/lib/JFFScheduler/JFFScheduler.m @@ -1,86 +1,88 @@ #import "JFFScheduler.h" -#import #import +#import -#include +@interface NSThread (JFFScheduler_Internal) -char jffSchedulerKey; +@property (nonatomic) JFFScheduler *jffScheduler; -@interface NSThread (JFFScheduler) +@end -@property (nonatomic, readonly) JFFScheduler *jffScheduler; +@implementation NSThread (JFFScheduler_Internal) -@end +@dynamic jffScheduler; -@implementation NSThread (JFFScheduler) ++ (void)load +{ + jClass_implementProperty(self, NSStringFromSelector(@selector(jffScheduler))); +} -- (JFFScheduler *)jffScheduler +- (JFFScheduler *)lazyJffScheduler { - id result = objc_getAssociatedObject(self, &jffSchedulerKey); + id result = self.jffScheduler; if (!result) { result = [JFFScheduler new]; - objc_setAssociatedObject(self, - &jffSchedulerKey, - result, - OBJC_ASSOCIATION_RETAIN_NONATOMIC); + self.jffScheduler = result; } return result; } @end -@interface JFFScheduler () - -@property (nonatomic) dispatch_queue_t queue; - -@end - @implementation JFFScheduler { NSMutableArray *_cancelBlocks; } --(void)dealloc +- (void)dealloc { [self cancelAllScheduledOperations]; - - dispatch_release(_queue); } -- (id)init +- (instancetype)init { self = [super init]; if (self) { - _queue = dispatch_get_current_queue(); - dispatch_retain(_queue); _cancelBlocks = [NSMutableArray new]; } return self; } -+ (id)sharedByThreadScheduler ++ (instancetype)sharedByThreadScheduler { NSThread *thread = [NSThread currentThread]; - return thread.jffScheduler; + return thread.lazyJffScheduler; +} + +- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)block + duration:(NSTimeInterval)duration + dispatchQueue:(dispatch_queue_t)dispatchQueue +{ + return [self addBlock:block + duration:duration + leeway:duration/10. + dispatchQueue:dispatchQueue]; } - (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)actionBlock duration:(NSTimeInterval)duration + leeway:(NSTimeInterval)leeway + dispatchQueue:(dispatch_queue_t)dispatchQueue { NSParameterAssert(actionBlock); if (!actionBlock) return ^(){ /* do nothing */ }; - __block dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, _queue); + __block dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatchQueue); int64_t delta = duration * NSEC_PER_SEC; dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, delta), delta, - 0 ); + leeway * NSEC_PER_SEC); __unsafe_unretained JFFScheduler *unretainedSelf = self; @@ -91,8 +93,7 @@ - (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)actionBlock return; dispatch_source_cancel(timer); - dispatch_release(timer); - timer = NULL; + timer = nil; [unretainedSelf->_cancelBlocks removeObject:unretainedCancelTimerBlockHolder.simpleBlock]; }; @@ -102,7 +103,7 @@ - (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)actionBlock actionBlock = [actionBlock copy]; dispatch_block_t eventHandlerBlock = [^void(void) { actionBlock(cancelTimerBlockHolder.onceSimpleBlock); - }copy]; + } copy]; dispatch_source_set_event_handler(timer, eventHandlerBlock); @@ -111,6 +112,24 @@ - (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)actionBlock return cancelTimerBlockHolder.onceSimpleBlock; } +- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)block + duration:(NSTimeInterval)duration +{ + return [self addBlock:block + duration:duration + leeway:duration/10.]; +} + +- (JFFCancelScheduledBlock)addBlock:(JFFScheduledBlock)actionBlock + duration:(NSTimeInterval)duration + leeway:(NSTimeInterval)leeway +{ + return [self addBlock:actionBlock + duration:duration + leeway:leeway + dispatchQueue:dispatch_get_main_queue()]; +} + - (void)cancelAllScheduledOperations { NSSet *cancelBlocks = [_cancelBlocks copy]; diff --git a/lib/JFFScheduler/JFFScheduler.xcodeproj/project.pbxproj b/lib/JFFScheduler/JFFScheduler.xcodeproj/project.pbxproj index 4aa7fcd..f951d02 100644 --- a/lib/JFFScheduler/JFFScheduler.xcodeproj/project.pbxproj +++ b/lib/JFFScheduler/JFFScheduler.xcodeproj/project.pbxproj @@ -304,7 +304,7 @@ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0440; + LastUpgradeCheck = 0500; }; buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "JFFScheduler" */; compatibilityVersion = "Xcode 3.2"; @@ -449,7 +449,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = JFFScheduler_Prefix.pch; INSTALL_PATH = /usr/local/lib; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = JFFScheduler; SKIP_INSTALL = YES; }; @@ -464,7 +464,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = JFFScheduler_Prefix.pch; INSTALL_PATH = /usr/local/lib; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = JFFScheduler; SKIP_INSTALL = YES; }; @@ -473,14 +473,18 @@ 1DEB922308733DC00010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; + ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; @@ -489,13 +493,16 @@ 1DEB922408733DC00010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; @@ -540,7 +547,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -570,7 +576,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; diff --git a/lib/JFFScheduler/NSObject+Scheduler.h b/lib/JFFScheduler/NSObject+Scheduler.h index 7fac782..947d23f 100755 --- a/lib/JFFScheduler/NSObject+Scheduler.h +++ b/lib/JFFScheduler/NSObject+Scheduler.h @@ -9,6 +9,7 @@ //invocation will be canceled at removing "receiver" object from memory - (void)performSelector:(SEL)selector timeInterval:(NSTimeInterval)timeInterval + leeway:(NSTimeInterval)leeway userInfo:(id)userInfo repeats:(BOOL)repeats; @@ -17,6 +18,7 @@ //invocation will be canceled at removing "receiver" or "scheduler" object from memory - (void)performSelector:(SEL)selector timeInterval:(NSTimeInterval)timeInterval + leeway:(NSTimeInterval)leeway userInfo:(id)userInfo repeats:(BOOL)repeats scheduler:(JFFScheduler *)scheduler; diff --git a/lib/JFFScheduler/NSObject+Scheduler.m b/lib/JFFScheduler/NSObject+Scheduler.m index 560e83c..67cfd4e 100755 --- a/lib/JFFScheduler/NSObject+Scheduler.m +++ b/lib/JFFScheduler/NSObject+Scheduler.m @@ -11,6 +11,7 @@ @implementation NSObject (Scheduler) - (void)performSelector:(SEL)selector timeInterval:(NSTimeInterval)timeInterval + leeway:(NSTimeInterval)leeway userInfo:(id)userInfo repeats:(BOOL)repeats scheduler:(JFFScheduler *)scheduler @@ -18,7 +19,7 @@ - (void)performSelector:(SEL)selector NSParameterAssert(scheduler); //use signature's number params - NSString* selectorString = NSStringFromSelector(selector); + NSString *selectorString = NSStringFromSelector(selector); NSUInteger numOfArgs = [selectorString numberOfCharacterFromString:@":"]; NSAssert1(numOfArgs == 0 || numOfArgs == 1, @"selector \"%@\" should has 0 or 1 parameters", @@ -37,17 +38,21 @@ - (void)performSelector:(SEL)selector : objc_msgSend(unretainedSelf, selector); }; - JFFCancelScheduledBlock cancel = [scheduler addBlock:block duration:timeInterval]; + JFFCancelScheduledBlock cancel = [scheduler addBlock:block + duration:timeInterval + leeway:leeway]; [self addOnDeallocBlock:cancel]; } - (void)performSelector:(SEL)selector timeInterval:(NSTimeInterval)timeInterval + leeway:(NSTimeInterval)leeway userInfo:(id)userInfo repeats:(BOOL)repeats { [self performSelector:selector timeInterval:timeInterval + leeway:leeway userInfo:userInfo repeats:repeats scheduler:[JFFScheduler sharedByThreadScheduler]]; diff --git a/lib/JFFSecureStorage/JFFSecureStorage.xcodeproj/project.pbxproj b/lib/JFFSecureStorage/JFFSecureStorage.xcodeproj/project.pbxproj index deca644..d3e86b7 100644 --- a/lib/JFFSecureStorage/JFFSecureStorage.xcodeproj/project.pbxproj +++ b/lib/JFFSecureStorage/JFFSecureStorage.xcodeproj/project.pbxproj @@ -290,7 +290,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; SDKROOT = iphoneos; }; name = Debug; @@ -306,7 +306,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; diff --git a/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.h b/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.h index b5db6db..ae77aae 100644 --- a/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.h +++ b/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.h @@ -8,12 +8,12 @@ extern "C" { #endif -void jffStoreSecureCredentials( NSString* login_ - , NSString* password_ - , NSURL* url_ ); - -NSString* jffGetSecureCredentialsForURL( NSString** login_ - , NSURL* url_ ); + void jffStoreSecureCredentials(NSString *login, + NSString *password, + NSURL *url); + + NSString* jffGetSecureCredentialsForURL(NSString **login, + NSURL *url); #ifdef __cplusplus } /* closing brace for extern "C" */ diff --git a/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.m b/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.m index 76af319..6ecc657 100755 --- a/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.m +++ b/lib/JFFSecureStorage/JFFSecureStorage/JFFSecureStorage.m @@ -4,138 +4,137 @@ #include -static NSString* const identifier_ = @"Login&Password"; +static NSString* const __identifier = @"Login&Password"; // TODO : Rewrite in C++. This can be easily reversed by tools like class_dump_z // http://code.google.com/p/networkpx/wiki/class_dump_z @protocol JFFSecureStorage < NSObject > --(void)setPassword:( NSString* )password_ - login:( NSString* )login_ - forURL:( NSURL* )url_; +- (void)setPassword:(NSString *)password + login:(NSString *)login + forURL:(NSURL *)url; --(NSString*)passwordAndLogin:( NSString** )login_ - forURL:( NSURL* )url_; +- (NSString *)passwordAndLogin:(NSString **)login + forURL:(NSURL *)url; @end -@interface JFFSimulatorSecureStorage : NSObject < JFFSecureStorage > +@interface JFFSimulatorSecureStorage : NSObject @end @implementation JFFSimulatorSecureStorage -+(NSString*)secureStorageFilePath ++ (NSString *)secureStorageFilePath { - NSArray* pathes_ = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory - , NSUserDomainMask - , YES ); - NSString* documentDirectory_ = [ pathes_ lastObject ]; - - return [ documentDirectory_ stringByAppendingPathComponent: @"JFFSimulatorSecureStorage.data" ]; + NSArray *pathes = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, + NSUserDomainMask, + YES); + NSString *documentDirectory = [pathes lastObject]; + + return [documentDirectory stringByAppendingPathComponent:@"JFFSimulatorSecureStorage.data"]; } --(void)setPassword:( NSString* )password_ - login:( NSString* )login_ - forURL:( NSURL* )url_ +- (void)setPassword:(NSString *)password + login:(NSString *)login + forURL:(NSURL *)url { - NSString* path_ = [ [ self class ] secureStorageFilePath ]; - - NSMutableDictionary* dict_ = [ [ NSMutableDictionary alloc ] initWithContentsOfFile: path_ ]; - dict_ = dict_ ?: [ NSMutableDictionary new ]; - - NSDictionary* loginPasswordData_ = @{ @"login" : login_, @"password" : password_ }; - - dict_[ [ url_ description ] ] = loginPasswordData_; - - [ dict_ writeToFile: path_ atomically: YES ]; + NSString *path = [[self class] secureStorageFilePath]; + + NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; + dict = dict ?: [NSMutableDictionary new]; + + NSDictionary *loginPasswordData = @{@"login" : login, @"password" : password}; + + dict[[url description]] = loginPasswordData; + + [dict writeToFile:path atomically:YES]; } --(NSString*)passwordAndLogin:( NSString** )login_ - forURL:( NSURL* )url_ +- (NSString *)passwordAndLogin:(NSString **)login + forURL:(NSURL *)url { - NSString* path_ = [ [ self class ] secureStorageFilePath ]; - NSDictionary* dict_ = [ [ NSDictionary alloc ] initWithContentsOfFile: path_ ]; - - NSDictionary* loginPasswordData_ = dict_[ [ url_ description ] ]; - - if ( login_ ) - { - *login_ = loginPasswordData_[ @"login" ]; + NSString *path = [[self class] secureStorageFilePath]; + NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; + + NSDictionary *loginPasswordData = dict[[url description]]; + + if (login) { + + *login = loginPasswordData[@"login"]; } - - return loginPasswordData_[ @"password" ]; + + return loginPasswordData[@"password"]; } @end @interface JFFDeviceSecureStorage : NSObject < JFFSecureStorage > { - NSMutableDictionary* _genericPasswordQuery; + NSMutableDictionary *_genericPasswordQuery; } -@property ( nonatomic, readonly ) NSDictionary* genericPasswordQuery; +@property (nonatomic, readonly) NSDictionary *genericPasswordQuery; @end @implementation JFFDeviceSecureStorage --(id)init +- (id)init { - self = [ super init ]; - - if ( self ) - { - self->_genericPasswordQuery = [ NSMutableDictionary new ]; - - self->_genericPasswordQuery[ (__bridge id)kSecAttrGeneric ] = identifier_; - self->_genericPasswordQuery[ (__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; - self->_genericPasswordQuery[ (__bridge id)kSecMatchLimit ] = (__bridge id)kSecMatchLimitOne; - self->_genericPasswordQuery[ (__bridge id)kSecReturnAttributes ] = (__bridge id)kCFBooleanTrue; + self = [super init]; + + if ( self ) { + + self->_genericPasswordQuery = [NSMutableDictionary new]; + + self->_genericPasswordQuery[(__bridge id)kSecAttrGeneric ] = __identifier; + self->_genericPasswordQuery[(__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; + self->_genericPasswordQuery[(__bridge id)kSecMatchLimit ] = (__bridge id)kSecMatchLimitOne; + self->_genericPasswordQuery[(__bridge id)kSecReturnAttributes] = (__bridge id)kCFBooleanTrue; } return self; } --(NSString*)passwordFromSecItemFormat:( NSDictionary* )dictionaryToConvert_ +- (NSString *)passwordFromSecItemFormat:(NSDictionary *)dictionaryToConvert { - NSMutableDictionary* returnDictionary_ = [ dictionaryToConvert_ mutableCopy ]; - - returnDictionary_[ (__bridge id)kSecReturnData ] = (__bridge id)kCFBooleanTrue; - returnDictionary_[ (__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; - - NSData* passwordData_ = nil; - NSString* password_ = nil; - - CFDictionaryRef cfquery_ = (__bridge CFDictionaryRef)returnDictionary_; - CFDictionaryRef cfresult_ = NULL; - - if ( SecItemCopyMatching( cfquery_, (CFTypeRef*)&cfresult_ ) == noErr) - { - passwordData_ = (__bridge_transfer NSData *)cfresult_; - - password_ = [ [ NSString alloc ] initWithBytes: [ passwordData_ bytes ] - length: [ passwordData_ length ] - encoding: NSUTF8StringEncoding ]; - } - else - { + NSMutableDictionary *returnDictionary = [dictionaryToConvert mutableCopy]; + + returnDictionary[(__bridge id)kSecReturnData] = (__bridge id)kCFBooleanTrue; + returnDictionary[(__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; + + NSData *passwordData = nil; + NSString *password = nil; + + CFDictionaryRef cfquery = (__bridge CFDictionaryRef)returnDictionary; + CFDictionaryRef cfresult = NULL; + + if (SecItemCopyMatching(cfquery, (CFTypeRef*)&cfresult) == noErr) { + + passwordData = (__bridge_transfer NSData *)cfresult; + + password = [[NSString alloc] initWithBytes:[passwordData bytes] + length:[passwordData length] + encoding:NSUTF8StringEncoding]; + + } else { NSAssert( NO, @"Serious error, no matching item found in the keychain.\n" ); } - - return password_; + + return password; } --(NSString*)passwordAndLogin:( NSString** )login_ - fromSecItemFormat:( NSDictionary* )dictionaryToConvert_ +- (NSString *)passwordAndLogin:(NSString **)login + fromSecItemFormat:(NSDictionary *)dictionaryToConvert { - if ( login_ ) - { - *login_ = dictionaryToConvert_[ (__bridge id)kSecAttrAccount ]; - NSLog( @"*login_: %@", *login_ ); + if (login) { + + *login = dictionaryToConvert[(__bridge id)kSecAttrAccount]; + NSLog(@"*login_: %@", *login); } - - return [ self passwordFromSecItemFormat: dictionaryToConvert_ ]; + + return [self passwordFromSecItemFormat:dictionaryToConvert]; } -(NSMutableDictionary*)dictionaryToSecItemFormat:( NSDictionary* )dictionaryToConvert_ @@ -153,94 +152,94 @@ -(NSMutableDictionary*)dictionaryToSecItemFormat:( NSDictionary* )dictionaryToCo -(NSMutableDictionary*)defaultKeychainItemData { - NSMutableDictionary* result_ = [ NSMutableDictionary new ]; - + NSMutableDictionary* result = [ NSMutableDictionary new ]; + // Default attributes for keychain item. - result_[ (__bridge id)kSecAttrAccount ] = @""; - result_[ (__bridge id)kSecAttrLabel ] = @""; - result_[ (__bridge id)kSecAttrDescription ] = @""; - + result[(__bridge id)kSecAttrAccount ] = @""; + result[(__bridge id)kSecAttrLabel ] = @""; + result[(__bridge id)kSecAttrDescription] = @""; + // Default data for keychain item. - result_[ (__bridge id)kSecValueData ] = @""; - result_[ (__bridge id)kSecAttrGeneric ] = identifier_; - - return result_; + result[(__bridge id)kSecValueData ] = @""; + result[(__bridge id)kSecAttrGeneric] = __identifier; + + return result; } --(NSDictionary*)queryForURL:( NSURL* )url_ +- (NSDictionary *)queryForURL:(NSURL *)url { - NSMutableDictionary* result_ = [ self.genericPasswordQuery mutableCopy ]; - result_[ (__bridge id)kSecAttrService ] = [ url_ description ]; - return [ result_ copy ]; + NSMutableDictionary *result = [self.genericPasswordQuery mutableCopy]; + result[(__bridge id)kSecAttrService] = [url description]; + return [result copy]; } --(void)writeToKeychainLogin:( NSString* )login_ - url:( NSURL* )url_ - password:( NSString* )password_ +- (void)writeToKeychainLogin:(NSString *)login + url:(NSURL *)url + password:(NSString *)password { - if ( [ login_ length ] == 0 ) + if ([login length] == 0) return; - - NSMutableDictionary* keychainItemData_ = [ self defaultKeychainItemData ]; - - keychainItemData_[ (__bridge id)kSecAttrAccount ] = login_; - keychainItemData_[ (__bridge id)kSecValueData ] = password_; - keychainItemData_[ (__bridge id)kSecAttrService ] = url_; - keychainItemData_[ (__bridge id)kSecAttrAccessible ] = (__bridge id)kSecAttrAccessibleWhenUnlocked; - - NSMutableDictionary* updateItem_ = nil; - - NSDictionary* tempQuery_ = [ self queryForURL: url_ ]; - - CFDictionaryRef cfquery_ = (__bridge_retained CFDictionaryRef)tempQuery_; - CFDictionaryRef cfresult_ = NULL; - - NSMutableDictionary* secDictionary_ = [ self dictionaryToSecItemFormat: keychainItemData_ ]; - - if ( SecItemCopyMatching( cfquery_, (CFTypeRef *)&cfresult_) == noErr ) - { - NSDictionary* attributes_ = (__bridge_transfer NSDictionary *)cfresult_; - - updateItem_ = [ attributes_ mutableCopy ]; - updateItem_[ (__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; - - CFDictionaryRef cfSecDictionary_ = (__bridge_retained CFDictionaryRef)secDictionary_; - CFDictionaryRef cfUpdateItem_ = (__bridge_retained CFDictionaryRef)updateItem_; - - BOOL result_ = SecItemUpdate( cfUpdateItem_, cfSecDictionary_ ) == noErr; + + NSMutableDictionary *keychainItemData = [self defaultKeychainItemData]; + + keychainItemData[(__bridge id)kSecAttrAccount ] = login; + keychainItemData[(__bridge id)kSecValueData ] = password; + keychainItemData[(__bridge id)kSecAttrService ] = url; + keychainItemData[(__bridge id)kSecAttrAccessible] = (__bridge id)kSecAttrAccessibleWhenUnlocked; + + NSMutableDictionary *updateItem= nil; + + NSDictionary *tempQuery = [self queryForURL:url]; + + CFDictionaryRef cfquery = (__bridge_retained CFDictionaryRef)tempQuery; + CFDictionaryRef cfresult = NULL; + + NSMutableDictionary* secDictionary = [ self dictionaryToSecItemFormat: keychainItemData ]; + + if (SecItemCopyMatching(cfquery, (CFTypeRef *)&cfresult) == noErr) { + + NSDictionary *attributes = (__bridge_transfer NSDictionary *)cfresult; + + updateItem = [attributes mutableCopy]; + updateItem[ (__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; + + CFDictionaryRef cfSecDictionary = (__bridge_retained CFDictionaryRef)secDictionary; + CFDictionaryRef cfUpdateItem = (__bridge_retained CFDictionaryRef)updateItem; + + BOOL result_ = SecItemUpdate(cfUpdateItem, cfSecDictionary) == noErr; NSAssert( result_, @"Couldn't update the Keychain Item." ); - CFRelease( cfSecDictionary_ ); - CFRelease( cfUpdateItem_ ); + CFRelease( cfSecDictionary ); + CFRelease( cfUpdateItem ); } else { // No previous item found, add the new one. - secDictionary_[ (__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; - - CFDictionaryRef cfSecDictionary_ = (__bridge_retained CFDictionaryRef)secDictionary_; - + secDictionary[ (__bridge id)kSecClass ] = (__bridge id)kSecClassGenericPassword; + + CFDictionaryRef cfSecDictionary_ = (__bridge_retained CFDictionaryRef)secDictionary; + BOOL result_ = SecItemAdd(cfSecDictionary_, nil ) == noErr; NSAssert( result_, @"Couldn't add the Keychain Item." ); CFRelease( cfSecDictionary_ ); } - CFRelease( cfquery_ ); + CFRelease( cfquery ); } --(NSString*)findPasswordAndLogin:( NSString** )login_ - forUrl:( NSURL* )url_ +- (NSString *)findPasswordAndLogin:(NSString **)login + forUrl:(NSURL *)url { - NSString* result_ = nil; - - NSDictionary* tempQuery_ = [ self queryForURL: url_ ]; - - CFDictionaryRef cfquery_ = (__bridge CFDictionaryRef)tempQuery_; - CFDictionaryRef cfresult_ = NULL; - - if ( SecItemCopyMatching( cfquery_, (CFTypeRef*)&cfresult_) == noErr ) + NSString *result_ = nil; + + NSDictionary *tempQuery = [self queryForURL:url]; + + CFDictionaryRef cfquery = (__bridge CFDictionaryRef)tempQuery; + CFDictionaryRef cfresult = NULL; + + if ( SecItemCopyMatching( cfquery, (CFTypeRef*)&cfresult) == noErr ) { - NSDictionary* outDictionary_ = (__bridge_transfer NSDictionary *)cfresult_; - result_ = [ self passwordAndLogin: login_ + NSDictionary* outDictionary_ = (__bridge_transfer NSDictionary *)cfresult; + result_ = [ self passwordAndLogin: login fromSecItemFormat: outDictionary_ ]; } diff --git a/lib/JFFSocial/JFFSocial.xcodeproj/project.pbxproj b/lib/JFFSocial/JFFSocial.xcodeproj/project.pbxproj index ec232fc..a1e714e 100644 --- a/lib/JFFSocial/JFFSocial.xcodeproj/project.pbxproj +++ b/lib/JFFSocial/JFFSocial.xcodeproj/project.pbxproj @@ -22,7 +22,10 @@ 37497DB21601D9CF00AF0C29 /* FoursquareCheckinsModel+APIParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497DB11601D9CF00AF0C29 /* FoursquareCheckinsModel+APIParser.m */; }; 37497DB51601DC3800AF0C29 /* NSArray+FqCheckinsAPIParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497DB41601DC3800AF0C29 /* NSArray+FqCheckinsAPIParser.m */; }; 37497DB81601DD2500AF0C29 /* NSDictionary+FqAPIResponseParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497DB71601DD2500AF0C29 /* NSDictionary+FqAPIResponseParser.m */; }; + 4C34A5311768840A00162C13 /* JFFTwitterResponseError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C34A5301768840A00162C13 /* JFFTwitterResponseError.m */; }; + 4C34A5341768842600162C13 /* JFFTwitterDirectMessageAlreadySentError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C34A5331768842600162C13 /* JFFTwitterDirectMessageAlreadySentError.m */; }; 4C3F01DE16DD0C9E00558DE6 /* JFFFacebookLoginFailedAccessForbidden.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C3F01DD16DD0C9E00558DE6 /* JFFFacebookLoginFailedAccessForbidden.m */; }; + 4C4A3AB5176745ED00C158B0 /* JFFTwitterResponseError+TweetsJSONParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4A3AB4176745EC00C158B0 /* JFFTwitterResponseError+TweetsJSONParser.m */; }; 4C70273616D683A00078A2F2 /* JFFSocialFacebookUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C70273516D683A00078A2F2 /* JFFSocialFacebookUser.m */; }; 4C70273916D684290078A2F2 /* JFFSocialFacebookUser+Parser.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C70273816D684290078A2F2 /* JFFSocialFacebookUser+Parser.m */; }; 4C70273C16D6870A0078A2F2 /* JFFAsyncFacebook.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C70273B16D6870A0078A2F2 /* JFFAsyncFacebook.m */; }; @@ -34,6 +37,8 @@ 4C75C74616D3ED3D003B0C43 /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C75C74516D3ED3D003B0C43 /* FacebookSDK.framework */; }; 4C75C74916D3EEB4003B0C43 /* JFFAsyncFacebookLogout.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C75C74816D3EEB4003B0C43 /* JFFAsyncFacebookLogout.m */; }; 4C75C74C16D3F10F003B0C43 /* JFFSocialFacebook.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C75C74B16D3F10E003B0C43 /* JFFSocialFacebook.m */; }; + 4CB4FE21177C929E00A45FC0 /* JFFAsyncFacebookLoginWithPublishPermissions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB4FE20177C929E00A45FC0 /* JFFAsyncFacebookLoginWithPublishPermissions.m */; }; + 4CB52D6016DF93C9001E64F0 /* JFFAsyncFacebookDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB52D5F16DF93C9001E64F0 /* JFFAsyncFacebookDialog.m */; }; 4CDFCF7A16DD15BF00E978E0 /* JFFFacebookLoginFailedPasswordWasChanged.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDFCF7916DD15BF00E978E0 /* JFFFacebookLoginFailedPasswordWasChanged.m */; }; 4CFC62B816D61E3800D084F7 /* JFFFacebookSDKErrors.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CFC62B716D61E3800D084F7 /* JFFFacebookSDKErrors.m */; }; 4CFC62BB16D61E7E00D084F7 /* JFFFacebookLoginFailedCanceledError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CFC62BA16D61E7E00D084F7 /* JFFFacebookLoginFailedCanceledError.m */; }; @@ -46,7 +51,6 @@ CE4F609415F8B87B00271035 /* JFFAsyncTwitterAccessRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4F609315F8B87B00271035 /* JFFAsyncTwitterAccessRequest.m */; }; CE4F609815F8BA5700271035 /* JFFSocialError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4F609715F8BA5700271035 /* JFFSocialError.m */; }; CE4F620115F8F0D000271035 /* JFFTwitterAccountAccessNotGrantedError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4F620015F8F0D000271035 /* JFFTwitterAccountAccessNotGrantedError.m */; }; - CE4F621015F8F57100271035 /* JFFAsyncTwitterCreateAccount.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4F620F15F8F57000271035 /* JFFAsyncTwitterCreateAccount.m */; }; CE4F621315F8F76100271035 /* JFFTwitterAccountCanceledCreationError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4F621215F8F76100271035 /* JFFTwitterAccountCanceledCreationError.m */; }; CE4F623E15F9D34800271035 /* JFFNoTwitterAccountsError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4F623D15F9D34800271035 /* JFFNoTwitterAccountsError.m */; }; CE5A033E15F9FE74005CC01A /* JFFTweet.m in Sources */ = {isa = PBXBuildFile; fileRef = CE5A033D15F9FE74005CC01A /* JFFTweet.m */; }; @@ -121,34 +125,6 @@ remoteGlobalIDString = 7E8F202A14F9484F00588C7D; remoteInfo = JFFSchedulerFW; }; - CE4F604015F8B56300271035 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2AAC07E0554694100DB518D; - remoteInfo = JFFUtils; - }; - CE4F604215F8B56300271035 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 65802A5B148BF2930040A93A; - remoteInfo = JFFUtilsMacOS; - }; - CE4F604415F8B56300271035 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 5391044314A88C04007315A3; - remoteInfo = "JFFUtils-clang"; - }; - CE4F604615F8B56300271035 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7E57F42414F93738002D139B; - remoteInfo = JFFUtilsFW; - }; CE5A018015F9EEC4005CC01A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CE5A017515F9EEC4005CC01A /* JFFNetwork.xcodeproj */; @@ -177,27 +153,6 @@ remoteGlobalIDString = 7E8F204314F9494300588C7D; remoteInfo = JFFNetworkFW; }; - CEAAC3D7160B41F90058F88A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = CE444A1C1608609100DD85B0; - remoteInfo = JFFUtilsTest; - }; - CEB2366B15FF6E3A005E5CF5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEB2365B15FF6E39005E5CF5 /* JFFUI.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2AAC07E0554694100DB518D; - remoteInfo = JFFUI; - }; - CEB2366D15FF6E3A005E5CF5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEB2365B15FF6E39005E5CF5 /* JFFUI.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 539103F014A88BE1007315A3; - remoteInfo = "JFFUI-clang"; - }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -244,8 +199,14 @@ 37497DB41601DC3800AF0C29 /* NSArray+FqCheckinsAPIParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+FqCheckinsAPIParser.m"; sourceTree = ""; }; 37497DB61601DD2400AF0C29 /* NSDictionary+FqAPIResponseParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+FqAPIResponseParser.h"; sourceTree = ""; }; 37497DB71601DD2500AF0C29 /* NSDictionary+FqAPIResponseParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+FqAPIResponseParser.m"; sourceTree = ""; }; + 4C34A52F1768840A00162C13 /* JFFTwitterResponseError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFTwitterResponseError.h; sourceTree = ""; }; + 4C34A5301768840A00162C13 /* JFFTwitterResponseError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFTwitterResponseError.m; sourceTree = ""; }; + 4C34A5321768842600162C13 /* JFFTwitterDirectMessageAlreadySentError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFTwitterDirectMessageAlreadySentError.h; sourceTree = ""; }; + 4C34A5331768842600162C13 /* JFFTwitterDirectMessageAlreadySentError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFTwitterDirectMessageAlreadySentError.m; sourceTree = ""; }; 4C3F01DC16DD0C9D00558DE6 /* JFFFacebookLoginFailedAccessForbidden.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFFacebookLoginFailedAccessForbidden.h; sourceTree = ""; }; 4C3F01DD16DD0C9E00558DE6 /* JFFFacebookLoginFailedAccessForbidden.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFFacebookLoginFailedAccessForbidden.m; sourceTree = ""; }; + 4C4A3AB3176745EB00C158B0 /* JFFTwitterResponseError+TweetsJSONParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JFFTwitterResponseError+TweetsJSONParser.h"; sourceTree = ""; }; + 4C4A3AB4176745EC00C158B0 /* JFFTwitterResponseError+TweetsJSONParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JFFTwitterResponseError+TweetsJSONParser.m"; sourceTree = ""; }; 4C70273416D683A00078A2F2 /* JFFSocialFacebookUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSocialFacebookUser.h; sourceTree = ""; }; 4C70273516D683A00078A2F2 /* JFFSocialFacebookUser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSocialFacebookUser.m; sourceTree = ""; }; 4C70273716D684290078A2F2 /* JFFSocialFacebookUser+Parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JFFSocialFacebookUser+Parser.h"; sourceTree = ""; }; @@ -267,6 +228,10 @@ 4C75C74816D3EEB4003B0C43 /* JFFAsyncFacebookLogout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncFacebookLogout.m; sourceTree = ""; }; 4C75C74A16D3F10E003B0C43 /* JFFSocialFacebook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSocialFacebook.h; sourceTree = ""; }; 4C75C74B16D3F10E003B0C43 /* JFFSocialFacebook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSocialFacebook.m; sourceTree = ""; }; + 4CB4FE1F177C929D00A45FC0 /* JFFAsyncFacebookLoginWithPublishPermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncFacebookLoginWithPublishPermissions.h; sourceTree = ""; }; + 4CB4FE20177C929E00A45FC0 /* JFFAsyncFacebookLoginWithPublishPermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncFacebookLoginWithPublishPermissions.m; sourceTree = ""; }; + 4CB52D5E16DF93C9001E64F0 /* JFFAsyncFacebookDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncFacebookDialog.h; sourceTree = ""; }; + 4CB52D5F16DF93C9001E64F0 /* JFFAsyncFacebookDialog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncFacebookDialog.m; sourceTree = ""; }; 4CDFCF7816DD15BF00E978E0 /* JFFFacebookLoginFailedPasswordWasChanged.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFFacebookLoginFailedPasswordWasChanged.h; sourceTree = ""; }; 4CDFCF7916DD15BF00E978E0 /* JFFFacebookLoginFailedPasswordWasChanged.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFFacebookLoginFailedPasswordWasChanged.m; sourceTree = ""; }; 4CFC62B616D61E3800D084F7 /* JFFFacebookSDKErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFFacebookSDKErrors.h; sourceTree = ""; }; @@ -283,7 +248,6 @@ CE4F601015F8B2BB00271035 /* JFFSocial.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFSocial.h; sourceTree = ""; }; CE4F601A15F8B30C00271035 /* JFFSocialTwitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSocialTwitter.h; sourceTree = ""; }; CE4F601B15F8B30C00271035 /* JFFSocialTwitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSocialTwitter.m; sourceTree = ""; }; - CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFUtils.xcodeproj; path = ../JFFUtils/JFFUtils.xcodeproj; sourceTree = ""; }; CE4F602115F8B56300271035 /* JFFScheduler.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFScheduler.xcodeproj; path = ../JFFScheduler/JFFScheduler.xcodeproj; sourceTree = ""; }; CE4F602415F8B56300271035 /* JFFAsyncOperations.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFAsyncOperations.xcodeproj; path = ../JFFAsyncOperations/JFFAsyncOperations.xcodeproj; sourceTree = ""; }; CE4F606C15F8B63F00271035 /* JFFSocialAccount.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSocialAccount.h; sourceTree = ""; }; @@ -296,8 +260,6 @@ CE4F609715F8BA5700271035 /* JFFSocialError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSocialError.m; sourceTree = ""; }; CE4F61FF15F8F0D000271035 /* JFFTwitterAccountAccessNotGrantedError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFTwitterAccountAccessNotGrantedError.h; sourceTree = ""; }; CE4F620015F8F0D000271035 /* JFFTwitterAccountAccessNotGrantedError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFTwitterAccountAccessNotGrantedError.m; sourceTree = ""; }; - CE4F620E15F8F56F00271035 /* JFFAsyncTwitterCreateAccount.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAsyncTwitterCreateAccount.h; sourceTree = ""; }; - CE4F620F15F8F57000271035 /* JFFAsyncTwitterCreateAccount.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAsyncTwitterCreateAccount.m; sourceTree = ""; }; CE4F621115F8F76100271035 /* JFFTwitterAccountCanceledCreationError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFTwitterAccountCanceledCreationError.h; sourceTree = ""; }; CE4F621215F8F76100271035 /* JFFTwitterAccountCanceledCreationError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFTwitterAccountCanceledCreationError.m; sourceTree = ""; }; CE4F623C15F9D34800271035 /* JFFNoTwitterAccountsError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFNoTwitterAccountsError.h; sourceTree = ""; }; @@ -322,7 +284,6 @@ CEAAC3C3160B41F90058F88A /* JFFSocialMediaItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSocialMediaItem.m; sourceTree = ""; }; CEB2350415FF6840005E5CF5 /* JFFSocialInstagram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSocialInstagram.h; sourceTree = ""; }; CEB2350515FF6840005E5CF5 /* JFFSocialInstagram.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSocialInstagram.m; sourceTree = ""; }; - CEB2365B15FF6E39005E5CF5 /* JFFUI.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFUI.xcodeproj; path = "/Users/user/Sources/paparam.ru/HumanCloud/lib-third-party/iAsync/test/JFFSocialTest/../../lib/JFFUI/JFFUI.xcodeproj"; sourceTree = ""; }; CEB2367515FF7638005E5CF5 /* JFFInvalidInstagramResponseURLError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFInvalidInstagramResponseURLError.h; sourceTree = ""; }; CEB2367615FF7638005E5CF5 /* JFFInvalidInstagramResponseURLError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFInvalidInstagramResponseURLError.m; sourceTree = ""; }; CEB2367D15FF7E80005E5CF5 /* JFFInstagramAuthedAccount.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFInstagramAuthedAccount.h; sourceTree = ""; }; @@ -461,6 +422,17 @@ path = ParserErrors; sourceTree = ""; }; + 4C34A51E1768827600162C13 /* ResponseError */ = { + isa = PBXGroup; + children = ( + 4C34A52F1768840A00162C13 /* JFFTwitterResponseError.h */, + 4C34A5301768840A00162C13 /* JFFTwitterResponseError.m */, + 4C34A5321768842600162C13 /* JFFTwitterDirectMessageAlreadySentError.h */, + 4C34A5331768842600162C13 /* JFFTwitterDirectMessageAlreadySentError.m */, + ); + path = ResponseError; + sourceTree = ""; + }; 4C70272216D6837A0078A2F2 /* Model */ = { isa = PBXGroup; children = ( @@ -511,12 +483,16 @@ children = ( 4C75C73F16D3EBD0003B0C43 /* JFFAsyncFacebookLogin.h */, 4C75C74016D3EBD0003B0C43 /* JFFAsyncFacebookLogin.m */, + 4CB4FE1F177C929D00A45FC0 /* JFFAsyncFacebookLoginWithPublishPermissions.h */, + 4CB4FE20177C929E00A45FC0 /* JFFAsyncFacebookLoginWithPublishPermissions.m */, 4C75C74216D3EC96003B0C43 /* JFFFacebookPublishAccessRequestAdapter.h */, 4C75C74316D3EC96003B0C43 /* JFFFacebookPublishAccessRequestAdapter.m */, 4C75C74716D3EEB4003B0C43 /* JFFAsyncFacebookLogout.h */, 4C75C74816D3EEB4003B0C43 /* JFFAsyncFacebookLogout.m */, 4C70273A16D6870A0078A2F2 /* JFFAsyncFacebook.h */, 4C70273B16D6870A0078A2F2 /* JFFAsyncFacebook.m */, + 4CB52D5E16DF93C9001E64F0 /* JFFAsyncFacebookDialog.h */, + 4CB52D5F16DF93C9001E64F0 /* JFFAsyncFacebookDialog.m */, ); path = AsyncAdapters; sourceTree = ""; @@ -581,11 +557,11 @@ CEB234F315FF67EC005E5CF5 /* Instagram */, 37063AA015FA3E0C00B4B059 /* Foursquare */, CE4F609515F8BA4300271035 /* Errors */, - CE4F601015F8B2BB00271035 /* JFFSocial.h */, CE4F606C15F8B63F00271035 /* JFFSocialAccount.h */, CE4F606D15F8B63F00271035 /* JFFSocialAccount.m */, CEAAC3C2160B41F90058F88A /* JFFSocialMediaItem.h */, CEAAC3C3160B41F90058F88A /* JFFSocialMediaItem.m */, + CE4F601015F8B2BB00271035 /* JFFSocial.h */, CE4F600E15F8B2BB00271035 /* Supporting Files */, ); path = JFFSocial; @@ -615,27 +591,13 @@ CE4F601D15F8B55300271035 /* Dependencies */ = { isa = PBXGroup; children = ( - CEB2365B15FF6E39005E5CF5 /* JFFUI.xcodeproj */, CE5A017515F9EEC4005CC01A /* JFFNetwork.xcodeproj */, - CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */, CE4F602115F8B56300271035 /* JFFScheduler.xcodeproj */, CE4F602415F8B56300271035 /* JFFAsyncOperations.xcodeproj */, ); name = Dependencies; sourceTree = ""; }; - CE4F601F15F8B56300271035 /* Products */ = { - isa = PBXGroup; - children = ( - CE4F604115F8B56300271035 /* libJFFUtils.a */, - CE4F604315F8B56300271035 /* libJFFUtilsMacOS.a */, - CE4F604515F8B56300271035 /* libJFFUtils-clang.a */, - CE4F604715F8B56300271035 /* JFFUtilsFW.framework */, - CEAAC3D8160B41F90058F88A /* JFFUtilsTest.octest */, - ); - name = Products; - sourceTree = ""; - }; CE4F602215F8B56300271035 /* Products */ = { isa = PBXGroup; children = ( @@ -664,8 +626,6 @@ CE4F609015F8B85300271035 /* JFFAsyncTwitterRequest.m */, CE4F609215F8B87B00271035 /* JFFAsyncTwitterAccessRequest.h */, CE4F609315F8B87B00271035 /* JFFAsyncTwitterAccessRequest.m */, - CE4F620E15F8F56F00271035 /* JFFAsyncTwitterCreateAccount.h */, - CE4F620F15F8F57000271035 /* JFFAsyncTwitterCreateAccount.m */, ); path = AsyncAdapters; sourceTree = ""; @@ -673,6 +633,8 @@ CE4F604915F8B5DC00271035 /* Parsers */ = { isa = PBXGroup; children = ( + 4C4A3AB3176745EB00C158B0 /* JFFTwitterResponseError+TweetsJSONParser.h */, + 4C4A3AB4176745EC00C158B0 /* JFFTwitterResponseError+TweetsJSONParser.m */, CE5A034215F9FFEF005CC01A /* NSArray+TweetsJSONParser.h */, CE5A034315F9FFEF005CC01A /* NSArray+TweetsJSONParser.m */, CE5A034515FA0187005CC01A /* JFFTwitterAccount+TwitterJSONApiParser.h */, @@ -699,6 +661,7 @@ CE4F609915F8BB0B00271035 /* Errors */ = { isa = PBXGroup; children = ( + 4C34A51E1768827600162C13 /* ResponseError */, CE4F61FF15F8F0D000271035 /* JFFTwitterAccountAccessNotGrantedError.h */, CE4F620015F8F0D000271035 /* JFFTwitterAccountAccessNotGrantedError.m */, CE4F621115F8F76100271035 /* JFFTwitterAccountCanceledCreationError.h */, @@ -747,15 +710,6 @@ path = Instagram; sourceTree = ""; }; - CEB2365C15FF6E39005E5CF5 /* Products */ = { - isa = PBXGroup; - children = ( - CEB2366C15FF6E3A005E5CF5 /* libJFFUI.a */, - CEB2366E15FF6E3A005E5CF5 /* libJFFUI copy.a */, - ); - name = Products; - sourceTree = ""; - }; CEB2367415FF760F005E5CF5 /* Errors */ = { isa = PBXGroup; children = ( @@ -836,7 +790,7 @@ CE4F5FFF15F8B2BB00271035 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = EmbeddedSources; }; buildConfigurationList = CE4F600215F8B2BB00271035 /* Build configuration list for PBXProject "JFFSocial" */; @@ -862,14 +816,6 @@ ProductGroup = CE4F602215F8B56300271035 /* Products */; ProjectRef = CE4F602115F8B56300271035 /* JFFScheduler.xcodeproj */; }, - { - ProductGroup = CEB2365C15FF6E39005E5CF5 /* Products */; - ProjectRef = CEB2365B15FF6E39005E5CF5 /* JFFUI.xcodeproj */; - }, - { - ProductGroup = CE4F601F15F8B56300271035 /* Products */; - ProjectRef = CE4F601E15F8B56300271035 /* JFFUtils.xcodeproj */; - }, ); projectRoot = ""; targets = ( @@ -929,34 +875,6 @@ remoteRef = CE4F603A15F8B56300271035 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - CE4F604115F8B56300271035 /* libJFFUtils.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFUtils.a; - remoteRef = CE4F604015F8B56300271035 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE4F604315F8B56300271035 /* libJFFUtilsMacOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFUtilsMacOS.a; - remoteRef = CE4F604215F8B56300271035 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE4F604515F8B56300271035 /* libJFFUtils-clang.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libJFFUtils-clang.a"; - remoteRef = CE4F604415F8B56300271035 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE4F604715F8B56300271035 /* JFFUtilsFW.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework.static; - path = JFFUtilsFW.framework; - remoteRef = CE4F604615F8B56300271035 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE5A018115F9EEC4005CC01A /* libJFFNetwork.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -985,28 +903,6 @@ remoteRef = CE5A018615F9EEC4005CC01A /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - CEAAC3D8160B41F90058F88A /* JFFUtilsTest.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = JFFUtilsTest.octest; - remoteRef = CEAAC3D7160B41F90058F88A /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEB2366C15FF6E3A005E5CF5 /* libJFFUI.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFUI.a; - remoteRef = CEB2366B15FF6E3A005E5CF5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CEB2366E15FF6E3A005E5CF5 /* libJFFUI copy.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - name = "libJFFUI copy.a"; - path = "libJFFUI-clang.a"; - remoteRef = CEB2366D15FF6E3A005E5CF5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; /* End PBXReferenceProxy section */ /* Begin PBXSourcesBuildPhase section */ @@ -1020,7 +916,6 @@ CE4F609415F8B87B00271035 /* JFFAsyncTwitterAccessRequest.m in Sources */, CE4F609815F8BA5700271035 /* JFFSocialError.m in Sources */, CE4F620115F8F0D000271035 /* JFFTwitterAccountAccessNotGrantedError.m in Sources */, - CE4F621015F8F57100271035 /* JFFAsyncTwitterCreateAccount.m in Sources */, CE4F621315F8F76100271035 /* JFFTwitterAccountCanceledCreationError.m in Sources */, CE4F623E15F9D34800271035 /* JFFNoTwitterAccountsError.m in Sources */, CE5A033E15F9FE74005CC01A /* JFFTweet.m in Sources */, @@ -1073,6 +968,11 @@ 4C70273C16D6870A0078A2F2 /* JFFAsyncFacebook.m in Sources */, 4C3F01DE16DD0C9E00558DE6 /* JFFFacebookLoginFailedAccessForbidden.m in Sources */, 4CDFCF7A16DD15BF00E978E0 /* JFFFacebookLoginFailedPasswordWasChanged.m in Sources */, + 4CB52D6016DF93C9001E64F0 /* JFFAsyncFacebookDialog.m in Sources */, + 4C4A3AB5176745ED00C158B0 /* JFFTwitterResponseError+TweetsJSONParser.m in Sources */, + 4C34A5311768840A00162C13 /* JFFTwitterResponseError.m in Sources */, + 4C34A5341768842600162C13 /* JFFTwitterDirectMessageAlreadySentError.m in Sources */, + 4CB4FE21177C929E00A45FC0 /* JFFAsyncFacebookLoginWithPublishPermissions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1090,15 +990,16 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -1106,16 +1007,20 @@ "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ., ../JFFJsonTools, + ../JFFRestKit, ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; }; name = Debug; @@ -1124,25 +1029,30 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, ., ../JFFJsonTools, + ../JFFRestKit, ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -1158,6 +1068,7 @@ ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFSocial/JFFSocial-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -1174,6 +1085,7 @@ ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFSocial/JFFSocial-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/lib/JFFSocial/JFFSocial/Errors/JFFSocialError.h b/lib/JFFSocial/JFFSocial/Errors/JFFSocialError.h index 5149e55..dfa2b3a 100644 --- a/lib/JFFSocial/JFFSocial/Errors/JFFSocialError.h +++ b/lib/JFFSocial/JFFSocial/Errors/JFFSocialError.h @@ -1,4 +1,4 @@ -#import +#import #import diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebook.m b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebook.m index 173216b..9c12384 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebook.m +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebook.m @@ -3,43 +3,41 @@ #import @interface JFFFacebookGeneralRequestLoader : NSObject < JFFAsyncOperationInterface > - -@property (nonatomic, copy) JFFAsyncOperationInterfaceResultHandler handler; -@property ( nonatomic ) FBSession* facebookSession; -@property ( nonatomic ) NSString *graphPath; -@property ( nonatomic ) NSString *HTTPMethod; -@property ( nonatomic ) NSDictionary *parameters; - -@property (nonatomic) FBRequest *fbRequest; -@property (weak, nonatomic) FBRequestConnection *requestConnection; - @end @implementation JFFFacebookGeneralRequestLoader +{ + FBRequestConnection *_requestConnection; +@public + FBSession *_facebookSession; + NSString *_graphPath; + NSString *_HTTPMethod; + NSDictionary *_parameters; +} - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { - self.handler = handler; + handler = [handler copy]; - self.fbRequest = [FBRequest requestForGraphPath:self.graphPath]; - self.fbRequest.session = self.facebookSession; - self.fbRequest.HTTPMethod = self.HTTPMethod; - [self.fbRequest.parameters addEntriesFromDictionary:self.parameters]; + FBRequest *fbRequest = [FBRequest requestForGraphPath:_graphPath]; + fbRequest.session = _facebookSession; + fbRequest.HTTPMethod = _HTTPMethod; + [fbRequest.parameters addEntriesFromDictionary:_parameters]; - self.requestConnection = [self.fbRequest startWithCompletionHandler:^(FBRequestConnection *connection, - FBGraphObject *graphObject, - NSError *error) { + _requestConnection = [fbRequest startWithCompletionHandler:^(FBRequestConnection *connection, + FBGraphObject *graphObject, + NSError *error) { - if ( self.handler ) - self.handler([graphObject copy], error); + if (handler) + handler([graphObject copy], error); }]; } - (void)cancel:(BOOL)canceled { - [self.requestConnection cancel]; + [_requestConnection cancel]; } @end @@ -51,10 +49,10 @@ JFFAsyncOperation jffGenericFacebookGraphRequestLoader(FBSession *facebook, { JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { JFFFacebookGeneralRequestLoader *object = [JFFFacebookGeneralRequestLoader new]; - object.facebookSession = facebook; - object.graphPath = graphPath; - object.HTTPMethod = HTTPMethod; - object.parameters = parameters; + object->_facebookSession = facebook; + object->_graphPath = graphPath; + object->_HTTPMethod = HTTPMethod; + object->_parameters = parameters; return object; }; diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookDialog.h b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookDialog.h new file mode 100644 index 0000000..09455e5 --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookDialog.h @@ -0,0 +1,18 @@ +#import + +#import + +@class FBSession; + +#ifdef __cplusplus +extern "C" { +#endif + + JFFAsyncOperation jffRequestFacebookDialog(FBSession *session, + NSDictionary *parameters, + NSString *message, + NSString *title); + +#ifdef __cplusplus +} /* closing brace for extern "C" */ +#endif diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookDialog.m b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookDialog.m new file mode 100644 index 0000000..a66497e --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookDialog.m @@ -0,0 +1,66 @@ +#import "JFFAsyncFacebookDialog.h" + +#import + +@interface JFFAsyncFacebookDialog : NSObject +@end + +@implementation JFFAsyncFacebookDialog +{ +@public + FBSession *_session; + NSDictionary *_parameters; + NSString *_message; + NSString *_title; +} + +- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler + cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler + progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress +{ + FBWebDialogHandler fbHandler = ^(FBWebDialogResult result, + NSURL *resultURL, + NSError *error) { + + if (result == FBWebDialogResultDialogNotCompleted) { + + if (cancelHandler) + cancelHandler(YES); + } + + if (handler) { + + handler(error?nil:@YES, nil); + } + }; + + [FBWebDialogs presentRequestsDialogModallyWithSession:_session + message:_message + title:_title + parameters:_parameters + handler:fbHandler]; +} + +@end + +JFFAsyncOperation jffRequestFacebookDialog(FBSession *session, + NSDictionary *parameters, + NSString *message, + NSString *title) +{ + NSCParameterAssert(session); + + JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + + JFFAsyncFacebookDialog *dialog = [JFFAsyncFacebookDialog new]; + + dialog->_session = session; + dialog->_parameters = parameters; + dialog->_message = message; + dialog->_title = title; + + return dialog; + }; + + return buildAsyncOperationWithAdapterFactory(factory); +} diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogin.m b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogin.m index 29ce1e5..8929d4f 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogin.m +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogin.m @@ -3,20 +3,19 @@ #import "JFFFacebookSDKErrors.h" #import "JFFFacebookAuthorizeError.h" -#import - #import #import @interface JFFAsyncFacebookLogin : NSObject - -@property (nonatomic) FBSession *facebookSession; -@property (nonatomic) NSArray *permissions; - @end @implementation JFFAsyncFacebookLogin +{ +@public + FBSession *_facebookSession; + NSArray *_permissions; +} #pragma mark - JFFAsyncOperationInterface @@ -26,45 +25,61 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler { handler = [handler copy]; - if (self.facebookSession.isOpen) { - [self handleLoginWithSession:self.facebookSession - error:nil - status:self.facebookSession.state - handler:handler]; - return; + NSMutableSet *requstPermissions = [[NSMutableSet alloc] initWithArray:_permissions]; + NSSet *currPermissions = [[NSSet alloc] initWithArray:_facebookSession.permissions]; + + if (_facebookSession.isOpen) { + + BOOL hasAllPermissions = [requstPermissions isSubsetOfSet:currPermissions]; + + if (hasAllPermissions) { + + [self handleLoginWithSession:_facebookSession + error:nil + status:_facebookSession.state + handler:handler]; + return; + } } - //For debug - // ACAccountStore *accountStore = [ACAccountStore new]; - // - // ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; - // - // NSDictionary *options = - // @{ACFacebookAppIdKey : [[FBSession activeSession] appID], - // ACFacebookPermissionsKey: [[FBSession activeSession] permissions], - // ACFacebookAudienceKey : ACFacebookAudienceOnlyMe}; - // - // [accountStore requestAccessToAccountsWithType:accountType options:options completion: - // ^(BOOL granted, NSError *error) - // { - // - // }]; + [requstPermissions unionSet:currPermissions]; + + //exclude publich pemissions + { + static NSSet *publishPermissions; + + // "share_item", + // "photo_upload", + // "video_upload", + // "installed", + // "status_update", + // "email", + // "user_birthday", + // "create_note", + if (!publishPermissions) { + + publishPermissions = [[NSSet alloc] initWithArray:@[@"publish_actions", @"publish_stream"]]; + } + + [requstPermissions minusSet:publishPermissions]; + } + + __block BOOL finished = NO; + __weak JFFAsyncFacebookLogin *weakSelf = self; FBSessionStateHandler fbHandler = ^(FBSession *session, FBSessionState status, NSError *error) { + if (finished) + return; + + finished = YES; + NSError *libError = error?[JFFFacebookSDKErrors newFacebookSDKErrorsWithNativeError:error]:nil; - JFFScheduler *scheduler = [JFFScheduler sharedByThreadScheduler]; - [scheduler addBlock:^(JFFCancelScheduledBlock cancel) { - - cancel(); - [self handleLoginWithSession:session error:libError status:status handler:handler]; - } duration:0.2]; + [weakSelf handleLoginWithSession:session error:libError status:status handler:handler]; }; - //[[FBSession activeSession] openWithBehavior:(FBSessionLoginBehaviorUseSystemAccountIfPresent) - // completionHandler:fbHandler]; - [FBSession openActiveSessionWithReadPermissions:self.permissions + [FBSession openActiveSessionWithReadPermissions:[requstPermissions allObjects] allowLoginUI:YES completionHandler:fbHandler]; } @@ -74,19 +89,15 @@ - (void)handleLoginWithSession:(FBSession *)session status:(FBSessionState)status handler:(JFFAsyncOperationInterfaceResultHandler)handler { - if (!error && status != FBSessionStateOpen && status != FBSessionStateOpenTokenExtended) { + if (!error && (!session.isOpen || !session.accessTokenData.accessToken)) { error = [JFFFacebookAuthorizeError new]; } if (handler) { - handler(error?nil:session.accessTokenData.accessToken, error); + handler(error?nil:session, error); } } -- (void)cancel:(BOOL)canceled -{ -} - @end JFFAsyncOperation jffFacebookLogin(FBSession *facebook, NSArray *permissions) @@ -95,8 +106,8 @@ JFFAsyncOperation jffFacebookLogin(FBSession *facebook, NSArray *permissions) JFFAsyncFacebookLogin *object = [JFFAsyncFacebookLogin new]; - object.facebookSession = facebook; - object.permissions = permissions; + object->_facebookSession = facebook; + object->_permissions = permissions; return object; }; diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLoginWithPublishPermissions.h b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLoginWithPublishPermissions.h new file mode 100644 index 0000000..a1dd167 --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLoginWithPublishPermissions.h @@ -0,0 +1,15 @@ +#import + +#import + +@class FBSession; + +#ifdef __cplusplus +extern "C" { +#endif + + JFFAsyncOperation jffFacebookLoginWithPublishPermissions(FBSession *facebook, NSArray *permissions); + +#ifdef __cplusplus +} /* closing brace for extern "C" */ +#endif diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLoginWithPublishPermissions.m b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLoginWithPublishPermissions.m new file mode 100644 index 0000000..76e8d50 --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLoginWithPublishPermissions.m @@ -0,0 +1,107 @@ +#import "JFFAsyncFacebookLoginWithPublishPermissions.h" + +#import "JFFFacebookSDKErrors.h" +#import "JFFFacebookAuthorizeError.h" + +#import + +#import + +#import + +@interface JFFAsyncFacebookLoginWithPublishPermissions : NSObject +@end + +@implementation JFFAsyncFacebookLoginWithPublishPermissions +{ +@public + FBSession *_facebookSession; + NSArray *_permissions; +} + +#pragma mark - JFFAsyncOperationInterface + +- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler + cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler + progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress +{ + handler = [handler copy]; + + NSMutableSet *requstPermissions = [[NSMutableSet alloc] initWithArray:_permissions]; + NSSet *currPermissions = [[NSSet alloc] initWithArray:_facebookSession.permissions]; + + if (_facebookSession.isOpen) { + + BOOL hasAllPermissions = [requstPermissions isSubsetOfSet:currPermissions]; + + if (hasAllPermissions) { + + [self handleLoginWithSession:_facebookSession + error:nil + status:_facebookSession.state + handler:handler]; + return; + } + } + + __block BOOL finished = NO; + __weak JFFAsyncFacebookLoginWithPublishPermissions *weakSelf = self; + + FBSessionStateHandler fbHandler = ^(FBSession *session, FBSessionState status, NSError *error) { + + if (finished) + return; + + finished = YES; + + NSError *libError = error?[JFFFacebookSDKErrors newFacebookSDKErrorsWithNativeError:error]:nil; + + [weakSelf handleLoginWithSession:session error:libError status:status handler:handler]; + }; + + [FBSession openActiveSessionWithPublishPermissions:[requstPermissions allObjects] + defaultAudience:(FBSessionDefaultAudienceEveryone) + allowLoginUI:YES + completionHandler:fbHandler]; +} + +- (void)handleLoginWithSession:(FBSession *)session + error:(NSError *)error + status:(FBSessionState)status + handler:(JFFAsyncOperationInterfaceResultHandler)handler +{ + if (!error && !session.isOpen) { + error = [JFFFacebookAuthorizeError new]; + } + + if (handler) { + handler(error?nil:session, error); + } +} + +@end + +JFFAsyncOperation jffFacebookLoginWithPublishPermissions(FBSession *facebook, NSArray *permissions) +{ + JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + + JFFAsyncFacebookLoginWithPublishPermissions *object = [JFFAsyncFacebookLoginWithPublishPermissions new]; + + object->_facebookSession = facebook; + object->_permissions = permissions; + + return object; + }; + + JFFAsyncOperation loader = buildAsyncOperationWithAdapterFactory(factory); + + NSDictionary *mergeParams = + @{ + @"method" : @"jffFacebookLoginWithPublishPermissions", + @"permissions" : [[NSSet alloc] initWithArray:permissions], + @"class" : NSStringFromClass([JFFAsyncFacebookLoginWithPublishPermissions class]) + }; + + return [JFFAsyncFacebookLoginWithPublishPermissions asyncOperationMergeLoaders:loader withArgument:mergeParams]; +} + diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.h b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.h index 06e2185..3e2eb08 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.h +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.h @@ -8,7 +8,7 @@ extern "C" { #endif - JFFAsyncOperation jffFacebookLogout(FBSession *facebook); + JFFAsyncOperation jffFacebookLogout(FBSession *facebook, BOOL renewSystemAuthorization); #ifdef __cplusplus } /* closing brace for extern "C" */ diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.m b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.m index f41f2cc..7bc6a99 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.m +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFAsyncFacebookLogout.m @@ -2,50 +2,63 @@ #import -@interface JFFAsyncFacebookLogout : NSObject - -@property (nonatomic) FBSession *facebookSession; -@property (nonatomic, copy) JFFAsyncOperationInterfaceResultHandler handler; +#import +@interface JFFAsyncFacebookLogout : NSObject @end - @implementation JFFAsyncFacebookLogout { JFFAsyncOperationInterfaceResultHandler _handler; +@public + FBSession *_session; + BOOL _renewSystemAuthorization; } #pragma mark - JFFAsyncOperationInterface -- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler - cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler - progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress +- (void)logout { - [self.facebookSession closeAndClearTokenInformation]; + [_session closeAndClearTokenInformation]; - _handler = [handler copy]; //TODO try to fix smart without delay each time [self performSelector:@selector(notifyFinished) withObject:nil afterDelay:1.]; } -- (void)notifyFinished +- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler + cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler + progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { - _handler(@YES, nil); + _handler = [handler copy]; + + if (_renewSystemAuthorization) { + + [FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) { + + [self logout]; + }]; + + return; + } + + [self logout]; } -- (void)cancel:(BOOL)canceled +- (void)notifyFinished { + _handler(@YES, nil); } @end -//TODO check if used -JFFAsyncOperation jffFacebookLogout(FBSession *facebook) +JFFAsyncOperation jffFacebookLogout(FBSession *session, BOOL renewSystemAuthorization) { JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { JFFAsyncFacebookLogout *object = [JFFAsyncFacebookLogout new]; - object.facebookSession = facebook; + object->_session = session; + object->_renewSystemAuthorization = renewSystemAuthorization; + return object; }; diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.h b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.h index f40a47a..8956f97 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.h +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.h @@ -2,11 +2,13 @@ #import +@class FBSession; + #ifdef __cplusplus extern "C" { #endif - JFFAsyncOperation jffFacebookPublishAccessRequest(NSArray *permissions); + JFFAsyncOperation jffFacebookPublishAccessRequest(FBSession *session, NSArray *permissions); #ifdef __cplusplus } /* closing brace for extern "C" */ diff --git a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.m b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.m index 9b2819e..ca0992c 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.m +++ b/lib/JFFSocial/JFFSocial/Facebook/AsyncAdapters/JFFFacebookPublishAccessRequestAdapter.m @@ -1,20 +1,21 @@ #import "JFFFacebookPublishAccessRequestAdapter.h" +#import "JFFFacebookSDKErrors.h" #import "JFFFacebookRequestPublishingAccessError.h" -#import - #import #import @interface JFFFacebookPublishAccessRequestAdapter : NSObject - -@property (nonatomic) NSArray *permissions; - @end @implementation JFFFacebookPublishAccessRequestAdapter +{ +@public + FBSession *_session; + NSArray *_permissions; +} #pragma mark - JFFAsyncOperationInterface @@ -24,71 +25,83 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler { handler = [handler copy]; - // if ([FBSession activeSession].isOpen) { - //TODO pass session, do not use [FBSession activeSession] - - FBSessionRequestPermissionResultHandler fbHandler = ^(FBSession *session, NSError *error) { - - NSError *libError = error?[JFFFacebookSDKErrors newFacebookSDKErrorsWithNativeError:error]:nil; - - [self handleLoginWithSession:[FBSession activeSession] - error:libError - handler:handler]; - }; - - [[FBSession activeSession] requestNewPublishPermissions:self.permissions - defaultAudience:(FBSessionDefaultAudienceFriends) - completionHandler:fbHandler]; + BOOL hasAllPermissions = [_permissions all:^BOOL(NSString *permission) { + + return [_session.permissions containsObject:permission]; + }]; + if (hasAllPermissions && _session.isOpen) { + + [self handleLoginWithSession:_session + error:nil + handler:handler]; + return; + } - // return; - // } - // + FBSessionDefaultAudience defaultAudience = FBSessionDefaultAudienceEveryone; - // ACAccountStore *accountStore = [ACAccountStore new]; - // - // ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; - // - // NSDictionary *options = - // @{ACFacebookAppIdKey : [[FBSession activeSession] appID], - // ACFacebookPermissionsKey: [[FBSession activeSession] permissions], - // ACFacebookAudienceKey : ACFacebookAudienceOnlyMe}; - // - // [accountStore requestAccessToAccountsWithType:accountType options:options completion: - // ^(BOOL granted, NSError *error) - // { - // - // }]; + if (_session.isOpen) { + FBSessionRequestPermissionResultHandler fbHandler = ^(FBSession *session, NSError *error) { + + NSError *libError = error?[JFFFacebookSDKErrors newFacebookSDKErrorsWithNativeError:error]:nil; + + [self handleLoginWithSession:session + error:libError + handler:handler]; + }; + + [_session requestNewPublishPermissions:_permissions + defaultAudience:(defaultAudience) + completionHandler:fbHandler]; + + return; + } - // TODO: Request access for publishing separate from reading + __block BOOL finished = NO; + __weak JFFFacebookPublishAccessRequestAdapter *weakSelf = self; + FBSessionStateHandler fbHandler = ^(FBSession *session, FBSessionState status, NSError *error) { + + if (finished) + return; + + finished = YES; + + NSError *libError = error?[JFFFacebookSDKErrors newFacebookSDKErrorsWithNativeError:error]:nil; + + [weakSelf handleLoginWithSession:session + error:libError + handler:handler]; + }; + [FBSession openActiveSessionWithPublishPermissions:_permissions + defaultAudience:(defaultAudience) + allowLoginUI:YES + completionHandler:fbHandler]; } - (void)handleLoginWithSession:(FBSession *)session error:(NSError *)error handler:(JFFAsyncOperationInterfaceResultHandler)handler { - if (session.state != FBSessionStateOpen && session.state != FBSessionStateOpenTokenExtended) { + if (!error && !session.isOpen) { error = [JFFFacebookRequestPublishingAccessError new]; } if (handler) { - handler(error?nil:session.accessTokenData.accessToken, error); + handler(error?nil:session, error); } } -- (void)cancel:(BOOL)canceled -{ -} - @end -JFFAsyncOperation jffFacebookPublishAccessRequest(NSArray *permissions) +JFFAsyncOperation jffFacebookPublishAccessRequest(FBSession *session, NSArray *permissions) { JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + JFFFacebookPublishAccessRequestAdapter *object = [JFFFacebookPublishAccessRequestAdapter new]; - object.permissions = permissions; + object->_session = session; + object->_permissions = permissions; return object; }; @@ -98,8 +111,8 @@ JFFAsyncOperation jffFacebookPublishAccessRequest(NSArray *permissions) NSDictionary *mergeParams = @{ @"method" : @"jffFacebookPublishAccessRequest", - @"permissions" : permissions, - @"class" : @"JFFFacebookPublishAccessRequestAdapter" + @"permissions" : [[NSSet alloc] initWithArray:permissions], + @"class" : NSStringFromClass([JFFFacebookPublishAccessRequestAdapter class]) }; return [JFFFacebookPublishAccessRequestAdapter asyncOperationMergeLoaders:loader withArgument:mergeParams]; diff --git a/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.h b/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.h index 5d222ff..44cc9aa 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.h +++ b/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.h @@ -2,6 +2,6 @@ @interface JFFSocialFacebookUser (Parser) -+ (id)newSocialFacebookUserWithJsonObject:(NSDictionary *)jsonObject error:(NSError **)outError; ++ (instancetype)newSocialFacebookUserWithJsonObject:(NSDictionary *)jsonObject error:(NSError **)outError; @end diff --git a/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.m b/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.m index 045d0a0..43a0d8a 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Details/JFFSocialFacebookUser+Parser.m @@ -4,33 +4,30 @@ @implementation JFFSocialFacebookUser (Parser) -+ (id)newSocialFacebookUserWithJsonObject:(NSDictionary *)jsonObject error:(NSError **)outError ++ (instancetype)newSocialFacebookUserWithJsonObject:(NSDictionary *)jsonObject + error:(NSError **)outError { - id jsonPattern = - @{ - @"id" : [NSString class], - @"name" : [NSString class], - @"gender" : [NSString class], - }; - - if (![JFFJsonObjectValidator validateJsonObject:jsonObject - withJsonPattern:jsonPattern - error:outError]) { - - return nil; - } - JFFSocialFacebookUser *result = [self new]; if (result) { - result.facebookID = jsonObject[@"id"]; - - result.name = jsonObject[@"name" ]; - result.gender = jsonObject[@"gender"]; + result.facebookID = jsonObject[@"id" ]; + result.email = jsonObject[@"email" ]?:@""; + result.name = jsonObject[@"name" ]?:@""; + result.gender = jsonObject[@"gender"]?:@""; + result.biography = jsonObject[@"bio" ]?:@""; - result.avatarURL = [jsonObject[@"pic_big" ] toURL]; - result.smallAvatarURL = [jsonObject[@"pic_small"] toURL]; + NSString *birthdayStr = jsonObject[@"birthday"]; + if (birthdayStr) { + + NSDateFormatter *formatter = [NSDateFormatter new]; + + formatter.dateFormat = @"MM/dd/yyyy"; + formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; + formatter.timeZone = [[NSTimeZone alloc] initWithName:@"GMT"]; + + result.birthday = [formatter dateFromString:birthdayStr]; + } } return result; diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookAuthorizeError.m b/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookAuthorizeError.m index 4fb6551..5077705 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookAuthorizeError.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookAuthorizeError.m @@ -2,7 +2,7 @@ @implementation JFFFacebookAuthorizeError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FACEBOOK_AUTHORIZATION_FAILED", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookError.h b/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookError.h index f915834..3bc6541 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookError.h +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookError.h @@ -1,4 +1,4 @@ -#import +#import #import diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookRequestPublishingAccessError.m b/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookRequestPublishingAccessError.m index 04e205e..7a68d6b 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookRequestPublishingAccessError.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/JFFFacebookRequestPublishingAccessError.m @@ -2,7 +2,7 @@ @implementation JFFFacebookRequestPublishingAccessError -- (id)init +- (instancetype)init { return [super initWithDescription:NSLocalizedString(@"FACEBOOK_GET_PUBLISH_PERMISSON_ERROR", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.h b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.h index 73865a2..4d9f9f0 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.h +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.h @@ -3,5 +3,4 @@ #import @interface JFFFacebookLoginFailedAccessForbidden : JFFFacebookSDKErrors - @end diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.m b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.m index c90ed29..efc974c 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedAccessForbidden.m @@ -6,7 +6,7 @@ @implementation JFFFacebookLoginFailedAccessForbidden -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FACEBOOK_LOGIN_ERROR_ACCESS_FORBIDDEN", nil)]; } @@ -43,9 +43,21 @@ + (BOOL)isMineFacebookNativeError_whenInvalidSettings:(NSError *)nativeError && [[subError domain] isEqualToString:ACErrorDomain]; } ++ (BOOL)isMineFacebookNativeError_whenForbidWebLogin:(NSError *)nativeError +{ + NSInteger code = [nativeError code]; + NSDictionary *userInfo = [nativeError userInfo]; + + return code == FBErrorLoginFailedOrCancelled + && [userInfo[FBErrorLoginFailedReason] isEqualToString:FBErrorLoginFailedReasonUserCancelledValue] + && [[nativeError domain] isEqualToString:FacebookSDKDomain]; +} + + (BOOL)isMineFacebookNativeError:(NSError *)nativeError { - BOOL result = [self isMineFacebookNativeError_whenInvalidSettings:nativeError]; + BOOL result = + [self isMineFacebookNativeError_whenInvalidSettings:nativeError] + || [self isMineFacebookNativeError_whenForbidWebLogin:nativeError]; if (result) return YES; diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedCanceledError.m b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedCanceledError.m index 2ad7cc0..699ec74 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedCanceledError.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedCanceledError.m @@ -4,7 +4,7 @@ @implementation JFFFacebookLoginFailedCanceledError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FACEBOOK_LOGIN_ERROR_CANCELED", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedPasswordWasChanged.m b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedPasswordWasChanged.m index 5058765..070821f 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedPasswordWasChanged.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookLoginFailedPasswordWasChanged.m @@ -6,13 +6,14 @@ @implementation JFFFacebookLoginFailedPasswordWasChanged -- (id)init +- (instancetype)init { - return [self initWithDescription:NSLocalizedString(@"FACEBOOK_LOGIN_ERROR_PASSWORD_WAS_CHANGED", nil)]; + return [self initWithDescription:NSLocalizedString(@"FACEBOOK_LOGIN_ERROR_USER_DENIED_PERMISSION", nil)]; } - (void)writeErrorWithJFFLogger { + [self writeErrorToNSLog]; } + (BOOL)isMineFacebookNativeError:(NSError *)nativeError diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.h b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.h index a99e9aa..deadbc9 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.h +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.h @@ -1,4 +1,4 @@ -#import +#import #import @@ -6,6 +6,6 @@ @property (nonatomic) NSError *nativeError; -+ (id)newFacebookSDKErrorsWithNativeError:(NSError *)nativeError; ++ (instancetype)newFacebookSDKErrorsWithNativeError:(NSError *)nativeError; @end diff --git a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.m b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.m index ff8b2cc..0cb7929 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Errors/SDKErrors/JFFFacebookSDKErrors.m @@ -13,7 +13,7 @@ + (NSString *)jffErrorsDomain return @"com.just_for_fun.facebook.sdk.errors.library"; } -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FACEBOOK_GENERAL_ERROR", nil)]; } @@ -23,7 +23,7 @@ + (BOOL)isMineFacebookNativeError:(NSError *)error return NO; } -+ (id)newFacebookSDKErrorsWithNativeError:(NSError *)nativeError ++ (instancetype)newFacebookSDKErrorsWithNativeError:(NSError *)nativeError { Class class = Nil; @@ -55,7 +55,7 @@ + (id)newFacebookSDKErrorsWithNativeError:(NSError *)nativeError return error; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFFacebookSDKErrors *copy = [super copyWithZone:zone]; @@ -66,9 +66,12 @@ - (id)copyWithZone:(NSZone *)zone return copy; } -- (void)writeErrorWithJFFLogger +- (NSString *)errorLogDescription { - [JFFLogger logErrorWithFormat:@"%@ nativeError:%@", [self localizedDescription], _nativeError]; + return [[NSString alloc] initWithFormat:@"%@ : %@ nativeError:%@", + [self class], + [self localizedDescription], + _nativeError]; } @end diff --git a/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.h b/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.h index 3b0c7a3..592c506 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.h +++ b/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.h @@ -2,30 +2,43 @@ #import -typedef void(^JFFFacebookDidLoginCallback)(NSString *login); -typedef void(^JFFFacebookDidLogoutCallback)(NSString *login); - @class FBSession; @interface JFFSocialFacebook : NSObject -+ (FBSession *)facebookSession; ++ (BOOL)isActiveFacebookSession; + ++ (JFFAsyncOperation)logoutLoaderWithRenewSystemAuthorization:(BOOL)renewSystemAuthorization; + ++ (JFFAsyncOperation)authTokenLoader; ++ (JFFAsyncOperation)authTokenLoaderWithPermissions:(NSArray *)permissions; ++ (JFFAsyncOperation)authFacebookSessionLoader; ++ (JFFAsyncOperation)authFacebookSessionLoaderWithPermissions:(NSArray *)permissions; -+ (JFFAsyncOperation)logoutLoader; -+ (JFFAsyncOperation)authLoader; ++ (JFFAsyncOperation)authFacebookSessionWithPublishPermissions:(NSArray *)permissions; + ++ (JFFAsyncOperation)publishStreamAccessSessionLoader; + (JFFAsyncOperation)userInfoLoader; -#pragma mark callbacks ++ (JFFAsyncOperation)userInfoLoaderWithFields:(NSArray *)fields + sessionLoader:(JFFAsyncOperation)sessionLoader; -+ (void)setDidLoginCallback:(JFFFacebookDidLoginCallback)didLoginCallback; -+ (void)setDidLogoutCallback:(JFFFacebookDidLogoutCallback)didLogoutCallback; ++ (JFFAsyncOperation)requestFacebookDialogWithParameters:(NSDictionary *)parameters + message:(NSString *)message + title:(NSString *)title; -//TODO hide this methods -+ (JFFAsyncOperation)graphLoaderWithPath:(NSString *)graphPath; +#pragma mark callbacks + ++ (JFFAsyncOperation)graphLoaderWithPath:(NSString *)graphPath + session:(FBSession *)session; + (JFFAsyncOperation)graphLoaderWithPath:(NSString *)graphPath httpMethod:(NSString *)HTTPMethod - parameters:(NSDictionary *)parameters; + parameters:(NSDictionary *)parameters + session:(FBSession *)session; + ++ (JFFAsyncOperation)postImage:(UIImage *)photo + withMessage:(NSString *)message; @end diff --git a/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.m b/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.m index a87d611..c601d11 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.m +++ b/lib/JFFSocial/JFFSocial/Facebook/JFFSocialFacebook.m @@ -3,39 +3,20 @@ #import "JFFAsyncFacebook.h" #import "JFFAsyncFacebookLogin.h" #import "JFFAsyncFacebookLogout.h" +#import "JFFAsyncFacebookDialog.h" +#import "JFFAsyncFacebookLoginWithPublishPermissions.h" #import "JFFSocialFacebookUser+Parser.h" -#import +#import "JFFFacebookPublishAccessRequestAdapter.h" -static JFFFacebookDidLoginCallback globalDidLoginCallback; -static JFFFacebookDidLogoutCallback globalDidLogoutCallback; +#import @implementation JFFSocialFacebook + (NSArray *)authPermissions { - NSArray *result = @[@"email", - @"user_birthday", - @"user_photos", - @"friends_location", - @"friends_photos", - @"friends_about_me", - @"user_about_me", - @"user_photos", - @"read_friendlists", - @"user_relationships", - /* - @"user_checkins", - @"friends_checkins", - - @"user_likes", - @"friends_likes", - - @"user_events", - @"friends_events" - */ - ]; + NSArray *result = @[@"email", @"user_birthday"]; return result; } @@ -44,59 +25,153 @@ + (FBSession *)facebookSession { FBSession *facebookSession = [FBSession activeSession]; - if (!facebookSession || ![facebookSession isOpen]) { + if (!facebookSession || !facebookSession.isOpen) { facebookSession = [[FBSession alloc] initWithPermissions:[self authPermissions]]; [FBSession setActiveSession:facebookSession]; } return facebookSession; } -+ (JFFAsyncOperation)logoutLoader ++ (void)setFacebookSession:(FBSession *)facebookSession { - FBSession *facebookSession = [FBSession activeSession]; - if (![facebookSession isOpen]) { - return asyncOperationWithResult([NSNull new]); - } - - JFFAsyncOperation logoutLoader = jffFacebookLogout(facebookSession); - logoutLoader = asyncOperationWithFinishCallbackBlock(logoutLoader, ^(id result, NSError *error) { + [FBSession setActiveSession:facebookSession]; +} + ++ (BOOL)isActiveFacebookSession +{ + return [[self facebookSession] isOpen]; +} + ++ (JFFAsyncOperation)logoutLoaderWithRenewSystemAuthorization:(BOOL)renewSystemAuthorization +{ + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { - if (result && globalDidLogoutCallback) - globalDidLogoutCallback(nil); - }); - - return logoutLoader; + FBSession *session = [FBSession activeSession]; + + JFFAsyncOperation loader = session + ?jffFacebookLogout(session, renewSystemAuthorization) + :asyncOperationWithResult([NSNull new]); + + doneCallback = [doneCallback copy]; + JFFDidFinishAsyncOperationHandler doneCallbackWrapper = ^(id result, NSError *error) { + + if (result) + [self setFacebookSession:nil]; + + if (doneCallback) + doneCallback(result, error); + }; + + return loader(progressCallback, + cancelCallback, + doneCallbackWrapper); + }; } -+ (JFFAsyncOperation)authLoader ++ (JFFAsyncOperation)authFacebookSessionLoaderWithPermissions:(NSArray *)permissions { - JFFAsyncOperation authLoader = jffFacebookLogin([self facebookSession], [self authPermissions]); + JFFAsyncOperation loader = ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + //TODO split perrmissions, first login for "email" "birthday" + //tthen for other ones + + FBSession *session = [self facebookSession]; + + NSMutableSet *currPermissions = [[NSMutableSet alloc] initWithArray:session.permissions]; + [currPermissions unionSet:[[NSSet alloc] initWithArray:permissions]]; + + JFFAsyncOperation loader = jffFacebookLogin(session, permissions); + + doneCallback = [doneCallback copy]; + JFFDidFinishAsyncOperationHandler doneCallbackWrapper = ^(FBSession *session, NSError *error) { + + if (session) + [self setFacebookSession:session]; + + if (doneCallback) + doneCallback(session, error); + }; + + return loader(progressCallback, cancelCallback, doneCallbackWrapper); + }; - authLoader = asyncOperationWithFinishCallbackBlock(authLoader, ^(id result, NSError *error) { + id mergeObject = + @{ + @"methodName" : NSStringFromSelector(_cmd), + @"permissions" : [[NSSet alloc] initWithArray:permissions] + }; + return [self asyncOperationMergeLoaders:loader withArgument:mergeObject]; +} + ++ (JFFAsyncOperation)authFacebookSessionWithPublishPermissions:(NSArray *)permissions +{ + JFFAsyncOperation loader = ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { - if (result && globalDidLoginCallback) { - globalDidLoginCallback(nil); - } - }); + FBSession *session = [self facebookSession]; + + NSMutableSet *currPermissions = [[NSMutableSet alloc] initWithArray:session.permissions]; + [currPermissions unionSet:[[NSSet alloc] initWithArray:permissions]]; + + JFFAsyncOperation loader = jffFacebookLoginWithPublishPermissions(session, [currPermissions allObjects]); + + doneCallback = [doneCallback copy]; + JFFDidFinishAsyncOperationHandler doneCallbackWrapper = ^(FBSession *session, NSError *error) { + + if (session) + [self setFacebookSession:session]; + + if (doneCallback) + doneCallback(session, error); + }; + + return loader(progressCallback, cancelCallback, doneCallbackWrapper); + }; id mergeObject = @{ - @"methodName" : NSStringFromSelector(_cmd), - @"className" : [self description] + @"methodName" : NSStringFromSelector(_cmd), + @"permissions" : [[NSSet alloc] initWithArray:permissions] }; - return [self asyncOperationMergeLoaders:authLoader withArgument:mergeObject]; + return [self asyncOperationMergeLoaders:loader withArgument:mergeObject]; } -#pragma mark callbacks ++ (JFFAsyncOperation)authFacebookSessionLoader +{ + return [self authFacebookSessionLoaderWithPermissions:[self authPermissions]]; +} + ++ (JFFAsyncOperation)publishStreamAccessSessionLoader +{ + JFFAsyncOperation authLoader = [self authFacebookSessionLoader]; + + JFFAsyncOperationBinder binder = ^JFFAsyncOperation(FBSession *session) { + + NSArray *permissions = @[@"publish_stream", @"user_birthday", @"email"]; + return jffFacebookPublishAccessRequest(session, permissions); + }; + + return bindSequenceOfAsyncOperations(authLoader, binder, nil); +} -+ (void)setDidLoginCallback:(JFFFacebookDidLoginCallback)didLoginCallback ++ (JFFAsyncOperation)authTokenLoader { - globalDidLoginCallback = [didLoginCallback copy]; + return [self authTokenLoaderWithPermissions:[self authPermissions]]; } -+ (void)setDidLogoutCallback:(JFFFacebookDidLogoutCallback)didLogoutCallback ++ (JFFAsyncOperation)authTokenLoaderWithPermissions:(NSArray *)permissions { - globalDidLogoutCallback = [didLogoutCallback copy]; + JFFAsyncOperationBinder binder = ^JFFAsyncOperation(FBSession *session) { + + return asyncOperationWithResult(session.accessTokenData.accessToken); + }; + + return bindSequenceOfAsyncOperations([self authFacebookSessionLoaderWithPermissions:permissions], binder, nil); } + (JFFAsyncOperationBinder)userParser @@ -112,34 +187,115 @@ + (JFFAsyncOperationBinder)userParser } + (JFFAsyncOperation)graphLoaderWithPath:(NSString *)graphPath + session:(FBSession *)session +{ + return [self graphLoaderWithPath:graphPath parameters:nil session:session]; +} + ++ (JFFAsyncOperation)graphLoaderWithPath:(NSString *)graphPath + parameters:(NSDictionary *)parameters + session:(FBSession *)session { - return [self graphLoaderWithPath:graphPath httpMethod:@"GET" parameters:nil]; + return [self graphLoaderWithPath:graphPath + httpMethod:@"GET" + parameters:parameters + session:session + ]; } + (JFFAsyncOperation)graphLoaderWithPath:(NSString *)graphPath httpMethod:(NSString *)HTTPMethod parameters:(NSDictionary *)parameters + session:(FBSession *)session { graphPath = [graphPath stringByReplacingOccurrencesOfString:@" " withString:@"+"]; - JFFAsyncOperation graphLoader = jffGenericFacebookGraphRequestLoader([JFFSocialFacebook facebookSession], graphPath, HTTPMethod, parameters); + JFFAsyncOperation graphLoader = jffGenericFacebookGraphRequestLoader(session, graphPath, HTTPMethod, parameters); return graphLoader; } -+ (JFFAsyncOperation)graphLoaderWithPath:(NSString *)graphPath andRequestTag:(NSString *)requestTag ++ (JFFAsyncOperation)userInfoLoader { - return [self graphLoaderWithPath:graphPath httpMethod:@"GET" parameters:nil]; + static NSArray *fields; + fields = fields?:@[@"id", @"email", @"name", @"gender", @"birthday", @"picture", @"bio"]; + + return [self userInfoLoaderWithFields:fields]; } -+ (JFFAsyncOperation)userInfoLoader ++ (JFFAsyncOperation)userInfoLoaderWithFields:(NSArray *)fields + sessionLoader:(JFFAsyncOperation)sessionLoader { - JFFAsyncOperation selfUserLoader = [self graphLoaderWithPath:@"me" andRequestTag:@"selfUser"]; + JFFAsyncOperationBinder userLoader = ^JFFAsyncOperation(FBSession *session) { + + NSDictionary *parameters; + + if ([fields count] > 0) { + + parameters = @{@"fields" : [fields componentsJoinedByString:@","]}; + } + + JFFAsyncOperation selfUserLoader = [self graphLoaderWithPath:@"me" + parameters:parameters + session:session]; + + JFFAsyncOperationBinder userParser = [self userParser]; + + JFFAsyncOperation userLoader = bindSequenceOfAsyncOperations(selfUserLoader, + userParser, + nil); + + return userLoader; + }; + + JFFAsyncOperation loader = bindSequenceOfAsyncOperations(sessionLoader, userLoader, nil); + + JFFAsyncOperation reloadSession = sequenceOfAsyncOperations([self logoutLoaderWithRenewSystemAuthorization:YES], sessionLoader, nil); + JFFAsyncOperation reloadUser = bindSequenceOfAsyncOperations(reloadSession, userLoader, nil); - JFFAsyncOperationBinder userParser = [self userParser]; + return trySequenceOfAsyncOperations(loader, reloadUser, nil); +} + ++ (JFFAsyncOperation)userInfoLoaderWithFields:(NSArray *)fields +{ + return [self userInfoLoaderWithFields:fields + sessionLoader:[self authFacebookSessionLoader]]; +} + ++ (JFFAsyncOperation)requestFacebookDialogWithParameters:(NSDictionary *)parameters + message:(NSString *)message + title:(NSString *)title +{ + JFFAsyncOperationBinder binder = ^JFFAsyncOperation(FBSession *session) { + + NSParameterAssert(session); + return jffRequestFacebookDialog([JFFSocialFacebook facebookSession], parameters, message, title); + }; - return bindSequenceOfAsyncOperations(selfUserLoader, - userParser, + return bindSequenceOfAsyncOperations([self authFacebookSessionLoader], + binder, nil); } ++ (JFFAsyncOperation)postImage:(UIImage *)image + withMessage:(NSString *)message +{ + NSDictionary *parameters = + @{ + @"message" : message?:@"", + @"image" : UIImageJPEGRepresentation(image, 1.) + }; + + JFFAsyncOperationBinder binder = ^(FBSession *session) { + + return [JFFSocialFacebook graphLoaderWithPath:@"me/photos" + httpMethod:@"POST" + parameters:parameters + session:session]; + }; + + JFFAsyncOperation getAccessLoader = [self publishStreamAccessSessionLoader]; + + return bindSequenceOfAsyncOperations(getAccessLoader, binder, nil); +} + @end diff --git a/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.h b/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.h index 2cd3888..c3208e0 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.h +++ b/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.h @@ -3,9 +3,14 @@ @interface JFFSocialFacebookUser : NSObject @property (nonatomic) NSString *facebookID; +@property (nonatomic) NSString *email; @property (nonatomic) NSString *name; @property (nonatomic) NSString *gender; -@property (nonatomic) NSURL *avatarURL; -@property (nonatomic) NSURL *smallAvatarURL; +@property (nonatomic) NSDate *birthday; +@property (nonatomic) NSString *biography; + +@property (nonatomic, readonly) NSURL *largeImageURL; + +- (NSURL *)imageURLForSize:(CGSize)size; @end diff --git a/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.m b/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.m index 3ea05d9..c9227f7 100644 --- a/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.m +++ b/lib/JFFSocial/JFFSocial/Facebook/Model/JFFSocialFacebookUser.m @@ -1,20 +1,82 @@ #import "JFFSocialFacebookUser.h" +//Image urls docs +// http://developers.facebook.com/docs/reference/api/using-pictures/ + @implementation JFFSocialFacebookUser +{ + NSURL *_largeImageURL; +} -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFSocialFacebookUser *copy = [[[self class] allocWithZone:zone] init]; if (copy) { - copy->_facebookID = [_facebookID copyWithZone:zone]; - copy->_name = [_name copyWithZone:zone]; - copy->_gender = [_gender copyWithZone:zone]; - copy->_avatarURL = [_avatarURL copyWithZone:zone]; - copy->_smallAvatarURL = [_smallAvatarURL copyWithZone:zone]; + copy->_facebookID = [_facebookID copyWithZone:zone]; + copy->_email = [_email copyWithZone:zone]; + copy->_name = [_name copyWithZone:zone]; + copy->_gender = [_gender copyWithZone:zone]; + copy->_birthday = [_birthday copyWithZone:zone]; + copy->_biography = [_biography copyWithZone:zone]; } return copy; } +- (BOOL)isEqual:(JFFSocialFacebookUser *)object +{ + if (self == object) + return YES; + + if (![object isKindOfClass:[self class]]) + return NO; + + return + [NSObject object:_facebookID isEqualTo:object->_facebookID] + && [NSObject object:_email isEqualTo:object->_email ] + && [NSObject object:_name isEqualTo:object->_name ] + && [NSObject object:_gender isEqualTo:object->_gender ] + && [NSObject object:_birthday isEqualTo:object->_birthday ] + && [NSObject object:_biography isEqualTo:object->_biography ] + ; +} + +- (NSUInteger)hash +{ + return + [_facebookID hash] + + [_email hash] + + [_name hash] + + [_gender hash] + + [_birthday hash] + + [_biography hash] + ; +} + +//http://graph.facebook.com/shaverm/picture?type=large +- (NSURL *)largeImageURL +{ + if (!_largeImageURL) { + + NSString *strURL = [[NSString alloc] initWithFormat:@"http://graph.facebook.com/%@/picture?type=large", _facebookID]; + _largeImageURL = [strURL toURL]; + } + + return _largeImageURL; +} + +// http://graph.facebook.com/shaverm/picture?width=40&height=60 +- (NSURL *)imageURLForSize:(CGSize)size +{ + NSString *strURL = [[NSString alloc] initWithFormat:@"http://graph.facebook.com/%@/picture?width=%lu&height=%lu", + _facebookID, + (unsigned long)roundf(size.width ), + (unsigned long)roundf(size.height) + ]; + NSURL *result = [strURL toURL]; + + return result; +} + @end diff --git a/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquaerLogin.m b/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquaerLogin.m index 5548eff..5d332c7 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquaerLogin.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquaerLogin.m @@ -1,9 +1,10 @@ #import "JFFAsyncFoursquaerLogin.h" -#import +#import #import "JFFFoursquareSessionStorage.h" +//TODO remove this class @interface JFFAsyncFoursquaerLogin : NSObject @property (copy, nonatomic) JFFCancelAsyncOperation cancelOperation; @@ -11,6 +12,9 @@ @interface JFFAsyncFoursquaerLogin : NSObject @end @implementation JFFAsyncFoursquaerLogin +{ + JFFCancelAsyncOperation _cancelOperation; +} - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler @@ -22,22 +26,21 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler NSURL *url = [[JFFFoursquareSessionStorage authURLString] toURL]; JFFAsyncOperation loader = [application asyncOperationWithApplicationURL:url]; - loader(nil, nil, ^(id result, NSError *error) { - handler (result, error); + _cancelOperation = loader(nil, nil, ^(id result, NSError *error) { + handler(result, error); }); } - (void)cancel:(BOOL)canceled { - if (self.cancelOperation) { - self.cancelOperation (canceled); + if (_cancelOperation) { + _cancelOperation(canceled); } } @end - -JFFAsyncOperation jffFoursquareLoginLoader () +JFFAsyncOperation jffFoursquareLoginLoader(void) { JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { return [JFFAsyncFoursquaerLogin new]; diff --git a/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.h b/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.h index 243db44..4ff8deb 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.h +++ b/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.h @@ -2,4 +2,4 @@ JFFAsyncOperation jffFoursquareRequestLoader (NSString *requestURL, NSString *httpMethod, NSString *accessToken, NSDictionary *parameters); -JFFAsyncOperation jffFoursquareRequestLoaderWithHTTPBody (NSString *requestURL, NSData *httpBody, NSString *accessToken); \ No newline at end of file +JFFAsyncOperation jffFoursquareRequestLoaderWithHTTPBody (NSString *requestURL, NSMutableData *httpBody, NSString *accessToken); diff --git a/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.m b/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.m index ec2a1c6..66795af 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/AsyncAdapters/JFFAsyncFoursquareRequest.m @@ -12,11 +12,11 @@ static JFFAsyncOperation generalFoursquareRequestLoader(NSString *requestURL, NSString *httpMethod, - NSData *httpBody, + NSMutableData *httpBody, NSString *accessToken, NSDictionary *parameters) { - assert(accessToken); + NSCParameterAssert(accessToken); JFFURLConnectionParams *params = [JFFURLConnectionParams new]; @@ -30,8 +30,8 @@ static JFFAsyncOperation generalFoursquareRequestLoader(NSString *requestURL, if ([httpMethod isEqualToString:@"POST"]) { params.url = [requestURL toURL]; if (httpBody) { - NSString *boundary = [NSString createUuid]; - params.httpBody = [httpBody dataForHTTPPostByAppendingParameters:fullParams boundary:boundary]; + NSString *boundary = [[NSUUID new] UUIDString]; + [httpBody appendHTTPParameters:fullParams boundary:boundary]; params.headers = @{ @"Content-Type" : @"multipart/form-data" }; } else { params.httpBody = [paramsString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; @@ -53,7 +53,7 @@ JFFAsyncOperation jffFoursquareRequestLoader (NSString *requestURL, NSString *ht parameters); } -JFFAsyncOperation jffFoursquareRequestLoaderWithHTTPBody (NSString *requestURL, NSData *httpBody, NSString *accessToken) +JFFAsyncOperation jffFoursquareRequestLoaderWithHTTPBody (NSString *requestURL, NSMutableData *httpBody, NSString *accessToken) { return generalFoursquareRequestLoader(requestURL, @"POST", diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthInvalidAccessTokenError.m b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthInvalidAccessTokenError.m index 55e6815..00a4e26 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthInvalidAccessTokenError.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthInvalidAccessTokenError.m @@ -2,7 +2,7 @@ @implementation JFFFoursquareAuthInvalidAccessTokenError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FOUTSQUARE_INVALID_ACCESS_TOKEN", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.h b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.h index 1d8746f..e8e04f9 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.h +++ b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.h @@ -1,13 +1,4 @@ -// -// JFFFoursquareAuthURLError.h -// JFFSocial -// -// Created by Maxim Malygin on 9/11/12. -// Copyright (c) 2012 EmbeddedSources. All rights reserved. -// - #import @interface JFFFoursquareAuthURLError : JFFSocialError - @end diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.m b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.m index a2f2275..4635656 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareAuthURLError.m @@ -2,7 +2,7 @@ @implementation JFFFoursquareAuthURLError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FOUTSQUARE_BAD_AUTH_URL", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareCachedAccessTokenError.m b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareCachedAccessTokenError.m index 4a7239d..390388c 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareCachedAccessTokenError.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareCachedAccessTokenError.m @@ -2,7 +2,7 @@ @implementation JFFFoursquareCachedAccessTokenError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FOUTSQUARE_CACHED_ACCESS_TOKEN_DOESNOT_EXIST", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareNotFoundUsersCheckinsError.m b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareNotFoundUsersCheckinsError.m index f87301e..5908de9 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareNotFoundUsersCheckinsError.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Errors/JFFFoursquareNotFoundUsersCheckinsError.m @@ -2,7 +2,7 @@ @implementation JFFFoursquareNotFoundUsersCheckinsError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FOUTSQUARE_USER_CHECKLIST_NOT_FOUND", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Errors/ParserErrors/JFFFoursquaerAPIInvalidResponseError.m b/lib/JFFSocial/JFFSocial/Foursquare/Errors/ParserErrors/JFFFoursquaerAPIInvalidResponseError.m index f7cd235..67db312 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Errors/ParserErrors/JFFFoursquaerAPIInvalidResponseError.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Errors/ParserErrors/JFFFoursquaerAPIInvalidResponseError.m @@ -2,7 +2,7 @@ @implementation JFFFoursquaerAPIInvalidresponseError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"FOUTSQUARE_INVALID_API_RESPONSE", nil)]; } diff --git a/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.h b/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.h index 3ae7aa9..2a1ab0b 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.h +++ b/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.h @@ -16,6 +16,6 @@ + (NSString *)redirectURI; -+ (id)shared; ++ (instancetype)shared; @end diff --git a/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.m b/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.m index 0cf53c6..2c087de 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/FoursquareSession/JFFFoursquareSessionStorage.m @@ -15,20 +15,17 @@ #define FOURSQUARE_CLIENT_ID @"2FYZ0AMUZV42YOTVLDINVQF21HHBVTVKWEH3A0QMGUEXW1ZC" #define FOURSQUARE_REDIRECT_URI @"fqWishdates://authorize" - @interface JFFFoursquareSessionStorage () @property (copy, nonatomic) JFFDidFinishAsyncOperationHandler authorizeHendler; @end - - @implementation JFFFoursquareSessionStorage #pragma mark - Singletone -+ (id)shared ++ (instancetype)shared { static JFFFoursquareSessionStorage *_sharedFoursquareSessionStorage = nil; static dispatch_once_t onceToken; @@ -72,7 +69,7 @@ - (void)openSessionWithHandler:(JFFDidFinishAsyncOperationHandler)hendler } else { - self.authorizeHendler (nil, [JFFFoursquareAuthURLError new]); + self.authorizeHendler(nil, [JFFFoursquareAuthURLError new]); } } diff --git a/lib/JFFSocial/JFFSocial/Foursquare/JFFSocialFoursquare.m b/lib/JFFSocial/JFFSocial/Foursquare/JFFSocialFoursquare.m index 70c15f4..e39769f 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/JFFSocialFoursquare.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/JFFSocialFoursquare.m @@ -146,7 +146,6 @@ + (JFFAsyncOperation)postComment:(NSString *)text toCheckin:(NSString *)checkinI NSDictionary *params = @{ @"text" : text }; - JFFAsyncOperationBinder postLoaderBinder = ^JFFAsyncOperation (NSString *accessToken) { return bindSequenceOfAsyncOperations(jffFoursquareRequestLoader(addPostURL, @"POST", accessToken, params), @@ -174,9 +173,15 @@ + (JFFAsyncOperation)addPostToCheckin:(NSString *)checkinID NSString *addPostURL = [NSString stringWithFormat:addPostURLFormat, checkinID]; NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:3]; - [params setObjectWithIgnoreNillValue:text forKey:@"text"]; - [params setObjectWithIgnoreNillValue:url forKey:@"url"]; - [params setObjectWithIgnoreNillValue:contentID forKey:@"contentId"]; + + if (text) + params[@"text"] = text; + + if (url) + params[@"url"] = url; + + if (contentID) + params[@"contentId"] = contentID; params = [params copy]; @@ -206,7 +211,7 @@ + (JFFAsyncOperationBinder)addPostResponseParser #pragma mark Add photo -//TODO: Post question to API developers + + (JFFAsyncOperation)addPhoto:(UIImage *)image toCheckin:(NSString *)checkinID text:(NSString *)text @@ -216,19 +221,29 @@ + (JFFAsyncOperation)addPhoto:(UIImage *)image static NSString *const addPhotoURL = @"https://api.foursquare.com/v2/photos/add"; NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:3]; - [params setObjectWithIgnoreNillValue:text forKey:@"postText"]; - [params setObjectWithIgnoreNillValue:url forKey:@"postUrl"]; - [params setObjectWithIgnoreNillValue:contentID forKey:@"postContentId"]; - [params setObjectWithIgnoreNillValue:checkinID forKey:@"checkinId"]; + + if (text) + params[@"postText"] = text; + + if (url) + params[@"postUrl"] = url; + + if (contentID) + params[@"postContentId"] = contentID; + + if (checkinID) + params[@"checkinId"] = checkinID; + params[@"post*"] = @"1"; - NSString *boundary = [NSString createUuid]; + NSString *boundary = [[NSUUID new] UUIDString]; + + NSMutableData *httpBody = [NSMutableData dataForHTTPPostWithData:UIImageJPEGRepresentation(image, 1.0) + andFileName:@"name" + andParameterName:@"photo" + boundary:boundary]; - NSData *imageData = [NSData dataForHTTPPostWithData:UIImageJPEGRepresentation(image, 1.0) - andFileName:@"name" - andParameterName:@"photo" - boundary:boundary]; - NSData *httpBody = [imageData dataForHTTPPostByAppendingParameters:params boundary:boundary]; + [httpBody appendHTTPParameters:params boundary:boundary]; JFFAsyncOperationBinder postLoaderBinder = ^JFFAsyncOperation(NSString *accessToken) { return bindSequenceOfAsyncOperations(jffFoursquareRequestLoaderWithHTTPBody(addPhotoURL, httpBody, accessToken), diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Model/FoursquareCheckinsModel.h b/lib/JFFSocial/JFFSocial/Foursquare/Model/FoursquareCheckinsModel.h index a9684c4..76d4e3d 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Model/FoursquareCheckinsModel.h +++ b/lib/JFFSocial/JFFSocial/Foursquare/Model/FoursquareCheckinsModel.h @@ -5,5 +5,4 @@ @property (nonatomic) NSString *checkinID; @property (nonatomic) NSString *type; - @end diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.h b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.h index b6be51f..28f064f 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.h +++ b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.h @@ -2,6 +2,6 @@ @interface FoursquareCheckinsModel (APIParser) -+ (id)fqCheckinModelWithDict:(NSDictionary *)dict error:(NSError **)outError; ++ (instancetype)fqCheckinModelWithDict:(NSDictionary *)dict error:(NSError **)outError; @end diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.m b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.m index adccb14..579da5f 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareCheckinsModel+APIParser.m @@ -2,7 +2,7 @@ @implementation FoursquareCheckinsModel (APIParser) -+ (id)fqCheckinModelWithDict:(NSDictionary *)jsonObject error:(NSError **)outError ++ (instancetype)fqCheckinModelWithDict:(NSDictionary *)jsonObject error:(NSError **)outError { id jsonPattern = @{ @"id" : [NSString class], diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.h b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.h index df2b17d..7f0a38f 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.h +++ b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.h @@ -2,6 +2,6 @@ @interface FoursquareUserModel (APIParser) -+ (id)fqUserModelWithDict:(NSDictionary *)dict error:(NSError **)outError; ++ (instancetype)fqUserModelWithDict:(NSDictionary *)dict error:(NSError **)outError; @end diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.m b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.m index 34773bf..119f61c 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/FoursquareUserModel+APIParser.m @@ -2,7 +2,7 @@ @implementation FoursquareUserModel (APIParser) -+ (id)fqUserModelWithDict:(NSDictionary *)dict error:(NSError **)outError ++ (instancetype)fqUserModelWithDict:(NSDictionary *)dict error:(NSError **)outError { //TODO use validator // id jsonPattern = @{ diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.h b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.h index a953071..4e61ef0 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.h +++ b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.h @@ -2,6 +2,6 @@ @interface NSDictionary (FqAPIresponseParser) -+ (id)fqApiresponseDictWithDict:(NSDictionary *)dict error:(NSError **)outError; ++ (instancetype)fqApiresponseDictWithDict:(NSDictionary *)dict error:(NSError **)outError; @end diff --git a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.m b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.m index 0603543..f60c5e7 100644 --- a/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.m +++ b/lib/JFFSocial/JFFSocial/Foursquare/Parsers/NSDictionary+FqAPIResponseParser.m @@ -2,7 +2,7 @@ @implementation NSDictionary (FqAPIresponseParser) -+ (id)fqApiresponseDictWithDict:(NSDictionary *)jsonObject error:(NSError **)outError ++ (instancetype)fqApiresponseDictWithDict:(NSDictionary *)jsonObject error:(NSError **)outError { id jsonPattern = @{ @"meta" : diff --git a/lib/JFFSocial/JFFSocial/Instagram/Details/JFFInstagramJSONDataAnalyzers.m b/lib/JFFSocial/JFFSocial/Instagram/Details/JFFInstagramJSONDataAnalyzers.m index 563b142..3e75e09 100644 --- a/lib/JFFSocial/JFFSocial/Instagram/Details/JFFInstagramJSONDataAnalyzers.m +++ b/lib/JFFSocial/JFFSocial/Instagram/Details/JFFInstagramJSONDataAnalyzers.m @@ -9,8 +9,8 @@ @implementation JFFInstagramAccount (JFFInstagramJSONDataAnalyzers) -+ (id)newInstagramAccountWithJSONObject:(NSDictionary *)userJsonObject - error:(NSError **)outError ++ (instancetype)newInstagramAccountWithJSONObject:(NSDictionary *)userJsonObject + error:(NSError **)outError { id jsonPattern = @{ @"username" : [NSString class], @@ -26,9 +26,12 @@ + (id)newInstagramAccountWithJSONObject:(NSDictionary *)userJsonObject JFFInstagramAccount *result = [self new]; - result.name = userJsonObject[@"username"]; - result.avatarURL = [userJsonObject[@"profile_picture"]toURL]; - result.instagramAccountId = userJsonObject[@"id"]; + if (result) { + + result.name = userJsonObject[@"username"]; + result.avatarURL = [userJsonObject[@"profile_picture"] toURL]; + result.instagramAccountId = userJsonObject[@"id"]; + } return result; } @@ -37,8 +40,8 @@ + (id)newInstagramAccountWithJSONObject:(NSDictionary *)userJsonObject @implementation JFFInstagramAuthedAccount (JFFInstagramJSONDataAnalyzers) -+ (id)newInstagramAuthedAccountWithJSONObject:(NSDictionary *)jsonObject - error:(NSError **)outError ++ (instancetype)newInstagramAuthedAccountWithJSONObject:(NSDictionary *)jsonObject + error:(NSError **)outError { id jsonPattern = @{ @"user" : [NSDictionary class], @@ -66,8 +69,8 @@ + (id)newInstagramAuthedAccountWithJSONObject:(NSDictionary *)jsonObject @implementation JFFInstagramMediaItemImage (JFFInstagramJSONDataAnalyzers) -+ (id)newInstagramMediaItemImageWithJsonObject:(NSDictionary *)jsonObject - error:(NSError **)outError ++ (instancetype)newInstagramMediaItemImageWithJsonObject:(NSDictionary *)jsonObject + error:(NSError **)outError { id jsonPattern = @{ @@ -97,8 +100,8 @@ + (id)newInstagramMediaItemImageWithJsonObject:(NSDictionary *)jsonObject @implementation JFFInstagramMediaItem (JFFInstagramJSONDataAnalyzers) -+ (id)newInstagramMediaItemWithJSONObject:(NSDictionary *)jsonObject - error:(NSError **)outError ++ (instancetype)newInstagramMediaItemWithJSONObject:(NSDictionary *)jsonObject + error:(NSError **)outError { id jsonPattern = @{ @"user" : [NSDictionary class], @@ -151,8 +154,8 @@ + (id)newInstagramMediaItemWithJSONObject:(NSDictionary *)jsonObject @implementation JFFInstagramComment (JFFInstagramJSONDataAnalyzers) -+ (id)newInstagramCommentWithJSONObject:(NSDictionary *)jsonObject - error:(NSError **)outError ++ (instancetype)newInstagramCommentWithJSONObject:(NSDictionary *)jsonObject + error:(NSError **)outError { id jsonPattern = @{ @"from" : [NSDictionary class], @@ -213,7 +216,7 @@ static BOOL validJeneralJSONObject(NSDictionary *jsonObject, NSError *__autorele static JFFAsyncOperationBinder generalJsonDataBinderWithAnalyzer(JFFAnalyzer analyzer) { - assert(analyzer); + NSCParameterAssert(analyzer); analyzer = [analyzer copy]; return ^JFFAsyncOperation(NSData *data) { diff --git a/lib/JFFSocial/JFFSocial/Instagram/Details/JFFSocialInstagramApi.m b/lib/JFFSocial/JFFSocial/Instagram/Details/JFFSocialInstagramApi.m index cd24e7c..fb4cea7 100644 --- a/lib/JFFSocial/JFFSocial/Instagram/Details/JFFSocialInstagramApi.m +++ b/lib/JFFSocial/JFFSocial/Instagram/Details/JFFSocialInstagramApi.m @@ -1,13 +1,13 @@ #import "JFFSocialInstagramApi.h" -#import +#import JFFAsyncOperation codeURLLoader(NSString *redirectURI, NSString *clientId ) { - assert([clientId length]>0); - assert([redirectURI length]>0); + NSCParameterAssert([clientId length]>0); + NSCParameterAssert([redirectURI length]>0); UIApplication *application = [UIApplication sharedApplication]; @@ -34,10 +34,10 @@ JFFAsyncOperation authedUserDataLoader(NSString *redirectURI, NSString *code ) { - assert([redirectURI length]>0); - assert([clientId length]>0); - assert([clientSecret length]>0); - assert([code length]>0); + NSCParameterAssert([redirectURI length]>0); + NSCParameterAssert([clientId length]>0); + NSCParameterAssert([clientSecret length]>0); + NSCParameterAssert([code length]>0); NSDictionary *params = @{ @"client_id" : clientId , @@ -60,8 +60,8 @@ JFFAsyncOperation userDataLoader(NSString *userID, NSString *accessToken ) { - assert([userID length]>0); - assert([accessToken length]>0); + NSCParameterAssert([userID length]>0); + NSCParameterAssert([accessToken length]>0); NSDictionary *params = @{ @"access_token" : accessToken, @@ -82,8 +82,8 @@ JFFAsyncOperation followersJSONDataLoader(NSString *userID, NSString *accessToken ) { - assert([userID length]>0); - assert([accessToken length]>0); + NSCParameterAssert([userID length]>0); + NSCParameterAssert([accessToken length]>0); NSDictionary *params = @{ @"access_token" : accessToken, @@ -102,8 +102,8 @@ JFFAsyncOperation mediaItemsDataLoader(NSString *userID, NSString *accessToken ) { - assert([userID length]>0); - assert([accessToken length]>0); + NSCParameterAssert([userID length]>0); + NSCParameterAssert([accessToken length]>0); NSDictionary *params = @{ @"access_token" : accessToken, @@ -123,9 +123,9 @@ JFFAsyncOperation commentMediaItemDataLoader(NSString *mediaItemId, NSString *comment, NSString *accessToken) { - assert([mediaItemId length]>0); - assert([comment length]>0); - assert([accessToken length]>0); + NSCParameterAssert([mediaItemId length]>0); + NSCParameterAssert([comment length]>0); + NSCParameterAssert([accessToken length]>0); NSDictionary *params = @{ @"access_token" : accessToken, diff --git a/lib/JFFSocial/JFFSocial/Instagram/Errors/JFFInvalidInstagramResponseURLError.m b/lib/JFFSocial/JFFSocial/Instagram/Errors/JFFInvalidInstagramResponseURLError.m index 6ce4dfd..925a4a2 100644 --- a/lib/JFFSocial/JFFSocial/Instagram/Errors/JFFInvalidInstagramResponseURLError.m +++ b/lib/JFFSocial/JFFSocial/Instagram/Errors/JFFInvalidInstagramResponseURLError.m @@ -2,12 +2,12 @@ @implementation JFFInvalidInstagramResponseURLError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"INVALID_INSTAGRAM_RESPONSE_URL", nil)]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFInvalidInstagramResponseURLError *copy = [super copyWithZone:zone]; diff --git a/lib/JFFSocial/JFFSocial/Instagram/JFFSocialInstagram.m b/lib/JFFSocial/JFFSocial/Instagram/JFFSocialInstagram.m index 8839d16..9f819f8 100644 --- a/lib/JFFSocial/JFFSocial/Instagram/JFFSocialInstagram.m +++ b/lib/JFFSocial/JFFSocial/Instagram/JFFSocialInstagram.m @@ -48,7 +48,7 @@ + (JFFAsyncOperation)instagramAccessTokenLoaderForCredentials:(JFFInstagramCrede JFFAsyncOperation loader = bindSequenceOfAsyncOperations(accountLoader, accountToAccessTokenBinder, nil); - loader = [self asyncOperationForPropertyWithName:@"accessToken" + loader = [self asyncOperationForPropertyWithName:NSStringFromSelector(@selector(accessToken)) asyncOperation:loader]; return loader(progressCallback, diff --git a/lib/JFFSocial/JFFSocial/JFFSocial.h b/lib/JFFSocial/JFFSocial/JFFSocial.h index 50fa5bf..9c06fac 100644 --- a/lib/JFFSocial/JFFSocial/JFFSocial.h +++ b/lib/JFFSocial/JFFSocial/JFFSocial.h @@ -43,5 +43,6 @@ //Facebook Errors #import +#import #import #import diff --git a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterAccessRequest.m b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterAccessRequest.m index e9d51b6..5a294ec 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterAccessRequest.m +++ b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterAccessRequest.m @@ -2,7 +2,6 @@ #import "JFFTwitterAccountAccessNotGrantedError.h" -#import #import @interface JFFAsyncTwitterAccessRequest : NSObject @@ -14,14 +13,15 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { - handler = [handler copy]; - progress = [progress copy]; + handler = [handler copy]; ACAccountStore *accountStore = [ACAccountStore new]; ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; - [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { + [accountStore requestAccessToAccountsWithType:accountType + options:nil + completion:^(BOOL granted, NSError *error) { if (!handler) return; @@ -30,7 +30,7 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler handler(nil, error); } else { if (granted) { - handler([NSNull null], nil); + handler([NSNull new], nil); } else { handler(nil, [JFFTwitterAccountAccessNotGrantedError new]); } @@ -38,8 +38,9 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler }]; } -- (void)cancel:(BOOL)canceled +- (BOOL)isForeignThreadResultCallback { + return YES; } @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterCreateAccount.h b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterCreateAccount.h deleted file mode 100644 index ece960e..0000000 --- a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterCreateAccount.h +++ /dev/null @@ -1,6 +0,0 @@ -#import - -#import - -//now always returns error -JFFAsyncOperation jffCreateTwitterAccountLoader(); diff --git a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterCreateAccount.m b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterCreateAccount.m deleted file mode 100644 index df60a22..0000000 --- a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterCreateAccount.m +++ /dev/null @@ -1,64 +0,0 @@ -#import "JFFAsyncTwitterCreateAccount.h" - -#import "JFFTwitterAccountCanceledCreationError.h" - -#import - -@interface JFFAsyncTwitterCreateAccount : NSObject -@end - -@implementation JFFAsyncTwitterCreateAccount - -- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler - cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler - progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress -{ - handler = [handler copy]; - progress = [progress copy]; - - TWTweetComposeViewController *viewController = [TWTweetComposeViewController new]; - - //hide the tweet screen - viewController.view.hidden = YES; - - UIViewController *controller = [UIViewController new]; - - //fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1 - viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) - { - if (result == TWTweetComposeViewControllerResultCancelled) - { - [controller dismissViewControllerAnimated:NO completion:^() - { - [controller.view removeFromSuperview]; - if(handler) - handler(nil, [JFFTwitterAccountCanceledCreationError new]); - }]; - } - else - { - assert(NO); - } - }; - - UIApplication* app = [UIApplication sharedApplication]; - [app.keyWindow addSubview: controller.view]; - [controller presentViewController:viewController animated:NO completion:nil]; - - //hide the keyboard - [viewController.view endEditing:YES]; -} - -- (void)cancel:(BOOL)canceled -{ -} - -@end - -JFFAsyncOperation jffCreateTwitterAccountLoader() -{ - JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { - return [JFFAsyncTwitterCreateAccount new]; - }; - return buildAsyncOperationWithAdapterFactory(factory); -} diff --git a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.h b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.h index e2cb303..7b0de90 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.h +++ b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.h @@ -2,7 +2,7 @@ #import -@class TWRequest; +@class SLRequest; @interface JFFTwitterResponse : NSObject @@ -11,4 +11,4 @@ @end -JFFAsyncOperation jffTwitterRequest(TWRequest *request_); +JFFAsyncOperation jffTwitterRequest(SLRequest *request); diff --git a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.m b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.m index 86bd851..da3027b 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.m +++ b/lib/JFFSocial/JFFSocial/Twitter/AsyncAdapters/JFFAsyncTwitterRequest.m @@ -1,29 +1,28 @@ #import "JFFAsyncTwitterRequest.h" -#import +#import @implementation JFFTwitterResponse @end @interface JFFAsyncTwitterRequest : NSObject - -@property (nonatomic) TWRequest *request; - @end @implementation JFFAsyncTwitterRequest +{ +@public + SLRequest *_request; +} - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { - handler = [ handler copy ]; - - [self.request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { + [_request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { if (!handler) return; - + if (error) { handler(nil, error); @@ -32,23 +31,24 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler JFFTwitterResponse *result = [JFFTwitterResponse new]; result.responseData = responseData; result.urlResponse = urlResponse; - + handler(result, nil); } }]; } -- (void)cancel:( BOOL )canceled_ +- (BOOL)isForeignThreadResultCallback { + return YES; } @end -JFFAsyncOperation jffTwitterRequest(TWRequest *request) +JFFAsyncOperation jffTwitterRequest(SLRequest *request) { JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { JFFAsyncTwitterRequest *object = [JFFAsyncTwitterRequest new]; - object.request = request; + object->_request = request; return object; }; diff --git a/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFNoTwitterAccountsError.m b/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFNoTwitterAccountsError.m index 5af9d16..d31b38b 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFNoTwitterAccountsError.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFNoTwitterAccountsError.m @@ -2,9 +2,13 @@ @implementation JFFNoTwitterAccountsError --(id)init +- (instancetype)init +{ + return [self initWithDescription:NSLocalizedString(@"NO_TWITTER_ACCOUNTS_ERROR", nil)]; +} + +- (void)writeErrorWithJFFLogger { - return [ self initWithDescription: NSLocalizedString( @"NO_TWITTER_ACCOUNTS_ERROR", nil ) ]; } @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountAccessNotGrantedError.m b/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountAccessNotGrantedError.m index d21d46e..5f0bb2a 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountAccessNotGrantedError.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountAccessNotGrantedError.m @@ -2,9 +2,9 @@ @implementation JFFTwitterAccountAccessNotGrantedError --(id)init +- (instancetype)init { - return [ self initWithDescription: NSLocalizedString( @"ACCESS_TO_TWITTER_ACCOUNTS_NOT_GRANTED", nil ) ]; + return [self initWithDescription:NSLocalizedString(@"ACCESS_TO_TWITTER_ACCOUNTS_NOT_GRANTED", nil)]; } - (void)writeErrorWithJFFLogger diff --git a/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountCanceledCreationError.m b/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountCanceledCreationError.m index 486cb85..e420c48 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountCanceledCreationError.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Errors/JFFTwitterAccountCanceledCreationError.m @@ -2,9 +2,9 @@ @implementation JFFTwitterAccountCanceledCreationError --(id)init +- (instancetype)init { - return [ self initWithDescription: NSLocalizedString( @"USER_HAS_CANCELED_CREATION_OF_TWITTER_ACCOUNT", nil ) ]; + return [self initWithDescription:NSLocalizedString(@"USER_HAS_CANCELED_CREATION_OF_TWITTER_ACCOUNT", nil)]; } @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterDirectMessageAlreadySentError.h b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterDirectMessageAlreadySentError.h new file mode 100644 index 0000000..59a637b --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterDirectMessageAlreadySentError.h @@ -0,0 +1,4 @@ +#import "JFFTwitterResponseError.h" + +@interface JFFTwitterDirectMessageAlreadySentError : JFFTwitterResponseError +@end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterDirectMessageAlreadySentError.m b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterDirectMessageAlreadySentError.m new file mode 100644 index 0000000..2135bb6 --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterDirectMessageAlreadySentError.m @@ -0,0 +1,10 @@ +#import "JFFTwitterDirectMessageAlreadySentError.h" + +@implementation JFFTwitterDirectMessageAlreadySentError + +- (instancetype)init +{ + return [self initWithDescription:NSLocalizedString(@"JFF_TWITTER_DIRECT_MESSAGE_ALREADY_SENT_ERROR", nil)]; +} + +@end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterResponseError.h b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterResponseError.h new file mode 100644 index 0000000..a93c84d --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterResponseError.h @@ -0,0 +1,8 @@ +#import + +@interface JFFTwitterResponseError : JFFSocialError + +@property (nonatomic) id context; +@property (nonatomic) id response; + +@end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterResponseError.m b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterResponseError.m new file mode 100644 index 0000000..0672bb0 --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Twitter/Errors/ResponseError/JFFTwitterResponseError.m @@ -0,0 +1,31 @@ +#import "JFFTwitterResponseError.h" + +@implementation JFFTwitterResponseError + +- (instancetype)init +{ + return [self initWithDescription:NSLocalizedString(@"JFF_TWITTER_RESPONSE_ERROR", nil)]; +} + +- (instancetype)copyWithZone:(NSZone *)zone +{ + JFFTwitterResponseError *result = [super copyWithZone:zone]; + + if (result) { + result->_context = [_context copyWithZone:zone]; + result->_response = [_response copyWithZone:zone]; + } + + return result; +} + +- (NSString *)errorLogDescription +{ + return [[NSString alloc] initWithFormat:@"%@ : %@ context:%@ response:%@", + [self class], + [self localizedDescription], + _context, + _response]; +} + +@end diff --git a/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.h b/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.h index a8877a3..aee1d05 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.h +++ b/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.h @@ -19,8 +19,4 @@ typedef void(^JFFSocialTwitterDidLoginCallback)(NSString *login); + (JFFAsyncOperation)sendTweetMessage:(NSString *)message; -#pragma mark callbacks - -+ (void)setDidLoginCallback:(JFFSocialTwitterDidLoginCallback)didLoginCallback; - @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.m b/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.m index d529809..2f2efdf 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.m +++ b/lib/JFFSocial/JFFSocial/Twitter/JFFSocialTwitter.m @@ -3,16 +3,74 @@ #import "JFFAsyncTwitterRequest.h" #import "JFFAsyncTwitterAccessRequest.h" -#import "JFFAsyncTwitterCreateAccount.h" #import "JFFNoTwitterAccountsError.h" #import "AsyncAnalyzers.h" -#import +#import "JFFTwitterDirectMessageAlreadySentError.h" + +#import +#import + +#import #import #define DEFAULT_SEARCH_RADIUS 100.0f -static JFFSocialTwitterDidLoginCallback globalDidLoginCallback; +@interface JFFTwitterReponsesCache : NSObject +@end + +@implementation JFFTwitterReponsesCache +{ + NSCache *_cache; +} + +- (NSCache *)cache +{ + if (!_cache) { + + _cache = [NSCache new]; + } + + return _cache; +} + +- (JFFAsyncOperation)loaderToSetData:(NSData *)data forKey:(NSString *)key +{ + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + JFFResponseDataWithUpdateData *cachedData = [JFFResponseDataWithUpdateData new]; + + cachedData.data = data; + cachedData.updateDate = [NSDate new]; + + [self.cache setObject:cachedData forKey:key]; + + if (doneCallback) + doneCallback([NSNull new], nil); + + return JFFStubCancelAsyncOperationBlock; + }; +} + +- (JFFAsyncOperation)cachedDataLoaderForKey:(NSString *)key +{ + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + if (doneCallback) { + + JFFResponseDataWithUpdateData *cachedData = [self.cache objectForKey:key]; + doneCallback(cachedData, cachedData?nil:[JFFSilentError newErrorWithDescription:@"no data for key"]); + } + + return JFFStubCancelAsyncOperationBlock; + }; +} + +@end static JFFSyncOperation twitterAccountsGetter() { @@ -33,47 +91,15 @@ static JFFSyncOperation twitterAccountsGetter() }; } -static JFFAsyncOperation twitterAccountsLoaderIOS5() +static BOOL isAuthorized() { - JFFAsyncOperation accountsLoader = ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, - JFFCancelAsyncOperationHandler cancelCallback, - JFFDidFinishAsyncOperationHandler doneCallback) { - - JFFSyncOperation twitterAccounts = twitterAccountsGetter(); - - NSArray *accounts = twitterAccounts(NULL); - - JFFAsyncOperation loader; - - if ([accounts count] > 0) { - loader = asyncOperationWithResult(accounts); - } else { - loader = sequenceOfAsyncOperations(jffCreateTwitterAccountLoader(), - asyncOperationWithSyncOperationInCurrentQueue(twitterAccounts), - nil); - } - - doneCallback = [doneCallback copy]; - JFFDidFinishAsyncOperationHandler doneCallbackWp = ^(id result, NSError *error) { - if (doneCallback) - doneCallback(result, error); - - if (globalDidLoginCallback && result) - globalDidLoginCallback(nil); - }; - - return loader(progressCallback, cancelCallback, doneCallbackWp); - }; - - return sequenceOfAsyncOperations(jffTwitterAccessRequestLoader(), - accountsLoader, - nil - ); + return [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]; } -static JFFAsyncOperation twitterAccountsLoaderIOS6() +static JFFAsyncOperation twitterAccountsLoader() { - if (![TWTweetComposeViewController canSendTweet]) { + if (!isAuthorized()) { + return asyncOperationWithError([JFFNoTwitterAccountsError new]); } @@ -83,20 +109,11 @@ static JFFAsyncOperation twitterAccountsLoaderIOS6() ); } -static JFFAsyncOperation twitterAccountsLoader() -{ - if ([[[UIDevice currentDevice] systemVersion] compare:@"6.0"] >= NSOrderedSame) { - return twitterAccountsLoaderIOS6(); - } - - return twitterAccountsLoaderIOS5(); -} - @implementation JFFSocialTwitter + (BOOL)isAuthorized { - return [TWTweetComposeViewController canSendTweet]; + return isAuthorized(); } + (JFFAsyncOperation)authorizationLoader @@ -104,33 +121,136 @@ + (JFFAsyncOperation)authorizationLoader return twitterAccountsLoader(); } ++ (JFFAsyncOperationBinder)dataLoaderForIdentifier +{ + return ^JFFAsyncOperation(id loadDataIdentifier) { + + NSString *urlString = loadDataIdentifier[@"urlString"]; + NSDictionary *parameters = loadDataIdentifier[@"parameters"]; + SLRequestMethod requestMethod = [loadDataIdentifier[@"requestMethod"] integerValue]; + + JFFAsyncOperationBinder requestBinder = ^JFFAsyncOperation(NSArray *accountStroreAndAccounts) { + + SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter + requestMethod:requestMethod + URL:[urlString toURL] + parameters:parameters]; + + request.account = accountStroreAndAccounts[1][0]; + + JFFAsyncOperation requestOperation = jffTwitterRequest(request); + + return requestOperation; + }; + + JFFAsyncOperation loaderOperation = bindSequenceOfAsyncOperations(twitterAccountsLoader(), + requestBinder, + nil); + + JFFAsyncOperation loader = bindSequenceOfAsyncOperations(loaderOperation, + twitterResponseToNSData(), + nil); + + return loader; + }; +} + ++ (JFFAsyncBinderForIdentifier)analyzerForDataWithAnalizer:(JFFAsyncOperationBinder)ayncAnalyzer +{ + ayncAnalyzer = [ayncAnalyzer copy]; + + return ^JFFAsyncOperationBinder(id loadDataIdentifier) { + + return ^JFFAsyncOperation(NSData *data) { + + JFFAsyncOperation jsonBuilder = asyncOperationBinderJsonDataParser()(data); + + JFFAsyncOperationBinder analyzer = ^JFFAsyncOperation(id jsonObject) { + + return ayncAnalyzer(@[jsonObject, loadDataIdentifier]); + }; + + return bindSequenceOfAsyncOperations(jsonBuilder, analyzer, nil); + }; + }; +} + ++ (JFFCacheKeyForIdentifier)cacheKeyForIdentifier +{ + return ^(id loadDataIdentifier) { + + return [loadDataIdentifier description]; + }; +} + ++ (id)cache +{ + static id result; + + if (!result) { + + result = [JFFTwitterReponsesCache new]; + } + + return result; +} + + (JFFAsyncOperation)generalTwitterApiDataLoaderWithURLString:(NSString *)urlString parameters:(NSDictionary *)parameters - requestMethod:(TWRequestMethod)requestMethod + requestMethod:(SLRequestMethod)requestMethod ayncAnalyzer:(JFFAsyncOperationBinder)ayncAnalyzer + cacheDataLifeTimeInSeconds:(NSTimeInterval)cacheDataLifeTimeInSeconds { - JFFAsyncOperationBinder requestBinder = ^JFFAsyncOperation(NSArray *accountStroreAndAccounts) { + ayncAnalyzer = [ayncAnalyzer copy]; + + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { - TWRequest *request = [[TWRequest alloc] initWithURL:[urlString toURL] - parameters:parameters - requestMethod:requestMethod]; + id loadDataIdentifier = + @{ + @"urlString" : urlString, + @"parameters" : parameters?:@{}, + @"requestMethod" : @(requestMethod), + }; - request.account = accountStroreAndAccounts[1][0]; + JFFAsyncOperation loader; - JFFAsyncOperation requestOperation = jffTwitterRequest(request); + if (cacheDataLifeTimeInSeconds == 0.) { + + loader = bindSequenceOfAsyncOperations([self dataLoaderForIdentifier](loadDataIdentifier), + [self analyzerForDataWithAnalizer:ayncAnalyzer](loadDataIdentifier), + nil); + } else { + + JFFSmartUrlDataLoaderFields *args = [JFFSmartUrlDataLoaderFields new]; + + args.loadDataIdentifier = loadDataIdentifier; + args.dataLoaderForIdentifier = [self dataLoaderForIdentifier]; + args.analyzerForData = [self analyzerForDataWithAnalizer:ayncAnalyzer]; + args.cacheKeyForIdentifier = [self cacheKeyForIdentifier]; + args.cacheDataLifeTimeInSeconds = cacheDataLifeTimeInSeconds; + args.cache = self.cache; + + loader = jSmartDataLoaderWithCache(args); + } - return requestOperation; + return loader(progressCallback, + cancelCallback, + doneCallback); }; - - JFFAsyncOperation loaderOperation = bindSequenceOfAsyncOperations(twitterAccountsLoader(), - requestBinder, - nil); - - return bindSequenceOfAsyncOperations(loaderOperation, - twitterResponseToNSData(), - asyncOperationBinderJsonDataParser(), - ayncAnalyzer, - nil); +} + ++ (JFFAsyncOperation)generalTwitterApiDataLoaderWithURLString:(NSString *)urlString + parameters:(NSDictionary *)parameters + requestMethod:(SLRequestMethod)requestMethod + ayncAnalyzer:(JFFAsyncOperationBinder)ayncAnalyzer +{ + return [self generalTwitterApiDataLoaderWithURLString:urlString + parameters:parameters + requestMethod:requestMethod + ayncAnalyzer:ayncAnalyzer + cacheDataLifeTimeInSeconds:0.]; } + (JFFAsyncOperation)usersNearbyCoordinatesLantitude:(double)lantitude longitude:(double)longitude @@ -147,17 +267,19 @@ + (JFFAsyncOperation)usersNearbyCoordinatesLantitude:(double)lantitude longitude return [self generalTwitterApiDataLoaderWithURLString:@"https://api.twitter.com/1.1/search/tweets.json" parameters:params - requestMethod:TWRequestMethodGET + requestMethod:SLRequestMethodGET ayncAnalyzer:asyncJSONObjectToTwitterTweets()]; } + (JFFAsyncOperation)followersLoader { NSString *urlString = @"https://api.twitter.com/1.1/followers/ids.json"; + JFFAsyncOperation followersIds = [self generalTwitterApiDataLoaderWithURLString:urlString parameters:nil - requestMethod:TWRequestMethodGET - ayncAnalyzer:jsonObjectToTwitterUsersIds()]; + requestMethod:SLRequestMethodGET + ayncAnalyzer:jsonObjectToTwitterUsersIds() + cacheDataLifeTimeInSeconds:10.*60.]; JFFAsyncOperationBinder usersForIds = ^JFFAsyncOperation(NSArray *ids) { @@ -165,14 +287,20 @@ + (JFFAsyncOperation)followersLoader return asyncOperationWithResult(@[]); } + ids = [ids sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) { + + return [obj1 compare:obj2]; + }]; + id params = @{ @"user_id" : [ids componentsJoinedByString:@","], }; JFFAsyncOperation result = [self generalTwitterApiDataLoaderWithURLString:@"https://api.twitter.com/1.1/users/lookup.json" parameters:params - requestMethod:TWRequestMethodGET - ayncAnalyzer:asyncJSONObjectToTwitterUsers()]; + requestMethod:SLRequestMethodGET + ayncAnalyzer:asyncJSONObjectToTwitterUsers() + cacheDataLifeTimeInSeconds:10.*60.]; return result; }; @@ -188,11 +316,26 @@ + (JFFAsyncOperation)sendDirectMessage:(NSString *)message }; NSString *urlString = @"https://api.twitter.com/1.1/direct_messages/new.json"; - JFFAsyncOperation result = [self generalTwitterApiDataLoaderWithURLString:urlString + JFFAsyncOperation loader = [self generalTwitterApiDataLoaderWithURLString:urlString parameters:params - requestMethod:TWRequestMethodPOST + requestMethod:SLRequestMethodPOST ayncAnalyzer:asyncJSONObjectToDirectTweet()]; - return result; + + loader = asyncOperationWithFinishHookBlock(loader, ^(id result, NSError *error, JFFDidFinishAsyncOperationHandler doneCallback) { + + if (!doneCallback) + return; + + if ([error isKindOfClass:[JFFTwitterDirectMessageAlreadySentError class]]) { + + result = [NSNull new]; + error = nil; + } + + doneCallback(result, error); + }); + + return loader; } + (JFFAsyncOperation)sendTweetMessage:(NSString *)message @@ -203,14 +346,9 @@ + (JFFAsyncOperation)sendTweetMessage:(NSString *)message JFFAsyncOperation result = [self generalTwitterApiDataLoaderWithURLString:@"http://api.twitter.com/1/statuses/update.json" parameters:params - requestMethod:TWRequestMethodPOST + requestMethod:SLRequestMethodPOST ayncAnalyzer:asyncJSONObjectToDirectTweet()]; return result; } -+ (void)setDidLoginCallback:(JFFSocialTwitterDidLoginCallback)didLoginCallback -{ - globalDidLoginCallback = [didLoginCallback copy]; -} - @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/AsyncAnalyzers.m b/lib/JFFSocial/JFFSocial/Twitter/Parsers/AsyncAnalyzers.m index 09fbb86..cc8066c 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/AsyncAnalyzers.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/AsyncAnalyzers.m @@ -5,11 +5,25 @@ #import "NSArray+TweetsJSONParser.h" #import "JFFTwitterAccount+TwitterJSONApiParser.h" +#import "JFFTwitterResponseError+TweetsJSONParser.h" #import "JFFDirectTweetMessage+TwitterJSONApiParser.h" +static JFFAsyncOperation parseTwitterResponseError(id jsonObject, id context) +{ + JFFTwitterResponseError *error = [JFFTwitterResponseError newTwitterResponseErrorWithTwitterJSONObject:jsonObject + context:context]; + + return error + ?asyncOperationWithError(error) + :asyncOperationWithResult(jsonObject); +} + JFFAsyncOperationBinder asyncJSONObjectToTwitterTweets() { - JFFAsyncOperationBinder parser = ^JFFAsyncOperation(NSDictionary *jsonObject) { + JFFAsyncOperationBinder parser = ^JFFAsyncOperation(NSArray *result) { + + NSDictionary *jsonObject = result[0]; + id context = result[1]; JFFSyncOperation loadDataBlock = ^id(NSError **outError) { @@ -19,7 +33,9 @@ JFFAsyncOperationBinder asyncJSONObjectToTwitterTweets() }]; return accounts; }; - return asyncOperationWithSyncOperation(loadDataBlock); + + JFFAsyncOperation loader = asyncOperationWithSyncOperation(loadDataBlock); + return sequenceOfAsyncOperations(parseTwitterResponseError(jsonObject, context), loader, nil); }; return parser; @@ -27,7 +43,10 @@ JFFAsyncOperationBinder asyncJSONObjectToTwitterTweets() JFFAsyncOperationBinder asyncJSONObjectToTwitterUsers() { - JFFAsyncOperationBinder parser = ^JFFAsyncOperation(NSArray *jsonObject) { + JFFAsyncOperationBinder parser = ^JFFAsyncOperation(NSArray *result) { + + NSArray *jsonObject = result[0]; + id context = result[1]; NSError *error; if (![JFFJsonObjectValidator validateJsonObject:jsonObject @@ -38,13 +57,16 @@ JFFAsyncOperationBinder asyncJSONObjectToTwitterUsers() } JFFSyncOperation loadDataBlock = ^id(NSError **outError) { + NSArray *accounts = [jsonObject map:^id(id object, NSError *__autoreleasing *outError) { return [JFFTwitterAccount newTwitterAccountWithTwitterJSONApiDictionary:object error:outError]; } error:outError]; return accounts; }; - return asyncOperationWithSyncOperation(loadDataBlock); + + JFFAsyncOperation loader = asyncOperationWithSyncOperation(loadDataBlock); + return sequenceOfAsyncOperations(parseTwitterResponseError(jsonObject, context), loader, nil); }; return parser; @@ -52,13 +74,20 @@ JFFAsyncOperationBinder asyncJSONObjectToTwitterUsers() JFFAsyncOperationBinder asyncJSONObjectToDirectTweet() { - JFFAsyncOperationBinder parser = ^JFFAsyncOperation(NSDictionary *jsonObject) { + JFFAsyncOperationBinder parser = ^JFFAsyncOperation(NSArray *result) { + + NSDictionary *jsonObject = result[0]; + id context = result[1]; + JFFSyncOperation loadDataBlock = ^id(NSError **error) { + id accounts = [JFFDirectTweetMessage newDirectTweetMessageWithTwitterJSONObject:jsonObject error:error]; return accounts; }; - return asyncOperationWithSyncOperation(loadDataBlock); + + JFFAsyncOperation loader = asyncOperationWithSyncOperation(loadDataBlock); + return sequenceOfAsyncOperations(parseTwitterResponseError(jsonObject, context), loader, nil); }; return parser; @@ -66,8 +95,13 @@ JFFAsyncOperationBinder asyncJSONObjectToDirectTweet() JFFAsyncOperationBinder jsonObjectToTwitterUsersIds() { - JFFAsyncOperationBinder result = ^JFFAsyncOperation(NSDictionary *jsonObject) { - return asyncOperationWithSyncOperation(^id(NSError *__autoreleasing *error) { + JFFAsyncOperationBinder result = ^JFFAsyncOperation(NSArray *result) { + + NSDictionary *jsonObject = result[0]; + id context = result[1]; + + JFFSyncOperation loadDataBlock = ^id(NSError *__autoreleasing *error) { + id jsonPattern = @{ @"ids" : @[[NSNumber class]], }; @@ -76,7 +110,10 @@ JFFAsyncOperationBinder jsonObjectToTwitterUsersIds() withJsonPattern:jsonPattern error:error]; return result?jsonObject[@"ids"]:nil; - }); + }; + + JFFAsyncOperation loader = asyncOperationWithSyncOperation(loadDataBlock); + return sequenceOfAsyncOperations(parseTwitterResponseError(jsonObject, context), loader, nil); }; return result; @@ -85,7 +122,8 @@ JFFAsyncOperationBinder jsonObjectToTwitterUsersIds() JFFAsyncOperationBinder twitterResponseToNSData() { JFFAsyncOperationBinder result = ^JFFAsyncOperation(JFFTwitterResponse *response) { - assert(response); + + NSCAssert(response, @"response can not be nil"); //TODO process JFFTwitterResponse fields if valid return asyncOperationWithResult(response.responseData); }; diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.h b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.h index 4f92b03..e0ff164 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.h +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.h @@ -2,7 +2,7 @@ @interface JFFDirectTweetMessage (TwitterJSONApiParser) -+ (id)newDirectTweetMessageWithTwitterJSONObject:(NSDictionary *)dict - error:(NSError **)error; ++ (instancetype)newDirectTweetMessageWithTwitterJSONObject:(NSDictionary *)dict + error:(NSError **)error; @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.m b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.m index 6fcf7b8..018bd70 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFDirectTweetMessage+TwitterJSONApiParser.m @@ -2,8 +2,8 @@ @implementation JFFDirectTweetMessage (TwitterJSONApiParser) -+ (id)newDirectTweetMessageWithTwitterJSONObject:(NSDictionary *)jsonObject - error:(NSError **)outError ++ (instancetype)newDirectTweetMessageWithTwitterJSONObject:(NSDictionary *)jsonObject + error:(NSError **)outError { id jsonPattern = @{ @"text" : [NSString class], diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.h b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.h index 22d07a0..bcd60ca 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.h +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.h @@ -2,7 +2,7 @@ @interface JFFTweet (TwitterJSONApiParser) -+ (id)newTweetWithTwitterJSONApiDictionary:(NSDictionary *)dict - error:(NSError **)error; ++ (instancetype)newTweetWithTwitterJSONApiDictionary:(NSDictionary *)dict + error:(NSError **)error; @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.m b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.m index 02e0118..c47645d 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTweet+TwitterJSONApiParser.m @@ -4,35 +4,35 @@ @implementation JFFTweet (TwitterJSONApiParser) -+ (id)newTweetWithTwitterJSONApiDictionary:(NSDictionary *)jsonObject - error:(NSError **)outError ++ (instancetype)newTweetWithTwitterJSONApiDictionary:(NSDictionary *)jsonObject + error:(NSError **)outError { id jsonPattern = @{ @"user" : [NSDictionary class], @"id_str" : [NSString class], @"text" : [NSString class], }; - + if (![JFFJsonObjectValidator validateJsonObject:jsonObject withJsonPattern:jsonPattern error:outError]) { return nil; } - + JFFTwitterAccount *user = [JFFTwitterAccount newTwitterAccountWithTwitterJSONApiDictionary:jsonObject[@"user"] error:outError]; - + if (!user) return nil; - + JFFTweet *result = [self new]; - + if (result) { result.tweetId = jsonObject[@"id_str"]; result.text = jsonObject[@"text"]; result.user = user; } - + return result; } diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.h b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.h index 4f5d890..86d6580 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.h +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.h @@ -2,7 +2,7 @@ @interface JFFTwitterAccount (TwitterJSONApiParser) -+ (id)newTwitterAccountWithTwitterJSONApiDictionary:(NSDictionary *)dict - error:(NSError **)error; ++ (instancetype)newTwitterAccountWithTwitterJSONApiDictionary:(NSDictionary *)dict + error:(NSError **)error; @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.m b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.m index 52f428f..5aae323 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterAccount+TwitterJSONApiParser.m @@ -2,8 +2,8 @@ @implementation JFFTwitterAccount (TwitterJSONApiParser) -+ (id)newTwitterAccountWithTwitterJSONApiDictionary:(NSDictionary *)jsonObject - error:(NSError **)outError ++ (instancetype)newTwitterAccountWithTwitterJSONApiDictionary:(NSDictionary *)jsonObject + error:(NSError **)outError { id jsonPattern = @{ @"id_str" : [NSString class], @@ -25,7 +25,7 @@ + (id)newTwitterAccountWithTwitterJSONApiDictionary:(NSDictionary *)jsonObject result.name = jsonObject[@"name" ]; { - NSString* avatarUrlString = jsonObject[@"profile_image_url"]; + NSString *avatarUrlString = jsonObject[@"profile_image_url"]; result.avatarURL = [avatarUrlString toURL]; } } diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterResponseError+TweetsJSONParser.h b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterResponseError+TweetsJSONParser.h new file mode 100644 index 0000000..39c4d94 --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterResponseError+TweetsJSONParser.h @@ -0,0 +1,8 @@ +#import "JFFTwitterResponseError.h" + +@interface JFFTwitterResponseError (TweetsJSONParser) + ++ (instancetype)newTwitterResponseErrorWithTwitterJSONObject:(NSDictionary *)jsonObject + context:(id)context; + +@end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterResponseError+TweetsJSONParser.m b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterResponseError+TweetsJSONParser.m new file mode 100644 index 0000000..e23d4f6 --- /dev/null +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/JFFTwitterResponseError+TweetsJSONParser.m @@ -0,0 +1,69 @@ +#import "JFFTwitterResponseError+TweetsJSONParser.h" + +#import "JFFTwitterDirectMessageAlreadySentError.h" + +@implementation JFFTwitterDirectMessageAlreadySentError (TweetsJSONParser) + ++ (BOOL)isMineTwitterResponseError:(NSDictionary *)errorJsonObject +{ + if (![errorJsonObject isKindOfClass:[NSDictionary class]]) + return NO; + + NSNumber *code = errorJsonObject[@"code"]; + + if (![code isKindOfClass:[NSNumber class]]) + return NO; + + if ([code unsignedIntegerValue] == 151) + return YES; + + return NO; +} + +@end + +@implementation JFFTwitterResponseError (TweetsJSONParser) + ++ (instancetype)newTwitterResponseErrorWithTwitterJSONObject:(NSDictionary *)jsonObject + context:(id)context +{ + if (![jsonObject isKindOfClass:[NSDictionary class]]) + return nil; + + NSDictionary *error = [jsonObject[@"errors"] firstObject]; + + if (!error) { + + return nil; + } + + Class classes[] = {[JFFTwitterDirectMessageAlreadySentError class]}; + + Class resultClass = Nil; + + for (size_t index = 0; index < sizeof(classes)/sizeof(classes[0]); ++index) { + + Class currentClass = classes[index]; + BOOL result = [currentClass isMineTwitterResponseError:error]; + + if (result) { + resultClass = currentClass; + break; + } + } + + if (!resultClass) + resultClass = [self class]; + + JFFTwitterResponseError *result = [resultClass new]; + + if (result) { + + result.context = context; + result.response = jsonObject; + } + + return result; +} + +@end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.h b/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.h index c466ad0..5575cd4 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.h +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.h @@ -2,6 +2,6 @@ @interface NSArray (TweetsJSONParser) -+ (id)newTweetsWithJSONObject:(NSDictionary *)jsonObject error:(NSError **)error; ++ (instancetype)newTweetsWithJSONObject:(NSDictionary *)jsonObject error:(NSError **)error; @end diff --git a/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.m b/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.m index eb83226..c6c5b09 100644 --- a/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.m +++ b/lib/JFFSocial/JFFSocial/Twitter/Parsers/NSArray+TweetsJSONParser.m @@ -4,26 +4,26 @@ @implementation NSArray (TweetsJSONParser) -+ (id)newTweetsWithJSONObject:(NSDictionary *)jsonObject error:(NSError **)outError ++ (instancetype)newTweetsWithJSONObject:(NSDictionary *)jsonObject error:(NSError **)outError { id jsonPattern = @{ @"statuses" : [NSArray class], }; - + if (![JFFJsonObjectValidator validateJsonObject:jsonObject withJsonPattern:jsonPattern error:outError]) { return nil; } - + NSArray *tweets = jsonObject[@"statuses"]; - + NSArray *result = [tweets map:^id(id object, NSError *__autoreleasing *outError) { return [JFFTweet newTweetWithTwitterJSONApiDictionary:object error:outError]; } error:outError]; - + return result; } diff --git a/lib/JFFStoreKit/JFFStoreKit.xcodeproj/project.pbxproj b/lib/JFFStoreKit/JFFStoreKit.xcodeproj/project.pbxproj index 843ae11..ff26fc8 100644 --- a/lib/JFFStoreKit/JFFStoreKit.xcodeproj/project.pbxproj +++ b/lib/JFFStoreKit/JFFStoreKit.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 37A360261642A4BC00FBA5DD /* JFFStoreKitInvalidProductIdentifierError.m in Sources */ = {isa = PBXBuildFile; fileRef = 37A360251642A4BC00FBA5DD /* JFFStoreKitInvalidProductIdentifierError.m */; }; 37D865291643FDA100ABFD13 /* SKPaymentTransaction+ReceiptInBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 37D865281643FDA100ABFD13 /* SKPaymentTransaction+ReceiptInBase64.m */; }; + 4C6C1D8817AA54D30087127E /* JFFStoreKitDisabledError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6C1D8717AA54D30087127E /* JFFStoreKitDisabledError.m */; }; + 4C6DA35617E1AD5F00501F48 /* asyncSKFinishTransaction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DA35517E1AD5F00501F48 /* asyncSKFinishTransaction.m */; }; + 4CF9DB8A17E05376007D769C /* asyncSKPendingTransactions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF9DB8917E05376007D769C /* asyncSKPendingTransactions.m */; }; CEBCBE011619A7D8007F805F /* SKProduct+LocalizedPriceString.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBCBE001619A7D8007F805F /* SKProduct+LocalizedPriceString.m */; }; CEBCBE071619AB0A007F805F /* asyncSKPaymentQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBCBE061619AB0A007F805F /* asyncSKPaymentQueue.m */; }; CEBCBE241619B1B2007F805F /* asyncPaymentOperations.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBCBE231619B1B2007F805F /* asyncPaymentOperations.m */; }; @@ -16,12 +19,10 @@ CED002321619A33E00368E7D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CED002311619A33E00368E7D /* Foundation.framework */; }; CED002371619A33E00368E7D /* JFFStoreKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = CED002361619A33E00368E7D /* JFFStoreKit.h */; }; CED002411619A33F00368E7D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CED002401619A33F00368E7D /* SenTestingKit.framework */; }; - CED002431619A33F00368E7D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CED002421619A33F00368E7D /* UIKit.framework */; }; CED002441619A33F00368E7D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CED002311619A33E00368E7D /* Foundation.framework */; }; CED002471619A33F00368E7D /* libJFFStoreKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CED0022E1619A33E00368E7D /* libJFFStoreKit.a */; }; CED0024D1619A33F00368E7D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CED0024B1619A33F00368E7D /* InfoPlist.strings */; }; CED002501619A33F00368E7D /* JFFStoreKitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CED0024F1619A33F00368E7D /* JFFStoreKitTests.m */; }; - CED002621619A3C000368E7D /* asyncSKRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = CED002611619A3C000368E7D /* asyncSKRequest.m */; }; CED85B6B161C2C4800F28EBC /* JFFStoreKitError.m in Sources */ = {isa = PBXBuildFile; fileRef = CED85B6A161C2C4800F28EBC /* JFFStoreKitError.m */; }; CED85B6E161C2C8000F28EBC /* JFFStoreKitCanNoLoadProductError.m in Sources */ = {isa = PBXBuildFile; fileRef = CED85B6D161C2C8000F28EBC /* JFFStoreKitCanNoLoadProductError.m */; }; CED85B71161C2F7C00F28EBC /* JFFStoreKitTransactionStateFailedError.m in Sources */ = {isa = PBXBuildFile; fileRef = CED85B70161C2F7C00F28EBC /* JFFStoreKitTransactionStateFailedError.m */; }; @@ -111,6 +112,12 @@ 37A360251642A4BC00FBA5DD /* JFFStoreKitInvalidProductIdentifierError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFStoreKitInvalidProductIdentifierError.m; sourceTree = ""; }; 37D865271643FDA100ABFD13 /* SKPaymentTransaction+ReceiptInBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SKPaymentTransaction+ReceiptInBase64.h"; sourceTree = ""; }; 37D865281643FDA100ABFD13 /* SKPaymentTransaction+ReceiptInBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SKPaymentTransaction+ReceiptInBase64.m"; sourceTree = ""; }; + 4C6C1D8617AA54D30087127E /* JFFStoreKitDisabledError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFStoreKitDisabledError.h; sourceTree = ""; }; + 4C6C1D8717AA54D30087127E /* JFFStoreKitDisabledError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFStoreKitDisabledError.m; sourceTree = ""; }; + 4C6DA35417E1AD5E00501F48 /* asyncSKFinishTransaction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asyncSKFinishTransaction.h; sourceTree = ""; }; + 4C6DA35517E1AD5F00501F48 /* asyncSKFinishTransaction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = asyncSKFinishTransaction.m; sourceTree = ""; }; + 4CF9DB8817E05376007D769C /* asyncSKPendingTransactions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asyncSKPendingTransactions.h; sourceTree = ""; }; + 4CF9DB8917E05376007D769C /* asyncSKPendingTransactions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = asyncSKPendingTransactions.m; sourceTree = ""; }; CEBCBDEB1619A425007F805F /* JFFAsyncOperations.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFAsyncOperations.xcodeproj; path = ../JFFAsyncOperations/JFFAsyncOperations.xcodeproj; sourceTree = ""; }; CEBCBDFF1619A7D8007F805F /* SKProduct+LocalizedPriceString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SKProduct+LocalizedPriceString.h"; sourceTree = ""; }; CEBCBE001619A7D8007F805F /* SKProduct+LocalizedPriceString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SKProduct+LocalizedPriceString.m"; sourceTree = ""; }; @@ -127,13 +134,10 @@ CED002361619A33E00368E7D /* JFFStoreKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFStoreKit.h; sourceTree = ""; }; CED0023F1619A33F00368E7D /* JFFStoreKitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JFFStoreKitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; CED002401619A33F00368E7D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; - CED002421619A33F00368E7D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; CED0024A1619A33F00368E7D /* JFFStoreKitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JFFStoreKitTests-Info.plist"; sourceTree = ""; }; CED0024C1619A33F00368E7D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; CED0024E1619A33F00368E7D /* JFFStoreKitTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFStoreKitTests.h; sourceTree = ""; }; CED0024F1619A33F00368E7D /* JFFStoreKitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JFFStoreKitTests.m; sourceTree = ""; }; - CED002601619A3C000368E7D /* asyncSKRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asyncSKRequest.h; sourceTree = ""; }; - CED002611619A3C000368E7D /* asyncSKRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = asyncSKRequest.m; sourceTree = ""; }; CED85B69161C2C4800F28EBC /* JFFStoreKitError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFStoreKitError.h; sourceTree = ""; }; CED85B6A161C2C4800F28EBC /* JFFStoreKitError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFStoreKitError.m; sourceTree = ""; }; CED85B6C161C2C8000F28EBC /* JFFStoreKitCanNoLoadProductError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFStoreKitCanNoLoadProductError.h; sourceTree = ""; }; @@ -156,7 +160,6 @@ buildActionMask = 2147483647; files = ( CED002411619A33F00368E7D /* SenTestingKit.framework in Frameworks */, - CED002431619A33F00368E7D /* UIKit.framework in Frameworks */, CED002441619A33F00368E7D /* Foundation.framework in Frameworks */, CED002471619A33F00368E7D /* libJFFStoreKit.a in Frameworks */, ); @@ -222,7 +225,6 @@ CEBCBDEB1619A425007F805F /* JFFAsyncOperations.xcodeproj */, CED002311619A33E00368E7D /* Foundation.framework */, CED002401619A33F00368E7D /* SenTestingKit.framework */, - CED002421619A33F00368E7D /* UIKit.framework */, ); name = Frameworks; sourceTree = ""; @@ -273,12 +275,14 @@ CED0025F1619A37E00368E7D /* asyncAdapters */ = { isa = PBXGroup; children = ( - CED002601619A3C000368E7D /* asyncSKRequest.h */, - CED002611619A3C000368E7D /* asyncSKRequest.m */, CEBCBE251619B729007F805F /* asyncSKProductRequest.h */, CEBCBE261619B729007F805F /* asyncSKProductRequest.m */, CEBCBE051619AB0A007F805F /* asyncSKPaymentQueue.h */, CEBCBE061619AB0A007F805F /* asyncSKPaymentQueue.m */, + 4C6DA35417E1AD5E00501F48 /* asyncSKFinishTransaction.h */, + 4C6DA35517E1AD5F00501F48 /* asyncSKFinishTransaction.m */, + 4CF9DB8817E05376007D769C /* asyncSKPendingTransactions.h */, + 4CF9DB8917E05376007D769C /* asyncSKPendingTransactions.m */, ); path = asyncAdapters; sourceTree = ""; @@ -288,6 +292,8 @@ children = ( CED85B69161C2C4800F28EBC /* JFFStoreKitError.h */, CED85B6A161C2C4800F28EBC /* JFFStoreKitError.m */, + 4C6C1D8617AA54D30087127E /* JFFStoreKitDisabledError.h */, + 4C6C1D8717AA54D30087127E /* JFFStoreKitDisabledError.m */, CED85B6C161C2C8000F28EBC /* JFFStoreKitCanNoLoadProductError.h */, CED85B6D161C2C8000F28EBC /* JFFStoreKitCanNoLoadProductError.m */, 37A360241642A4BC00FBA5DD /* JFFStoreKitInvalidProductIdentifierError.h */, @@ -343,7 +349,7 @@ CED002251619A33E00368E7D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0450; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = EmbeddedSources; }; buildConfigurationList = CED002281619A33E00368E7D /* Build configuration list for PBXProject "JFFStoreKit" */; @@ -465,7 +471,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CED002621619A3C000368E7D /* asyncSKRequest.m in Sources */, CEBCBE011619A7D8007F805F /* SKProduct+LocalizedPriceString.m in Sources */, CEBCBE071619AB0A007F805F /* asyncSKPaymentQueue.m in Sources */, CEBCBE241619B1B2007F805F /* asyncPaymentOperations.m in Sources */, @@ -475,6 +480,9 @@ CED85B71161C2F7C00F28EBC /* JFFStoreKitTransactionStateFailedError.m in Sources */, 37A360261642A4BC00FBA5DD /* JFFStoreKitInvalidProductIdentifierError.m in Sources */, 37D865291643FDA100ABFD13 /* SKPaymentTransaction+ReceiptInBase64.m in Sources */, + 4C6C1D8817AA54D30087127E /* JFFStoreKitDisabledError.m in Sources */, + 4CF9DB8A17E05376007D769C /* asyncSKPendingTransactions.m in Sources */, + 4C6DA35617E1AD5F00501F48 /* asyncSKFinishTransaction.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -512,13 +520,12 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -527,6 +534,7 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( @@ -534,6 +542,7 @@ ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; }; name = Debug; @@ -542,14 +551,14 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( @@ -557,6 +566,7 @@ ., ); IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -568,6 +578,7 @@ DSTROOT = /tmp/JFFStoreKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFStoreKit/JFFStoreKit-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -580,6 +591,7 @@ DSTROOT = /tmp/JFFStoreKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "JFFStoreKit/JFFStoreKit-Prefix.pch"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.h b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.h index 03070c6..0ff34fc 100644 --- a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.h +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.h @@ -1,5 +1,7 @@ #import +#import + @interface JFFStoreKitCanNoLoadProductError : JFFStoreKitError @property (nonatomic) NSString *productIdentifier; diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.m b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.m index 164a09d..25b458e 100644 --- a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.m +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitCanNoLoadProductError.m @@ -2,12 +2,12 @@ @implementation JFFStoreKitCanNoLoadProductError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"STORE_KIT_CAN_NOT_LOAD_PRODUCT", nil)]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFStoreKitCanNoLoadProductError *copy = [super copyWithZone:zone]; @@ -18,4 +18,8 @@ - (id)copyWithZone:(NSZone *)zone return copy; } +- (void)writeErrorWithJFFLogger +{ +} + @end diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitDisabledError.h b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitDisabledError.h new file mode 100644 index 0000000..1dbd642 --- /dev/null +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitDisabledError.h @@ -0,0 +1,6 @@ +#import + +#import + +@interface JFFStoreKitDisabledError : JFFStoreKitError +@end diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitDisabledError.m b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitDisabledError.m new file mode 100644 index 0000000..029ae9e --- /dev/null +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitDisabledError.m @@ -0,0 +1,14 @@ +#import "JFFStoreKitDisabledError.h" + +@implementation JFFStoreKitDisabledError + +- (instancetype)init +{ + return [self initWithDescription:NSLocalizedString(@"JFFSTOREKIT_PURCHASE_DISABLED_ERROR", nil)]; +} + +- (void)writeErrorWithJFFLogger +{ +} + +@end diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitError.h b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitError.h index a6aad64..b91e0e8 100644 --- a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitError.h +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitError.h @@ -1,5 +1,4 @@ -#import +#import @interface JFFStoreKitError : JFFError - @end diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.h b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.h index 1bef4a5..708bd9d 100644 --- a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.h +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.h @@ -1,13 +1,6 @@ -// -// JFFStoreKitInvalidProductIdentifierError.h -// JFFStoreKit -// -// Created by Maxim Malygin on 11/1/12. -// Copyright (c) 2012 EmbeddedSources. All rights reserved. -// +#import -#import "JFFStoreKitCanNoLoadProductError.h" +#import @interface JFFStoreKitInvalidProductIdentifierError : JFFStoreKitCanNoLoadProductError - @end diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.m b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.m index 3a2f40b..eb0cd83 100644 --- a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.m +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitInvalidProductIdentifierError.m @@ -2,7 +2,7 @@ @implementation JFFStoreKitInvalidProductIdentifierError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"STORE_KIT_INVALID_PRODUCT_IDENTIFIER", nil)]; } @@ -10,7 +10,7 @@ - (id)init - (void)writeErrorWithJFFLogger { #ifndef DEBUG - [super writeErrorWithJFFLogger]; + [JFFLogger logErrorWithFormat:@"%@ : %@", [self class], [self errorLogDescription]]; #endif //DEBUG } diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.h b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.h index 42ba2e1..a20488f 100644 --- a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.h +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.h @@ -1,7 +1,11 @@ #import +#import + +@class SKPaymentTransaction; + @interface JFFStoreKitTransactionStateFailedError : JFFStoreKitError -@property (nonatomic, strong) NSError *originalError; +@property (nonatomic) SKPaymentTransaction *transaction; @end diff --git a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.m b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.m index 0e14867..355c63d 100644 --- a/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.m +++ b/lib/JFFStoreKit/JFFStoreKit/Errors/JFFStoreKitTransactionStateFailedError.m @@ -2,18 +2,18 @@ @implementation JFFStoreKitTransactionStateFailedError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"STORE_KIT_TRANSACTION_STATE_FAILED", nil)]; } -- (id)copyWithZone:(NSZone *)zone +- (instancetype)copyWithZone:(NSZone *)zone { JFFStoreKitTransactionStateFailedError *copy = [super copyWithZone:zone]; if (copy) { - copy->_originalError = [_originalError copyWithZone:zone]; + copy->_transaction = _transaction; } return copy; diff --git a/lib/JFFStoreKit/JFFStoreKit/JFFStoreKit.h b/lib/JFFStoreKit/JFFStoreKit/JFFStoreKit.h index afdb59d..b7fd0f5 100644 --- a/lib/JFFStoreKit/JFFStoreKit/JFFStoreKit.h +++ b/lib/JFFStoreKit/JFFStoreKit/JFFStoreKit.h @@ -5,7 +5,11 @@ #import #import +#import +#import +//Errors +#import #import #import diff --git a/lib/JFFStoreKit/JFFStoreKit/SKProduct+LocalizedPriceString.m b/lib/JFFStoreKit/JFFStoreKit/SKProduct+LocalizedPriceString.m index aecad03..e4bb930 100644 --- a/lib/JFFStoreKit/JFFStoreKit/SKProduct+LocalizedPriceString.m +++ b/lib/JFFStoreKit/JFFStoreKit/SKProduct+LocalizedPriceString.m @@ -2,14 +2,10 @@ @implementation SKProduct (LocalizedPriceString) --(NSString *)localizedPriceString +- (NSString *)localizedPriceString { - NSNumberFormatter *numberFormatter = [NSNumberFormatter new]; - [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; - [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; - [numberFormatter setLocale:self.priceLocale]; - NSString *result = [numberFormatter stringFromNumber:self.price]; - return result; + return [NSString localizedPrice:self.price + priceLocale:self.priceLocale]; } @end diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKFinishTransaction.h b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKFinishTransaction.h new file mode 100644 index 0000000..b34e417 --- /dev/null +++ b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKFinishTransaction.h @@ -0,0 +1,5 @@ +#import + +@class SKPaymentTransaction; + +JFFAsyncOperation asyncOperationFinishTransaction(SKPaymentTransaction *transaction); diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKFinishTransaction.m b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKFinishTransaction.m new file mode 100644 index 0000000..492cd84 --- /dev/null +++ b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKFinishTransaction.m @@ -0,0 +1,133 @@ +#import "asyncSKFinishTransaction.h" + +#import "JFFStoreKitDisabledError.h" +#import "JFFStoreKitTransactionStateFailedError.h" + +static NSString *const mergeObject = @"002fc0c2-07c3-41c4-8296-d6f4c038655a"; + +@interface JFFAsyncSKFinishTransaction : NSObject < +SKPaymentTransactionObserver, +JFFAsyncOperationInterface +> + +@end + +@implementation JFFAsyncSKFinishTransaction +{ + SKPaymentQueue *_queue; + SKPaymentTransaction *_transaction; + BOOL _addedToObservers; + JFFAsyncOperationInterfaceResultHandler _handler; +} + +- (void)dealloc +{ + [self unsubscribeFromObservervation]; + _handler = nil; +} + +- (void)doNothing:(id)objetc +{ +} + +- (void)unsubscribeFromObservervation +{ + if (_addedToObservers) { + [_queue removeTransactionObserver:self]; + _addedToObservers = NO; + } +} + ++ (instancetype)newFAsyncSKFinishTransactionWithTransaction:(SKPaymentTransaction *)transaction +{ + JFFAsyncSKFinishTransaction *result = [self new]; + + if (result) { + result->_transaction = transaction; + result->_queue = [SKPaymentQueue defaultQueue]; + + [result->_queue addTransactionObserver:result]; + result->_addedToObservers = YES; + } + + return result; +} + +- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler + cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler + progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress +{ + if (![SKPaymentQueue canMakePayments]) { + handler(nil, [JFFStoreKitDisabledError new]); + return; + } + + _handler = [handler copy]; + + [_queue finishTransaction:_transaction]; + + BOOL contains = [_queue.transactions containsObject:_transaction]; + + if (!contains) { + + [self finishOperation]; + } +} + +- (void)finishOperation +{ + [self unsubscribeFromObservervation]; + _handler(_transaction, nil); +} + +#pragma mark SKPaymentTransactionObserver + +- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions +{ + if ([transactions containsObject:_transaction]) + [self finishOperation]; +} + +- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions +{ + if (![queue.transactions containsObject:_transaction]) + [self finishOperation]; + + switch (_transaction.transactionState) + { + case SKPaymentTransactionStateFailed: + { + if (_transaction.error.code != SKErrorPaymentCancelled) { + // Optionally, display an error here. + } + JFFStoreKitTransactionStateFailedError *error = [JFFStoreKitTransactionStateFailedError new]; + [self unsubscribeFromObservervation]; + _handler(nil, error); + break; + } + default: + break; + } +} + +@end + +JFFAsyncOperation asyncOperationFinishTransaction(SKPaymentTransaction *transaction) +{ + NSCParameterAssert(transaction.transactionState == SKPaymentTransactionStatePurchased + || transaction.transactionState == SKPaymentTransactionStateRestored + || transaction.transactionState == SKPaymentTransactionStateFailed + ); + + JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + return [JFFAsyncSKFinishTransaction newFAsyncSKFinishTransactionWithTransaction:transaction]; + }; + JFFAsyncOperation loader = buildAsyncOperationWithAdapterFactory(factory); + + id key = + @{ + @"cmd" : @(__FUNCTION__), + @"transactionIdentifier" : transaction.transactionIdentifier, + }; + return [mergeObject asyncOperationMergeLoaders:loader withArgument:key]; +} diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPaymentQueue.m b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPaymentQueue.m index 009c1a2..7aeb30f 100644 --- a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPaymentQueue.m +++ b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPaymentQueue.m @@ -1,7 +1,10 @@ #import "asyncSKPaymentQueue.h" +#import "JFFStoreKitDisabledError.h" #import "JFFStoreKitTransactionStateFailedError.h" +#import "asyncSKFinishTransaction.h" + @interface JFFAsyncSKPaymentAdapter : NSObject < SKPaymentTransactionObserver, JFFAsyncOperationInterface @@ -24,16 +27,17 @@ - (void)dealloc - (void)doNothing:(id)objetc { - } - (void)unsubscribeFromObservervation { - if (_addedToObservers) + if (_addedToObservers) { [_queue removeTransactionObserver:self]; + _addedToObservers = NO; + } } -+ (id)newAsyncSKPaymentAdapterWithRequest:(SKPayment *)payment ++ (instancetype)newAsyncSKPaymentAdapterWithRequest:(SKPayment *)payment { JFFAsyncSKPaymentAdapter *result = [self new]; @@ -53,30 +57,24 @@ - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress { if (![SKPaymentQueue canMakePayments]) { - //TODO create separate error - //!!!! remove after ios 6.0 - handler(nil, [JFFError newErrorWithDescription:@"Warn the user that purchases are disabled."]); + handler(nil, [JFFStoreKitDisabledError new]); return; } - _handler = [handler copy]; + _handler = [handler copy]; SKPaymentTransaction *transaction = [self ownPurchasedTransaction]; - if (!transaction) { + if (transaction) { - [_queue addPayment:_payment]; + [self unsubscribeFromObservervation]; + _handler(transaction, nil); } else { - _handler(transaction, nil); - [self unsubscribeFromObservervation]; + [_queue addPayment:_payment]; } } -- (void)cancel:(BOOL)canceled -{ -} - - (SKPaymentTransaction *)ownPurchasedTransaction { //SKPayment @@ -100,20 +98,6 @@ - (SKPaymentTransaction *)ownTransactionForTransactions:(NSArray *)transactions #pragma mark SKPaymentTransactionObserver -- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions -{ -} - -- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error -{ - -} - -- (void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads -{ - -} - - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { if (!_handler) { @@ -133,22 +117,25 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran { case SKPaymentTransactionStatePurchased: { - _handler(transaction, nil); [self unsubscribeFromObservervation]; + _handler(transaction, nil); break; } case SKPaymentTransactionStateFailed: { - [_queue finishTransaction:transaction]; + if (transaction.error.code != SKErrorPaymentCancelled) { + // Optionally, display an error here. + } JFFStoreKitTransactionStateFailedError *error = [JFFStoreKitTransactionStateFailedError new]; - _handler(nil, error); + error.transaction = transaction; [self unsubscribeFromObservervation]; + _handler(nil, error); break; } case SKPaymentTransactionStateRestored: { - _handler(transaction, nil); [self unsubscribeFromObservervation]; + _handler(transaction, nil); break; } default: @@ -157,11 +144,6 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran // TODO call progress with SKPaymentTransactionStatePurchasing } -- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue -{ - -} - @end JFFAsyncOperation asyncOperationWithSKPayment(SKPayment *payment) @@ -169,5 +151,19 @@ JFFAsyncOperation asyncOperationWithSKPayment(SKPayment *payment) JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { return [JFFAsyncSKPaymentAdapter newAsyncSKPaymentAdapterWithRequest:payment]; }; - return buildAsyncOperationWithAdapterFactory(factory); + JFFAsyncOperation loader = buildAsyncOperationWithAdapterFactory(factory); + + loader = bindTrySequenceOfAsyncOperations(loader, ^JFFAsyncOperation(JFFStoreKitTransactionStateFailedError *error) { + + if (![error isKindOfClass:[JFFStoreKitTransactionStateFailedError class]]) { + + return asyncOperationWithError(error); + } + + JFFAsyncOperation loader = trySequenceOfAsyncOperations(asyncOperationFinishTransaction(error.transaction), asyncOperationWithResult(@YES), nil); + + return sequenceOfAsyncOperations(loader, asyncOperationWithError(error), nil); + }, nil); + + return loader; } diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPendingTransactions.h b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPendingTransactions.h new file mode 100644 index 0000000..898d527 --- /dev/null +++ b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPendingTransactions.h @@ -0,0 +1,3 @@ +#import + +JFFAsyncOperation allPendingTransactionsLoader(); diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPendingTransactions.m b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPendingTransactions.m new file mode 100644 index 0000000..b124c58 --- /dev/null +++ b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKPendingTransactions.m @@ -0,0 +1,147 @@ +#import "asyncSKPendingTransactions.h" + +#import "JFFStoreKitDisabledError.h" + +#import + +static NSString *const mergeObject = @"c8e5abce-1ab9-11e3-9a3b-f23c91aec05e"; + +@interface JFFAsyncSKPendingTransactions : NSObject < +SKPaymentTransactionObserver, +JFFAsyncOperationInterface +> +@end + +@implementation JFFAsyncSKPendingTransactions +{ + SKPaymentQueue *_queue; + BOOL _addedToObservers; + JFFAsyncOperationInterfaceResultHandler _handler; + JFFScheduler *_scheduler; +} + +- (void)dealloc +{ + [self unsubscribeFromObservervation]; + _handler = nil; +} + +- (void)doNothing:(id)objetc +{ +} + +- (void)unsubscribeFromObservervation +{ + if (_addedToObservers) { + [_queue removeTransactionObserver:self]; + _addedToObservers = NO; + } +} + ++ (instancetype)newAsyncSKPendingTransactions +{ + JFFAsyncSKPendingTransactions *result = [self new]; + + if (result) { + result->_queue = [SKPaymentQueue defaultQueue]; + + [result->_queue addTransactionObserver:result]; + result->_addedToObservers = YES; + } + + return result; +} + +- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler + cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler + progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress +{ + if (![SKPaymentQueue canMakePayments]) { + handler(nil, [JFFStoreKitDisabledError new]); + return; + } + + _handler = [handler copy]; + + [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; + + _scheduler = [JFFScheduler new]; + + __weak JFFAsyncSKPendingTransactions *weakSelf = self; + + JFFScheduledBlock actionBlock = ^(JFFCancelScheduledBlock cancel) { + + [weakSelf finishWithTransactions:@[]]; + cancel(); + }; + + [_scheduler addBlock:actionBlock duration:0.2 leeway:0.02]; +} + +- (void)finishWithTransactions:(NSArray *)transactions +{ + transactions = [self pendingTransactionsForTransactions:transactions]?:@[]; + + if (_handler) + _handler(transactions, nil); + + _scheduler = nil; +} + +- (NSArray *)pendingTransactionsForTransactions:(NSArray *)transactions +{ + NSArray *result = [transactions select:^BOOL(SKPaymentTransaction *transaction) { + + return transaction.transactionState == SKPaymentTransactionStateRestored; + }]; + + return result; +} + +#pragma mark SKPaymentTransactionObserver + +- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions +{ + if (!_handler) { + return; + } + + //TODO fix workaround for IOS 6.0 + [self performSelector:@selector(doNothing:) withObject:self afterDelay:1.]; + + [self finishWithTransactions:transactions]; + [self unsubscribeFromObservervation]; +} + +- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue +{ + //TODO finish here operation +} + +- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error +{ + if (_handler) + _handler(nil, error); + + _scheduler = nil; +} + +@end + +static JFFAsyncOperation privateAllPendingTransactionsLoader() +{ + JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + return [JFFAsyncSKPendingTransactions newAsyncSKPendingTransactions]; + }; + + JFFAsyncOperation loader = buildAsyncOperationWithAdapterFactory(factory); + + return [mergeObject asyncOperationMergeLoaders:loader withArgument:@(__FUNCTION__)]; +} + +JFFAsyncOperation allPendingTransactionsLoader() +{ + JFFAsyncOperation loader = privateAllPendingTransactionsLoader(); + + return loader; +} diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKProductRequest.m b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKProductRequest.m index 0b8ff46..58a0303 100644 --- a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKProductRequest.m +++ b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKProductRequest.m @@ -3,6 +3,8 @@ #import "JFFStoreKitCanNoLoadProductError.h" #import "JFFStoreKitInvalidProductIdentifierError.h" +#import + @interface JFFAsyncSKProductsRequestAdapter : NSObject < JFFAsyncOperationInterface, SKProductsRequestDelegate @@ -18,7 +20,7 @@ @implementation JFFAsyncSKProductsRequestAdapter NSString *_productIdentifier; } -- (id)initWithProductIdentifier:(NSString *)productIdentifier +- (instancetype)initWithProductIdentifier:(NSString *)productIdentifier { self = [super init]; @@ -55,14 +57,26 @@ - (void)requestDidFinish:(SKRequest *)request { NSArray *products = _response.products; if ([products hasElements]) { - _handler([products lastObject], nil); + + SKProduct *product = [products firstMatch:^BOOL(SKProduct *product) { + + return [product.productIdentifier isEqualToString:_productIdentifier]; + }]; + + if (!product) { + + [JFFLogger logErrorWithFormat:@"requestDidFinish products does not contains product with id: %@", _productIdentifier]; + product = [products lastObject]; + } + + _handler(product, nil); } else { NSString *invalidIdentifier = [_response.invalidProductIdentifiers lastObject]; JFFStoreKitCanNoLoadProductError *error = ([invalidIdentifier isEqualToString:_productIdentifier]) - ? [JFFStoreKitInvalidProductIdentifierError new] - : [JFFStoreKitCanNoLoadProductError new]; + ?[JFFStoreKitInvalidProductIdentifierError new] + :[JFFStoreKitCanNoLoadProductError new]; error.productIdentifier = _productIdentifier; _handler(nil, error); @@ -71,6 +85,7 @@ - (void)requestDidFinish:(SKRequest *)request - (void)request:(SKRequest *)request didFailWithError:(NSError *)error { + error = error?:[[JFFSilentError alloc] initWithDescription:@"SKRequest no inet connection"]; _handler(nil, error); } diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKRequest.h b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKRequest.h deleted file mode 100644 index 6fd1d15..0000000 --- a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKRequest.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -#import - -@class SKRequest; - -JFFAsyncOperation asyncOperationWithSKRequest(SKRequest *request); diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKRequest.m b/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKRequest.m deleted file mode 100644 index 177bd24..0000000 --- a/lib/JFFStoreKit/JFFStoreKit/asyncAdapters/asyncSKRequest.m +++ /dev/null @@ -1,61 +0,0 @@ -#import "asyncSKRequest.h" - -@interface JFFAsyncSKRequestAdapter : NSObject < -JFFAsyncOperationInterface, -SKRequestDelegate -> - -@end - -@implementation JFFAsyncSKRequestAdapter -{ - SKRequest *_request; - JFFAsyncOperationInterfaceResultHandler _handler; -} - -+ (id)newAsyncSKRequestAdapterWithRequest:(SKRequest *)request -{ - JFFAsyncSKRequestAdapter *result = [self new]; - - if (result) { - result->_request = request; - request.delegate = result; - } - - return result; -} - -- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler - cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler - progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress -{ - _handler = [handler copy]; -} - -- (void)cancel:(BOOL)canceled -{ - if (canceled) - [_request cancel]; -} - -#pragma mark SKRequestDelegate - -- (void)requestDidFinish:(SKRequest *)request -{ - _handler(request, nil); -} - -- (void)request:(SKRequest *)request didFailWithError:(NSError *)error -{ - _handler(nil, error); -} - -@end - -JFFAsyncOperation asyncOperationWithSKRequest(SKRequest *request) -{ - JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { - return [JFFAsyncSKRequestAdapter newAsyncSKRequestAdapterWithRequest:request]; - }; - return buildAsyncOperationWithAdapterFactory(factory); -} diff --git a/lib/JFFStoreKit/JFFStoreKit/asyncPaymentOperations.m b/lib/JFFStoreKit/JFFStoreKit/asyncPaymentOperations.m index cd309cb..7a8cf49 100644 --- a/lib/JFFStoreKit/JFFStoreKit/asyncPaymentOperations.m +++ b/lib/JFFStoreKit/JFFStoreKit/asyncPaymentOperations.m @@ -2,6 +2,7 @@ #import "asyncSKPaymentQueue.h" #import "asyncSKProductRequest.h" +#import "asyncSKFinishTransaction.h" @implementation JFFPurchsing @@ -24,27 +25,34 @@ + (JFFAsyncOperation)purcheserWithProductIdentifier:(NSString *)productIdentifie + (JFFAsyncOperation)purcheserWithProduct:(SKProduct *)product srvCallback:(JFFAsyncOperationBinder)srvCallback { - SKPayment *payment = [SKPayment paymentWithProduct:product]; - JFFAsyncOperation paymentloader = asyncOperationWithSKPayment(payment); - - JFFAsyncOperationBinder srvPaymentBinder = ^JFFAsyncOperation(SKPaymentTransaction *transaction) { - JFFAsyncOperation srvLoader = srvCallback(transaction); + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + SKPayment *payment = [SKPayment paymentWithProduct:product]; + JFFAsyncOperation paymentloader = asyncOperationWithSKPayment(payment); - JFFAsyncOperationBinder removeTransaction = ^JFFAsyncOperation(id srvResult) { - SKPaymentQueue *queue = [SKPaymentQueue defaultQueue]; - [queue finishTransaction:transaction]; + JFFAsyncOperationBinder srvPaymentBinder = ^JFFAsyncOperation(SKPaymentTransaction *transaction) { + + JFFAsyncOperation srvLoader = srvCallback(transaction); + + JFFAsyncOperationBinder removeTransaction = ^JFFAsyncOperation(id srvResult) { + + JFFAsyncOperation finishTransaction = asyncOperationFinishTransaction(transaction); + return sequenceOfAsyncOperations(finishTransaction, asyncOperationWithResult(srvResult), nil); + }; - return asyncOperationWithResult(srvResult); + return bindSequenceOfAsyncOperations(srvLoader, + removeTransaction, + nil); }; - return bindSequenceOfAsyncOperations(srvLoader, - removeTransaction, - nil); + JFFAsyncOperation loader = bindSequenceOfAsyncOperations(paymentloader, + srvPaymentBinder, + nil); + + return loader(progressCallback, cancelCallback, doneCallback); }; - - return bindSequenceOfAsyncOperations(paymentloader, - srvPaymentBinder, - nil); } @end diff --git a/lib/JFFTestTools/JFFTestTools.xcodeproj/project.pbxproj b/lib/JFFTestTools/JFFTestTools.xcodeproj/project.pbxproj index 3e3ee0d..accf7d5 100755 --- a/lib/JFFTestTools/JFFTestTools.xcodeproj/project.pbxproj +++ b/lib/JFFTestTools/JFFTestTools.xcodeproj/project.pbxproj @@ -7,20 +7,19 @@ objects = { /* Begin PBXBuildFile section */ - 1B160AD7154BE3F200702B1D /* performTimeCalculator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B160AD5154BE3F200702B1D /* performTimeCalculator.h */; }; - 1B160AD8154BE3F200702B1D /* performTimeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B160AD6154BE3F200702B1D /* performTimeCalculator.m */; }; + 1B160AD7154BE3F200702B1D /* testTools.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B160AD5154BE3F200702B1D /* testTools.h */; }; + 1B160AD8154BE3F200702B1D /* testTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B160AD6154BE3F200702B1D /* testTools.m */; }; 1B2D8B52154BF28100360296 /* JFFTestTools.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B2D8B51154BF28100360296 /* JFFTestTools.h */; }; 1BE0542F154826DA00270B58 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BE0542E154826DA00270B58 /* Foundation.framework */; }; 1BE054431548273000270B58 /* GHAsyncTestCase+MainThreadTests.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BE054411548273000270B58 /* GHAsyncTestCase+MainThreadTests.h */; }; 1BE054441548273000270B58 /* GHAsyncTestCase+MainThreadTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE054421548273000270B58 /* GHAsyncTestCase+MainThreadTests.m */; }; 1BE054B0154828F000270B58 /* NSObject+InstancesCount.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BE054AE154828EF00270B58 /* NSObject+InstancesCount.h */; }; 1BE054B1154828F000270B58 /* NSObject+InstancesCount.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE054AF154828EF00270B58 /* NSObject+InstancesCount.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - 7ED1F49417DF5BD20003CDD4 /* GHUnitIOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7ED1F49317DF5BD20003CDD4 /* GHUnitIOS.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 1B160AD5154BE3F200702B1D /* performTimeCalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = performTimeCalculator.h; sourceTree = ""; }; - 1B160AD6154BE3F200702B1D /* performTimeCalculator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = performTimeCalculator.m; sourceTree = ""; }; + 1B160AD5154BE3F200702B1D /* testTools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = testTools.h; sourceTree = ""; }; + 1B160AD6154BE3F200702B1D /* testTools.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = testTools.m; sourceTree = ""; }; 1B2D8B51154BF28100360296 /* JFFTestTools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFTestTools.h; sourceTree = ""; }; 1BE0542B154826DA00270B58 /* libJFFTestTools.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFTestTools.a; sourceTree = BUILT_PRODUCTS_DIR; }; 1BE0542E154826DA00270B58 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -29,7 +28,6 @@ 1BE054421548273000270B58 /* GHAsyncTestCase+MainThreadTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GHAsyncTestCase+MainThreadTests.m"; sourceTree = ""; }; 1BE054AE154828EF00270B58 /* NSObject+InstancesCount.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+InstancesCount.h"; sourceTree = ""; }; 1BE054AF154828EF00270B58 /* NSObject+InstancesCount.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+InstancesCount.m"; sourceTree = ""; }; - 7ED1F49317DF5BD20003CDD4 /* GHUnitIOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GHUnitIOS.framework; path = ../../frameworks/GHUnitIOS.framework; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -38,7 +36,6 @@ buildActionMask = 2147483647; files = ( 1BE0542F154826DA00270B58 /* Foundation.framework in Frameworks */, - 7ED1F49417DF5BD20003CDD4 /* GHUnitIOS.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -65,7 +62,6 @@ 1BE0542D154826DA00270B58 /* Frameworks */ = { isa = PBXGroup; children = ( - 7ED1F49317DF5BD20003CDD4 /* GHUnitIOS.framework */, 1BE0542E154826DA00270B58 /* Foundation.framework */, ); name = Frameworks; @@ -78,8 +74,8 @@ 1BE054AF154828EF00270B58 /* NSObject+InstancesCount.m */, 1BE054411548273000270B58 /* GHAsyncTestCase+MainThreadTests.h */, 1BE054421548273000270B58 /* GHAsyncTestCase+MainThreadTests.m */, - 1B160AD5154BE3F200702B1D /* performTimeCalculator.h */, - 1B160AD6154BE3F200702B1D /* performTimeCalculator.m */, + 1B160AD5154BE3F200702B1D /* testTools.h */, + 1B160AD6154BE3F200702B1D /* testTools.m */, 1B2D8B51154BF28100360296 /* JFFTestTools.h */, 1BE05431154826DA00270B58 /* Supporting Files */, ); @@ -103,7 +99,7 @@ files = ( 1BE054431548273000270B58 /* GHAsyncTestCase+MainThreadTests.h in Headers */, 1BE054B0154828F000270B58 /* NSObject+InstancesCount.h in Headers */, - 1B160AD7154BE3F200702B1D /* performTimeCalculator.h in Headers */, + 1B160AD7154BE3F200702B1D /* testTools.h in Headers */, 1B2D8B52154BF28100360296 /* JFFTestTools.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -134,7 +130,7 @@ 1BE05422154826DA00270B58 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0500; }; buildConfigurationList = 1BE05425154826DA00270B58 /* Build configuration list for PBXProject "JFFTestTools" */; compatibilityVersion = "Xcode 3.2"; @@ -160,7 +156,7 @@ files = ( 1BE054441548273000270B58 /* GHAsyncTestCase+MainThreadTests.m in Sources */, 1BE054B1154828F000270B58 /* NSObject+InstancesCount.m in Sources */, - 1B160AD8154BE3F200702B1D /* performTimeCalculator.m in Sources */, + 1B160AD8154BE3F200702B1D /* testTools.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -171,9 +167,10 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -187,11 +184,15 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; IPHONEOS_DEPLOYMENT_TARGET = 5.1; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; @@ -200,17 +201,21 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; IPHONEOS_DEPLOYMENT_TARGET = 5.1; diff --git a/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.h b/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.h index 18aef2c..988b231 100755 --- a/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.h +++ b/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.h @@ -6,14 +6,14 @@ typedef void (^TestAsyncRequestBlock)(JFFSimpleBlock); //GHAsyncTestCase category @interface NSObject (MainThreadTests) -- (void)performAsyncRequestOnMainThreadWithBlock:(TestAsyncRequestBlock)block +- (void)performAsyncRequestOnMainThreadWithBlock:(void(^)(JFFSimpleBlock))block selector:(SEL)selector; --(void)waitForeverForAsyncRequestOnMainThreadWithBlock:( TestAsyncRequestBlock )block_ - selector:( SEL )selector_; +- (void)waitForeverForAsyncRequestOnMainThreadWithBlock:(void (^)(JFFSimpleBlock))block + selector:(SEL)selector; --(void)performAsyncRequestOnMainThreadWithBlock:( TestAsyncRequestBlock )block_ - selector:( SEL )selector_ - timeout:( NSTimeInterval )timeout_; +- (void)performAsyncRequestOnMainThreadWithBlock:(void (^)(JFFSimpleBlock))block + selector:(SEL)selector + timeout:(NSTimeInterval)timeout; @end diff --git a/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.m b/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.m index e81b684..36172c3 100755 --- a/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.m +++ b/lib/JFFTestTools/JFFTestTools/GHAsyncTestCase+MainThreadTests.m @@ -6,61 +6,60 @@ @implementation NSObject (MainThreadTests) --(void)performAsyncRequestOnMainThreadWithBlock:( TestAsyncRequestBlock )block_ - selector:( SEL )selector_ +- (void)performAsyncRequestOnMainThreadWithBlock:(TestAsyncRequestBlock)block + selector:(SEL)selector { - [ self performAsyncRequestOnMainThreadWithBlock: block_ - selector: selector_ - timeout: 30000. ]; + [self performAsyncRequestOnMainThreadWithBlock:block + selector:selector + timeout:30000.]; } --(void)waitForeverForAsyncRequestOnMainThreadWithBlock:( TestAsyncRequestBlock )block_ - selector:( SEL )selector_ +- (void)waitForeverForAsyncRequestOnMainThreadWithBlock:(void (^)(JFFSimpleBlock))block + selector:(SEL)selector { - [ self performAsyncRequestOnMainThreadWithBlock: block_ - selector: selector_ - timeout: INFINITY ]; + [self performAsyncRequestOnMainThreadWithBlock:block + selector:selector + timeout:INFINITY]; } --(void)performAsyncRequestOnMainThreadWithBlock:( TestAsyncRequestBlock )block_ - selector:( SEL )selector_ - timeout:( NSTimeInterval )timeout_; +- (void)performAsyncRequestOnMainThreadWithBlock:(void (^)(JFFSimpleBlock))block + selector:(SEL)selector + timeout:(NSTimeInterval)timeout { - block_ = [ block_ copy ]; - void (^autoreleaseBlock_)() = ^void() - { - @autoreleasepool - { - void (^didFinishCallback_)(void) = ^void() - { - objc_msgSend( self - , @selector( notify:forSelector: ) - , kGHUnitWaitStatusSuccess - , selector_ ); + block = [block copy]; + void (^autoreleaseBlock)() = ^void() { + + @autoreleasepool { + + void (^didFinishCallback)(void) = ^void() { + + objc_msgSend(self, + @selector(notify:forSelector:), + kGHUnitWaitStatusSuccess, + selector); }; - - block_( [ didFinishCallback_ copy ] ); + + block([didFinishCallback copy]); } }; - - objc_msgSend( self, @selector( prepare ), nil ); - - dispatch_async( dispatch_get_main_queue(), autoreleaseBlock_ ); - - objc_msgSend( self - , @selector( waitForStatus:timeout: ) - , kGHUnitWaitStatusSuccess - , timeout_ ); + + objc_msgSend(self, @selector(prepare), nil); + + dispatch_async(dispatch_get_main_queue(), autoreleaseBlock); + + objc_msgSend(self, + @selector(waitForStatus:timeout:), + kGHUnitWaitStatusSuccess, + timeout); } -+(void)load ++ (void)load { - Class class_ = NSClassFromString( @"GHAsyncTestCase" ); - if ( class_ ) - { - [ self addInstanceMethodIfNeedWithSelector: @selector( performAsyncRequestOnMainThreadWithBlock:selector: ) - toClass: class_ ]; + Class class = NSClassFromString(@"GHAsyncTestCase"); + if (class) { + [self addInstanceMethodIfNeedWithSelector:@selector(performAsyncRequestOnMainThreadWithBlock:selector:) + toClass:class]; } } -@end \ No newline at end of file +@end diff --git a/lib/JFFTestTools/JFFTestTools/JFFTestTools.h b/lib/JFFTestTools/JFFTestTools/JFFTestTools.h index cb0f889..697f5f8 100755 --- a/lib/JFFTestTools/JFFTestTools/JFFTestTools.h +++ b/lib/JFFTestTools/JFFTestTools/JFFTestTools.h @@ -1,7 +1,8 @@ #ifndef JFF_TEST_TOOLS_HEADER_INCLUDED #define JFF_TEST_TOOLS_HEADER_INCLUDED -#import +#import #import +#import #endif //JFF_TEST_TOOLS_HEADER_INCLUDED diff --git a/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.h b/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.h index 11039ea..21a614c 100755 --- a/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.h +++ b/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.h @@ -2,8 +2,8 @@ @interface NSObject (InstancesCount) -+(void)enableInstancesCounting; ++ (void)enableInstancesCounting; -+(NSUInteger)instancesCount; ++ (NSUInteger)instancesCount; @end diff --git a/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.m b/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.m index cacb36f..867a730 100644 --- a/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.m +++ b/lib/JFFTestTools/JFFTestTools/NSObject+InstancesCount.m @@ -8,7 +8,7 @@ @interface JFFNSObjectInstancesCounter : NSObject -@property ( nonatomic, retain ) NSMutableDictionary* instancesNumberByClassName; +@property (nonatomic, retain) NSMutableDictionary *instancesNumberByClassName; @end @@ -16,23 +16,23 @@ @implementation JFFNSObjectInstancesCounter - (void)dealloc { - [self->_instancesNumberByClassName release]; + [_instancesNumberByClassName release]; [super dealloc]; } -- (id)init +- (instancetype)init { - self = [ super init ]; + self = [super init]; if (self) { - self->_instancesNumberByClassName = [NSMutableDictionary new]; + _instancesNumberByClassName = [NSMutableDictionary new]; } return self; } -+ (id)sharedObjectInstancesCounter ++ (instancetype)sharedObjectInstancesCounter { static dispatch_once_t once; static id instance; @@ -44,10 +44,10 @@ - (void)incrementInstancesCountForClass:(Class)class { @synchronized(self) { NSString *className = NSStringFromClass(class); - NSNumber *number = self->_instancesNumberByClassName[className]; + NSNumber *number = _instancesNumberByClassName[className]; NSUInteger instancesCount = [number unsignedIntValue]; NSNumber* instancesCountNum = @(++instancesCount); - self->_instancesNumberByClassName[className] = instancesCountNum; + _instancesNumberByClassName[className] = instancesCountNum; } } @@ -55,10 +55,10 @@ - (void)decrementInstancesCountForClass:(Class)class { @synchronized(self) { NSString *className = NSStringFromClass(class); - NSNumber *number = self->_instancesNumberByClassName[className]; + NSNumber *number = _instancesNumberByClassName[className]; NSUInteger instancesCount = [number unsignedIntValue]; NSNumber* instancesCountNum = @(--instancesCount); - self->_instancesNumberByClassName[className] = instancesCountNum; + _instancesNumberByClassName[className] = instancesCountNum; } } @@ -83,64 +83,64 @@ + (id)instancesCounterAllocatorForClass:(Class)class return result; } -+ (id)allocWithZoneHook:(NSZone *)zone ++ (id)allocWithZoneHook { [self doesNotRecognizeSelector:_cmd]; return nil; } -+(id)alloCWithZonePrototype:( NSZone* )zone_ ++ (id)alloCWithZonePrototype { - return [ JFFNSObjectInstancesCounter instancesCounterAllocatorForClass: [ self class ] - nativeAllocor: ^id( void ) - { - return [ self allocWithZoneHook: zone_ ]; - } ]; + return [JFFNSObjectInstancesCounter instancesCounterAllocatorForClass:[self class] + nativeAllocor:^id(void) { + + return [self allocWithZoneHook]; + }]; } -+(id)alloCWithZoneToAdding:( NSZone* )zone_ ++ (id)alloCWithZoneToAdding { return [JFFNSObjectInstancesCounter instancesCounterAllocatorForClass:[self class] - nativeAllocor:^id(void) - { - return [super allocWithZone:zone_]; + nativeAllocor:^id(void) { + + return [super alloc]; }]; } --(void)enableInstancesCountingForClass:( Class )class_ +- (void)enableInstancesCountingForClass:(Class)class { - @synchronized( self ) - { - NSString* className_ = NSStringFromClass( class_ ); - NSNumber* number_ = self->_instancesNumberByClassName[ className_ ]; - if ( !number_ ) - { - self->_instancesNumberByClassName[ className_ ] = @0; - + @synchronized(self) { + + NSString *className = NSStringFromClass(class); + NSNumber *number = _instancesNumberByClassName[className]; + if (!number) { + + _instancesNumberByClassName[className] = @0; + { - BOOL methodAdded_ = [ [ self class ] addClassMethodIfNeedWithSelector:@selector(alloCWithZoneToAdding:) - toClass:class_ - newMethodSelector:@selector(allocWithZone:)]; - - if (!methodAdded_) { + BOOL methodAdded = [[self class] addClassMethodIfNeedWithSelector:@selector(alloCWithZoneToAdding) + toClass:class + newMethodSelector:@selector(alloc)]; + + if (!methodAdded) { // create name allocWithZoneHook dynamicaly and allocWithZonePrototype use block instead - [[self class] hookClassMethodForClass:class_ - withSelector:@selector(allocWithZone:) - prototypeMethodSelector:@selector(alloCWithZonePrototype:) - hookMethodSelector:@selector(allocWithZoneHook:)]; + [[self class] hookClassMethodForClass:class + withSelector:@selector(alloc) + prototypeMethodSelector:@selector(alloCWithZonePrototype) + hookMethodSelector:@selector(allocWithZoneHook)]; } } } } } --(NSUInteger)instancesCountForClass:( Class )class_ +- (NSUInteger)instancesCountForClass:(Class)class { - @synchronized( self ) + @synchronized(self) { - NSString* className_ = NSStringFromClass( class_ ); - NSNumber* number_ = self->_instancesNumberByClassName[ className_ ]; - return [ number_ unsignedIntValue ]; + NSString *className = NSStringFromClass(class); + NSNumber *number = _instancesNumberByClassName[className]; + return [number unsignedIntValue]; } } @@ -148,7 +148,7 @@ -(NSUInteger)instancesCountForClass:( Class )class_ @implementation JFFOnDeallocBlockOwner (InstancesCount) -+(void)enableInstancesCounting ++ (void)enableInstancesCounting { NSAssert(NO, @"Can not enable enstances counting for this class"); } @@ -157,14 +157,14 @@ +(void)enableInstancesCounting @implementation NSObject (InstancesCount) -+(void)enableInstancesCounting ++ (void)enableInstancesCounting { - [ [ JFFNSObjectInstancesCounter sharedObjectInstancesCounter ] enableInstancesCountingForClass: [ self class ] ]; + [[JFFNSObjectInstancesCounter sharedObjectInstancesCounter] enableInstancesCountingForClass:[self class]]; } -+(NSUInteger)instancesCount ++ (NSUInteger)instancesCount { - return [ [ JFFNSObjectInstancesCounter sharedObjectInstancesCounter ] instancesCountForClass: [ self class ] ]; + return [[JFFNSObjectInstancesCounter sharedObjectInstancesCounter] instancesCountForClass:[self class]]; } @end diff --git a/lib/JFFTestTools/JFFTestTools/performTimeCalculator.h b/lib/JFFTestTools/JFFTestTools/performTimeCalculator.h deleted file mode 100755 index 9943be1..0000000 --- a/lib/JFFTestTools/JFFTestTools/performTimeCalculator.h +++ /dev/null @@ -1,5 +0,0 @@ -#include - -#import - -NSTimeInterval performTimeCalculator( JFFSimpleBlock block_, NSUInteger times_ ); diff --git a/lib/JFFTestTools/JFFTestTools/performTimeCalculator.m b/lib/JFFTestTools/JFFTestTools/performTimeCalculator.m deleted file mode 100755 index e210f88..0000000 --- a/lib/JFFTestTools/JFFTestTools/performTimeCalculator.m +++ /dev/null @@ -1,18 +0,0 @@ -#import "performTimeCalculator.h" - -#include - -NSTimeInterval performTimeCalculator(JFFSimpleBlock block, NSUInteger times) -{ - NSTimeInterval result = DBL_MAX; - - for (NSUInteger index = 0; index < times; ++index) { - NSDate* startDate = [NSDate new]; - @autoreleasepool { - block(); - } - NSDate* endDate = [NSDate new]; - result = fmin(result, [endDate timeIntervalSinceDate:startDate]); - } - return result; -} diff --git a/lib/JFFTestTools/JFFTestTools/testTools.h b/lib/JFFTestTools/JFFTestTools/testTools.h new file mode 100644 index 0000000..420be0b --- /dev/null +++ b/lib/JFFTestTools/JFFTestTools/testTools.h @@ -0,0 +1,8 @@ +#include + +#import + +NSTimeInterval performTimeCalculator(JFFSimpleBlock block, NSUInteger times); + +void performAsyncRequestOnMainThreadWithBlock(void (^block)(JFFSimpleBlock), + NSTimeInterval timeout); diff --git a/lib/JFFTestTools/JFFTestTools/testTools.m b/lib/JFFTestTools/JFFTestTools/testTools.m new file mode 100644 index 0000000..5319090 --- /dev/null +++ b/lib/JFFTestTools/JFFTestTools/testTools.m @@ -0,0 +1,48 @@ +#import "testTools.h" + +#include + +NSTimeInterval performTimeCalculator(JFFSimpleBlock block, NSUInteger times) +{ + NSTimeInterval result = DBL_MAX; + + for (NSUInteger index = 0; index < times; ++index) { + NSDate* startDate = [NSDate new]; + @autoreleasepool { + block(); + } + NSDate* endDate = [NSDate new]; + result = fmin(result, [endDate timeIntervalSinceDate:startDate]); + } + return result; +} + +void performAsyncRequestOnMainThreadWithBlock(void (^block)(JFFSimpleBlock), + NSTimeInterval timeout) +{ + NSCondition *condition = [NSCondition new]; + + block = [block copy]; + void (^autoreleaseBlock)() = ^void() { + + @autoreleasepool { + + void (^didFinishCallback)(void) = ^void() { + + [condition lock]; + [condition signal]; + [condition unlock]; + }; + + block([didFinishCallback copy]); + } + }; + + dispatch_async(dispatch_get_main_queue(), autoreleaseBlock); + + NSDate *timeoutDate = [[NSDate new] dateByAddingTimeInterval:timeout]; + + [condition lock]; + [condition waitUntilDate:timeoutDate]; + [condition unlock]; +} \ No newline at end of file diff --git a/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.h b/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.h index 1f9e37b..ec8c566 100755 --- a/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.h +++ b/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.h @@ -5,17 +5,17 @@ @interface JFFActionSheetsContainer : NSObject -+(id)sharedActionSheetsContainer; ++ (instancetype)sharedActionSheetsContainer; --(NSUInteger)count; +- (NSUInteger)count; --(void)addActionSheet:( JFFActionSheet* )actionSheet_ withView:( UIView* )view_; --(void)removeActionSheet:( JFFActionSheet* )actionSheet_; --(BOOL)containsActionSheet:( JFFActionSheet* )actionSheet_; +- (void)addActionSheet:(JFFActionSheet *)actionSheet_ withView:(UIView *)view; +- (void)removeActionSheet:(JFFActionSheet *)actionSheet_; +- (BOOL)containsActionSheet:(JFFActionSheet *)actionSheet_; --(JFFPendingActionSheet*)firstPendingActionSheet; +- (JFFPendingActionSheet *)firstPendingActionSheet; --(NSArray*)allActionSheets; --(void)removeAllActionSheets; +- (NSArray *)allActionSheets; +- (void)removeAllActionSheets; @end diff --git a/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.m b/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.m index ee6db9e..a2c99eb 100644 --- a/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.m +++ b/lib/JFFUI/AlertView/Detail/JFFActionSheetsContainer.m @@ -5,20 +5,19 @@ @implementation JFFActionSheetsContainer { - NSMutableArray* _activeActionSheets; + NSMutableArray *_activeActionSheets; } -+(id)sharedActionSheetsContainer ++ (instancetype)sharedActionSheetsContainer { static id instance_ = nil; - if ( !instance_ ) - { - instance_ = [ self new ]; + if (!instance_) { + instance_ = [self new]; } return instance_; } --(void)addActionSheet:( JFFActionSheet* )actionSheet_ withView:( UIView* )view_ +- (void)addActionSheet:( JFFActionSheet* )actionSheet_ withView:( UIView* )view_ { if ( !_activeActionSheets ) { @@ -31,7 +30,7 @@ -(void)addActionSheet:( JFFActionSheet* )actionSheet_ withView:( UIView* )view_ [ _activeActionSheets addObject: pendingActionSheet_ ]; } --(void)removeActionSheet:( JFFActionSheet* )actionSheet_ +- (void)removeActionSheet:( JFFActionSheet* )actionSheet_ { if ( !_activeActionSheets ) return; @@ -46,39 +45,38 @@ -(void)removeActionSheet:( JFFActionSheet* )actionSheet_ - (BOOL)containsActionSheet:(JFFActionSheet *)actionSheet { - return [_activeActionSheets any:^BOOL(JFFPendingActionSheet *pendingActionSheet) - { + return [_activeActionSheets any:^BOOL(JFFPendingActionSheet *pendingActionSheet) { return pendingActionSheet.actionSheet == actionSheet; }]; } --(JFFPendingActionSheet*)firstPendingActionSheet +- (JFFPendingActionSheet *)firstPendingActionSheet { - return [ _activeActionSheets noThrowObjectAtIndex: 0 ]; + return [_activeActionSheets firstObject]; } --(NSUInteger)count +- (NSUInteger)count { return [ _activeActionSheets count ]; } --(JFFPendingActionSheet*)objectToRemove:( JFFActionSheet* )actionSheet_ +- (JFFPendingActionSheet *)objectToRemove:(JFFActionSheet *)actionSheet_ { - return [_activeActionSheets firstMatch:^BOOL(JFFPendingActionSheet *pendingActionSheet_) - { + return [_activeActionSheets firstMatch:^BOOL(JFFPendingActionSheet *pendingActionSheet_) { + return pendingActionSheet_.actionSheet == actionSheet_; }]; } --(NSArray*)allActionSheets +- (NSArray *)allActionSheets { - return [ _activeActionSheets map: ^id( JFFPendingActionSheet* object_ ) + return [_activeActionSheets map:^id(JFFPendingActionSheet *object) { - return object_.actionSheet; - } ]; + return object.actionSheet; + }]; } --(void)removeAllActionSheets +- (void)removeAllActionSheets { _activeActionSheets = nil; } diff --git a/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.h b/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.h index 23885cb..0e168a3 100644 --- a/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.h +++ b/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.h @@ -6,7 +6,7 @@ @interface JFFAlertViewsContainer : NSObject -+ (id)sharedAlertViewsContainer; ++ (instancetype)sharedAlertViewsContainer; - (NSUInteger)count; diff --git a/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.m b/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.m index c5b08b1..e65bbe5 100644 --- a/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.m +++ b/lib/JFFUI/AlertView/Detail/JFFAlertViewsContainer.m @@ -7,7 +7,7 @@ @implementation JFFAlertViewsContainer NSMutableArray *_activeAlertViews; } -+ (id)sharedAlertViewsContainer ++ (instancetype)sharedAlertViewsContainer { static id instance = nil; if (!instance) @@ -19,8 +19,7 @@ + (id)sharedAlertViewsContainer - (void)addAlertView:(JFFAlertView *)alertView { - if (!_activeAlertViews) - { + if (!_activeAlertViews) { _activeAlertViews = [[NSMutableArray alloc] initWithCapacity:1]; } @@ -45,9 +44,9 @@ - (BOOL)containsAlertView:(JFFAlertView *)alertView return [_activeAlertViews containsObject:alertView]; } -- (JFFAlertView*)firstAlertView +- (JFFAlertView *)firstAlertView { - return [_activeAlertViews noThrowObjectAtIndex:0]; + return [_activeAlertViews firstObject]; } - (NSUInteger)count diff --git a/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.h b/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.h index 8c3f92b..a0b0698 100644 --- a/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.h +++ b/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.h @@ -4,10 +4,10 @@ @interface JFFPendingActionSheet : NSObject -@property ( nonatomic ) JFFActionSheet* actionSheet; -@property ( nonatomic ) UIView* view; +@property (nonatomic) JFFActionSheet *actionSheet; +@property (nonatomic) UIView *view; --(id)initWithActionSheet:( JFFActionSheet* )actionSheet_ - view:( UIView* )view_; +- (instancetype)initWithActionSheet:(JFFActionSheet *)actionSheet + view:(UIView *)view; @end diff --git a/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.m b/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.m index ad4b243..a251939 100755 --- a/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.m +++ b/lib/JFFUI/AlertView/Detail/JFFPendingActionSheet.m @@ -2,15 +2,15 @@ @implementation JFFPendingActionSheet --(id)initWithActionSheet:( JFFActionSheet* )actionSheet_ - view:( UIView* )view_ +- (instancetype)initWithActionSheet:(JFFActionSheet *)actionSheet + view:(UIView *)view { - self = [ super init ]; + self = [super init]; - if ( self ) - { - self.actionSheet = actionSheet_; - self.view = view_; + if (self) { + + self.actionSheet = actionSheet; + self.view = view; } return self; diff --git a/lib/JFFUI/AlertView/Detail/JFFWaitAlertView.mm b/lib/JFFUI/AlertView/Detail/JFFWaitAlertView.mm index 641979d..07c2abe 100644 --- a/lib/JFFUI/AlertView/Detail/JFFWaitAlertView.mm +++ b/lib/JFFUI/AlertView/Detail/JFFWaitAlertView.mm @@ -4,13 +4,13 @@ @interface JFFAlertView (JFFWaitAlertView) -@property ( nonatomic, readonly ) UIAlertView* alertView; +@property (nonatomic, readonly) UIAlertView *alertView; @end @implementation JFFWaitAlertView --(void)showActivityIndicatorView +- (void)showActivityIndicatorView { UIActivityIndicatorView* indicator_ = [ [ UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge ]; @@ -23,7 +23,7 @@ -(void)showActivityIndicatorView #pragma mark UIAlertViewDelegate --(void)willPresentAlertView:( UIAlertView* )alertView_ +- (void)willPresentAlertView:(UIAlertView *)alertView_ { SEL selector_ = @selector( willPresentAlertView: ); if ( [ [ self superclass ] hasInstanceMethodWithSelector: selector_ ] ) diff --git a/lib/JFFUI/AlertView/Detail/NSObject+JFFAlertButton.h b/lib/JFFUI/AlertView/Detail/NSObject+JFFAlertButton.h index 6e0867c..d0fa174 100755 --- a/lib/JFFUI/AlertView/Detail/NSObject+JFFAlertButton.h +++ b/lib/JFFUI/AlertView/Detail/NSObject+JFFAlertButton.h @@ -4,6 +4,6 @@ @interface NSObject (JFFAlertButton) --(JFFAlertButton*)toAlertButton; +- (JFFAlertButton *)toAlertButton; @end diff --git a/lib/JFFUI/AlertView/JFFActionSheet.h b/lib/JFFUI/AlertView/JFFActionSheet.h index 2afcb83..3fd1691 100644 --- a/lib/JFFUI/AlertView/JFFActionSheet.h +++ b/lib/JFFUI/AlertView/JFFActionSheet.h @@ -4,26 +4,26 @@ @interface JFFActionSheet : NSObject -@property ( nonatomic ) BOOL dismissBeforeEnterBackground; -@property ( nonatomic ) NSInteger cancelButtonIndex; -@property ( nonatomic, readonly ) NSInteger numberOfButtons; +@property (nonatomic) BOOL dismissBeforeEnterBackground; +@property (nonatomic) NSInteger cancelButtonIndex; +@property (nonatomic, readonly) NSInteger numberOfButtons; //cancelButtonTitle, otherButtonTitles - pass NSString(button title) or JFFAlertButton -+(id)actionSheetWithTitle:( NSString* )title_ - cancelButtonTitle:( id )cancel_button_title_ - destructiveButtonTitle:( id )destructive_button_title_ - otherButtonTitles:( id )other_button_titles_, ... NS_REQUIRES_NIL_TERMINATION; ++ (instancetype)actionSheetWithTitle:(NSString *)title + cancelButtonTitle:(id)cancelButtonTitle + destructiveButtonTitle:(id)destructiveButtonTitle + otherButtonTitles:(id)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; --(void)showInView:( UIView* )view_; +- (void)showInView:( UIView* )view_; --(void)dismissWithClickedButtonIndex:( NSInteger )buttonIndex_ - animated:( BOOL )animated_; +- (void)dismissWithClickedButtonIndex:( NSInteger )buttonIndex_ + animated:( BOOL )animated_; //pass NSString(button title) or JFFAlertButton --(NSInteger)addActionButton:( id )alertButton_; +- (NSInteger)addActionButton:( id )alertButton_; --(void)addActionButtonWithTitle:( NSString* )title_ ation:( JFFSimpleBlock )action_; +- (void)addActionButtonWithTitle:( NSString* )title_ ation:( JFFSimpleBlock )action_; -+(void)dismissAllActionSheets; ++ (void)dismissAllActionSheets; @end diff --git a/lib/JFFUI/AlertView/JFFActionSheet.m b/lib/JFFUI/AlertView/JFFActionSheet.m index 117da8d..6e9c1d2 100644 --- a/lib/JFFUI/AlertView/JFFActionSheet.m +++ b/lib/JFFUI/AlertView/JFFActionSheet.m @@ -11,51 +11,51 @@ @interface JFFActionSheet () < UIActionSheetDelegate > @implementation JFFActionSheet { - NSMutableArray* _alertButtons; - UIActionSheet* _actionSheet; + NSMutableArray *_alertButtons; + UIActionSheet *_actionSheet; } --(void)dealloc +- (void)dealloc { - [ [ NSNotificationCenter defaultCenter ] removeObserver: self ]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } -+(void)dismissAllActionSheets ++ (void)dismissAllActionSheets { - JFFActionSheetsContainer* container_ = [ JFFActionSheetsContainer sharedActionSheetsContainer ]; - - for ( JFFActionSheet* actionSheet_ in [ container_ allActionSheets ] ) - { - [ actionSheet_ dismissWithClickedButtonIndex: [ actionSheet_ cancelButtonIndex ] - animated: NO ]; + JFFActionSheetsContainer *container = [ JFFActionSheetsContainer sharedActionSheetsContainer ]; + + for (JFFActionSheet *actionSheet in [container allActionSheets]) { + + [actionSheet dismissWithClickedButtonIndex:[actionSheet cancelButtonIndex] + animated:NO]; } - [ container_ removeAllActionSheets ]; + [container removeAllActionSheets]; } --(id)initWithTitle:( NSString* )title_ - cancelButtonTitle:( NSString* )cancelButtonTitle_ -destructiveButtonTitle:( NSString* )destructiveButtonTitle_ -otherButtonTitlesArray:( NSArray* )otherButtonTitles_ +- (instancetype)initWithTitle:(NSString *)title + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + otherButtonTitlesArray:(NSArray *)otherButtonTitles { - self = [ super init ]; - - if ( self ) - { - _actionSheet = [ [ UIActionSheet alloc ] initWithTitle: title_ - delegate: self - cancelButtonTitle: nil - destructiveButtonTitle: destructiveButtonTitle_ - otherButtonTitles: nil ]; - - for ( NSString* buttonTitle_ in otherButtonTitles_ ) - { - [ _actionSheet addButtonWithTitle: buttonTitle_ ]; + self = [super init]; + + if (self) { + + _actionSheet = [[UIActionSheet alloc] initWithTitle:title + delegate:self + cancelButtonTitle:nil + destructiveButtonTitle:destructiveButtonTitle + otherButtonTitles:nil]; + + for (NSString *buttonTitle in otherButtonTitles) { + + [_actionSheet addButtonWithTitle:buttonTitle]; } - if (cancelButtonTitle_) - { - [_actionSheet addButtonWithTitle:cancelButtonTitle_]; + if (cancelButtonTitle) { + + [_actionSheet addButtonWithTitle:cancelButtonTitle]; _actionSheet.cancelButtonIndex = _actionSheet.numberOfButtons - 1; } @@ -68,7 +68,7 @@ -(id)initWithTitle:( NSString* )title_ return self; } --(NSInteger)addActionButton:( id )alertButtonObject_ +- (NSInteger)addActionButton:(id)alertButtonObject_ { JFFAlertButton* alertButton_ = [ alertButtonObject_ toAlertButton ]; NSInteger index_ = [ _actionSheet addButtonWithTitle: alertButton_.title ]; @@ -86,10 +86,10 @@ - (NSInteger)addButtonWithTitle:(NSString *)title return [self addActionButton:title]; } -+ (id)actionSheetWithTitle:(NSString *)title - cancelButtonTitle:(id)cancelButtonTitle - destructiveButtonTitle:(id)destructiveButtonTitle - otherButtonTitles:(id)otherButtonTitles, ... ++ (instancetype)actionSheetWithTitle:(NSString *)title + cancelButtonTitle:(id)cancelButtonTitle + destructiveButtonTitle:(id)destructiveButtonTitle + otherButtonTitles:(id)otherButtonTitles, ... { NSMutableArray *otherActionButtons = [NSMutableArray new]; NSMutableArray *otherActionStringTitles = [NSMutableArray new]; @@ -128,7 +128,7 @@ + (id)actionSheetWithTitle:(NSString *)title return actionSheet; } --(void)showInView:( UIView* )view_ +- (void)showInView:(UIView *)view_ { JFFActionSheetsContainer* container_ = [ JFFActionSheetsContainer sharedActionSheetsContainer ]; @@ -140,17 +140,17 @@ -(void)showInView:( UIView* )view_ [ container_ addActionSheet: self withView: view_ ]; } --(void)applicationDidEnterBackground:( id )sender_ +- (void)applicationDidEnterBackground:( id )sender_ { - if ( self.dismissBeforeEnterBackground ) - { + if (self.dismissBeforeEnterBackground) { + [ self dismissWithClickedButtonIndex: [ self cancelButtonIndex ] animated: NO ]; } } #pragma mark UIActionSheetDelegate --(void)actionSheet:( UIActionSheet* )actionSheet_ clickedButtonAtIndex:( NSInteger )button_index_ +- (void)actionSheet:( UIActionSheet* )actionSheet_ clickedButtonAtIndex:( NSInteger )button_index_ { JFFAlertButton* alertButton_ = _alertButtons[ button_index_ ]; @@ -158,7 +158,7 @@ -(void)actionSheet:( UIActionSheet* )actionSheet_ clickedButtonAtIndex:( NSInteg alertButton_.action(); } --(void)actionSheet:( UIActionSheet* )actionSheet_ didDismissWithButtonIndex:( NSInteger )button_index_ +- (void)actionSheet:( UIActionSheet* )actionSheet_ didDismissWithButtonIndex:( NSInteger )button_index_ { JFFActionSheetsContainer* container_ = [ JFFActionSheetsContainer sharedActionSheetsContainer ]; [ container_ removeActionSheet: self ]; @@ -168,15 +168,29 @@ -(void)actionSheet:( UIActionSheet* )actionSheet_ didDismissWithButtonIndex:( NS [ actionSheetsStruct_.actionSheet->_actionSheet showInView: actionSheetsStruct_.view ]; } +- (void)willPresentActionSheet:(UIActionSheet *)actionSheet +{ + NSArray *buttons = [actionSheet.subviews select:^BOOL(UIView* view) { + return [view isKindOfClass:[UIButton class]]; + }]; + + [_alertButtons enumerateObjectsUsingBlock:^(JFFAlertButton *button, NSUInteger idx, BOOL *stop) { + + if (button.backgroundImage) { + [buttons[idx] setBackgroundImage:button.backgroundImage forState:UIControlStateNormal]; + } + }]; +} + #pragma mark - #pragma mark forward ActionSeet methods --(id)forwardingTargetForSelector:( SEL )selector_ +- (id)forwardingTargetForSelector:(SEL)selector { return _actionSheet; } --(void)dismissWithClickedButtonIndex:( NSInteger )buttonIndex_ animated:( BOOL )animated_ +- (void)dismissWithClickedButtonIndex:( NSInteger )buttonIndex_ animated:( BOOL )animated_ { JFFActionSheetsContainer* container_ = [ JFFActionSheetsContainer sharedActionSheetsContainer ]; diff --git a/lib/JFFUI/AlertView/JFFAlertButton.h b/lib/JFFUI/AlertView/JFFAlertButton.h index 6e31392..a85d302 100644 --- a/lib/JFFUI/AlertView/JFFAlertButton.h +++ b/lib/JFFUI/AlertView/JFFAlertButton.h @@ -2,11 +2,14 @@ #import +@class UIImage; + @interface JFFAlertButton : NSObject @property (nonatomic) NSString *title; +@property (nonatomic) UIImage *backgroundImage; @property (nonatomic, copy) JFFSimpleBlock action; -+ (id)newAlertButton:(NSString *)title action:(JFFSimpleBlock)action; ++ (instancetype)newAlertButton:(NSString *)title action:(JFFSimpleBlock)action; @end diff --git a/lib/JFFUI/AlertView/JFFAlertButton.m b/lib/JFFUI/AlertView/JFFAlertButton.m index 6aaf39a..1262c68 100644 --- a/lib/JFFUI/AlertView/JFFAlertButton.m +++ b/lib/JFFUI/AlertView/JFFAlertButton.m @@ -2,7 +2,7 @@ @implementation JFFAlertButton -- (id)initButton:(NSString *)title action:(JFFSimpleBlock)action +- (instancetype)initButton:(NSString *)title action:(JFFSimpleBlock)action { self = [super init]; @@ -15,7 +15,7 @@ - (id)initButton:(NSString *)title action:(JFFSimpleBlock)action return self; } -+ (id)newAlertButton:(NSString *)title action:(JFFSimpleBlock)action ++ (instancetype)newAlertButton:(NSString *)title action:(JFFSimpleBlock)action { return [[self alloc] initButton:title action:action]; } diff --git a/lib/JFFUI/AlertView/JFFAlertView.h b/lib/JFFUI/AlertView/JFFAlertView.h index bcdf9e3..015294f 100644 --- a/lib/JFFUI/AlertView/JFFAlertView.h +++ b/lib/JFFUI/AlertView/JFFAlertView.h @@ -1,19 +1,22 @@ #import +#import + @class JFFAlertButton; @interface JFFAlertView : NSObject @property (nonatomic) BOOL dismissBeforeEnterBackground; @property (nonatomic, copy) JFFSimpleBlock didPresentHandler; +@property (nonatomic, copy) JFFSimpleBlock didDismissHandler; @property (nonatomic, readonly) BOOL isOnScreen; //cancelButtonTitle, otherButtonTitles - pass NSString(button title) or JFFAlertButton -+ (id)alertWithTitle:(NSString *)title - message:(NSString *)message - cancelButtonTitle:(id)cancelButtonTitle - otherButtonTitles:(id)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; ++ (instancetype)alertWithTitle:(NSString *)title + message:(NSString *)message + cancelButtonTitle:(id)cancelButtonTitle + otherButtonTitles:(id)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; //pass NSString(button title) or JFFAlertButton - (void)addAlertButton:(id)alertButton; @@ -21,22 +24,21 @@ - (void)addAlertButtonWithTitle:(NSString *)title action:(JFFSimpleBlock)action; -+ (id)waitAlertWithTitle:(NSString *)title - cancelButton:(JFFAlertButton *)button; ++ (instancetype)waitAlertWithTitle:(NSString *)title + cancelButton:(JFFAlertButton *)button; + (void)dismissAllAlertViews; + (void)showAlertWithTitle:(NSString *)title description:(NSString *)description; ++ (void)showAlertWithTitle:(NSString *)title + description:(NSString *)description + exclusive:(BOOL)isExclusive; + + (void)showExclusiveAlertWithTitle:(NSString *)title description:(NSString *)description; -+(void)showAlertWithTitle:( NSString* )title_ - description:( NSString* )description_ - exclusive:( BOOL )isExclusive_; - - + (void)showErrorWithDescription:(NSString *)description; + (void)showExclusiveErrorWithDescription:(NSString *)description; + (void)showInformationWithDescription:(NSString *)description; diff --git a/lib/JFFUI/AlertView/JFFAlertView.m b/lib/JFFUI/AlertView/JFFAlertView.m index 9f9751e..5493974 100644 --- a/lib/JFFUI/AlertView/JFFAlertView.m +++ b/lib/JFFUI/AlertView/JFFAlertView.m @@ -7,7 +7,7 @@ #import "JFFWaitAlertView.h" -@interface JFFAlertView () < UIAlertViewDelegate > +@interface JFFAlertView () + (void)activeAlertsAddAlert:(JFFAlertView *)alertView; - (void)forceShow; @@ -19,7 +19,7 @@ @implementation JFFAlertView BOOL _exclusive; NSMutableArray * _alertButtons; UIAlertView * _alertView ; - + BOOL _ignoreDismiss; } @@ -27,7 +27,7 @@ @implementation JFFAlertView - (void)dealloc { - [NSThread assertMainThread]; + NSParameterAssert([NSThread isMainThread]); _alertView.delegate = nil; [self stopMonitoringBackgroundEvents]; @@ -93,6 +93,24 @@ + (void)showAlertWithTitle:(NSString *)title [alert show]; } ++ (void)showAlertWithTitle:(NSString *)title + description:(NSString *)description + exclusive:(BOOL)isExclusive +{ + JFFAlertView *alert = [JFFAlertView alertWithTitle:title + message:description + cancelButtonTitle:NSLocalizedString(@"OK", nil) + otherButtonTitles:nil]; + + if (isExclusive) { + + [alert exclusiveShow]; + } else { + + [alert show]; + } +} + + (void)showExclusiveAlertWithTitle:(NSString *)title description:(NSString *)description { @@ -112,7 +130,7 @@ + (void)showErrorWithDescription:(NSString *)description + (void)showInformationWithDescription:(NSString *)description { - [self showAlertWithTitle:NSLocalizedString(@"INFORMATION", nil) + [self showAlertWithTitle:NSLocalizedString(@"JFF_ALERT_INFORMATION", nil) description:description]; } @@ -129,10 +147,10 @@ + (void)showExclusiveAlertWithDescription:(NSString *)description description:description]; } -+ (id)waitAlertWithTitle:(NSString *)title - cancelButton:(JFFAlertButton *)button ++ (instancetype)waitAlertWithTitle:(NSString *)title + cancelButton:(JFFAlertButton *)button { - button = button ?: [NSLocalizedString(@"CANCEL", nil) toAlertButton]; + button = button ?: [NSLocalizedString(@"CANCEL_ACTION", nil) toAlertButton]; title = [title ?: @"" stringByAppendingString:@"\n\n"]; @@ -146,35 +164,33 @@ + (id)waitAlertWithTitle:(NSString *)title return alertView; } -- (id)initWithTitle:(NSString *)title - message:(NSString *)message - delegate:(id /**/)delegate - cancelButtonTitle:(NSString *)cancelButtonTitle - otherButtonTitles:(NSString *)otherButtonTitles, ... +- (instancetype)initWithTitle:(NSString *)title + message:(NSString *)message + delegate:(id /**/)delegate + cancelButtonTitle:(NSString *)cancelButtonTitle + otherButtonTitles:(NSString *)otherButtonTitles, ... { NSAssert(NO, @"dont use this constructor of JFFAlertView"); return nil; } -- (id)initWithTitle:(NSString *)title - message:(NSString *)message - cancelButtonTitle:(NSString *)cancelButtonTitle -otherButtonTitlesArray:(NSArray *)otherButtonTitles +- (instancetype)initWithTitle:(NSString *)title + message:(NSString *)message + cancelButtonTitle:(NSString *)cancelButtonTitle + otherButtonTitlesArray:(NSArray *)otherButtonTitles { self = [super init]; - if (nil == self) - { + if (nil == self) { return nil; } _alertView = [[UIAlertView alloc] initWithTitle:title - message:message - delegate:self - cancelButtonTitle:cancelButtonTitle - otherButtonTitles:nil]; - - if (nil == _alertView) - { + message:message + delegate:self + cancelButtonTitle:cancelButtonTitle + otherButtonTitles:nil]; + + if (nil == _alertView) { return nil; } @@ -215,12 +231,12 @@ - (NSInteger)addButtonWithTitle:(NSString *)title return [self addAlertButtonWithIndex:title]; } -+ (id)alertWithTitle:(NSString *)title - message:(NSString *)message - cancelButtonTitle:(id)cancelButtonTitle - otherButtonTitles:(id)otherButtonTitles, ... ++ (instancetype)alertWithTitle:(NSString *)title + message:(NSString *)message + cancelButtonTitle:(id)cancelButtonTitle + otherButtonTitles:(id)otherButtonTitles, ... { - [NSThread assertMainThread]; + NSParameterAssert([NSThread isMainThread]); NSMutableArray *otherAlertButtons = [NSMutableArray new]; NSMutableArray *otherAlertStringTitles = [NSMutableArray new]; @@ -235,11 +251,11 @@ + (id)alertWithTitle:(NSString *)title [otherAlertButtons addObject:alertButton]; [otherAlertStringTitles addObject:alertButton.title]; } - va_end( args ); + va_end(args); JFFAlertButton *cancelButton = [cancelButtonTitle toAlertButton]; - if (cancelButton) - { + if (cancelButton) { + [otherAlertButtons insertObject:cancelButton atIndex:0]; } @@ -283,8 +299,7 @@ - (void)exclusiveShow - (void)applicationDidEnterBackground:(id)sender { - if (self.dismissBeforeEnterBackground) - { + if (_dismissBeforeEnterBackground) { [self forceDismiss]; } } @@ -300,8 +315,8 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto { JFFAlertButton *alertButton = _alertButtons[buttonIndex]; - if (alertButton) - { + if (alertButton) { + _ignoreDismiss = YES; alertButton.action(); _ignoreDismiss = NO; @@ -316,10 +331,15 @@ - (void)didPresentAlertView:(UIAlertView *)alertView - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { + JFFSimpleBlock didDismissHandler = _didDismissHandler; + [[self class] activeAlertsRemoveAlert:self]; JFFAlertViewsContainer *container = [JFFAlertViewsContainer sharedAlertViewsContainer]; [[container firstAlertView] forceShow]; + + if (didDismissHandler) + didDismissHandler(); } - (BOOL)isOnScreen @@ -344,23 +364,4 @@ - (void)stopMonitoringBackgroundEvents [[NSNotificationCenter defaultCenter] removeObserver:self]; } -+(void)showAlertWithTitle:( NSString* )title_ - description:( NSString* )description_ - exclusive:( BOOL )isExclusive_ -{ - JFFAlertView* alert_ = [ JFFAlertView alertWithTitle: title_ - message: description_ - cancelButtonTitle: NSLocalizedString( @"OK", nil ) - otherButtonTitles: nil ]; - - if ( isExclusive_ ) - { - [ alert_ exclusiveShow ]; - } - else - { - [ alert_ show ]; - } -} - @end diff --git a/lib/JFFUI/Categories/JFFAlertView+Async.h b/lib/JFFUI/Categories/JFFAlertView+Async.h new file mode 100644 index 0000000..1bf66a5 --- /dev/null +++ b/lib/JFFUI/Categories/JFFAlertView+Async.h @@ -0,0 +1,13 @@ +#import + +#import + +#import + +typedef JFFAlertView*(^JFFAlertViewBuilder)(); + +@interface JFFAlertView (Async) + ++ (JFFAsyncOperation)showAlerLoaderWithBuilder:(JFFAlertViewBuilder)builder; + +@end diff --git a/lib/JFFUI/Categories/JFFAlertView+Async.m b/lib/JFFUI/Categories/JFFAlertView+Async.m new file mode 100644 index 0000000..4ebd060 --- /dev/null +++ b/lib/JFFUI/Categories/JFFAlertView+Async.m @@ -0,0 +1,64 @@ +#import "JFFAlertView+Async.h" + +#import + +@interface JFFShowAlerLoader : NSObject +@end + +@implementation JFFShowAlerLoader +{ +@public + JFFAlertView *_alertView; +} + +- (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler + cancelHandler:(JFFAsyncOperationInterfaceCancelHandler)cancelHandler + progressHandler:(JFFAsyncOperationInterfaceProgressHandler)progress +{ + if (!_alertView) { + + if (cancelHandler) + cancelHandler(YES); + return; + } + + _alertView.didDismissHandler = ^() { + + if (handler) + handler([NSNull new], nil); + }; + + [_alertView show]; +} + +- (void)cancel:(BOOL)canceled +{ + if (canceled) + [_alertView forceDismiss]; +} + +@end + +@implementation JFFAlertView (Async) + ++ (JFFAsyncOperation)showAlerLoaderWithBuilder:(JFFAlertViewBuilder)builder +{ + NSParameterAssert(builder); + builder = [builder copy]; + + JFFAsyncOperationInstanceBuilder objectFactory = ^id() { + + JFFAlertView *alertView = builder(); + + NSParameterAssert([alertView isKindOfClass:[JFFAlertView class]]); + + JFFShowAlerLoader *loader = [JFFShowAlerLoader new]; + + loader->_alertView = alertView; + + return loader; + }; + return buildAsyncOperationWithAdapterFactory(objectFactory); +} + +@end diff --git a/lib/JFFUI/Extensions/UIApplication+OpenApplicationAsyncOp.h b/lib/JFFUI/Categories/UIApplication+OpenApplicationAsyncOp.h similarity index 100% rename from lib/JFFUI/Extensions/UIApplication+OpenApplicationAsyncOp.h rename to lib/JFFUI/Categories/UIApplication+OpenApplicationAsyncOp.h diff --git a/lib/JFFUI/Extensions/UIApplication+OpenApplicationAsyncOp.m b/lib/JFFUI/Categories/UIApplication+OpenApplicationAsyncOp.m similarity index 93% rename from lib/JFFUI/Extensions/UIApplication+OpenApplicationAsyncOp.m rename to lib/JFFUI/Categories/UIApplication+OpenApplicationAsyncOp.m index c5f0f72..78b467e 100644 --- a/lib/JFFUI/Extensions/UIApplication+OpenApplicationAsyncOp.m +++ b/lib/JFFUI/Categories/UIApplication+OpenApplicationAsyncOp.m @@ -12,14 +12,14 @@ @interface JFFOpenApplicationWithURLDelegateProxy : NSObject< JFFAsyncOperationInterface > -@property (nonatomic) NSURL *url; -@property (nonatomic) UIApplication *application; - @end @implementation JFFOpenApplicationWithURLDelegateProxy { JFFAsyncOperationInterfaceResultHandler _handler; +@public + NSURL *_url; + UIApplication *_application; } - (void)asyncOperationWithResultHandler:(JFFAsyncOperationInterfaceResultHandler)handler @@ -68,6 +68,7 @@ - (void)applicationWillEnterForeground:(UIApplication *)application { [self performSelector:@selector(finishWithURL:) timeInterval:.5 + leeway:.1 userInfo:nil repeats:NO]; } @@ -79,11 +80,12 @@ @implementation UIApplication (OpenApplicationAsyncOp) - (JFFAsyncOperation)asyncOperationWithApplicationURL:(NSURL *)url { JFFAsyncOperationInstanceBuilder factory = ^id< JFFAsyncOperationInterface >() { + JFFOpenApplicationWithURLDelegateProxy *proxy = [JFFOpenApplicationWithURLDelegateProxy new]; - proxy.url = url; - proxy.application = self; + proxy->_url = url; + proxy->_application = self; return proxy; }; diff --git a/lib/JFFUI/Categories/UINib+FirstObject.h b/lib/JFFUI/Categories/UINib+FirstObject.h new file mode 100644 index 0000000..91384e8 --- /dev/null +++ b/lib/JFFUI/Categories/UINib+FirstObject.h @@ -0,0 +1,7 @@ +#import + +@interface UINib (FirstObject) + ++ (id)firstObjectOfNibNamed:(NSString *)nibName owner:(id)ownerOrNil; + +@end diff --git a/lib/JFFUI/Extensions/UINib+FirstObject.m b/lib/JFFUI/Categories/UINib+FirstObject.m old mode 100755 new mode 100644 similarity index 77% rename from lib/JFFUI/Extensions/UINib+FirstObject.m rename to lib/JFFUI/Categories/UINib+FirstObject.m index eeed80c..83b867f --- a/lib/JFFUI/Extensions/UINib+FirstObject.m +++ b/lib/JFFUI/Categories/UINib+FirstObject.m @@ -4,7 +4,7 @@ @implementation UINib (FirstObject) + (id)firstObjectOfNibNamed:(NSString *)nibName owner:(id)ownerOrNil { - UINib *nib = [ self nibWithNibName:nibName bundle:nil]; + UINib *nib = [self nibWithNibName:nibName bundle:nil]; return [nib instantiateWithOwner:ownerOrNil options:nil][0]; } diff --git a/lib/JFFUtils/Extensions/UIWebView+UserAgent.h b/lib/JFFUI/Categories/UIWebView+UserAgent.h old mode 100755 new mode 100644 similarity index 100% rename from lib/JFFUtils/Extensions/UIWebView+UserAgent.h rename to lib/JFFUI/Categories/UIWebView+UserAgent.h diff --git a/lib/JFFUtils/Extensions/UIWebView+UserAgent.m b/lib/JFFUI/Categories/UIWebView+UserAgent.m similarity index 78% rename from lib/JFFUtils/Extensions/UIWebView+UserAgent.m rename to lib/JFFUI/Categories/UIWebView+UserAgent.m index a0b8407..375d617 100644 --- a/lib/JFFUtils/Extensions/UIWebView+UserAgent.m +++ b/lib/JFFUI/Categories/UIWebView+UserAgent.m @@ -1,10 +1,10 @@ #import "UIWebView+UserAgent.h" -#include "JGCDAdditions.h" +#import -static NSString* globalUserAgent; +static NSString *globalUserAgent; -static NSString* userAgent() +static NSString *userAgent() { NSString *js = @"navigator.userAgent"; UIWebView *webView = [UIWebView new]; @@ -31,8 +31,11 @@ + (NSString *)threadSafeUserAgent globalUserAgent = userAgent(); }; - safe_dispatch_sync(dispatch_get_main_queue(), - block); + if ([NSThread isMainThread]) { + block(); + } else { + dispatch_sync(dispatch_get_main_queue(), block); + } }); return globalUserAgent; @@ -48,7 +51,7 @@ + (void)setUserAgentAddition:(NSString *)userAgentAddition webViewUserAgent, userAgentAddition]; - NSDictionary *dictionnary = @{@"UserAgent": newUserAgent}; + NSDictionary *dictionnary = @{ @"UserAgent": newUserAgent }; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary]; } diff --git a/lib/JFFUI/Errors/JFFOpenApplicationError.m b/lib/JFFUI/Errors/JFFOpenApplicationError.m index 0adb9db..7e30d87 100644 --- a/lib/JFFUI/Errors/JFFOpenApplicationError.m +++ b/lib/JFFUI/Errors/JFFOpenApplicationError.m @@ -2,9 +2,13 @@ @implementation JFFOpenApplicationError -- (id)init +- (instancetype)init { return [self initWithDescription:NSLocalizedString(@"JFFUI_OPEN_APPLICATION_ERROR", nil)]; } +- (void)writeErrorWithJFFLogger +{ +} + @end diff --git a/lib/JFFUI/Errors/JFFUIError.h b/lib/JFFUI/Errors/JFFUIError.h index f42f20c..c697ffd 100644 --- a/lib/JFFUI/Errors/JFFUIError.h +++ b/lib/JFFUI/Errors/JFFUIError.h @@ -1,5 +1,4 @@ -#import +#import @interface JFFUIError : JFFError - @end diff --git a/lib/JFFUI/Extensions/UINib+FirstObject.h b/lib/JFFUI/Extensions/UINib+FirstObject.h deleted file mode 100755 index 1164da7..0000000 --- a/lib/JFFUI/Extensions/UINib+FirstObject.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface UINib (FirstObject) - -+(id)firstObjectOfNibNamed:( NSString* )nib_name_ owner:( id )owner_or_nil_; - -@end diff --git a/lib/JFFUI/GridView/JFFGridView.h b/lib/JFFUI/GridView/JFFGridView.h new file mode 100644 index 0000000..cb1d585 --- /dev/null +++ b/lib/JFFUI/GridView/JFFGridView.h @@ -0,0 +1,39 @@ +#import + +typedef NS_ENUM(NSUInteger, JFFGridOrientation) +{ + JFFGridOrientationUndefined, + JFFGridOrientationVertical, + JFFGridOrientationGorizontal +}; + +@class JFFRemoveButton; + +@interface JFFGridViewContext : NSObject + +@property (nonatomic) JFFRemoveButton *removeButton; +@property (nonatomic) UIView *view; + +@end + +@protocol JFFGridViewDelegate; + +@interface JFFGridView : UIView + +@property (weak, nonatomic) IBOutlet id delegate; + +@property (nonatomic, readonly) UIScrollView *scrollView; + +- (void)reloadData; +- (void)reloadDataWithRange:(NSRange)range; + +- (void)scrollToIndex:(NSInteger)index; + +- (id)dequeueReusableElementWithIdentifier:(NSString *)identifier; + +- (void)removeElementWithIndex:(NSUInteger)index animated:(BOOL)animated; +- (NSMutableSet *)visibleIndexes; +- (id)elementByIndex:(NSUInteger)index; +- (CGRect)rectForElementWithIndex:(NSUInteger)index; + +@end diff --git a/lib/JFFUI/GridView/JFFGridView.m b/lib/JFFUI/GridView/JFFGridView.m new file mode 100644 index 0000000..5fbe040 --- /dev/null +++ b/lib/JFFUI/GridView/JFFGridView.m @@ -0,0 +1,490 @@ +#import "JFFGridView.h" + +#import "JFFGridViewDelegate.h" + +#import "UIView+AddSubviewAndScale.h" + +#import + +#include + +static NSString *const JFFElementIndex = @"JFFElementIndex"; +static NSInteger const MinColumnCount = 2; + +@implementation UIView (ReuseIdentifier) + ++ (NSString *)jffGridViewReuseIdentifierBase +{ + return NSStringFromClass([self class]); +} + +- (NSString *)jffGridViewReuseIdentifier +{ + return [[self class] jffGridViewReuseIdentifierBase]; +} + +@end + +@implementation JFFGridViewContext +@end + +@interface JFFGridView () + +@property (nonatomic) UIScrollView* scrollView; +@property (nonatomic) CGRect previousFrame; +@property (nonatomic) BOOL forceRelayout; +@property (nonatomic) NSUInteger currentlyUsedIndex; +@property (nonatomic) JFFGridOrientation prevOrientation; + +@property (nonatomic) NSMutableDictionary* reusableElementsByIdentifier; +@property (nonatomic) NSMutableDictionary* elementContextByIndex; + +@property (nonatomic, readonly) CGFloat rowHeight; +@property (nonatomic, readonly) CGFloat colWidth; +@property (nonatomic, readonly) NSUInteger colCount; + +- (void)relayoutElementsAnimated:(BOOL)animated; + +@end + +@implementation JFFGridView + +- (void)dealloc +{ + _scrollView.delegate = nil; +} + +- (void)initialize +{ + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; + + self.scrollView = scrollView; + self.scrollView.delegate = self; + + [self addSubviewAndScale:self.scrollView]; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + + [self initialize]; + + return self; +} + +- (instancetype)init +{ + self = [super init]; + + [self initialize]; + + return self; +} + +- (void)awakeFromNib +{ + [super awakeFromNib]; + + [self initialize]; +} + +- (NSMutableDictionary *)elementContextByIndex +{ + if (!_elementContextByIndex) { + + _elementContextByIndex = [NSMutableDictionary new]; + } + + return _elementContextByIndex; +} + +- (void)setNeedsLayout +{ + self.forceRelayout = YES; + [super setNeedsLayout]; +} + +#pragma mark internal methods + +- (BOOL)isVerticalGrid +{ + return [self.delegate verticalGridView:self]; +} + +- (CGFloat)rowHeight +{ + if ([self isVerticalGrid]) { + + return self.colWidth * [ self.delegate widthHeightRelationInGridView: self ]; + } + return fmax(1.f, self.frame.size.height - [self.delegate verticalOffsetInGridView:self]); +} + +- (CGFloat)colWidth +{ + if ([self isVerticalGrid]) { + + return (self.frame.size.width - [self.delegate horizontalOffsetInGridView:self]) / self.colCount; + } + return self.rowHeight / [ self.delegate widthHeightRelationInGridView: self ]; +} + +- (NSUInteger)colCount +{ + return [self.delegate numberOfElementsInRowInGridView:self]; +} + +- (NSUInteger)firstVisibleIndex +{ + NSInteger fromIndex = 0; + if ([self isVerticalGrid]) { + + fromIndex = floor(self.scrollView.contentOffset.y / self.rowHeight) * self.colCount; + } else { + fromIndex = floor( self.scrollView.contentOffset.x / self.colWidth ); + } + + NSUInteger numberOfElements = [self.delegate numberOfElementsInGridView:self]; + + self.currentlyUsedIndex = fmin(numberOfElements, fmax( 0, fromIndex ) ); + + return fmin( numberOfElements, fmax( 0, fromIndex ) ); +} + +- (NSUInteger)lastVisibleIndex +{ + NSInteger toIndex = 0; + if ([self isVerticalGrid]) { + + CGFloat vericalOffset = [self.delegate verticalOffsetInGridView:self]; + CGFloat bottomScrollOffset = self.scrollView.contentOffset.y - vericalOffset + self.frame.size.height; + toIndex = ceil((bottomScrollOffset) / self.rowHeight) * self.colCount; + } else { + + CGFloat horizontalOffset = [self.delegate horizontalOffsetInGridView:self]; + CGFloat rightScrollOffset = self.scrollView.contentOffset.x - horizontalOffset + self.frame.size.width; + toIndex = ceil((rightScrollOffset) / self.colWidth); + } + + NSUInteger numberOfElements = [self.delegate numberOfElementsInGridView:self]; + return fmin( numberOfElements, fmax(0, toIndex)); +} + +- (NSRange)visibleIndexesRange +{ + NSInteger fromIndex = [self firstVisibleIndex]; + NSInteger toIndex = [self lastVisibleIndex]; + + return NSMakeRange(fromIndex, toIndex - fromIndex); +} + +- (CGRect)rectForElementWithIndex:(NSUInteger)index +{ + NSUInteger col = [self isVerticalGrid] ? index % self.colCount : index; + NSUInteger row = [self isVerticalGrid] ? index / self.colCount : 0; + + CGFloat horizontalOffset = [self.delegate horizontalOffsetInGridView:self]; + CGFloat vericalOffset = [self.delegate verticalOffsetInGridView:self]; + + return CGRectMake(col * self.colWidth + horizontalOffset, + row * self.rowHeight + vericalOffset, + self.colWidth - horizontalOffset, + self.rowHeight - vericalOffset ); +} + +- (void)expandContentSize +{ + NSUInteger rowCount = [self isVerticalGrid] ? ceil([self.delegate numberOfElementsInGridView:self] / (CGFloat)self.colCount ) : 1; + NSUInteger colCount = [self isVerticalGrid] ? self.colCount : [self.delegate numberOfElementsInGridView:self]; + + self.scrollView.contentSize = CGSizeMake(self.colWidth * colCount + [self.delegate horizontalOffsetInGridView:self], + self.rowHeight * rowCount + [self.delegate verticalOffsetInGridView:self]); +} + +- (NSMutableSet *)visibleIndexes +{ + NSRange range = [self visibleIndexesRange]; + NSMutableSet *result = [NSMutableSet setWithCapacity:range.length]; + for (NSUInteger index = range.location; index < range.location + range.length; ++index) { + + [result addObject:@(index)]; + } + return result; +} + +- (NSSet *)indexesToUpdate +{ + NSMutableSet *elementsIndexes = [NSMutableSet setWithArray:[self.elementContextByIndex allKeys]]; + NSMutableSet *result = [self visibleIndexes]; + [result minusSet:elementsIndexes]; + return result; +} + +- (NSMutableSet *)unvisibleElementsIndexes +{ + NSMutableSet *result = [NSMutableSet setWithArray:[self.elementContextByIndex allKeys]]; + NSMutableSet *visibleIndexes = [self visibleIndexes]; + [result minusSet:visibleIndexes]; + return result; +} + +- (id)elementByIndex:(NSUInteger)index +{ + JFFGridViewContext *result = self.elementContextByIndex[@(index)]; + return result.view; +} + +- (void)makeReusableElement:(UIView *)view +{ + NSMutableArray *reusableElements = self.reusableElementsByIdentifier[[view jffGridViewReuseIdentifier]]; + if ([reusableElements count] == 0) { + + reusableElements = [NSMutableArray arrayWithObject:view]; + self.reusableElementsByIdentifier[[view jffGridViewReuseIdentifier]] = reusableElements; + } else { + + [reusableElements addObject:view]; + } +} + +- (void)removeUnvisibleElements +{ + NSMutableSet *unvisibleElementsIndexes = [self unvisibleElementsIndexes]; + + for (NSNumber *index in unvisibleElementsIndexes) { + + UIView *view = [self elementByIndex:[index unsignedIntValue]]; + [self makeReusableElement:view]; + [self.elementContextByIndex removeObjectForKey:index]; + + [view removeFromSuperview]; + } +} + +- (void)updateElementAtIndex:(NSNumber *)index + position:(NSUInteger)position +{ + JFFGridViewContext *context = [JFFGridViewContext new]; + context.view = [self.delegate gridView:self + elementAtIndex:[index unsignedIntValue]]; + + NSAssert(context.view, @"View cannot be nil "); + + context.view.frame = [self rectForElementWithIndex:position]; + context.view.autoresizingMask = UIViewAutoresizingNone; + + [self.scrollView addSubview:context.view]; + [self.scrollView sendSubviewToBack:context.view]; + + self.elementContextByIndex[index] = context; +} + +- (void)updateElementAtIndex:(NSNumber *)index +{ + [self updateElementAtIndex:index position:[index unsignedIntValue]]; +} + +#pragma mark reloading / relayout / scroll + +- (void)removeElementAtIndex:(NSUInteger)index +{ + NSNumber *indexKey = @(index); + JFFGridViewContext *context = self.elementContextByIndex[indexKey]; + [context.view removeFromSuperview]; + + [self.elementContextByIndex removeObjectForKey:indexKey]; +} + +- (void)reindexElementsFromIndex:(NSUInteger)index +{ + JFFGridViewContext *context = self.elementContextByIndex[@(++index)]; + while (context) { + + NSNumber *newIndex = @(index - 1); + + self.elementContextByIndex[newIndex] = context; + [self.elementContextByIndex removeObjectForKey:@(index)]; + + [self.delegate gridView:self + didMoveElement:context.view + toIndex:index - 1]; + + context = self.elementContextByIndex[@(++index)]; + } +} + +- (void)prepareNewVisibleElementAtIndex:( NSUInteger )actIndex +{ + NSUInteger lastVisibleIndex = [self lastVisibleIndex] - 1; + JFFGridViewContext *context_ = self.elementContextByIndex[@(lastVisibleIndex)]; + UIView *elementView = context_.view; + if ( !elementView + && lastVisibleIndex < [ self.delegate numberOfElementsInGridView: self ] + && actIndex <= lastVisibleIndex ) { + + [self updateElementAtIndex:@(lastVisibleIndex) + position:lastVisibleIndex + 1]; + } +} + +- (void)removeElementWithIndex:(NSUInteger)index animated:(BOOL)animated +{ + [self removeElementAtIndex:index]; + + [self reindexElementsFromIndex:index]; + + [self prepareNewVisibleElementAtIndex:index]; + + [self relayoutElementsAnimated:animated]; +} + +- (void)removeElementsWithRange:(NSRange)range +{ + for (NSUInteger index = range.location; index < range.location + range.length; ++index) { + + [self removeElementAtIndex:index]; + } + + [self relayoutElementsAnimated:NO]; +} + +- (void)updateElements +{ + NSArray *indexesToUpdate = [[self indexesToUpdate] allObjects]; + + [self removeUnvisibleElements]; + + for (NSNumber *index in indexesToUpdate) { + + [self updateElementAtIndex:index]; + } +} + +- (void)reloadDataWithRange:(NSRange)range +{ + [self removeElementsWithRange:range]; + + [self updateElements]; + + [self expandContentSize]; +} + +- (NSRange)activeIndexesRange +{ + NSArray *activeIndexes = [_elementContextByIndex allKeys]; + if ( [_elementContextByIndex count] == 0) + return NSMakeRange(0, 0); + + activeIndexes = [activeIndexes sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { + return [obj1 compare:obj2]; + }]; + + NSInteger fromIndex = [activeIndexes[0] integerValue]; + NSInteger toIndex = [[activeIndexes lastObject] integerValue] + 1; + + return NSMakeRange(fromIndex, toIndex - fromIndex); +} + +- (void)reloadData +{ + [self reloadDataWithRange:[self activeIndexesRange]]; +} + +- (void)scrollToIndex:(NSInteger)index_ +{ + if ( self.colCount < MinColumnCount ) + return; + + if ([self isVerticalGrid]) { + + self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, index_ * self.rowHeight / self.colCount) ; + } else { + + self.scrollView.contentOffset = CGPointMake(index_ * self.colWidth, self.scrollView.contentOffset.y); + } +} + +- (void)reloadScrollView +{ + if (self.colCount < 2) /// Temp solution to avoid core during Teasers View Init + return; + + if ([self isVerticalGrid] && (self.prevOrientation != JFFGridOrientationVertical)) { + + self.scrollView.contentOffset = CGPointMake( self.scrollView.contentOffset.x, self.currentlyUsedIndex * self.rowHeight / self.colCount ) ; + + self.prevOrientation = JFFGridOrientationVertical; + } else if (![self isVerticalGrid] && (self.prevOrientation != JFFGridOrientationGorizontal)) { + + self.scrollView.contentOffset = CGPointMake( self.currentlyUsedIndex * self.colWidth, self.scrollView.contentOffset.y ); + self.prevOrientation = JFFGridOrientationGorizontal; + } +} + +- (void)relayoutElementsAnimated:( BOOL )animated +{ + void (^animations)( void ) = ^ + { + for (NSNumber *index in [self.elementContextByIndex allKeys]) + { + UIView *view = [self elementByIndex:[index unsignedIntValue]]; + view.frame = [self rectForElementWithIndex:[index unsignedIntValue]]; + } + + [self updateElements]; + [self expandContentSize]; + }; + + if (animated) + [UIView animateWithOptions:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState + animations:animations]; + else + animations(); +} + +- (void)relayoutElements +{ + [self relayoutElementsAnimated:NO]; +} + +- (void)layoutSubviews +{ + if (self.forceRelayout || !CGRectEqualToRect(self.frame, self.previousFrame)) { + [self reloadScrollView]; + [self relayoutElements]; + } + + self.previousFrame = self.frame; + self.forceRelayout = NO; +} + +- (NSMutableDictionary *)reusableElementsByIdentifier +{ + if (!_reusableElementsByIdentifier) { + + _reusableElementsByIdentifier = [NSMutableDictionary new]; + } + + return _reusableElementsByIdentifier; +} + +- (id)dequeueReusableElementWithIdentifier:(NSString *)identifier +{ + NSMutableArray *reusableElements = self.reusableElementsByIdentifier[identifier]; + if ([reusableElements count] == 0) + return nil; + + UIView *reusableElement = [reusableElements lastObject]; + [reusableElements removeLastObject]; + return reusableElement; +} + +#pragma mark UIScrollViewDelegate + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ + [self updateElements]; +} + +@end diff --git a/lib/JFFUI/GridView/JFFGridViewDelegate.h b/lib/JFFUI/GridView/JFFGridViewDelegate.h new file mode 100644 index 0000000..c069ac2 --- /dev/null +++ b/lib/JFFUI/GridView/JFFGridViewDelegate.h @@ -0,0 +1,31 @@ +#import + +@class JFFGridView; + +@protocol JFFGridViewDelegate + +@required +- (NSUInteger)numberOfElementsInGridView:(JFFGridView *)gridView; + +- (NSUInteger)numberOfElementsInRowInGridView:(JFFGridView *)gridView; + +- (UIView *)gridView:(JFFGridView *)gridView + elementAtIndex:( NSUInteger )index_; + +- (CGFloat)widthHeightRelationInGridView:(JFFGridView *)gridView; + +- (CGFloat)horizontalOffsetInGridView:(JFFGridView *)gridView; + +- (CGFloat)verticalOffsetInGridView:(JFFGridView *)gridView; + +@optional +- (void)gridView:(JFFGridView *)gridView +removeElementAtIndex:(NSUInteger)index; + +- (void)gridView:(JFFGridView *)gridView + didMoveElement:(UIView *)view_ + toIndex:(NSUInteger)index; + +- (BOOL)verticalGridView:(JFFGridView *)gridView; + +@end diff --git a/lib/JFFUI/GridView/JFFGridViewDelegate.m b/lib/JFFUI/GridView/JFFGridViewDelegate.m new file mode 100644 index 0000000..33452d7 --- /dev/null +++ b/lib/JFFUI/GridView/JFFGridViewDelegate.m @@ -0,0 +1,21 @@ +#import "JFFGridViewDelegate.h" + +@implementation NSObject (JFFGridViewDelegate) + +- (void)gridView:(JFFGridView *)gridView +removeElementAtIndex:(NSUInteger)index +{ +} + +- (void)gridView:(JFFGridView *)gridView + didMoveElement:(UIView *)view + toIndex:(NSUInteger)index +{ +} + +- (BOOL)verticalGridView:(JFFGridView *)gridView +{ + return YES; +} + +@end diff --git a/lib/JFFUI/JFFDialogProtocol.h b/lib/JFFUI/JFFDialogProtocol.h new file mode 100644 index 0000000..f8bec06 --- /dev/null +++ b/lib/JFFUI/JFFDialogProtocol.h @@ -0,0 +1,15 @@ +#import + +typedef void (^JFFCompleteDialogCallbackBlock)(id result, NSError *error, BOOL isCanceled); + +@protocol JFFDialogProtocol + +@property (copy, nonatomic) JFFCompleteDialogCallbackBlock onCompleteDialogBlock; + +@required +- (void)completeDialogWithResult:(id)result error:(NSError *)error isCanceled:(BOOL)isCancaled; +- (void)completeDialogWithError:(NSError *)error; +- (void)completeDialogWithResult:(id)result; +- (void)cancelDialog; + +@end diff --git a/lib/JFFUI/JFFUI.h b/lib/JFFUI/JFFUI.h index 00b4e4c..333dc83 100644 --- a/lib/JFFUI/JFFUI.h +++ b/lib/JFFUI/JFFUI.h @@ -1,15 +1,8 @@ -#import -#import -#import -#import - -#import -#import -#import #import #import #import +#import #import #import @@ -19,9 +12,40 @@ #import #import +#import +#import #import + +#import + +#import + +//Alert View +#import +#import +#import +#import + +//Stripe views +#import +#import + #import #import -#import +//Grid View +#import +#import + +//Categories +#import +#import +#import +#import + +#import +#import +#import +#import +#import diff --git a/lib/JFFUI/JFFUI.xcodeproj/project.pbxproj b/lib/JFFUI/JFFUI.xcodeproj/project.pbxproj index d9e8c0f..edaa89e 100644 --- a/lib/JFFUI/JFFUI.xcodeproj/project.pbxproj +++ b/lib/JFFUI/JFFUI.xcodeproj/project.pbxproj @@ -26,8 +26,6 @@ 1B7F58981435D53300FF06EC /* UIView+AddSubviewAndScale.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B7F58961435D53300FF06EC /* UIView+AddSubviewAndScale.m */; }; 1B7F589B1435D58000FF06EC /* UIView+AnimationWithBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B7F58991435D58000FF06EC /* UIView+AnimationWithBlocks.h */; }; 1B7F589C1435D58000FF06EC /* UIView+AnimationWithBlocks.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B7F589A1435D58000FF06EC /* UIView+AnimationWithBlocks.m */; }; - 1B81FAEF14330E4400997278 /* UINib+FirstObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B81FAED14330E4400997278 /* UINib+FirstObject.h */; }; - 1B81FAF014330E4400997278 /* UINib+FirstObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B81FAEE14330E4400997278 /* UINib+FirstObject.m */; }; 1BB414DE154835340032B7D5 /* JFFPendingActionSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BB414DC154835340032B7D5 /* JFFPendingActionSheet.h */; }; 1BB414DF154835340032B7D5 /* JFFPendingActionSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BB414DD154835340032B7D5 /* JFFPendingActionSheet.m */; }; 1BD361691455A0630036F786 /* JFFPageSlider.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD361671455A0630036F786 /* JFFPageSlider.h */; }; @@ -35,6 +33,46 @@ 1BD3616C1455A2F80036F786 /* JFFPageSliderDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD3616B1455A2F80036F786 /* JFFPageSliderDelegate.h */; }; 1BE053B715480F4400270B58 /* JFFActionSheetsContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BE053B515480F4400270B58 /* JFFActionSheetsContainer.h */; }; 1BE053B815480F4400270B58 /* JFFActionSheetsContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE053B615480F4400270B58 /* JFFActionSheetsContainer.m */; }; + 4C21FA7D16EF4F59005C4E57 /* JFFStripeView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C21FA7916EF4F59005C4E57 /* JFFStripeView.h */; }; + 4C21FA7E16EF4F59005C4E57 /* JFFStripeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C21FA7A16EF4F59005C4E57 /* JFFStripeView.m */; }; + 4C21FA7F16EF4F59005C4E57 /* JFFStripeViewDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C21FA7B16EF4F59005C4E57 /* JFFStripeViewDelegate.h */; }; + 4C21FA8016EF4F59005C4E57 /* JFFStripeViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C21FA7C16EF4F59005C4E57 /* JFFStripeViewDelegate.m */; }; + 4C2CFD951754A29F00E87F22 /* JFFAlertView+Async.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C2CFD931754A29E00E87F22 /* JFFAlertView+Async.h */; }; + 4C2CFD961754A29F00E87F22 /* JFFAlertView+Async.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C2CFD941754A29E00E87F22 /* JFFAlertView+Async.m */; }; + 4C2CFD991754A4CD00E87F22 /* UINib+FirstObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C2CFD971754A4CD00E87F22 /* UINib+FirstObject.h */; }; + 4C2CFD9A1754A4CD00E87F22 /* UINib+FirstObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C2CFD981754A4CD00E87F22 /* UINib+FirstObject.m */; }; + 4C2CFD9D1754A4FA00E87F22 /* UIApplication+OpenApplicationAsyncOp.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C2CFD9B1754A4F900E87F22 /* UIApplication+OpenApplicationAsyncOp.h */; }; + 4C2CFD9E1754A4FA00E87F22 /* UIApplication+OpenApplicationAsyncOp.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C2CFD9C1754A4FA00E87F22 /* UIApplication+OpenApplicationAsyncOp.m */; }; + 4C3D54311772033600EE1C73 /* UIImage+RotateImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C3D542F1772033600EE1C73 /* UIImage+RotateImage.h */; }; + 4C3D54321772033600EE1C73 /* UIImage+RotateImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C3D54301772033600EE1C73 /* UIImage+RotateImage.m */; }; + 4C4E8EA6180BFA4B002D8A7B /* UITableView+CellsSelections.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C4E8EA4180BFA4B002D8A7B /* UITableView+CellsSelections.h */; }; + 4C4E8EA7180BFA4B002D8A7B /* UITableView+CellsSelections.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4E8EA5180BFA4B002D8A7B /* UITableView+CellsSelections.m */; }; + 4C4E8EAA180BFB1A002D8A7B /* UITableView+BlocksAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C4E8EA8180BFB1A002D8A7B /* UITableView+BlocksAdditions.h */; }; + 4C4E8EAB180BFB1A002D8A7B /* UITableView+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4E8EA9180BFB1A002D8A7B /* UITableView+BlocksAdditions.m */; }; + 4C5040D5181126ED003F4B12 /* UIImage+WriteToTmpFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5040D3181126ED003F4B12 /* UIImage+WriteToTmpFile.h */; }; + 4C5040D6181126ED003F4B12 /* UIImage+WriteToTmpFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5040D4181126ED003F4B12 /* UIImage+WriteToTmpFile.m */; }; + 4C696BEC1742769A00C7D53D /* JFFGridView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C696BE51742769A00C7D53D /* JFFGridView.h */; }; + 4C696BED1742769A00C7D53D /* JFFGridView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C696BE61742769A00C7D53D /* JFFGridView.m */; }; + 4C696BEE1742769A00C7D53D /* JFFGridViewDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C696BE71742769A00C7D53D /* JFFGridViewDelegate.h */; }; + 4C696BEF1742769A00C7D53D /* JFFGridViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C696BE81742769A00C7D53D /* JFFGridViewDelegate.m */; }; + 4C8973931761F33C00E24F7B /* UIWebView+UserAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8973911761F33C00E24F7B /* UIWebView+UserAgent.h */; }; + 4C8973941761F33C00E24F7B /* UIWebView+UserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8973921761F33C00E24F7B /* UIWebView+UserAgent.m */; }; + 4CB4C1A31770530C00F275BC /* UIImage+ScaleToSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB4C1A11770530C00F275BC /* UIImage+ScaleToSize.h */; }; + 4CB4C1A41770530C00F275BC /* UIImage+ScaleToSize.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB4C1A21770530C00F275BC /* UIImage+ScaleToSize.m */; }; + 4CB4C1A71770535700F275BC /* UIImage+FixOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB4C1A51770535700F275BC /* UIImage+FixOrientation.h */; }; + 4CB4C1A81770535700F275BC /* UIImage+FixOrientation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB4C1A61770535700F275BC /* UIImage+FixOrientation.m */; }; + 4CB4C1AF1770539900F275BC /* UIImage+ImageWithColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB4C1AD1770539900F275BC /* UIImage+ImageWithColor.h */; }; + 4CB4C1B01770539900F275BC /* UIImage+ImageWithColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB4C1AE1770539900F275BC /* UIImage+ImageWithColor.m */; }; + 4CB4C1B31770592B00F275BC /* UIImage+DrawImageInImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB4C1B11770592B00F275BC /* UIImage+DrawImageInImage.h */; }; + 4CB4C1B41770592B00F275BC /* UIImage+DrawImageInImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB4C1B21770592B00F275BC /* UIImage+DrawImageInImage.m */; }; + 4CB4C1B71770667E00F275BC /* UIImage+JpegPackImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB4C1B51770667E00F275BC /* UIImage+JpegPackImage.h */; }; + 4CB4C1B81770667E00F275BC /* UIImage+JpegPackImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB4C1B61770667E00F275BC /* UIImage+JpegPackImage.m */; }; + 4CBBA1A917662275007317E6 /* JFFCameraFlashModeType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CBBA1A517662275007317E6 /* JFFCameraFlashModeType.h */; }; + 4CBBA1AA17662275007317E6 /* JFFPhotoCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CBBA1A617662275007317E6 /* JFFPhotoCamera.h */; }; + 4CBBA1AB17662275007317E6 /* JFFPhotoCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBBA1A717662275007317E6 /* JFFPhotoCamera.m */; }; + 4CBBA1AC17662275007317E6 /* JFFPhotoCameraType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CBBA1A817662275007317E6 /* JFFPhotoCameraType.h */; }; + 4CC3865116DE68630079F968 /* UIViewController+Dialog.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC3864F16DE68630079F968 /* UIViewController+Dialog.h */; }; + 4CC3865216DE68630079F968 /* UIViewController+Dialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC3865016DE68630079F968 /* UIViewController+Dialog.m */; }; 539103CA14A88BE1007315A3 /* JFFUI_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* JFFUI_Prefix.pch */; }; 539103CB14A88BE1007315A3 /* JFFAlertButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 655E9DB21392E8C00074BD61 /* JFFAlertButton.h */; }; 539103CC14A88BE1007315A3 /* JFFAlertView.h in Headers */ = {isa = PBXBuildFile; fileRef = 655E9DB41392E8C00074BD61 /* JFFAlertView.h */; }; @@ -42,7 +80,6 @@ 539103CE14A88BE1007315A3 /* JFFUI.h in Headers */ = {isa = PBXBuildFile; fileRef = 655E9E4A1392ED360074BD61 /* JFFUI.h */; }; 539103CF14A88BE1007315A3 /* JFFActionSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D996F16139F5D370075A325 /* JFFActionSheet.h */; }; 539103D014A88BE1007315A3 /* NSObject+JFFAlertButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D996F1C139F61200075A325 /* NSObject+JFFAlertButton.h */; }; - 539103D214A88BE1007315A3 /* UINib+FirstObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B81FAED14330E4400997278 /* UINib+FirstObject.h */; }; 539103D314A88BE1007315A3 /* UIWebView+HideWhenLoading.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B7F583E1435BDC000FF06EC /* UIWebView+HideWhenLoading.h */; }; 539103D414A88BE1007315A3 /* UIView+AddSubviewAndScale.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B7F58951435D53300FF06EC /* UIView+AddSubviewAndScale.h */; }; 539103D514A88BE1007315A3 /* UIView+AnimationWithBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B7F58991435D58000FF06EC /* UIView+AnimationWithBlocks.h */; }; @@ -56,7 +93,6 @@ 539103DE14A88BE1007315A3 /* NSError+Alert.m in Sources */ = {isa = PBXBuildFile; fileRef = 655E9DB71392E8C00074BD61 /* NSError+Alert.m */; }; 539103DF14A88BE1007315A3 /* JFFActionSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D996F17139F5D370075A325 /* JFFActionSheet.m */; }; 539103E014A88BE1007315A3 /* NSObject+JFFAlertButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D996F1D139F61200075A325 /* NSObject+JFFAlertButton.m */; }; - 539103E214A88BE1007315A3 /* UINib+FirstObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B81FAEE14330E4400997278 /* UINib+FirstObject.m */; }; 539103E314A88BE1007315A3 /* UIWebView+HideWhenLoading.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B7F583F1435BDC000FF06EC /* UIWebView+HideWhenLoading.m */; }; 539103E414A88BE1007315A3 /* UIView+AddSubviewAndScale.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B7F58961435D53300FF06EC /* UIView+AddSubviewAndScale.m */; }; 539103E514A88BE1007315A3 /* UIView+AnimationWithBlocks.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B7F589A1435D58000FF06EC /* UIView+AnimationWithBlocks.m */; }; @@ -87,10 +123,6 @@ CE9A9154165671D200EFE858 /* JFFUIError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE9A9152165671D200EFE858 /* JFFUIError.m */; }; CE9A91571656722900EFE858 /* JFFOpenApplicationError.h in Headers */ = {isa = PBXBuildFile; fileRef = CE9A91551656722900EFE858 /* JFFOpenApplicationError.h */; }; CE9A91581656722900EFE858 /* JFFOpenApplicationError.m in Sources */ = {isa = PBXBuildFile; fileRef = CE9A91561656722900EFE858 /* JFFOpenApplicationError.m */; }; - CEA097C615FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.h in Headers */ = {isa = PBXBuildFile; fileRef = CEA097C415FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.h */; }; - CEA097C715FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA097C515FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.m */; }; - CEE235EA1608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = CEE235E81608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.h */; }; - CEE235EB1608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE235E91608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -113,8 +145,6 @@ 1B7F58961435D53300FF06EC /* UIView+AddSubviewAndScale.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AddSubviewAndScale.m"; sourceTree = ""; }; 1B7F58991435D58000FF06EC /* UIView+AnimationWithBlocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AnimationWithBlocks.h"; sourceTree = ""; }; 1B7F589A1435D58000FF06EC /* UIView+AnimationWithBlocks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AnimationWithBlocks.m"; sourceTree = ""; }; - 1B81FAED14330E4400997278 /* UINib+FirstObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UINib+FirstObject.h"; path = "Extensions/UINib+FirstObject.h"; sourceTree = SOURCE_ROOT; }; - 1B81FAEE14330E4400997278 /* UINib+FirstObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UINib+FirstObject.m"; path = "Extensions/UINib+FirstObject.m"; sourceTree = SOURCE_ROOT; }; 1BB414DC154835340032B7D5 /* JFFPendingActionSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPendingActionSheet.h; sourceTree = ""; }; 1BB414DD154835340032B7D5 /* JFFPendingActionSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFPendingActionSheet.m; sourceTree = ""; }; 1BD361671455A0630036F786 /* JFFPageSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPageSlider.h; sourceTree = ""; }; @@ -122,6 +152,47 @@ 1BD3616B1455A2F80036F786 /* JFFPageSliderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPageSliderDelegate.h; sourceTree = ""; }; 1BE053B515480F4400270B58 /* JFFActionSheetsContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFActionSheetsContainer.h; sourceTree = ""; }; 1BE053B615480F4400270B58 /* JFFActionSheetsContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFActionSheetsContainer.m; sourceTree = ""; }; + 4C21FA7916EF4F59005C4E57 /* JFFStripeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFStripeView.h; sourceTree = ""; }; + 4C21FA7A16EF4F59005C4E57 /* JFFStripeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFStripeView.m; sourceTree = ""; }; + 4C21FA7B16EF4F59005C4E57 /* JFFStripeViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFStripeViewDelegate.h; sourceTree = ""; }; + 4C21FA7C16EF4F59005C4E57 /* JFFStripeViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFStripeViewDelegate.m; sourceTree = ""; }; + 4C2CFD931754A29E00E87F22 /* JFFAlertView+Async.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JFFAlertView+Async.h"; sourceTree = ""; }; + 4C2CFD941754A29E00E87F22 /* JFFAlertView+Async.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JFFAlertView+Async.m"; sourceTree = ""; }; + 4C2CFD971754A4CD00E87F22 /* UINib+FirstObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UINib+FirstObject.h"; sourceTree = ""; }; + 4C2CFD981754A4CD00E87F22 /* UINib+FirstObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINib+FirstObject.m"; sourceTree = ""; }; + 4C2CFD9B1754A4F900E87F22 /* UIApplication+OpenApplicationAsyncOp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIApplication+OpenApplicationAsyncOp.h"; sourceTree = ""; }; + 4C2CFD9C1754A4FA00E87F22 /* UIApplication+OpenApplicationAsyncOp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+OpenApplicationAsyncOp.m"; sourceTree = ""; }; + 4C3D542F1772033600EE1C73 /* UIImage+RotateImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+RotateImage.h"; sourceTree = ""; }; + 4C3D54301772033600EE1C73 /* UIImage+RotateImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+RotateImage.m"; sourceTree = ""; }; + 4C4E8EA4180BFA4B002D8A7B /* UITableView+CellsSelections.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+CellsSelections.h"; sourceTree = ""; }; + 4C4E8EA5180BFA4B002D8A7B /* UITableView+CellsSelections.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+CellsSelections.m"; sourceTree = ""; }; + 4C4E8EA8180BFB1A002D8A7B /* UITableView+BlocksAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+BlocksAdditions.h"; sourceTree = ""; }; + 4C4E8EA9180BFB1A002D8A7B /* UITableView+BlocksAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+BlocksAdditions.m"; sourceTree = ""; }; + 4C5040D3181126ED003F4B12 /* UIImage+WriteToTmpFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+WriteToTmpFile.h"; sourceTree = ""; }; + 4C5040D4181126ED003F4B12 /* UIImage+WriteToTmpFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+WriteToTmpFile.m"; sourceTree = ""; }; + 4C696BE51742769A00C7D53D /* JFFGridView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFGridView.h; sourceTree = ""; }; + 4C696BE61742769A00C7D53D /* JFFGridView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFGridView.m; sourceTree = ""; }; + 4C696BE71742769A00C7D53D /* JFFGridViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFGridViewDelegate.h; sourceTree = ""; }; + 4C696BE81742769A00C7D53D /* JFFGridViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFGridViewDelegate.m; sourceTree = ""; }; + 4C8973911761F33C00E24F7B /* UIWebView+UserAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIWebView+UserAgent.h"; sourceTree = ""; }; + 4C8973921761F33C00E24F7B /* UIWebView+UserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIWebView+UserAgent.m"; sourceTree = ""; }; + 4CB4C1A11770530C00F275BC /* UIImage+ScaleToSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ScaleToSize.h"; sourceTree = ""; }; + 4CB4C1A21770530C00F275BC /* UIImage+ScaleToSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ScaleToSize.m"; sourceTree = ""; }; + 4CB4C1A51770535700F275BC /* UIImage+FixOrientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+FixOrientation.h"; sourceTree = ""; }; + 4CB4C1A61770535700F275BC /* UIImage+FixOrientation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+FixOrientation.m"; sourceTree = ""; }; + 4CB4C1AD1770539900F275BC /* UIImage+ImageWithColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ImageWithColor.h"; sourceTree = ""; }; + 4CB4C1AE1770539900F275BC /* UIImage+ImageWithColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ImageWithColor.m"; sourceTree = ""; }; + 4CB4C1B11770592B00F275BC /* UIImage+DrawImageInImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+DrawImageInImage.h"; sourceTree = ""; }; + 4CB4C1B21770592B00F275BC /* UIImage+DrawImageInImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+DrawImageInImage.m"; sourceTree = ""; }; + 4CB4C1B51770667E00F275BC /* UIImage+JpegPackImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+JpegPackImage.h"; sourceTree = ""; }; + 4CB4C1B61770667E00F275BC /* UIImage+JpegPackImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+JpegPackImage.m"; sourceTree = ""; }; + 4CBBA1A517662275007317E6 /* JFFCameraFlashModeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFCameraFlashModeType.h; sourceTree = ""; }; + 4CBBA1A617662275007317E6 /* JFFPhotoCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPhotoCamera.h; sourceTree = ""; }; + 4CBBA1A717662275007317E6 /* JFFPhotoCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFPhotoCamera.m; sourceTree = ""; }; + 4CBBA1A817662275007317E6 /* JFFPhotoCameraType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFPhotoCameraType.h; sourceTree = ""; }; + 4CC3864E16DE67B60079F968 /* JFFDialogProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JFFDialogProtocol.h; sourceTree = ""; }; + 4CC3864F16DE68630079F968 /* UIViewController+Dialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Dialog.h"; sourceTree = ""; }; + 4CC3865016DE68630079F968 /* UIViewController+Dialog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Dialog.m"; sourceTree = ""; }; 539103F014A88BE1007315A3 /* libJFFUI-clang.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libJFFUI-clang.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 655E9DB21392E8C00074BD61 /* JFFAlertButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFAlertButton.h; sourceTree = ""; }; 655E9DB31392E8C00074BD61 /* JFFAlertButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFAlertButton.m; sourceTree = ""; }; @@ -144,10 +215,6 @@ CE9A9152165671D200EFE858 /* JFFUIError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFUIError.m; sourceTree = ""; }; CE9A91551656722900EFE858 /* JFFOpenApplicationError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFOpenApplicationError.h; sourceTree = ""; }; CE9A91561656722900EFE858 /* JFFOpenApplicationError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFOpenApplicationError.m; sourceTree = ""; }; - CEA097C415FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIApplication+OpenApplicationAsyncOp.h"; path = "Extensions/UIApplication+OpenApplicationAsyncOp.h"; sourceTree = SOURCE_ROOT; }; - CEA097C515FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIApplication+OpenApplicationAsyncOp.m"; path = "Extensions/UIApplication+OpenApplicationAsyncOp.m"; sourceTree = SOURCE_ROOT; }; - CEE235E81608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImageView+CachedAsyncImageLoader.h"; path = "Extensions/UIImageView+CachedAsyncImageLoader.h"; sourceTree = SOURCE_ROOT; }; - CEE235E91608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIImageView+CachedAsyncImageLoader.m"; path = "Extensions/UIImageView+CachedAsyncImageLoader.m"; sourceTree = SOURCE_ROOT; }; D2AAC07E0554694100DB518D /* libJFFUI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFUI.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -202,14 +269,18 @@ 08FB77AEFE84172EC02AAC07 /* Classes */ = { isa = PBXGroup; children = ( + 4CB4C1A0177052F800F275BC /* UIImage */, + 4CBBA16F1766130A007317E6 /* PhotoCamera */, + 4C2CFD921754A28F00E87F22 /* Categories */, + 4C696BE41742769A00C7D53D /* GridView */, CE9A914F165671C000EFE858 /* Errors */, 1B5E1ACA14D01F900075049A /* UIViewController */, 1BD361651455A04B0036F786 /* StripeView */, 1B295556143DCB0500532BD7 /* UITableView */, 1B7F58941435D50F00FF06EC /* UIView */, 1B7F583B1435BDC000FF06EC /* UIWebView */, - 1B793977142B76FD00B43DC8 /* Extensions */, 655E9DB11392E8C00074BD61 /* AlertView */, + 4CC3864E16DE67B60079F968 /* JFFDialogProtocol.h */, 655E9E4A1392ED360074BD61 /* JFFUI.h */, ); name = Classes; @@ -222,6 +293,10 @@ 1B295559143DCB3A00532BD7 /* JULoadMoreCellscalculator.m */, 1B29555D143DCB7300532BD7 /* UITableView+WithinUpdates.h */, 1B29555E143DCB7300532BD7 /* UITableView+WithinUpdates.m */, + 4C4E8EA4180BFA4B002D8A7B /* UITableView+CellsSelections.h */, + 4C4E8EA5180BFA4B002D8A7B /* UITableView+CellsSelections.m */, + 4C4E8EA8180BFB1A002D8A7B /* UITableView+BlocksAdditions.h */, + 4C4E8EA9180BFB1A002D8A7B /* UITableView+BlocksAdditions.m */, ); path = UITableView; sourceTree = ""; @@ -235,24 +310,12 @@ CE5EF36E167CE536009BD15D /* UIViewController+PerformSegueWithCallback.m */, CE5EF368167CE4D8009BD15D /* UIViewController+ForceRemoveFromParentViewController.h */, CE5EF369167CE4D8009BD15D /* UIViewController+ForceRemoveFromParentViewController.m */, + 4CC3864F16DE68630079F968 /* UIViewController+Dialog.h */, + 4CC3865016DE68630079F968 /* UIViewController+Dialog.m */, ); path = UIViewController; sourceTree = ""; }; - 1B793977142B76FD00B43DC8 /* Extensions */ = { - isa = PBXGroup; - children = ( - 1B81FAED14330E4400997278 /* UINib+FirstObject.h */, - 1B81FAEE14330E4400997278 /* UINib+FirstObject.m */, - CEA097C415FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.h */, - CEA097C515FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.m */, - CEE235E81608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.h */, - CEE235E91608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.m */, - ); - name = Extensions; - path = ./JFFUI/Extensions; - sourceTree = ""; - }; 1B7F583B1435BDC000FF06EC /* UIWebView */ = { isa = PBXGroup; children = ( @@ -279,6 +342,10 @@ 1BD361651455A04B0036F786 /* StripeView */ = { isa = PBXGroup; children = ( + 4C21FA7916EF4F59005C4E57 /* JFFStripeView.h */, + 4C21FA7A16EF4F59005C4E57 /* JFFStripeView.m */, + 4C21FA7B16EF4F59005C4E57 /* JFFStripeViewDelegate.h */, + 4C21FA7C16EF4F59005C4E57 /* JFFStripeViewDelegate.m */, 1BD361671455A0630036F786 /* JFFPageSlider.h */, 1BD361681455A0630036F786 /* JFFPageSlider.m */, 1BD3616B1455A2F80036F786 /* JFFPageSliderDelegate.h */, @@ -294,6 +361,72 @@ name = "Other Sources"; sourceTree = ""; }; + 4C2CFD921754A28F00E87F22 /* Categories */ = { + isa = PBXGroup; + children = ( + 4C2CFD931754A29E00E87F22 /* JFFAlertView+Async.h */, + 4C2CFD941754A29E00E87F22 /* JFFAlertView+Async.m */, + 4C2CFD971754A4CD00E87F22 /* UINib+FirstObject.h */, + 4C2CFD981754A4CD00E87F22 /* UINib+FirstObject.m */, + 4C2CFD9B1754A4F900E87F22 /* UIApplication+OpenApplicationAsyncOp.h */, + 4C2CFD9C1754A4FA00E87F22 /* UIApplication+OpenApplicationAsyncOp.m */, + 4C8973911761F33C00E24F7B /* UIWebView+UserAgent.h */, + 4C8973921761F33C00E24F7B /* UIWebView+UserAgent.m */, + ); + path = Categories; + sourceTree = ""; + }; + 4C696BE41742769A00C7D53D /* GridView */ = { + isa = PBXGroup; + children = ( + 4C696BE51742769A00C7D53D /* JFFGridView.h */, + 4C696BE61742769A00C7D53D /* JFFGridView.m */, + 4C696BE71742769A00C7D53D /* JFFGridViewDelegate.h */, + 4C696BE81742769A00C7D53D /* JFFGridViewDelegate.m */, + ); + path = GridView; + sourceTree = ""; + }; + 4C72998D176893EF0042DBFE /* Details */ = { + isa = PBXGroup; + children = ( + 4C3D542F1772033600EE1C73 /* UIImage+RotateImage.h */, + 4C3D54301772033600EE1C73 /* UIImage+RotateImage.m */, + ); + path = Details; + sourceTree = ""; + }; + 4CB4C1A0177052F800F275BC /* UIImage */ = { + isa = PBXGroup; + children = ( + 4CB4C1A11770530C00F275BC /* UIImage+ScaleToSize.h */, + 4CB4C1A21770530C00F275BC /* UIImage+ScaleToSize.m */, + 4CB4C1A51770535700F275BC /* UIImage+FixOrientation.h */, + 4CB4C1A61770535700F275BC /* UIImage+FixOrientation.m */, + 4CB4C1AD1770539900F275BC /* UIImage+ImageWithColor.h */, + 4CB4C1AE1770539900F275BC /* UIImage+ImageWithColor.m */, + 4CB4C1B11770592B00F275BC /* UIImage+DrawImageInImage.h */, + 4CB4C1B21770592B00F275BC /* UIImage+DrawImageInImage.m */, + 4CB4C1B51770667E00F275BC /* UIImage+JpegPackImage.h */, + 4CB4C1B61770667E00F275BC /* UIImage+JpegPackImage.m */, + 4C5040D3181126ED003F4B12 /* UIImage+WriteToTmpFile.h */, + 4C5040D4181126ED003F4B12 /* UIImage+WriteToTmpFile.m */, + ); + path = UIImage; + sourceTree = ""; + }; + 4CBBA16F1766130A007317E6 /* PhotoCamera */ = { + isa = PBXGroup; + children = ( + 4C72998D176893EF0042DBFE /* Details */, + 4CBBA1A517662275007317E6 /* JFFCameraFlashModeType.h */, + 4CBBA1A617662275007317E6 /* JFFPhotoCamera.h */, + 4CBBA1A717662275007317E6 /* JFFPhotoCamera.m */, + 4CBBA1A817662275007317E6 /* JFFPhotoCameraType.h */, + ); + path = PhotoCamera; + sourceTree = ""; + }; 655E9DB11392E8C00074BD61 /* AlertView */ = { isa = PBXGroup; children = ( @@ -352,7 +485,6 @@ 539103CE14A88BE1007315A3 /* JFFUI.h in Headers */, 539103CF14A88BE1007315A3 /* JFFActionSheet.h in Headers */, 539103D014A88BE1007315A3 /* NSObject+JFFAlertButton.h in Headers */, - 539103D214A88BE1007315A3 /* UINib+FirstObject.h in Headers */, 539103D314A88BE1007315A3 /* UIWebView+HideWhenLoading.h in Headers */, 539103D414A88BE1007315A3 /* UIView+AddSubviewAndScale.h in Headers */, 539103D514A88BE1007315A3 /* UIView+AnimationWithBlocks.h in Headers */, @@ -375,9 +507,9 @@ 655E9E4B1392ED360074BD61 /* JFFUI.h in Headers */, 8D996F18139F5D370075A325 /* JFFActionSheet.h in Headers */, 8D996F1E139F61200075A325 /* NSObject+JFFAlertButton.h in Headers */, - 1B81FAEF14330E4400997278 /* UINib+FirstObject.h in Headers */, 1B7F58421435BDC000FF06EC /* UIWebView+HideWhenLoading.h in Headers */, 1B7F58971435D53300FF06EC /* UIView+AddSubviewAndScale.h in Headers */, + 4C5040D5181126ED003F4B12 /* UIImage+WriteToTmpFile.h in Headers */, 1B7F589B1435D58000FF06EC /* UIView+AnimationWithBlocks.h in Headers */, 1B29555A143DCB3A00532BD7 /* JULoadMoreCellscalculator.h in Headers */, 1B29555F143DCB7300532BD7 /* UITableView+WithinUpdates.h in Headers */, @@ -389,12 +521,30 @@ 1BB414DE154835340032B7D5 /* JFFPendingActionSheet.h in Headers */, 1B260343156546D900316C7C /* JFFAlertViewsContainer.h in Headers */, 1B2812EA1578C1F400BC70D9 /* JFFWaitAlertView.h in Headers */, - CEA097C615FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.h in Headers */, - CEE235EA1608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.h in Headers */, CE9A9153165671D200EFE858 /* JFFUIError.h in Headers */, CE9A91571656722900EFE858 /* JFFOpenApplicationError.h in Headers */, CE5EF36A167CE4D8009BD15D /* UIViewController+ForceRemoveFromParentViewController.h in Headers */, CE5EF36F167CE536009BD15D /* UIViewController+PerformSegueWithCallback.h in Headers */, + 4CC3865116DE68630079F968 /* UIViewController+Dialog.h in Headers */, + 4C21FA7D16EF4F59005C4E57 /* JFFStripeView.h in Headers */, + 4C21FA7F16EF4F59005C4E57 /* JFFStripeViewDelegate.h in Headers */, + 4C696BEC1742769A00C7D53D /* JFFGridView.h in Headers */, + 4C696BEE1742769A00C7D53D /* JFFGridViewDelegate.h in Headers */, + 4C2CFD951754A29F00E87F22 /* JFFAlertView+Async.h in Headers */, + 4C4E8EAA180BFB1A002D8A7B /* UITableView+BlocksAdditions.h in Headers */, + 4C2CFD991754A4CD00E87F22 /* UINib+FirstObject.h in Headers */, + 4C2CFD9D1754A4FA00E87F22 /* UIApplication+OpenApplicationAsyncOp.h in Headers */, + 4C4E8EA6180BFA4B002D8A7B /* UITableView+CellsSelections.h in Headers */, + 4C8973931761F33C00E24F7B /* UIWebView+UserAgent.h in Headers */, + 4CBBA1A917662275007317E6 /* JFFCameraFlashModeType.h in Headers */, + 4CBBA1AA17662275007317E6 /* JFFPhotoCamera.h in Headers */, + 4CBBA1AC17662275007317E6 /* JFFPhotoCameraType.h in Headers */, + 4CB4C1A31770530C00F275BC /* UIImage+ScaleToSize.h in Headers */, + 4CB4C1A71770535700F275BC /* UIImage+FixOrientation.h in Headers */, + 4CB4C1AF1770539900F275BC /* UIImage+ImageWithColor.h in Headers */, + 4CB4C1B31770592B00F275BC /* UIImage+DrawImageInImage.h in Headers */, + 4CB4C1B71770667E00F275BC /* UIImage+JpegPackImage.h in Headers */, + 4C3D54311772033600EE1C73 /* UIImage+RotateImage.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -441,7 +591,7 @@ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0500; }; buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "JFFUI" */; compatibilityVersion = "Xcode 3.2"; @@ -474,7 +624,6 @@ 539103DE14A88BE1007315A3 /* NSError+Alert.m in Sources */, 539103DF14A88BE1007315A3 /* JFFActionSheet.m in Sources */, 539103E014A88BE1007315A3 /* NSObject+JFFAlertButton.m in Sources */, - 539103E214A88BE1007315A3 /* UINib+FirstObject.m in Sources */, 539103E314A88BE1007315A3 /* UIWebView+HideWhenLoading.m in Sources */, 539103E414A88BE1007315A3 /* UIView+AddSubviewAndScale.m in Sources */, 539103E514A88BE1007315A3 /* UIView+AnimationWithBlocks.m in Sources */, @@ -495,26 +644,42 @@ 655E9DBD1392E8C00074BD61 /* NSError+Alert.m in Sources */, 8D996F19139F5D370075A325 /* JFFActionSheet.m in Sources */, 8D996F1F139F61200075A325 /* NSObject+JFFAlertButton.m in Sources */, - 1B81FAF014330E4400997278 /* UINib+FirstObject.m in Sources */, + 4C4E8EA7180BFA4B002D8A7B /* UITableView+CellsSelections.m in Sources */, 1B7F58431435BDC000FF06EC /* UIWebView+HideWhenLoading.m in Sources */, 1B7F58981435D53300FF06EC /* UIView+AddSubviewAndScale.m in Sources */, + 4C5040D6181126ED003F4B12 /* UIImage+WriteToTmpFile.m in Sources */, 1B7F589C1435D58000FF06EC /* UIView+AnimationWithBlocks.m in Sources */, 1B49CFA8143C6D3500E8AACE /* UIWebViewNewFeaturesRuntime.m in Sources */, 1B29555B143DCB3A00532BD7 /* JULoadMoreCellscalculator.m in Sources */, 1B295560143DCB7300532BD7 /* UITableView+WithinUpdates.m in Sources */, 1BD3616A1455A0630036F786 /* JFFPageSlider.m in Sources */, 1B3A3855147683E9007D8C10 /* UIView+AllSubviews.m in Sources */, + 4C4E8EAB180BFB1A002D8A7B /* UITableView+BlocksAdditions.m in Sources */, 1B5E1AD314D0203B0075049A /* UIViewController+PresentTopViewController.m in Sources */, 1BE053B815480F4400270B58 /* JFFActionSheetsContainer.m in Sources */, 1BB414DF154835340032B7D5 /* JFFPendingActionSheet.m in Sources */, 1B260344156546D900316C7C /* JFFAlertViewsContainer.m in Sources */, 1B2812EB1578C1F400BC70D9 /* JFFWaitAlertView.mm in Sources */, - CEA097C715FF4EE90080DEF7 /* UIApplication+OpenApplicationAsyncOp.m in Sources */, - CEE235EB1608893B00B34AD8 /* UIImageView+CachedAsyncImageLoader.m in Sources */, CE9A9154165671D200EFE858 /* JFFUIError.m in Sources */, CE9A91581656722900EFE858 /* JFFOpenApplicationError.m in Sources */, CE5EF36B167CE4D8009BD15D /* UIViewController+ForceRemoveFromParentViewController.m in Sources */, CE5EF370167CE536009BD15D /* UIViewController+PerformSegueWithCallback.m in Sources */, + 4CC3865216DE68630079F968 /* UIViewController+Dialog.m in Sources */, + 4C21FA7E16EF4F59005C4E57 /* JFFStripeView.m in Sources */, + 4C21FA8016EF4F59005C4E57 /* JFFStripeViewDelegate.m in Sources */, + 4C696BED1742769A00C7D53D /* JFFGridView.m in Sources */, + 4C696BEF1742769A00C7D53D /* JFFGridViewDelegate.m in Sources */, + 4C2CFD961754A29F00E87F22 /* JFFAlertView+Async.m in Sources */, + 4C2CFD9A1754A4CD00E87F22 /* UINib+FirstObject.m in Sources */, + 4C2CFD9E1754A4FA00E87F22 /* UIApplication+OpenApplicationAsyncOp.m in Sources */, + 4C8973941761F33C00E24F7B /* UIWebView+UserAgent.m in Sources */, + 4CBBA1AB17662275007317E6 /* JFFPhotoCamera.m in Sources */, + 4CB4C1A41770530C00F275BC /* UIImage+ScaleToSize.m in Sources */, + 4CB4C1A81770535700F275BC /* UIImage+FixOrientation.m in Sources */, + 4CB4C1B01770539900F275BC /* UIImage+ImageWithColor.m in Sources */, + 4CB4C1B41770592B00F275BC /* UIImage+DrawImageInImage.m in Sources */, + 4CB4C1B81770667E00F275BC /* UIImage+JpegPackImage.m in Sources */, + 4C3D54321772033600EE1C73 /* UIImage+RotateImage.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -525,7 +690,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; DSTROOT = /tmp/JFFUI.dst; @@ -535,6 +699,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = JFFUI_Prefix.pch; INSTALL_PATH = /usr/local/lib; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = JFFUI; SKIP_INSTALL = YES; }; @@ -544,13 +709,13 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; DSTROOT = /tmp/JFFUI.dst; GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = JFFUI_Prefix.pch; INSTALL_PATH = /usr/local/lib; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = JFFUI; SKIP_INSTALL = YES; }; @@ -559,17 +724,19 @@ 1DEB922308733DC00010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; + CLANG_ENABLE_MODULES = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( - ../JFFCache, ../, + "../../lib-third-party/libturbojpeg-ios", ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; @@ -578,16 +745,18 @@ 1DEB922408733DC00010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; + CLANG_ENABLE_MODULES = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( - ../JFFCache, ../, + "../../lib-third-party/libturbojpeg-ios", ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; diff --git a/lib/JFFUI/PhotoCamera/Details/UIImage+RotateImage.h b/lib/JFFUI/PhotoCamera/Details/UIImage+RotateImage.h new file mode 100644 index 0000000..b5e1cb3 --- /dev/null +++ b/lib/JFFUI/PhotoCamera/Details/UIImage+RotateImage.h @@ -0,0 +1,7 @@ +#import + +@interface UIImage (RotateImage) + +- (instancetype)rotatedImageWithRadians:(double)radians; + +@end diff --git a/lib/JFFUI/PhotoCamera/Details/UIImage+RotateImage.m b/lib/JFFUI/PhotoCamera/Details/UIImage+RotateImage.m new file mode 100644 index 0000000..68ef724 --- /dev/null +++ b/lib/JFFUI/PhotoCamera/Details/UIImage+RotateImage.m @@ -0,0 +1,29 @@ +#import "UIImage+RotateImage.h" + +@implementation UIImage (RotateImage) + +- (instancetype)rotatedImageWithRadians:(double)radians +{ + CGSize rotatedSize = self.size; + + // Create the bitmap context + UIGraphicsBeginImageContext(rotatedSize); + CGContextRef bitmap = UIGraphicsGetCurrentContext(); + + // Move the origin to the middle of the image so we will rotate and scale around the center. + CGContextTranslateCTM(bitmap, rotatedSize.width/2.f, rotatedSize.height/2.f); + + // // Rotate the image context + CGContextRotateCTM(bitmap, radians); + + // Now, draw the rotated/scaled image into the context + CGContextScaleCTM(bitmap, 1.f, -1.f); + CGRect rect = CGRectMake(-rotatedSize.width/2, -rotatedSize.height/2, rotatedSize.width, rotatedSize.height); + CGContextDrawImage(bitmap, rect, [self CGImage]); + + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return newImage; +} + +@end diff --git a/lib/JFFUI/PhotoCamera/JFFCameraFlashModeType.h b/lib/JFFUI/PhotoCamera/JFFCameraFlashModeType.h new file mode 100644 index 0000000..87a4491 --- /dev/null +++ b/lib/JFFUI/PhotoCamera/JFFCameraFlashModeType.h @@ -0,0 +1,11 @@ +#ifndef JFFUI_JFFCameraFlashModeType_h +#define JFFUI_JFFCameraFlashModeType_h + +typedef NS_ENUM(NSUInteger, JFFCameraFlashModeType) +{ + JFFCameraFlashModeAuto, + JFFCameraFlashModeOn, + JFFCameraFlashModeOff +}; + +#endif //JFFUI_JFFCameraFlashModeType_h diff --git a/lib/JFFUI/PhotoCamera/JFFPhotoCamera.h b/lib/JFFUI/PhotoCamera/JFFPhotoCamera.h new file mode 100644 index 0000000..82f19db --- /dev/null +++ b/lib/JFFUI/PhotoCamera/JFFPhotoCamera.h @@ -0,0 +1,40 @@ +#import + +#include +#include + +typedef void(^PhotoCameraMakePhotoResult)(UIImage *image, NSError *error); + +typedef NS_ENUM(NSUInteger, JFFAVCaptureVideoOrientation) +{ + JFFAVCaptureVideoOrientationPortrait = 1, + JFFAVCaptureVideoOrientationPortraitUpsideDown = 2, + JFFAVCaptureVideoOrientationLandscapeRight = 3, + JFFAVCaptureVideoOrientationLandscapeLeft = 4, +}; + +@class AVCaptureVideoPreviewLayer; + +@interface JFFPhotoCamera : NSObject + +@property (nonatomic, readonly) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer; +@property (nonatomic, copy) NSString *sessionPreset; +@property (nonatomic) JFFCameraFlashModeType flashMode; +@property (nonatomic) JFFPhotoCameraType photoCameraType; +@property (nonatomic) BOOL fixOrientation; //default is YES +@property (nonatomic) BOOL rotateImage; //default is YES + +@property (nonatomic) JFFAVCaptureVideoOrientation videoOrientation; + +- (instancetype)initPhotoCameraType:(JFFPhotoCameraType)photoCameraType; + ++ (NSArray *)allActiveCameras; + +- (void)startRunning; +- (void)stopRunning; + +- (BOOL)isRunning; + +- (void)makePhotoWithCallback:(PhotoCameraMakePhotoResult)callback; + +@end diff --git a/lib/JFFUI/PhotoCamera/JFFPhotoCamera.m b/lib/JFFUI/PhotoCamera/JFFPhotoCamera.m new file mode 100644 index 0000000..0bc4761 --- /dev/null +++ b/lib/JFFUI/PhotoCamera/JFFPhotoCamera.m @@ -0,0 +1,306 @@ +#import "JFFPhotoCamera.h" + +#import "UIImage+RotateImage.h" +#import "UIImage+FixOrientation.h" + +#import + +static JFFMutableAssignArray *__allActiveCameras; + +#define dDeviceOrientation [[UIDevice currentDevice] orientation] +#define isPortrait UIDeviceOrientationIsPortrait (dDeviceOrientation) +#define isLandscape UIDeviceOrientationIsLandscape(dDeviceOrientation) + +@implementation UIImage (JFFPhotoCamera) + +- (UIImage *)fixOrientationForPhotoCameraType:(JFFPhotoCameraType)photoCameraType + fixOrientation:(BOOL)fixOrientation + rotateImage:(BOOL)rotateImage +{ + UIImage *result = self; + + if (fixOrientation) + result = [result fixOrientation]; + + if (isLandscape) { + + if (rotateImage) { + + const CGFloat radians = M_PI_2 * ((photoCameraType == JFFPhotoCameraFront)?1:-1); + result = [result rotatedImageWithRadians:radians]; + } + else if (photoCameraType == JFFPhotoCameraFront) { + + const CGFloat radians = M_PI; + result = [result rotatedImageWithRadians:radians]; + } + } + + return result; +} + +@end + +@implementation JFFPhotoCamera +{ + AVCaptureSession *_captureSession; + AVCaptureDeviceInput *_frontCamInput; + AVCaptureDeviceInput *_backCamInput; + AVCaptureStillImageOutput *_camImageOutput; + AVCaptureDevice *_frontCameraDevice; + AVCaptureDevice *_backCameraDevice; + + AVCaptureVideoPreviewLayer *_internalCaptureVideoPreviewLayer; + + AVCaptureFlashMode _flashMode; +} + +@synthesize photoCameraType = _photoCameraType; + +@dynamic captureVideoPreviewLayer; + ++ (instancetype)allocWithZone:(NSZone *)zone +{ + JFFPhotoCamera *result = [super allocWithZone:zone]; + + if (result) { + + if (!__allActiveCameras) + __allActiveCameras = [JFFMutableAssignArray new]; + [__allActiveCameras addObject:result]; + } + + return result; +} + +- (instancetype)init +{ + return [self initPhotoCameraType:JFFPhotoCameraBack]; +} + +- (instancetype)initPhotoCameraType:(JFFPhotoCameraType)photoCameraType +{ + self = [super init]; + + if (self) { + + _fixOrientation = YES; + _rotateImage = YES; + _photoCameraType = photoCameraType; + + [self initCaptureSessions]; + [self setupCaptureInputs ]; + [self setupImageOutput ]; + } + + return self; +} + ++ (NSArray *)allActiveCameras +{ + return [__allActiveCameras array]; +} + +- (void)initCaptureSessions +{ + _captureSession = [AVCaptureSession new]; +} + +- (void)setupCaptureInputs +{ + NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; + + for (AVCaptureDevice *device in videoDevices) { + + if (device.position == AVCaptureDevicePositionFront) { + _frontCameraDevice = device; + break; + } + } + + NSError *error; + _frontCamInput = [AVCaptureDeviceInput deviceInputWithDevice:_frontCameraDevice error:&error]; + + NSAssert(!error, @"frontCamInput not intialized"); + + _backCameraDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; + + _backCamInput = [AVCaptureDeviceInput deviceInputWithDevice:_backCameraDevice error:&error]; + + NSAssert(!error, @"frontCamInput not intialized"); + + [_captureSession addInput:(_photoCameraType == JFFPhotoCameraFront)?_frontCamInput:_backCamInput]; +} + +- (CALayer *)captureVideoPreviewLayer +{ + if (!_internalCaptureVideoPreviewLayer) { + + _internalCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession]; + [_internalCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; + } + + return _internalCaptureVideoPreviewLayer; +} + +- (void)setupImageOutput +{ + _camImageOutput = [AVCaptureStillImageOutput new]; + + NSDictionary *outputSettings = @{ AVVideoCodecKey : AVVideoCodecJPEG }; + + [_camImageOutput setOutputSettings:outputSettings]; + + [_captureSession addOutput:_camImageOutput]; +} + +#pragma mark - Properties + +- (NSString *)sessionPreset +{ + return _captureSession.sessionPreset; +} + +- (void)setSessionPreset:(NSString *)sessionPreset +{ + _captureSession.sessionPreset = sessionPreset; +} + +- (JFFAVCaptureVideoOrientation)videoOrientation +{ + AVCaptureConnection *videoConnection = [self videoConnectionFromImageOutput:_camImageOutput]; + return videoConnection.videoOrientation; +} + +- (void)setVideoOrientation:(JFFAVCaptureVideoOrientation)videoOrientation +{ + AVCaptureConnection *videoConnection = [self videoConnectionFromImageOutput:_camImageOutput]; + videoConnection.videoOrientation = videoOrientation; +} + +- (JFFCameraFlashModeType)flashMode +{ + //TODO check is front camera + return _backCameraDevice.flashMode == AVCaptureFlashModeAuto + ? JFFCameraFlashModeAuto + : _backCameraDevice.flashMode == AVCaptureFlashModeOn + ? JFFCameraFlashModeOn + : JFFCameraFlashModeOff; +} + +- (void)setFlashMode:(JFFCameraFlashModeType)flashMode +{ + AVCaptureFlashMode deviceFlashMode = flashMode == JFFCameraFlashModeAuto + ?AVCaptureFlashModeAuto + :flashMode == JFFCameraFlashModeOn + ?AVCaptureFlashModeOn + :AVCaptureFlashModeOff; + + NSError *error; + [_backCameraDevice lockForConfiguration:&error]; + [error writeErrorWithJFFLogger]; + + _backCameraDevice.flashMode = deviceFlashMode; + + [_backCameraDevice unlockForConfiguration]; +} + +- (JFFPhotoCameraType)photoCameraType +{ + return _photoCameraType; +} + +- (void)setPhotoCameraType:(JFFPhotoCameraType)photoCameraType +{ + if (_photoCameraType == photoCameraType) + return; + + BOOL frontCameraWasActive = (_photoCameraType == JFFPhotoCameraFront); + + _photoCameraType = photoCameraType; + + BOOL isRunning = _captureSession.isRunning; + + if (isRunning) + [_captureSession stopRunning]; + + [_captureSession beginConfiguration]; + + [_captureSession removeInput: frontCameraWasActive?_frontCamInput:_backCamInput]; + [_captureSession addInput: frontCameraWasActive?_backCamInput :_frontCamInput]; + + [_captureSession commitConfiguration]; + + if (isRunning) + [_captureSession startRunning]; +} + +- (void)startRunning +{ + NSParameterAssert(_captureSession); + [_captureSession startRunning]; +} + +- (void)stopRunning +{ + NSParameterAssert(_captureSession); + [_captureSession stopRunning]; +} + +- (BOOL)isRunning +{ + return _captureSession.isRunning; +} + +- (AVCaptureConnection *)videoConnectionFromImageOutput:(AVCaptureStillImageOutput *)imageOutput +{ + AVCaptureConnection *videoConnection; + + for (AVCaptureConnection *connection in imageOutput.connections) { + for (AVCaptureInputPort *port in [connection inputPorts]) { + if ([[port mediaType] isEqual:AVMediaTypeVideo]) { + videoConnection = connection; + break; + } + } + if (videoConnection) { + break; + } + } + return videoConnection; +} + +- (void)makePhotoWithCallback:(PhotoCameraMakePhotoResult)callback +{ + NSParameterAssert(callback); + + AVCaptureStillImageOutput *cameraImageOutput = _camImageOutput; + + AVCaptureConnection *videoConnection = [self videoConnectionFromImageOutput:cameraImageOutput]; + + callback = [callback copy]; + + BOOL fixOrientation = self.fixOrientation; + BOOL rotateImage = self.rotateImage; + + JFFPhotoCameraType photoCameraType = _photoCameraType; + + [cameraImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) { + + if (error) { + callback(nil, error); + return; + } + + NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; + UIImage *photoImage = [[UIImage alloc] initWithData:imageData]; + + photoImage = [photoImage fixOrientationForPhotoCameraType:photoCameraType + fixOrientation:fixOrientation + rotateImage:rotateImage]; + + callback(photoImage, nil); + }]; +} + +@end diff --git a/lib/JFFUI/PhotoCamera/JFFPhotoCameraType.h b/lib/JFFUI/PhotoCamera/JFFPhotoCameraType.h new file mode 100644 index 0000000..92f5d91 --- /dev/null +++ b/lib/JFFUI/PhotoCamera/JFFPhotoCameraType.h @@ -0,0 +1,10 @@ +#ifndef JFFUI_JFFPhotoCameraType_h +#define JFFUI_JFFPhotoCameraType_h + +typedef NS_ENUM(NSUInteger, JFFPhotoCameraType) +{ + JFFPhotoCameraBack, + JFFPhotoCameraFront +}; + +#endif diff --git a/lib/JFFUI/StripeView/JFFPageSlider.h b/lib/JFFUI/StripeView/JFFPageSlider.h index 66dd48e..32d7896 100644 --- a/lib/JFFUI/StripeView/JFFPageSlider.h +++ b/lib/JFFUI/StripeView/JFFPageSlider.h @@ -13,10 +13,10 @@ @property (nonatomic, readonly) NSInteger lastIndex; @property (nonatomic, readonly) NSMutableDictionary *viewByIndex; -@property (nonatomic, weak) IBOutlet id< JFFPageSliderDelegate > delegate; +@property (weak, nonatomic) IBOutlet id delegate; -- (id)initWithFrame:(CGRect)frame - delegate:(id< JFFPageSliderDelegate >)delegate; +- (instancetype)initWithFrame:(CGRect)frame + delegate:(id< JFFPageSliderDelegate >)delegate; - (void)reloadData; @@ -37,4 +37,5 @@ - (void)removeViewsInRange:(JSignedRange)range; - (void)syncContentOffsetWithActiveElement; + @end diff --git a/lib/JFFUI/StripeView/JFFPageSlider.m b/lib/JFFUI/StripeView/JFFPageSlider.m index 8c1a766..e36df87 100644 --- a/lib/JFFUI/StripeView/JFFPageSlider.m +++ b/lib/JFFUI/StripeView/JFFPageSlider.m @@ -5,12 +5,12 @@ #include -@interface JFFPageSlider () < UIScrollViewDelegate > +@interface JFFPageSlider () -@property ( nonatomic ) UIScrollView *scrollView; -@property ( nonatomic ) NSInteger activeIndex; -@property ( nonatomic ) NSInteger firstIndex; -@property ( nonatomic ) NSMutableDictionary *viewByIndex; +@property (nonatomic) UIScrollView *scrollView; +@property (nonatomic) NSInteger activeIndex; +@property (nonatomic) NSInteger firstIndex; +@property (nonatomic) NSMutableDictionary *viewByIndex; @end @@ -21,15 +21,15 @@ @implementation JFFPageSlider NSRange _previousVisiableIndexesRange; } --(void)dealloc +- (void)dealloc { self.scrollView.delegate = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; } -- (id)initWithFrame:(CGRect)frame - delegate:(id< JFFPageSliderDelegate >)delegate +- (instancetype)initWithFrame:(CGRect)frame + delegate:(id< JFFPageSliderDelegate >)delegate { self = [super initWithFrame:frame]; @@ -41,11 +41,11 @@ - (id)initWithFrame:(CGRect)frame return self; } --(void)initialize +- (void)initialize { - _viewByIndex = [ NSMutableDictionary new ]; + _viewByIndex = [NSMutableDictionary new]; - _scrollView = [ [ UIScrollView alloc ] initWithFrame: self.bounds ]; + _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; _scrollView.backgroundColor = [ UIColor clearColor ]; _scrollView.delegate = self; _scrollView.clipsToBounds = YES; @@ -56,9 +56,6 @@ -(void)initialize NSRange range_ = { 0, 1 }; _previousVisiableIndexesRange = range_; - - if (self.delegate) - [self reloadData]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning:) @@ -83,17 +80,14 @@ - (void)didReceiveMemoryWarning:(NSNotification *)notification } } --(CGRect)elementFrameForIndex:( NSInteger )index_ +- (CGRect)elementFrameForIndex:(NSInteger)index { - CGFloat x_ = self.bounds.size.width * ( index_ - _firstIndex ); - CGRect frame_ = { { x_, 0.f }, { self.bounds.size.width, self.bounds.size.height } }; - - - - return frame_; + CGFloat x = self.bounds.size.width * (index - _firstIndex); + CGRect frame = CGRectMake(x, 0.f, self.bounds.size.width, self.bounds.size.height); + return frame; } --(void)removeAllElements +- (void)removeAllElements { [_viewByIndex enumerateKeysAndObjectsUsingBlock:^(id key, UIView *view, BOOL *stop) { [view removeFromSuperview]; @@ -101,7 +95,7 @@ -(void)removeAllElements [_viewByIndex removeAllObjects]; } --(void)updateScrollViewContentSize +- (void)updateScrollViewContentSize { //calls layoutSubviews _scrollView.contentSize = CGSizeMake(self.bounds.size.width * _cachedNumberOfElements, @@ -148,7 +142,7 @@ - (void)reloadData [self updateScrollViewContentSize]; } --(CGPoint)offsetForIndex:( NSInteger )index_ +- (CGPoint)offsetForIndex:( NSInteger )index_ { CGPoint result_ = { ( index_ - _firstIndex ) * _scrollView.bounds.size.width , _scrollView.contentOffset.y }; @@ -179,7 +173,7 @@ - (NSArray *)visibleElements return nil; } --(void)slideForward +- (void)slideForward { [self doesNotRecognizeSelector:_cmd]; } @@ -189,7 +183,7 @@ - (void)slideBackward [self doesNotRecognizeSelector:_cmd]; } --(void)slideToIndex:( NSInteger )index_ animated:( BOOL )animated_ +- (void)slideToIndex:( NSInteger )index_ animated:( BOOL )animated_ { _previousIndex = self.activeIndex; self.activeIndex = index_; @@ -197,7 +191,7 @@ -(void)slideToIndex:( NSInteger )index_ animated:( BOOL )animated_ [ _scrollView setContentOffset: offset_ animated: animated_ ]; } --(void)removeViewAtIndex:( NSInteger )index_ +- (void)removeViewAtIndex:( NSInteger )index_ { NSAssert( index_ != _activeIndex, @"Can not remove View at active index" ); @@ -212,7 +206,7 @@ -(void)removeViewAtIndex:( NSInteger )index_ [ _viewByIndex removeObjectForKey: numberIndex_ ]; } --(void)removeViewsInRange:( JSignedRange )range_ +- (void)removeViewsInRange:( JSignedRange )range_ { for ( NSInteger index_ = range_.location; index_ < range_.location + range_.length; @@ -230,52 +224,48 @@ -(void)removeViewsInRange:( JSignedRange )range_ [ _scrollView setContentOffset: offset_ animated: NO ]; } --(void)slideToIndex:( NSInteger )index_ +- (void)slideToIndex:( NSInteger )index_ { [ self slideToIndex: index_ animated: NO ]; } --(NSRange)visiableIndexesRange -{ - if ( _scrollView.bounds.size.width == 0 ) - { +- (NSRange)visiableIndexesRange +{ + if (_scrollView.bounds.size.width == 0) { NSLog(@"[!!!ERROR!!!] division by zero"); return _previousVisiableIndexesRange; } - NSInteger first_index_ = floorf( _scrollView.contentOffset.x / _scrollView.bounds.size.width ) + _firstIndex; - NSInteger last_index_ = ceilf( _scrollView.contentOffset.x / _scrollView.bounds.size.width ) + _firstIndex; + NSInteger firstIndex = floorf( _scrollView.contentOffset.x / _scrollView.bounds.size.width ) + _firstIndex; + NSInteger lastIndex = ceilf( _scrollView.contentOffset.x / _scrollView.bounds.size.width ) + _firstIndex; + lastIndex = fmin( lastIndex, self.lastIndex ); - last_index_ = fmin( last_index_, self.lastIndex ); + firstIndex = firstIndex > 0 ?: 0; - first_index_ = first_index_ > 0 ?: 0; - - NSRange range_ = { first_index_, last_index_ - first_index_ + 1 }; + NSRange range_ = { firstIndex, lastIndex - firstIndex + 1 }; _previousVisiableIndexesRange = range_; return _previousVisiableIndexesRange; } --(NSInteger)lastIndex +- (NSInteger)lastIndex { return _firstIndex + _cachedNumberOfElements - 1; } --(void)shiftRightElementsFromIndex:( NSInteger )shiftFromIndex - toIndex:( NSInteger )to_index_ +- (void)shiftRightElementsFromIndex:(NSInteger)shiftFromIndex + toIndex:(NSInteger)toIndex { - for (NSInteger index_ = to_index_; index_ >= shiftFromIndex; --index_) { + for (NSInteger index = toIndex; index >= shiftFromIndex; --index) { - UIView *view_ = [ self elementAtIndex: index_ ]; - if ( !view_ ) - { + UIView *view = [self elementAtIndex:index]; + if (!view) continue; - } - - [ self cacheAndPositionView: view_ toIndex: index_ ]; + + [self cacheAndPositionView:view toIndex:index]; } } --(void)inserElementAtIndex:( NSInteger )index_ +- (void)inserElementAtIndex:( NSInteger )index_ { NSInteger prevLastIndex_ = self.lastIndex; @@ -287,51 +277,46 @@ -(void)inserElementAtIndex:( NSInteger )index_ self.firstIndex = fmin( _firstIndex, index_ ); if ( index_ <= prevLastIndex_ ) - { [ self shiftRightElementsFromIndex: index_ toIndex: prevLastIndex_ ]; - } [ self addViewForIndex: index_ ]; [ self updateScrollViewContentSize ]; + [ self slideToIndex: _activeIndex ]; } --(void)pushFrontElement +- (void)pushFrontElement { [ self inserElementAtIndex: self.lastIndex + 1 ]; } --(void)pushBackElement +- (void)pushBackElement { [ self inserElementAtIndex: self.firstIndex - 1 ]; } #pragma mark UIScrollViewDelegate --(void)scrollViewDidScroll:(UIScrollView *)scrollView +- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - NSRange previuosRange_ = _previousVisiableIndexesRange; - NSRange index_range_ = [ self visiableIndexesRange ]; - - if ( NSEqualRanges( previuosRange_, index_range_ ) ) - { + NSRange previuosRange = _previousVisiableIndexesRange; + NSRange indexRange = [self visiableIndexesRange]; + + if (NSEqualRanges(previuosRange, indexRange)) return; - } - - NSInteger to_index_ = index_range_.location + index_range_.length; - for ( NSInteger index_ = index_range_.location; index_ < to_index_; ++index_ ) - { - if ( [ self elementAtIndex: index_ ] ) - { + + NSInteger toIndex = indexRange.location + indexRange.length; + for (NSInteger index = indexRange.location; index < toIndex; ++index) { + + if ([self elementAtIndex:index]) continue; - } - - [ self addViewForIndex: index_ ]; + + [self addViewForIndex:index]; } } --(void)syncContentOffsetWithActiveElement +- (void)syncContentOffsetWithActiveElement { if (_scrollView.bounds.size.width == 0) { @@ -350,4 +335,14 @@ -(void)syncContentOffsetWithActiveElement to: self.activeIndex ]; } +- (void)scrollViewDidEndDecelerating:( UIScrollView* )scrollView_ +{ + [ self syncContentOffsetWithActiveElement ]; +} + +- (void)scrollViewDidEndScrollingAnimation:( UIScrollView* )scrollView_ +{ + [ self syncContentOffsetWithActiveElement ]; +} + @end diff --git a/lib/JFFUI/StripeView/JFFPageSliderDelegate.h b/lib/JFFUI/StripeView/JFFPageSliderDelegate.h index 51273df..c7f7cee 100755 --- a/lib/JFFUI/StripeView/JFFPageSliderDelegate.h +++ b/lib/JFFUI/StripeView/JFFPageSliderDelegate.h @@ -5,17 +5,17 @@ @protocol JFFPageSliderDelegate < NSObject > @required --(NSInteger)numberOfElementsInStripeView:( JFFPageSlider* )pageSlider_; +- (NSInteger)numberOfElementsInStripeView:( JFFPageSlider* )pageSlider_; --(UIView*)stripeView:( JFFPageSlider* )pageSlider_ - elementAtIndex:( NSInteger )index_; +- (UIView *)stripeView:(JFFPageSlider *)pageSlider_ + elementAtIndex:(NSInteger)index_; --(void)pageSlider:( JFFPageSlider* )pageSlider_ -didChangeActiveElementFrom:( NSInteger )previousIndex_ - to:( NSInteger )activeIndex_; +- (void)pageSlider:(JFFPageSlider *)pageSlider +didChangeActiveElementFrom:(NSInteger)previousIndex + to:(NSInteger)activeIndex; @optional --(void)pageSlider:( JFFPageSlider* )pageSlider_ -handleMemoryWarningForElementAtIndex:( NSInteger )element_index_; +- (void)pageSlider:(JFFPageSlider *)pageSlider +handleMemoryWarningForElementAtIndex:(NSInteger)element_index_; @end diff --git a/lib/JFFUI/StripeView/JFFStripeView.h b/lib/JFFUI/StripeView/JFFStripeView.h new file mode 100644 index 0000000..7a60d9e --- /dev/null +++ b/lib/JFFUI/StripeView/JFFStripeView.h @@ -0,0 +1,42 @@ +#import + +@protocol JFFStripeViewDelegate; + +@interface JFFStripeView : UIView + +@property (nonatomic, readonly) UIScrollView *scrollView; +@property (nonatomic, readonly) UILabel *warningLabel; +@property (nonatomic, readonly) UIView *activeElementView; +@property (nonatomic, readonly) NSUInteger activeElement; + +@property (weak, nonatomic) IBOutlet id delegate; + +- (instancetype)initWithFrame:(CGRect)frame + delegate:(id)delegate; + +- (void)reloadData; + +- (void)relayoutElements; + +- (id)dequeueReusableElement; + +- (UIView *)elementAtIndex:(NSUInteger)index; + +- (NSOrderedSet *)visibleIndexes; + +- (void)removeElementWithIndex:(NSUInteger)index + animated:(BOOL)animated; + +- (void)insertElementAtIndex:(NSUInteger)index + animated:(BOOL)animated; + +- (void)exchangeElementAtIndex:(NSUInteger)firstIndex + withElementAtIndex:(NSUInteger)secondIndex; + +- (void)slideForward; + +- (void)slideToIndex:(NSInteger)index animated:(BOOL)animated; + +- (void)slideToIndex:(NSInteger)index; + +@end diff --git a/lib/JFFUI/StripeView/JFFStripeView.m b/lib/JFFUI/StripeView/JFFStripeView.m new file mode 100644 index 0000000..fc1706a --- /dev/null +++ b/lib/JFFUI/StripeView/JFFStripeView.m @@ -0,0 +1,735 @@ +#import "JFFStripeView.h" + +#import "JFFStripeViewDelegate.h" + +#import "UIView+AnimationWithBlocks.h" + +@interface JFFStripeView () + +@property (nonatomic) UIScrollView *scrollView; +@property (nonatomic) CGRect previousFrame; + +@property (nonatomic, readonly) CGFloat elementWidth; + +@property (nonatomic) NSUInteger activeElement; + +@property (nonatomic) NSMutableDictionary *elementsByIndex; +@property (nonatomic) NSMutableArray *reusableElements; + +- (void)removeElementWithIndex:(NSUInteger)index; + +- (void)initialize; + +@end + +@implementation JFFStripeView +{ + CGFloat _rightInset; + CGFloat _leftInset; + NSUInteger _activeElement; +} + +- (void)dealloc +{ + _scrollView.delegate = nil; +} + ++ (Class)scrollViewClass +{ + return [UIScrollView class]; +} + +- (NSUInteger)pageCount +{ + NSUInteger totalCount = [_delegate numberOfElementsInStripeView:self]; + + return ceil((CGFloat)totalCount / [_delegate elementsPerPageInStripeView:self]); +} + +- (void)setActiveElement:(NSUInteger)activeElement +{ + NSUInteger previousActiveElement = _activeElement; + _activeElement = activeElement; + + //TODO remove active element at all + [_delegate stripeView:self +didChangeActiveElementFrom:previousActiveElement + to:_activeElement]; + + [_delegate stripeView:self + didChangeActivePage:_activeElement / [_delegate elementsPerPageInStripeView:self] + numberOfPages:[self pageCount]]; +} + +- (void)layoutSubviews +{ + if (!CGRectEqualToRect(self.frame, self.previousFrame)) { + + [self relayoutElements]; + } + + self.previousFrame = self.frame; +} + +- (UIScrollView *)scrollView +{ + if (!_scrollView) { + + _scrollView = [[[[self class] scrollViewClass] alloc] initWithFrame:CGRectZero]; + _scrollView.backgroundColor = [UIColor clearColor]; + _scrollView.delegate = self; + _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _scrollView.clipsToBounds = NO; + _scrollView.pagingEnabled = YES; + _scrollView.bounces = YES; + } + + return _scrollView; +} + +- (CGFloat)elementWidth +{ + NSUInteger elementsPerPage = [_delegate elementsPerPageInStripeView:self]; + + CGFloat offset = [_delegate elementOffsetInStripeView:self]; + + return self.scrollView.frame.size.width / elementsPerPage - offset; +} + +- (instancetype)initWithFrame:(CGRect)frame + delegate:(id)delegate +{ + self = [super initWithFrame:frame]; + + if (self) { + + _delegate = delegate; + [self initialize]; + } + + return self; +} + +- (instancetype)init:(CGRect)frame +{ + NSAssert(NO, @"Unsupported initializer. Use 'initWithFrame:delegate:' instead" ); + return nil; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + NSAssert( NO, @"Unsupported initializer. Use 'initWithFrame:delegate:' instead" ); + return nil; +} + +- (void)awakeFromNib +{ + [super awakeFromNib]; + + [self initialize]; +} + +- (void)initialize +{ + self.clipsToBounds = YES; + self.backgroundColor = [UIColor clearColor]; + + UIView *backgroundView = [_delegate backgroundViewForStripeView:self]; + if (backgroundView) { + + backgroundView.frame = self.bounds; + backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [self addSubview:backgroundView]; + } + + CGFloat elementOffset = [_delegate elementOffsetInStripeView:self]; + + _rightInset = [_delegate rightFractionInsetInStripeView:self] * self.bounds.size.width - elementOffset; + _leftInset = [_delegate leftFractionInsetInStripeView:self ] * self.bounds.size.width; + + self.scrollView.frame = UIEdgeInsetsInsetRect( self.bounds, UIEdgeInsetsMake( 0.f, -_leftInset, 0.f, -_rightInset ) ); + [self addSubview:self.scrollView]; + + UIView *overlayView = [_delegate overlayViewForStripeView:self]; + overlayView.frame = self.bounds; + [self addSubview:overlayView]; +} + +- (NSInteger)minInternalIndex +{ + return [_delegate isCyclicStripeView:self]?- 1:0; +} + +- (NSInteger)maxInternalIndex +{ + NSInteger maxIndex = [_delegate numberOfElementsInStripeView:self]; + maxIndex = maxIndex == 0 ? 0 : maxIndex - 1; + + if ([_delegate isCyclicStripeView:self]) { + + return maxIndex + [_delegate elementsPerPageInStripeView:self]; + } + + return maxIndex; +} + +- (NSUInteger)convertInternalIndex:(NSInteger)index +{ + if ([_delegate isCyclicStripeView:self]) { + + NSUInteger count = [_delegate numberOfElementsInStripeView:self]; + return ( NSUInteger )(index + count) % count; + } + + return index; +} + +- (CGRect)rectForElementWithIndex:(NSInteger)index +{ + CGFloat elementWidth = self.elementWidth; + CGFloat elementOffset = [_delegate elementOffsetInStripeView: self ]; + + CGFloat x = elementOffset * (index + 1) + index * elementWidth; + CGFloat vericalOffset = [_delegate elementVericalOffsetInStripeView:self]; + return CGRectMake(x, vericalOffset, + ceil(elementWidth), self.scrollView.frame.size.height - 2 * vericalOffset); +} + +- (NSInteger)firstVisibleIndex +{ + CGFloat x = self.scrollView.contentOffset.x + _leftInset; + + /*if ( self.superview.clipsToBounds && self.frame.origin.x < 0 ) + { + x_ -= self.frame.origin.x; + }*/ + + NSInteger minIndex = [self minInternalIndex]; + NSInteger positionBasedIndex = floorf(x / ([_delegate elementOffsetInStripeView:self] + self.elementWidth)); + + NSInteger result = fmax(minIndex, positionBasedIndex); + return result; +} + +- (NSInteger)lastVisibleIndexWithFirstVisibleIndex:(NSInteger)firstVisibleIndex +{ + CGFloat x = self.scrollView.contentOffset.x + self.scrollView.frame.size.width - _rightInset - [_delegate elementOffsetInStripeView:self]; + + /*if ( self.superview.clipsToBounds + && CGRectGetMaxX( self.frame ) > CGRectGetMaxX( self.superview.bounds ) ) + { + x_ -= ( CGRectGetMaxX( self.frame ) - CGRectGetMaxX( self.superview.bounds ) ); + }*/ + + NSInteger maxIndex = [self maxInternalIndex]; + NSInteger positionBasedIndex = ceilf(x / ( [_delegate elementOffsetInStripeView:self] + self.elementWidth)) - 1; + + NSInteger result = fmin(maxIndex, positionBasedIndex); + result = fmax(result, firstVisibleIndex); + return result; +} + +- (JSignedRange)visibleIndexesRange +{ + if ([_delegate numberOfElementsInStripeView:self] == 0) + return JSignedRangeMake(0, 0); + + NSUInteger firstVisibleIndex = [self firstVisibleIndex]; + NSUInteger lastVisibleIndex = [self lastVisibleIndexWithFirstVisibleIndex:firstVisibleIndex]; + return JSignedRangeMake(firstVisibleIndex, lastVisibleIndex - firstVisibleIndex + 1); +} + +- (NSMutableOrderedSet *)mutableVisibleIndexes +{ + JSignedRange signedRange = [self visibleIndexesRange]; + + JFFProducerBlock block = ^id(NSUInteger index) { + + return @(signedRange.location + index); + }; + + NSMutableOrderedSet *result = [NSMutableOrderedSet setWithSize:signedRange.length + producer:block]; + + return result; +} + +- (NSOrderedSet *)visibleIndexes +{ + return [[self mutableVisibleIndexes] copy]; +} + +- (NSOrderedSet *)indexesToUpdate +{ + NSOrderedSet *controllersIndexes = [[NSOrderedSet alloc] initWithArray:[_elementsByIndex allKeys]?:@[]]; + NSMutableOrderedSet *result = [self mutableVisibleIndexes]; + [result minusOrderedSet:controllersIndexes]; + return result; +} + +- (NSOrderedSet *)unvisibleControllersIndexes +{ + NSMutableOrderedSet *result = [[NSMutableOrderedSet alloc] initWithArray:[_elementsByIndex allKeys]?:@[]]; + + NSOrderedSet *visibleIndexes = [self visibleIndexes]; + [result minusOrderedSet:visibleIndexes]; + return [result copy]; +} + +- (void)removeUnvisibleControllers +{ + NSOrderedSet *unvisibleControllersIndexes = [self unvisibleControllersIndexes]; + + for (NSNumber *index in unvisibleControllersIndexes ) { + + UIView *element = _elementsByIndex[index]; + [self.reusableElements addObject:element]; + [_elementsByIndex removeObjectForKey:index]; + + [element removeFromSuperview]; + } +} + +- (id)dequeueReusableElement +{ + if ([_reusableElements count] == 0) + return nil; + + UIView *reusableController = [_reusableElements lastObject]; + [_reusableElements removeLastObject]; + return reusableController; +} + +- (void)addElement:(UIView *)element + toPosition:(NSInteger)position +{ + CGAffineTransform scaleTransform = CGAffineTransformIdentity; + element.transform = scaleTransform; + element.frame = [self rectForElementWithIndex:position]; + element.autoresizingMask = UIViewAutoresizingNone; + [self.scrollView addSubview:element]; + [_scrollView sendSubviewToBack:element]; +} + +- (void)addElementAtIndex:(NSNumber *)index + toPosition:(NSInteger)position +{ + UIView *element = [_delegate stripeView:self + elementAtIndex:[self convertInternalIndex:[index intValue]]]; + + if (!element) + return; + + [self addElement:element toPosition:position]; + + self.elementsByIndex[index] = element; +} + +- (void)updateElements +{ + NSArray *indexesToUpdate = [[self indexesToUpdate] array]; + + [self removeUnvisibleControllers]; + + for (NSNumber *index in indexesToUpdate) { + + [self addElementAtIndex:index toPosition:[index intValue]]; + } +} + +- (void)adjustContentSizeAndSetElementIndex:(NSUInteger)elementIndex +{ + NSUInteger pageIndex = elementIndex / [_delegate elementsPerPageInStripeView:self]; + + UIScrollView *scrollView = self.scrollView; + + CGFloat stripeWidth = scrollView.frame.size.width; + + NSUInteger pageCount = [self pageCount]; + + CGFloat contentWidth = pageCount * stripeWidth; + CGFloat contentOffsetX = pageIndex * stripeWidth; + + scrollView.contentSize = CGSizeMake(contentWidth, self.scrollView.frame.size.height); + scrollView.contentOffset = CGPointMake(contentOffsetX, 0.f); + + if ([_delegate isCyclicStripeView:self]) { + + scrollView.contentInset = UIEdgeInsetsMake(0.f, stripeWidth, 0.f, stripeWidth); + } else { + + scrollView.contentInset = UIEdgeInsetsZero; + } + + [_delegate stripeView:self + didChangeActivePage:pageIndex + numberOfPages:[self pageCount]]; +} + +- (void)removeElementWithIndex:(NSUInteger)index +{ + UIView *element = [self elementAtIndex:index]; + [element removeFromSuperview]; + [_elementsByIndex removeObjectForKey:@(index)]; +} + +- (void)removeElements +{ + NSArray *views = [_elementsByIndex allValues]; + _elementsByIndex = nil; + + for (UIView *view in views) { + + [view removeFromSuperview]; + [self.reusableElements addObject:view]; + } +} + +- (void)reloadData +{ + [self removeElements]; + + //TODO35 do not notify delegate when reload, because get and set at the same time + self.activeElement = [_delegate activeElementForStripeView:self]; + + [self adjustContentSizeAndSetElementIndex:self.activeElement]; + + [self updateElements]; +} + +- (NSUInteger)activeElement +{ + return fmin(_activeElement, [_delegate numberOfElementsInStripeView:self] - 1); +} + +-(UIView *)activeElementView +{ + NSUInteger activeElementIndex = self.activeElement; + return [self elementAtIndex:activeElementIndex]; +} + +- (void)relayoutElementsAnimated:(BOOL)animated + updateElements:(BOOL)updateElements +{ + if (animated) { + + [UIView beginAnimations:@"StripeViewRelayout" context:nil]; + + CGFloat animationDuration = [_delegate animationDurationOnStripeViewRelayout:self]; + if (animationDuration >= 0.f) { + + [UIView setAnimationDuration:animationDuration]; + [UIView setAnimationBeginsFromCurrentState:YES]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; + } else { + + [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; + [UIView setAnimationBeginsFromCurrentState:YES]; + } + } + + [_elementsByIndex enumerateKeysAndObjectsUsingBlock:^(NSNumber *index, UIView *element, BOOL *stop) { + + element.frame = [self rectForElementWithIndex:[index intValue]]; + }]; + + //self.activeElement = [_delegate activeElementForStripeView: self ]; + + [self adjustContentSizeAndSetElementIndex:self.activeElement]; + + if (updateElements) { + + [ self updateElements ]; + } + + if (animated) { + + [UIView commitAnimations]; + } +} + +- (void)setFrame:(CGRect)newFrame +{ + self.scrollView.delegate = nil; + [super setFrame: newFrame]; + self.scrollView.delegate = self; +} + +- (void)relayoutElements +{ + [_delegate willRelayoutStripeView:self]; + + BOOL animationEnabled = [_delegate animationEnabledOnStripeViewRelayout:self]; + + [self relayoutElementsAnimated:animationEnabled + updateElements:YES]; + + [_delegate didRelayoutStripeView:self]; +} + +- (NSMutableDictionary *)elementsByIndex +{ + if (!_elementsByIndex) { + + _elementsByIndex = [NSMutableDictionary new]; + } + + return _elementsByIndex; +} + +- (NSMutableArray *)reusableElements +{ + if (!_reusableElements) { + + _reusableElements = [NSMutableArray new]; + } + + return _reusableElements; +} + +- (UIView *)elementAtIndex:(NSUInteger)index +{ + return _elementsByIndex[@(index)]; +} + +#pragma mark Remove element methods + +- (void)reindexElementsFromIndex:(NSUInteger)index + insertAction:(BOOL)yes +{ + NSUInteger currentIndex = yes + ? fmin([self lastVisibleIndexWithFirstVisibleIndex:[self firstVisibleIndex]], [_delegate numberOfElementsInStripeView:self] - 1) + : index; + + UIView* element_ = [self elementAtIndex:yes?--currentIndex:++currentIndex]; + BOOL removeLastElement = yes; + while ( element_ && currentIndex >= index ) + { + NSNumber* newIndex = @(currentIndex + ( yes ? 1 : -1 )); + + //local TODO move for insert action + if (removeLastElement) { + + [self removeElementWithIndex:[newIndex intValue]]; + removeLastElement = NO; + } + self.elementsByIndex[newIndex] = element_; + + [_elementsByIndex removeObjectForKey:@(currentIndex)]; + + element_ = _elementsByIndex[@( yes ? --currentIndex : ++currentIndex)]; + } +} + +- (void)prepareNewVisibleElementAtInsertAction:(BOOL)yes + actionIndex:(NSUInteger)actIndex +{ + NSUInteger firstVisibleIndex = [self firstVisibleIndex]; + + if (yes) { + + UIView* elementView = _elementsByIndex[@(firstVisibleIndex)]; + if ( !elementView + && firstVisibleIndex >= 1 + && actIndex <= firstVisibleIndex + && firstVisibleIndex < [_delegate numberOfElementsInStripeView: self ] ) + { + [self addElementAtIndex:@(firstVisibleIndex - 1) + toPosition:firstVisibleIndex]; + } + return; + } + + NSUInteger lastVisibleIndex = [self lastVisibleIndexWithFirstVisibleIndex:firstVisibleIndex]; + UIView *elementView = _elementsByIndex[@(lastVisibleIndex)]; + if ( !elementView + && lastVisibleIndex < [_delegate numberOfElementsInStripeView:self] + && actIndex <= lastVisibleIndex ) + { + [self addElementAtIndex:@(lastVisibleIndex) + toPosition:lastVisibleIndex + 1]; + } +} + +- (void)removeElementWithIndex:(NSUInteger)index animated:(BOOL)animated +{ + [self removeElementWithIndex:index]; + + [self reindexElementsFromIndex:index insertAction:NO]; + + [self prepareNewVisibleElementAtInsertAction:NO actionIndex:index]; + + [self relayoutElementsAnimated:animated updateElements:YES]; +} + +#pragma mark Insert element methods + +- (void)addElementWithIndex:(NSUInteger)index animated:(BOOL)animated +{ + JFFSimpleBlock animations = ^() { + + NSOrderedSet* visibleIndexes = [self visibleIndexes]; + + NSNumber *numIndex_ = @(index); + if ([visibleIndexes containsObject:numIndex_]) { + + [ self addElementAtIndex: numIndex_ toPosition: index ]; + } + }; + + if (animated) { + + [UIView animateWithOptions:(UIViewAnimationOptionCurveEaseIn) + animations:animations]; + } else { + + animations(); + } +} + +- (void)insertElementAtIndex:(NSUInteger)index + animated:(BOOL)animated +{ + [self reindexElementsFromIndex:index insertAction:YES]; + + [self addElementWithIndex:index animated:NO]; + + [self prepareNewVisibleElementAtInsertAction:YES actionIndex:index]; + + [self relayoutElementsAnimated:animated updateElements:YES]; +} + +#pragma mark Move element methods + +- (void)prepareNewVisibleElementAtIndex:(NSUInteger)index + position:(NSUInteger)position +{ + UIView *controller = _elementsByIndex[@(position)]; + if (!controller) { + + UIView *element = [_delegate stripeView:self + elementAtIndex:[self convertInternalIndex:index]]; + + [self addElement:element toPosition:position]; + + self.elementsByIndex[@(position)] = element; + } +} + +- (void)exchangeElementAtIndex:(NSUInteger)firstIndex + withElementAtIndex:(NSUInteger)secondIndex +{ + [self prepareNewVisibleElementAtIndex:firstIndex position:secondIndex]; + [self prepareNewVisibleElementAtIndex:secondIndex position:firstIndex ]; + + NSNumber *fromIndexNum = @(firstIndex ); + NSNumber *toIndexNum = @(secondIndex); + + UIView *firstView = _elementsByIndex[fromIndexNum]; + UIView *secondView = _elementsByIndex[toIndexNum ]; + + self.elementsByIndex[fromIndexNum] = secondView; + self.elementsByIndex[toIndexNum ] = firstView ; + + [self relayoutElementsAnimated:YES updateElements:NO]; +} + +#pragma mark UIScrollViewDelegate + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ + [self updateElements]; + + if ([_delegate respondsToSelector:@selector(stripeViewDidScroll:)]) + [_delegate stripeViewDidScroll:self]; +} + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate +{ + [_delegate stripeViewWasDragged:self]; +} + +- (void)syncContentOffsetWithActiveElement +{ + if ([_delegate numberOfElementsInStripeView:self] == 0) + return; + + NSInteger activeElement = self.scrollView.contentOffset.x / self.scrollView.frame.size.width * [_delegate elementsPerPageInStripeView:self]; + + NSUInteger elementsCount = [_delegate numberOfElementsInStripeView:self]; + if ([_delegate isCyclicStripeView:self] && (activeElement < 0 || activeElement >= elementsCount)) + { + activeElement = ( activeElement + elementsCount ) % elementsCount; + + [self adjustContentSizeAndSetElementIndex:activeElement]; + } + + self.activeElement = activeElement; + + //local TODO remove this + [_delegate didStopScrollingStripeView:self]; +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView +{ + [self syncContentOffsetWithActiveElement]; +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView +{ + [self syncContentOffsetWithActiveElement]; +} + +//local TODO remove this method +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView +{ + if ([_delegate respondsToSelector:@selector(didStartScrollingStripeView:)]) + [_delegate didStartScrollingStripeView:self]; + + [_delegate stripeView:self willChangeActiveElementFrom:self.activeElement]; +} + +- (void)slideForward +{ + if ([_delegate numberOfElementsInStripeView:self] <= 1) + return; + + CGPoint contentOffset = self.scrollView.contentOffset; + + if ([_delegate isCyclicStripeView:self] + || ( contentOffset.x + self.scrollView.frame.size.width <= self.scrollView.contentSize.width)) + { + [_delegate didStartScrollingStripeView:self]; + + contentOffset.x += self.scrollView.frame.size.width; + [self.scrollView setContentOffset:contentOffset animated:YES]; + } +} + +- (void)slideToIndex:(NSInteger)index animated:(BOOL)animated +{ + if ((index < 0) || (index >= [_delegate numberOfElementsInStripeView:self])) + return; + + CGPoint contentOffset = self.scrollView.contentOffset; + + if ([_delegate respondsToSelector:@selector(didStartScrollingStripeView:)]) + [_delegate didStartScrollingStripeView:self]; + + contentOffset.x = self.scrollView.frame.size.width * ( index / [_delegate elementsPerPageInStripeView:self]); + [self.scrollView setContentOffset:contentOffset animated:animated]; + + self.activeElement = index; + + if (!animated) { + + [_delegate didStopScrollingStripeView:self]; + } +} + +- (void)slideToIndex:(NSInteger)index +{ + [self slideToIndex:index animated:YES]; +} + +@end diff --git a/lib/JFFUI/StripeView/JFFStripeViewDelegate.h b/lib/JFFUI/StripeView/JFFStripeViewDelegate.h new file mode 100644 index 0000000..4620ab6 --- /dev/null +++ b/lib/JFFUI/StripeView/JFFStripeViewDelegate.h @@ -0,0 +1,58 @@ +#import + +@class JFFStripeView; + +@protocol JFFStripeViewDelegate< NSObject > + +- (NSUInteger)numberOfElementsInStripeView:(JFFStripeView *)stripeView; + +- (UIView *)stripeView:(JFFStripeView *)stripeView + elementAtIndex:(NSUInteger)index; + +- (NSUInteger)elementsPerPageInStripeView:(JFFStripeView *)stripeView; + +//TODO change to active page? +- (NSUInteger)activeElementForStripeView:(JFFStripeView *)stripeView; + +@optional + +- (void)stripeViewDidScroll:(JFFStripeView *)stripeView; + +- (CGFloat)elementOffsetInStripeView:(JFFStripeView *)stripeView; + +- (CGFloat)elementVericalOffsetInStripeView:(JFFStripeView *)stripeView; + +-(UIView*)backgroundViewForStripeView:(JFFStripeView *)stripeView; + +-(UIView*)overlayViewForStripeView:(JFFStripeView *)stripeView; + +- (CGFloat)leftFractionInsetInStripeView:(JFFStripeView *)stripeView; +- (CGFloat)rightFractionInsetInStripeView:(JFFStripeView *)stripeView; + +- (void)stripeView:(JFFStripeView *)stripeView +willChangeActiveElementFrom:(NSUInteger)activeElement; + +- (void)stripeView:(JFFStripeView *)stripeView +didChangeActiveElementFrom:(NSUInteger)oldActiveElement + to:(NSUInteger)newActiveElement; + +- (void)willRelayoutStripeView:(JFFStripeView *)stripeView; +- (void)didRelayoutStripeView:(JFFStripeView *)stripeView; + +- (void)didStartScrollingStripeView:(JFFStripeView *)stripeView; +- (void)didStopScrollingStripeView:(JFFStripeView *)stripeView; + +- (BOOL)isCyclicStripeView:(JFFStripeView *)stripeView; + +- (void)stripeView:(JFFStripeView *)stripeView +didChangeActivePage:(NSUInteger)activePage + numberOfPages:(NSUInteger)numberOfPages; + +- (void)stripeViewWasDragged:(JFFStripeView *)stripeView; + +#pragma mark - +#pragma mark animations +- (BOOL)animationEnabledOnStripeViewRelayout:(JFFStripeView *)stripeView; +- (CGFloat)animationDurationOnStripeViewRelayout:(JFFStripeView *)stripeView; + +@end diff --git a/lib/JFFUI/StripeView/JFFStripeViewDelegate.m b/lib/JFFUI/StripeView/JFFStripeViewDelegate.m new file mode 100644 index 0000000..dae4f37 --- /dev/null +++ b/lib/JFFUI/StripeView/JFFStripeViewDelegate.m @@ -0,0 +1,89 @@ +#import "JFFStripeViewDelegate.h" + +@implementation NSObject ( ESStripeViewControllerDelegate ) + +- (CGFloat)elementOffsetInStripeView:(JFFStripeView *)stripeView +{ + return 0.f; +} + +- (CGFloat)elementVericalOffsetInStripeView:(JFFStripeView *)stripeView +{ + return [self elementOffsetInStripeView:stripeView]; +} + +- (NSUInteger)activeElementForStripeView:(JFFStripeView *)stripeView +{ + return 0; +} + +- (UIView *)backgroundViewForStripeView:(JFFStripeView *)stripeView +{ + return nil; +} + +- (UIView *)overlayViewForStripeView:(JFFStripeView *)stripeView +{ + return nil; +} + +- (CGFloat)leftFractionInsetInStripeView:(JFFStripeView *)stripeView +{ + return 0.f; +} + +- (CGFloat)rightFractionInsetInStripeView:(JFFStripeView *)stripeView +{ + return 0.f; +} + +- (void)stripeView:(JFFStripeView *)stripeView +willChangeActiveElementFrom:(NSUInteger)active_element_ +{ +} + +- (void)stripeView:(JFFStripeView *)stripeView +didChangeActiveElementFrom:(NSUInteger)oldActiveElement + to:(NSUInteger)newActiveElement +{ +} + +- (void)willRelayoutStripeView:(JFFStripeView *)stripeView +{ +} + +- (void)didRelayoutStripeView:(JFFStripeView *)stripeView +{ +} + +- (void)didStopScrollingStripeView:(JFFStripeView *)stripeView +{ +} + +- (BOOL)isCyclicStripeView:(JFFStripeView *)stripeView +{ + return NO; +} + +- (void)stripeView:(JFFStripeView *)stripeView +didChangeActivePage:(NSUInteger)activePage + numberOfPages:(NSUInteger)numberOfPages +{ +} + +- (void)stripeViewWasDragged:(JFFStripeView *)stripeView +{ +} + +- (BOOL)animationEnabledOnStripeViewRelayout:(JFFStripeView *)stripeView +{ + return NO; +} + +- (CGFloat)animationDurationOnStripeViewRelayout:(JFFStripeView *)stripeView +{ + // feature disabled + return -1.f; +} + +@end diff --git a/lib/JFFUI/UIImage/UIImage+DrawImageInImage.h b/lib/JFFUI/UIImage/UIImage+DrawImageInImage.h new file mode 100644 index 0000000..d8af8a8 --- /dev/null +++ b/lib/JFFUI/UIImage/UIImage+DrawImageInImage.h @@ -0,0 +1,9 @@ +#import + +@interface UIImage (DrawImageInImage) + +- (instancetype)drawInImage:(UIImage *)bgImage + atPoint:(CGPoint)point + size:(CGSize)size; + +@end diff --git a/lib/JFFUI/UIImage/UIImage+DrawImageInImage.m b/lib/JFFUI/UIImage/UIImage+DrawImageInImage.m new file mode 100644 index 0000000..48fd178 --- /dev/null +++ b/lib/JFFUI/UIImage/UIImage+DrawImageInImage.m @@ -0,0 +1,21 @@ +#import "UIImage+DrawImageInImage.h" + +//source: http://stackoverflow.com/questions/7313023/overlay-an-image-over-another-image-in-ios + +@implementation UIImage (DrawImageInImage) + +- (instancetype)drawInImage:(UIImage *)bgImage + atPoint:(CGPoint)point + size:(CGSize)size +{ + UIGraphicsBeginImageContextWithOptions(size, NO, 0.f); + + [bgImage drawAsPatternInRect:CGRectMake(0.f, 0.f, size.width, size.height)]; + [self drawInRect:CGRectMake(point.x, point.y, self.size.width, self.size.height)]; + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return newImage; +} + +@end diff --git a/lib/JFFUtils/UIImage/UIImage+FixOrientation.h b/lib/JFFUI/UIImage/UIImage+FixOrientation.h similarity index 68% rename from lib/JFFUtils/UIImage/UIImage+FixOrientation.h rename to lib/JFFUI/UIImage/UIImage+FixOrientation.h index f6fdca4..b0aed29 100644 --- a/lib/JFFUtils/UIImage/UIImage+FixOrientation.h +++ b/lib/JFFUI/UIImage/UIImage+FixOrientation.h @@ -2,6 +2,6 @@ @interface UIImage (FixOrientation) -- (UIImage *)fixOrientation; +- (instancetype)fixOrientation; @end diff --git a/lib/JFFUtils/UIImage/UIImage+FixOrientation.m b/lib/JFFUI/UIImage/UIImage+FixOrientation.m similarity index 98% rename from lib/JFFUtils/UIImage/UIImage+FixOrientation.m rename to lib/JFFUI/UIImage/UIImage+FixOrientation.m index 4dc6bbc..42ad49a 100644 --- a/lib/JFFUtils/UIImage/UIImage+FixOrientation.m +++ b/lib/JFFUI/UIImage/UIImage+FixOrientation.m @@ -4,7 +4,9 @@ @implementation UIImage (FixOrientation) //source: http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload -- (UIImage *)fixOrientation { +//TODO move to JFFUI because it's UI + +- (instancetype)fixOrientation { // No-op if the orientation is already correct if (self.imageOrientation == UIImageOrientationUp) return self; diff --git a/lib/JFFUI/UIImage/UIImage+ImageWithColor.h b/lib/JFFUI/UIImage/UIImage+ImageWithColor.h new file mode 100644 index 0000000..a49f8b4 --- /dev/null +++ b/lib/JFFUI/UIImage/UIImage+ImageWithColor.h @@ -0,0 +1,7 @@ +#import + +@interface UIImage (ImageWithColor) + ++ (instancetype)newImageWithColor:(UIColor *)color andSize:(CGSize)size; + +@end diff --git a/lib/JFFUI/UIImage/UIImage+ImageWithColor.m b/lib/JFFUI/UIImage/UIImage+ImageWithColor.m new file mode 100644 index 0000000..953fa27 --- /dev/null +++ b/lib/JFFUI/UIImage/UIImage+ImageWithColor.m @@ -0,0 +1,22 @@ +#import "UIImage+ImageWithColor.h" + +@implementation UIImage (ImageWithColor) + ++ (instancetype)newImageWithColor:(UIColor *)color andSize:(CGSize)size +{ + UIImage *img; + + CGRect rect = CGRectMake(0, 0, size.width, size.height); + UIGraphicsBeginImageContext(rect.size); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(context, color.CGColor); + CGContextFillRect(context, rect); + + img = UIGraphicsGetImageFromCurrentImageContext(); + + UIGraphicsEndImageContext(); + + return img; +} + +@end diff --git a/lib/JFFUI/UIImage/UIImage+JpegPackImage.h b/lib/JFFUI/UIImage/UIImage+JpegPackImage.h new file mode 100644 index 0000000..e7c0cc8 --- /dev/null +++ b/lib/JFFUI/UIImage/UIImage+JpegPackImage.h @@ -0,0 +1,8 @@ +#import + +@interface UIImage (JpegPackImage) + +- (void)jffJpegPackImageToDataFilePath:(NSString *)filePath + compression:(CGFloat)compression; + +@end diff --git a/lib/JFFUI/UIImage/UIImage+JpegPackImage.m b/lib/JFFUI/UIImage/UIImage+JpegPackImage.m new file mode 100644 index 0000000..f6fe83a --- /dev/null +++ b/lib/JFFUI/UIImage/UIImage+JpegPackImage.m @@ -0,0 +1,310 @@ +#import "UIImage+JpegPackImage.h" + +#include + +#include + +//1. TODO - Move to separate library + +//based on example: https://code.google.com/p/sumatrapdf/source/browse/trunk/ext/libjpeg-turbo/example.c?r=2397 + +/* + * Sample routine for JPEG compression. We assume that the target file name + * and a compression quality factor are passed in. + */ + +typedef struct +{ + const char *filename; + int quality; + JSAMPLE * imageBuffer; + unsigned int imageWidth; + unsigned int imageHeight; + int bytesPerRow; + J_COLOR_SPACE colorSpace; + int inputComponents; + +} JpegCompressInfoArg; + +LOCAL(void) +write_JPEG_file(JpegCompressInfoArg *args) +{ + /* This struct contains the JPEG compression parameters and pointers to + * working space (which is allocated as needed by the JPEG library). + * It is possible to have several such structures, representing multiple + * compression/decompression processes, in existence at once. We refer + * to any one struct (and its associated working data) as a "JPEG object". + */ + struct jpeg_compress_struct cinfo; + /* This struct represents a JPEG error handler. It is declared separately + * because applications often want to supply a specialized error handler + * (see the second half of this file for an example). But here we just + * take the easy way out and use the standard error handler, which will + * print a message on stderr and call exit() if compression fails. + * Note that this struct must live as long as the main JPEG parameter + * struct, to avoid dangling-pointer problems. + */ + struct jpeg_error_mgr jerr; + /* More stuff */ + FILE * outfile; /* target file */ + JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ + int row_stride; /* physical row width in image buffer */ + + /* Step 1: allocate and initialize JPEG compression object */ + + /* We have to set up the error handler first, in case the initialization + * step fails. (Unlikely, but it could happen if you are out of memory.) + * This routine fills in the contents of struct jerr, and returns jerr's + * address which we place into the link field in cinfo. + */ + cinfo.err = jpeg_std_error(&jerr); + /* Now we can initialize the JPEG compression object. */ + jpeg_create_compress(&cinfo); + + /* Step 2: specify data destination (eg, a file) */ + /* Note: steps 2 and 3 can be done in either order. */ + + /* Here we use the library-supplied code to send compressed data to a + * stdio stream. You can also write your own code to do something else. + * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that + * requires it in order to write binary files. + */ + if ((outfile = fopen(args->filename, "wb")) == NULL) { + fprintf(stderr, "can't open %s\n", args->filename); + exit(1);//TODO create outError when error + } + jpeg_stdio_dest(&cinfo, outfile); + + /* Step 3: set parameters for compression */ + + /* First we supply a description of the input image. + * Four fields of the cinfo struct must be filled in: + */ + cinfo.image_width = args->imageWidth; /* image width and height, in pixels */ + cinfo.image_height = args->imageHeight; + cinfo.input_components = args->inputComponents; /* # of color components per pixel */ + cinfo.in_color_space = args->colorSpace; /* colorspace of input image */ + /* Now use the library's routine to set default compression parameters. + * (You must set at least cinfo.in_color_space before calling this, + * since the defaults depend on the source color space.) + */ + jpeg_set_defaults(&cinfo); + /* Now you can set any non-default parameters you wish to. + * Here we just illustrate the use of quality (quantization table) scaling: + */ + jpeg_set_quality(&cinfo, args->quality, TRUE /* limit to baseline-JPEG values */); + + /* Step 4: Start compressor */ + + /* TRUE ensures that we will write a complete interchange-JPEG file. + * Pass TRUE unless you are very sure of what you're doing. + */ + jpeg_start_compress(&cinfo, TRUE); + + /* Step 5: while (scan lines remain to be written) */ + /* jpeg_write_scanlines(...); */ + + /* Here we use the library's state variable cinfo.next_scanline as the + * loop counter, so that we don't have to keep track ourselves. + * To keep things simple, we pass one scanline per call; you can pass + * more if you wish, though. + */ + row_stride = args->bytesPerRow; /* JSAMPLEs per row in image_buffer */ + + while (cinfo.next_scanline < cinfo.image_height) { + /* jpeg_write_scanlines expects an array of pointers to scanlines. + * Here the array is only one element long, but you could pass + * more than one scanline at a time if that's more convenient. + */ + row_pointer[0] = & args->imageBuffer[cinfo.next_scanline * row_stride]; + (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + + /* Step 6: Finish compression */ + + jpeg_finish_compress(&cinfo); + /* After finish_compress, we can close the output file. */ + fclose(outfile); + + /* Step 7: release JPEG compression object */ + + /* This is an important step since it will release a good deal of memory. */ + jpeg_destroy_compress(&cinfo); + + /* And we're done! */ +} + +static inline J_COLOR_SPACE glibColorspace(CGImageRef imageRef, + CGColorSpaceRef colorSpace, + int *numberOfComponents) +{ + CGColorSpaceModel model = CGColorSpaceGetModel(colorSpace); + + NSCParameterAssert(model == kCGColorSpaceModelRGB); + + CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef); + +#ifdef DEBUG + { + static CGImageAlphaInfo supportedAlphaInfo[] = + { + kCGImageAlphaPremultipliedLast, + kCGImageAlphaPremultipliedFirst, + kCGImageAlphaNoneSkipLast, + kCGImageAlphaNoneSkipFirst, + }; + + const size_t size = sizeof(supportedAlphaInfo)/sizeof(supportedAlphaInfo[0]); + size_t index = 0; + + for (; index < size; ++index) { + + if (supportedAlphaInfo[index] == alphaInfo) + break; + } + NSCAssert(index != size, @"unsupported alpha type"); + } +#endif //DEBUG + + CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef); + + BOOL isLittle = (bitmapInfo & kCGBitmapByteOrder16Little) || (bitmapInfo & kCGBitmapByteOrder32Little); + BOOL isBig = (bitmapInfo & kCGBitmapByteOrder16Big ) || (bitmapInfo & kCGBitmapByteOrder32Big ); + BOOL reverseOrder = (isLittle || isBig); + + //table - alpha | order | result + // kCGImageAlphaPremultipliedLast | normal | RGBA + // kCGImageAlphaPremultipliedLast | reverse | ABGR + // kCGImageAlphaPremultipliedFirst | normal | ARGB + // kCGImageAlphaPremultipliedFirst | reverse | BGRA + // kCGImageAlphaNoneSkipLast | normal | RGBX + // kCGImageAlphaNoneSkipLast | reverse | XBGR + // kCGImageAlphaNoneSkipFirst | normal | XRGB + // kCGImageAlphaNoneSkipFirst | reverse | BGRX + + static J_COLOR_SPACE alphaInfoToJCS[][2] = + { + //normal | reverse + {JCS_UNKNOWN , JCS_UNKNOWN },//- kCGImageAlphaNone + {JCS_EXT_RGBA, JCS_EXT_ABGR},//+ kCGImageAlphaPremultipliedLast + {JCS_EXT_ARGB, JCS_EXT_BGRA},//+ kCGImageAlphaPremultipliedFirst + {JCS_UNKNOWN , JCS_UNKNOWN },//- kCGImageAlphaLast + {JCS_UNKNOWN , JCS_UNKNOWN },//- kCGImageAlphaFirst + {JCS_EXT_RGBX, JCS_EXT_XBGR},//+ kCGImageAlphaNoneSkipLast + {JCS_EXT_XRGB, JCS_EXT_BGRX},//+ kCGImageAlphaNoneSkipFirst + {JCS_UNKNOWN , JCS_UNKNOWN },//- kCGImageAlphaOnly + }; + + J_COLOR_SPACE result = alphaInfoToJCS[alphaInfo][reverseOrder?1:0]; + + NSCAssert(result != JCS_UNKNOWN, @"unsupported colorspace -> todo implement"); + + *numberOfComponents = 4; + + return result; +} + +static NSString *filePathToRGBAImage(CGImageRef imageRef, + size_t *rawDataLength, + void **rawData) +{ + size_t width = CGImageGetWidth (imageRef); + size_t height = CGImageGetHeight(imageRef); + + size_t bytesPerRow = CGImageGetBytesPerRow(imageRef); + + *rawDataLength = bytesPerRow*CGImageGetHeight(imageRef); + + NSString *filePath = [[NSUUID new] UUIDString]; + filePath = [NSString cachesPathByAppendingPathComponent:filePath]; + const char *filePathPtr = [filePath cStringUsingEncoding:NSUTF8StringEncoding]; + + FILE *file = fopen(filePathPtr, "w+"); + + if (file == NULL) { + + printf("Error opening file %s!\n\n" , filePathPtr); + exit(1); + return nil; + } + + fseek(file, (*rawDataLength)-1, SEEK_SET); + fprintf(file, "%c", 0x00); + fseek(file, 0, SEEK_SET); + + int fd = fileno(file); + *rawData = mmap(NULL, (*rawDataLength), PROT_WRITE, MAP_SHARED, fd, 0); + + if (*rawData == MAP_FAILED) { + + int code = errno; + printf("Error opening mmap file %i!\n\n" , code); + fclose(file); + exit(1); + return nil; + } + + fclose(file); + + size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef); + + CGColorSpaceRef colorspace = CGImageGetColorSpace(imageRef); + + CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef); + + CGContextRef contextRef = CGBitmapContextCreate(*rawData, + width, + height, + bitsPerComponent, + bytesPerRow, + colorspace, + bitmapInfo); + + CGContextDrawImage(contextRef, CGRectMake(0, 0, width, height), imageRef); + + CGContextRelease(contextRef); + + return filePath; +} + +static void UIImageJPEGRepresentationFilePath(UIImage *image, CGFloat compressionQuality, NSString *resultFilePath) +{ + JpegCompressInfoArg args; + + args.filename = [resultFilePath cStringUsingEncoding:NSUTF8StringEncoding]; + + CGImageRef imageRef = image.CGImage; + + args.imageWidth = (unsigned int)CGImageGetWidth (imageRef); + args.imageHeight = (unsigned int)CGImageGetHeight(imageRef); + + NSString *bitmapFile; + void *rawData; + size_t rawDataLength; + { + bitmapFile = filePathToRGBAImage(imageRef, &rawDataLength, &rawData); + args.imageBuffer = (JSAMPLE *)rawData; + } + + CGColorSpaceRef colorSpaceRef = CGImageGetColorSpace(imageRef); + + args.colorSpace = glibColorspace(imageRef, colorSpaceRef, &args.inputComponents); + + args.quality = (int)compressionQuality*100.f; + args.bytesPerRow = (int)CGImageGetBytesPerRow(imageRef); + + write_JPEG_file(&args); + + [[NSFileManager defaultManager] removeItemAtPath:bitmapFile error:NULL]; + munmap(rawData, rawDataLength); +} + +@implementation UIImage (JpegPackImage) + +- (void)jffJpegPackImageToDataFilePath:(NSString *)filePath + compression:(CGFloat)compression +{ + UIImageJPEGRepresentationFilePath(self, compression, filePath); +} + +@end diff --git a/lib/JFFUI/UIImage/UIImage+ScaleToSize.h b/lib/JFFUI/UIImage/UIImage+ScaleToSize.h new file mode 100644 index 0000000..277a2e6 --- /dev/null +++ b/lib/JFFUI/UIImage/UIImage+ScaleToSize.h @@ -0,0 +1,10 @@ +#import + +@interface UIImage (ScaleToSize) + +- (instancetype)imageScaledToSize:(CGSize)targetSize + contentMode:(UIViewContentMode)contentMode; + +- (instancetype)imageScale:(CGFloat)scale; + +@end diff --git a/lib/JFFUtils/UIImage/UIImage+ScaleToSize.m b/lib/JFFUI/UIImage/UIImage+ScaleToSize.m similarity index 60% rename from lib/JFFUtils/UIImage/UIImage+ScaleToSize.m rename to lib/JFFUI/UIImage/UIImage+ScaleToSize.m index 1c2824c..126a5a5 100644 --- a/lib/JFFUtils/UIImage/UIImage+ScaleToSize.m +++ b/lib/JFFUI/UIImage/UIImage+ScaleToSize.m @@ -27,4 +27,21 @@ - (UIImage *)imageScaledToSize:(CGSize)targetSize return newImage; } +- (instancetype)imageScale:(CGFloat)scale +{ + UIGraphicsBeginImageContext(self.size); + CGContextRef currentContext = UIGraphicsGetCurrentContext(); + + CGContextTranslateCTM(currentContext, self.size.width/2.f, self.size.height/2.f); + + CGContextScaleCTM(currentContext, scale, -scale); + + CGRect drawRect = CGRectMake(-self.size.width/2.f, -self.size.height/2.f, self.size.width, self.size.height); + CGContextDrawImage(currentContext, drawRect, self.CGImage); + UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return cropped; +} + @end diff --git a/lib/JFFUtils/UIImage/UIImage+WriteToTmpFile.h b/lib/JFFUI/UIImage/UIImage+WriteToTmpFile.h similarity index 100% rename from lib/JFFUtils/UIImage/UIImage+WriteToTmpFile.h rename to lib/JFFUI/UIImage/UIImage+WriteToTmpFile.h diff --git a/lib/JFFUtils/UIImage/UIImage+WriteToTmpFile.m b/lib/JFFUI/UIImage/UIImage+WriteToTmpFile.m similarity index 77% rename from lib/JFFUtils/UIImage/UIImage+WriteToTmpFile.m rename to lib/JFFUI/UIImage/UIImage+WriteToTmpFile.m index cb20979..9b80869 100644 --- a/lib/JFFUtils/UIImage/UIImage+WriteToTmpFile.m +++ b/lib/JFFUI/UIImage/UIImage+WriteToTmpFile.m @@ -1,7 +1,7 @@ #import "UIImage+WriteToTmpFile.h" -#import "NSString+UUIDCreation.h" -#import "NSString+PathExtensions.h" +#import +#import @implementation UIImage (WriteToTmpFile) diff --git a/lib/JFFUI/UITableView/JULoadMoreCellscalculator.h b/lib/JFFUI/UITableView/JULoadMoreCellscalculator.h index 8cd58db..30b862a 100644 --- a/lib/JFFUI/UITableView/JULoadMoreCellscalculator.h +++ b/lib/JFFUI/UITableView/JULoadMoreCellscalculator.h @@ -5,42 +5,42 @@ @protocol JUTableViewHolder @required --(UITableView*)tableView; --(NSInteger)currentCount; --(void)setCurrentCount:( NSInteger )count_; +- (UITableView *)tableView; +- (NSInteger)currentCount; +- (void)setCurrentCount:(NSInteger)count; @end @interface JULoadMoreCellscalculator : NSObject -@property ( nonatomic ) NSInteger currentCount; -@property ( nonatomic ) NSUInteger pageSize; -@property ( nonatomic ) NSUInteger totalElementsCount; +@property (nonatomic) NSInteger currentCount; +@property (nonatomic) NSUInteger pageSize; +@property (nonatomic) NSUInteger totalElementsCount; -@property ( nonatomic, readonly ) BOOL isPagingDisabled; -@property ( nonatomic, readonly ) BOOL isPagingEnabled ; -@property ( nonatomic, readonly ) NSUInteger numberOfRows ; +@property (nonatomic, readonly) BOOL isPagingDisabled; +@property (nonatomic, readonly) BOOL isPagingEnabled ; +@property (nonatomic, readonly) NSUInteger numberOfRows ; --(NSArray*)prepareIndexPathEntriesForBottomCells:( NSUInteger )cellsCount_; --(NSUInteger)suggestElementsToAddCountForIndexPath:( NSIndexPath* )indexPath_ - overflowOccured:( BOOL* )isOverflow_; --(NSUInteger)suggestElementsToAddCountForIndex:( NSUInteger )index_ - overflowOccured:( BOOL* )outIsOverflow_; +- (NSArray *)prepareIndexPathEntriesForBottomCells:(NSUInteger)cellsCount_; +- (NSUInteger)suggestElementsToAddCountForIndexPath:(NSIndexPath *)indexPath_ + overflowOccured:(BOOL *)isOverflow_; +- (NSUInteger)suggestElementsToAddCountForIndex:(NSUInteger)index_ + overflowOccured:(BOOL *)outIsOverflow; -@property ( nonatomic, readonly ) BOOL hasNoElements; -@property ( nonatomic, readonly ) BOOL allElementsLoaded; -@property ( nonatomic, readonly ) NSIndexPath* loadMoreIndexPath; +@property (nonatomic, readonly) BOOL hasNoElements; +@property (nonatomic, readonly) BOOL allElementsLoaded; +@property (nonatomic, readonly) NSIndexPath *loadMoreIndexPath; --(BOOL)isLoadMoreIndexPath:( NSIndexPath* )indexPath_; +- (BOOL)isLoadMoreIndexPath:(NSIndexPath *)indexPath_; --(NSInteger)currentCountToStartWith:( NSInteger )totalElementsCount_; +- (NSInteger)currentCountToStartWith:(NSInteger)totalElementsCount_; -+(NSArray*)defaultUpdateScopeForIndex:( NSUInteger )index_; ++ (NSArray *)defaultUpdateScopeForIndex:(NSUInteger)index_; --(void)autoLoadingScrollTableView:( id )tableViewHolder_ - toRowAtIndexPath:( NSIndexPath* )indexPath_ - atScrollPosition:( UITableViewScrollPosition )scrollPosition_ - animated:( BOOL )animated_; +- (void)autoLoadingScrollTableView:(id)tableViewHolder_ + toRowAtIndexPath:(NSIndexPath *)indexPath_ + atScrollPosition:(UITableViewScrollPosition)scrollPosition_ + animated:(BOOL)animated_; @end diff --git a/lib/JFFUI/UITableView/JULoadMoreCellscalculator.m b/lib/JFFUI/UITableView/JULoadMoreCellscalculator.m index 9c119c5..1863108 100755 --- a/lib/JFFUI/UITableView/JULoadMoreCellscalculator.m +++ b/lib/JFFUI/UITableView/JULoadMoreCellscalculator.m @@ -118,11 +118,11 @@ -(NSUInteger)suggestElementsToAddCountForIndex:( NSUInteger )index_ static const NSUInteger loadMorePlaceholderSize_ = 1; NSUInteger restOfTheItems_ = self.totalElementsCount - self.currentCount; - + float items_count_for_index_path_ = 1 + index_; - NSUInteger pages_expected_ = ceil( items_count_for_index_path_ / self.pageSize ); + NSUInteger pages_expected_ = ceilf( items_count_for_index_path_ / self.pageSize ); NSUInteger elements_expected_ = pages_expected_ * self.pageSize; - + //check if paging disabled BOOL isOverflow_ = ( elements_expected_ >= self.totalElementsCount ); if ( isOverflow_ ) @@ -172,9 +172,9 @@ -(NSInteger)currentCountToStartWith:( NSInteger )total_elements_count_ } --(void)insertToTableView:( id )tableViewHolder_ - bottomCells:(NSUInteger)cells_count_ - overflowOccured:( BOOL )is_overflow_ +- (void)insertToTableView:(id)tableViewHolder + bottomCells:(NSUInteger)cells_count_ + overflowOccured:(BOOL)is_overflow_ { NSDebugLog( @"[BEGIN] : insertToBottomCells" ); if ( 0 == cells_count_ ) @@ -184,32 +184,30 @@ -(void)insertToTableView:( id )tableViewHolder_ return; } - NSArray* index_paths_ = [ self prepareIndexPathEntriesForBottomCells: cells_count_ ]; + NSArray* indexPaths = [ self prepareIndexPathEntriesForBottomCells: cells_count_ ]; NSDebugLog( @"index_path_[%d] : %@ .. %@", [ index_paths_ count ], index_paths_[ 0 ], [ index_paths_ lastObject ] ); NSDebugLog( @"page size : %d", [ self pageSize ] ); - [ tableViewHolder_.tableView withinUpdates: ^void( void ) + [ tableViewHolder.tableView withinUpdates: ^void( void ) { NSDebugLog( @"beginUpdates" ); - NSArray* load_more_path_array_ = @[ self.loadMoreIndexPath ]; - - [ [ tableViewHolder_ tableView ] reloadRowsAtIndexPaths: load_more_path_array_ - withRowAnimation: UITableViewRowAnimationNone ]; - - - [ [ tableViewHolder_ tableView ] insertRowsAtIndexPaths: index_paths_ - withRowAnimation: UITableViewRowAnimationNone ]; - - + NSArray* loadMorePathArray = @[ self.loadMoreIndexPath ]; + + [[tableViewHolder tableView] reloadRowsAtIndexPaths:loadMorePathArray + withRowAnimation:UITableViewRowAnimationNone]; + + [[tableViewHolder tableView] insertRowsAtIndexPaths:indexPaths + withRowAnimation:UITableViewRowAnimationNone]; + NSDebugLog( @"Updating currentCount..." ); self.currentCount += cells_count_; if ( is_overflow_ && ( self.currentCount < self.totalElementsCount ) ) { ++self.currentCount; } - [ tableViewHolder_ setCurrentCount: self.currentCount ]; - + [tableViewHolder setCurrentCount:self.currentCount]; + NSDebugLog( @"currentCount : %d", self.currentCount ); NSDebugLog( @"endUpdates" ); } ]; diff --git a/lib/JFFUI/UITableView/UITableView+BlocksAdditions.h b/lib/JFFUI/UITableView/UITableView+BlocksAdditions.h new file mode 100644 index 0000000..f213b8d --- /dev/null +++ b/lib/JFFUI/UITableView/UITableView+BlocksAdditions.h @@ -0,0 +1,9 @@ +#import + +typedef void(^JFFVisitIndexPath)(NSIndexPath *indexPath); + +@interface UITableView (BlocksAdditions) + +- (void)enumerateAllIndexPaths:(JFFVisitIndexPath)block; + +@end diff --git a/lib/JFFUI/UITableView/UITableView+BlocksAdditions.m b/lib/JFFUI/UITableView/UITableView+BlocksAdditions.m new file mode 100644 index 0000000..6780550 --- /dev/null +++ b/lib/JFFUI/UITableView/UITableView+BlocksAdditions.m @@ -0,0 +1,26 @@ +#import "UITableView+BlocksAdditions.h" + +@implementation UITableView (BlocksAdditions) + +- (void)enumerateAllIndexPaths:(JFFVisitIndexPath)block +{ + NSParameterAssert(block); + + NSUInteger numberOfSections = [self numberOfSections]; + + for (NSUInteger section = 0; section < numberOfSections; ++section) { + + @autoreleasepool { + NSUInteger numberOfRows = [self numberOfRowsInSection:section]; + for (NSUInteger row = 0; row < numberOfRows; ++row) { + + @autoreleasepool { + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section]; + block(indexPath); + } + } + } + } +} + +@end diff --git a/lib/JFFUI/UITableView/UITableView+CellsSelections.h b/lib/JFFUI/UITableView/UITableView+CellsSelections.h new file mode 100644 index 0000000..7738849 --- /dev/null +++ b/lib/JFFUI/UITableView/UITableView+CellsSelections.h @@ -0,0 +1,8 @@ +#import + +@interface UITableView (CellsSelections) + +- (void)selectAllRowsAnimated:(BOOL)animated; +- (void)deselectAllRowsAnimated:(BOOL)animated; + +@end diff --git a/lib/JFFUI/UITableView/UITableView+CellsSelections.m b/lib/JFFUI/UITableView/UITableView+CellsSelections.m new file mode 100644 index 0000000..2594371 --- /dev/null +++ b/lib/JFFUI/UITableView/UITableView+CellsSelections.m @@ -0,0 +1,23 @@ +#import "UITableView+CellsSelections.h" + +#import "UITableView+BlocksAdditions.h" + +@implementation UITableView (CellsSelections) + +- (void)selectAllRowsAnimated:(BOOL)animated +{ + [self enumerateAllIndexPaths:^(NSIndexPath *indexPath) { + + [self selectRowAtIndexPath:indexPath animated:animated scrollPosition:(UITableViewScrollPositionNone)]; + }]; +} + +- (void)deselectAllRowsAnimated:(BOOL)animated +{ + [self enumerateAllIndexPaths:^(NSIndexPath *indexPath) { + + [self deselectRowAtIndexPath:indexPath animated:animated]; + }]; +} + +@end diff --git a/lib/JFFUI/UITableView/UITableView+WithinUpdates.h b/lib/JFFUI/UITableView/UITableView+WithinUpdates.h index 1003310..4ef336e 100755 --- a/lib/JFFUI/UITableView/UITableView+WithinUpdates.h +++ b/lib/JFFUI/UITableView/UITableView+WithinUpdates.h @@ -2,6 +2,6 @@ @interface UITableView (WithinUpdates) --(void)withinUpdates:( void (^)( void ) )block_; +- (void)withinUpdates:(void (^)(void))block; @end diff --git a/lib/JFFUI/UITableView/UITableView+WithinUpdates.m b/lib/JFFUI/UITableView/UITableView+WithinUpdates.m index e5a6f3a..ac67203 100755 --- a/lib/JFFUI/UITableView/UITableView+WithinUpdates.m +++ b/lib/JFFUI/UITableView/UITableView+WithinUpdates.m @@ -2,17 +2,17 @@ @implementation UITableView (WithinUpdates) --(void)withinUpdates:( void (^)( void ) )block_ +- (void)withinUpdates:(void (^)(void))block { - [ self beginUpdates ]; - + [self beginUpdates]; + @try { - block_(); + block(); } @finally { - [ self endUpdates ]; + [self endUpdates]; } } diff --git a/lib/JFFUI/UIView/UIView+AddSubviewAndScale.h b/lib/JFFUI/UIView/UIView+AddSubviewAndScale.h index 141ebff..1ecb6ec 100755 --- a/lib/JFFUI/UIView/UIView+AddSubviewAndScale.h +++ b/lib/JFFUI/UIView/UIView+AddSubviewAndScale.h @@ -2,6 +2,6 @@ @interface UIView (AddSubviewAndScale) --(void)addSubviewAndScale:( UIView* )view_; +- (void)addSubviewAndScale:(UIView *)view; @end diff --git a/lib/JFFUI/UIView/UIView+AddSubviewAndScale.m b/lib/JFFUI/UIView/UIView+AddSubviewAndScale.m index 991a251..5acab27 100755 --- a/lib/JFFUI/UIView/UIView+AddSubviewAndScale.m +++ b/lib/JFFUI/UIView/UIView+AddSubviewAndScale.m @@ -2,13 +2,13 @@ @implementation UIView (AddSubviewAndScale) --(void)addSubviewAndScale:( UIView* )view_ +- (void)addSubviewAndScale:(UIView *)view { - [ view_ removeFromSuperview ]; - - view_.frame = self.bounds; - view_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [ self addSubview: view_ ]; + [view removeFromSuperview]; + + view.frame = self.bounds; + view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [self addSubview:view]; } @end diff --git a/lib/JFFUI/UIView/UIView+AllSubviews.h b/lib/JFFUI/UIView/UIView+AllSubviews.h index 87ff46a..370172c 100755 --- a/lib/JFFUI/UIView/UIView+AllSubviews.h +++ b/lib/JFFUI/UIView/UIView+AllSubviews.h @@ -2,10 +2,10 @@ @interface UIView (AllSubviews) --(UIView*)findSubviewOfClass:( Class )class_; +- (instancetype)findSubviewOfClass:(Class)cls; --(void)logAllSubviews; +- (void)logAllSubviews; --(void)removeAllSubviews; +- (void)removeAllSubviews; @end diff --git a/lib/JFFUI/UIView/UIView+AllSubviews.m b/lib/JFFUI/UIView/UIView+AllSubviews.m index 9f79624..ab3f00f 100755 --- a/lib/JFFUI/UIView/UIView+AllSubviews.m +++ b/lib/JFFUI/UIView/UIView+AllSubviews.m @@ -2,41 +2,40 @@ @implementation UIView (AllSubviews) --(UIView*)findSubviewOfClass:( Class )class_ +- (instancetype)findSubviewOfClass:(Class)cls { - if ( [ self isKindOfClass: class_ ] ) + if ([self isKindOfClass:cls]) return self; - - for ( UIView* subview_ in self.subviews ) - { - UIView* overlay_view_ = [ subview_ findSubviewOfClass: class_ ]; - if ( overlay_view_ ) - { - return overlay_view_; + + for (UIView *subview in self.subviews) { + + UIView *overlayView = [subview findSubviewOfClass:cls]; + if (overlayView) { + return overlayView; } } return nil; } --(void)logAllSubviewsWithLevel:( NSUInteger )level_ +- (void)logAllSubviewsWithLevel:(NSUInteger)level { - NSLog( @"level: %d view: %@", level_++, self ); - - for ( UIView* sub_view_ in self.subviews ) + NSLog( @"level: %lu view: %@", (unsigned long)level++, self ); + + for (UIView *subView in self.subviews) { - [ sub_view_ logAllSubviewsWithLevel: level_ ]; + [subView logAllSubviewsWithLevel:level]; } } --(void)logAllSubviews +- (void)logAllSubviews { - [ self logAllSubviewsWithLevel: 0 ]; + [self logAllSubviewsWithLevel:0]; } --(void)removeAllSubviews +- (void)removeAllSubviews { - [ self.subviews makeObjectsPerformSelector: @selector( removeFromSuperview ) ]; + [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; } @end diff --git a/lib/JFFUI/UIView/UIView+AnimationWithBlocks.h b/lib/JFFUI/UIView/UIView+AnimationWithBlocks.h index fb64487..c484aa6 100755 --- a/lib/JFFUI/UIView/UIView+AnimationWithBlocks.h +++ b/lib/JFFUI/UIView/UIView+AnimationWithBlocks.h @@ -1,10 +1,19 @@ +#import + #import +typedef void(^JFFCompletionBlock)(BOOL finished); + @interface UIView (AnimationWithBlocks) -+(void)animateWithAnimations:( void (^)( void ) )animations_; +//TODO add header for JFFSimpleBlocks ++ (void)animateWithAnimations:(JFFSimpleBlock)animations; + ++ (void)animateWithOptions:(UIViewAnimationOptions )options + animations:(JFFSimpleBlock)animations; -+(void)animateWithOptions:( UIViewAnimationOptions )options_ - animations:( void (^)( void ) )animations_; ++ (void)animateWithOptions:(UIViewAnimationOptions )options + animations:(JFFSimpleBlock)animations + completion:(JFFCompletionBlock)completion; @end diff --git a/lib/JFFUI/UIView/UIView+AnimationWithBlocks.m b/lib/JFFUI/UIView/UIView+AnimationWithBlocks.m index d925990..5c35177 100755 --- a/lib/JFFUI/UIView/UIView+AnimationWithBlocks.m +++ b/lib/JFFUI/UIView/UIView+AnimationWithBlocks.m @@ -1,24 +1,33 @@ #import "UIView+AnimationWithBlocks.h" -static NSTimeInterval default_animation_duration_ = 0.2; -static NSTimeInterval default_animation_delay_ = 0.0; +static NSTimeInterval defaultAnimationDuration = 0.2; +static NSTimeInterval defaultAnimationDelay = 0.0; @implementation UIView (AnimationWithBlocks) -+(void)animateWithAnimations:( void (^)( void ) )animations_ ++ (void)animateWithAnimations:(JFFSimpleBlock)animations { - [ self animateWithDuration: default_animation_duration_ - animations: animations_ ]; + [self animateWithDuration:defaultAnimationDuration + animations:animations]; } -+(void)animateWithOptions:( UIViewAnimationOptions )options_ - animations:( void (^)( void ) )animations_ ++ (void)animateWithOptions:(UIViewAnimationOptions)options + animations:(JFFSimpleBlock)animations { - [ self animateWithDuration: default_animation_duration_ - delay: default_animation_delay_ - options: options_ - animations: animations_ - completion: nil ]; + [self animateWithOptions:options + animations:animations + completion:nil]; +} + ++ (void)animateWithOptions:(UIViewAnimationOptions)options + animations:(JFFSimpleBlock)animations + completion:(JFFCompletionBlock)completion +{ + [self animateWithDuration:defaultAnimationDuration + delay:defaultAnimationDelay + options:options + animations:animations + completion:completion]; } @end diff --git a/lib/JFFUI/UIViewController/UIViewController+Dialog.h b/lib/JFFUI/UIViewController/UIViewController+Dialog.h new file mode 100644 index 0000000..79fea7c --- /dev/null +++ b/lib/JFFUI/UIViewController/UIViewController+Dialog.h @@ -0,0 +1,6 @@ +#import + +#import + +@interface UIViewController (Dialog) +@end diff --git a/lib/JFFUI/UIViewController/UIViewController+Dialog.m b/lib/JFFUI/UIViewController/UIViewController+Dialog.m new file mode 100644 index 0000000..ef3a8c8 --- /dev/null +++ b/lib/JFFUI/UIViewController/UIViewController+Dialog.m @@ -0,0 +1,37 @@ +#import "UIViewController+Dialog.h" + +@implementation UIViewController (Dialog) + +@dynamic onCompleteDialogBlock; + ++ (void)load +{ + jClass_implementProperty(self, NSStringFromSelector(@selector(onCompleteDialogBlock))); +} + +#pragma mark - + +- (void)completeDialogWithError:(NSError *)error +{ + [self completeDialogWithResult:nil error:error isCanceled:NO]; +} + +- (void)completeDialogWithResult:(id)result +{ + [self completeDialogWithResult:result error:nil isCanceled:NO]; +} + +- (void)cancelDialog +{ + [self completeDialogWithResult:nil error:nil isCanceled:YES]; +} + +- (void)completeDialogWithResult:(id)result error:(NSError *)error isCanceled:(BOOL)isCancaled +{ + JFFCompleteDialogCallbackBlock onCompleteDialogBlock = self.onCompleteDialogBlock; + if (onCompleteDialogBlock) { + onCompleteDialogBlock(result, error, isCancaled); + } +} + +@end diff --git a/lib/JFFUI/UIViewController/UIViewController+PerformSegueWithCallback.m b/lib/JFFUI/UIViewController/UIViewController+PerformSegueWithCallback.m index eeb0c79..dc7d04e 100644 --- a/lib/JFFUI/UIViewController/UIViewController+PerformSegueWithCallback.m +++ b/lib/JFFUI/UIViewController/UIViewController+PerformSegueWithCallback.m @@ -1,7 +1,5 @@ #import "UIViewController+PerformSegueWithCallback.h" -static char performSegueCallbackKey; - @interface UIViewControllerPrepareForSegueHook : NSObject @end @@ -38,18 +36,25 @@ - (void)prepareForSeguePrototype:(UIStoryboardSegue *)segue sender:(id)sender @end -@implementation UIViewController (PerformSegueWithCallback) +@interface UIViewController (PerformSegueWithCallback_Properties) -- (JFFPerformSegueCallback)performSegueCallback -{ - return objc_getAssociatedObject(self, &performSegueCallbackKey); -} +@property (copy, nonatomic) JFFPerformSegueCallback performSegueCallback; -- (void)setPerformSegueCallback:(JFFPerformSegueCallback)callback +@end + +@implementation UIViewController (PerformSegueWithCallback_Properties) + +@dynamic performSegueCallback; + ++ (void)load { - objc_setAssociatedObject(self, &performSegueCallbackKey, callback, OBJC_ASSOCIATION_COPY_NONATOMIC); + jClass_implementProperty(self, NSStringFromSelector(@selector(performSegueCallback))); } +@end + +@implementation UIViewController (PerformSegueWithCallback) + - (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender callback:(JFFPerformSegueCallback)callback diff --git a/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.h b/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.h index 8cd7e61..717db0c 100755 --- a/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.h +++ b/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.h @@ -3,6 +3,6 @@ @interface UIWebView (HideWhenLoading) //warning: this method broke delegate property of UIWebView --(void)hideWhenLoadingHTMLString:( NSString* )html_string_; +- (void)hideWhenLoadingHTMLString:(NSString *)htmlString; @end diff --git a/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.m b/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.m index d51c689..b331f6a 100644 --- a/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.m +++ b/lib/JFFUI/UIWebView/UIWebView+HideWhenLoading.m @@ -1,18 +1,27 @@ #import "UIWebView+HideWhenLoading.h" -static char property_key_; - @class JUIWebViewDelegateProxy; @interface UIWebView (HideWhenLoadingInternal) -@property ( nonatomic ) JUIWebViewDelegateProxy* proxy; +@property (nonatomic) JUIWebViewDelegateProxy *proxy; + +@end + +@implementation UIWebView (HideWhenLoadingInternal) + +@dynamic proxy; + ++ (void)load +{ + jClass_implementProperty(self, NSStringFromSelector(@selector(proxy))); +} @end @interface JUIWebViewDelegateProxy : NSObject < UIWebViewDelegate > -@property ( nonatomic ) UIWebView* webView; +@property (nonatomic) UIWebView *webView; @end @@ -20,20 +29,20 @@ @implementation JUIWebViewDelegateProxy #pragma mark UIWebViewDelegate --(void)didFinishLoading +- (void)didFinishLoading { self.webView.hidden = NO; - + self.webView.delegate = nil; self.webView.proxy = nil; } --(void)webViewDidFinishLoad:( UIWebView* )web_view_ +- (void)webViewDidFinishLoad:(UIWebView *)webView { - [ self didFinishLoading ]; + [self didFinishLoading]; } --(void)webView:( UIWebView* )web_view_ didFailLoadWithError:( NSError* )error +- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { [self didFinishLoading]; } @@ -42,17 +51,7 @@ -(void)webView:( UIWebView* )web_view_ didFailLoadWithError:( NSError* )error @implementation UIWebView (HideWhenLoading) --(JUIWebViewDelegateProxy*)proxy -{ - return ( JUIWebViewDelegateProxy* )objc_getAssociatedObject( self, &property_key_ ); -} - -- (void)setProxy:(JUIWebViewDelegateProxy *)proxy -{ - objc_setAssociatedObject(self, &property_key_, proxy, OBJC_ASSOCIATION_RETAIN_NONATOMIC) ; -} - --(void)hideWhenLoadingHTMLString:( NSString* )html_string_ +- (void)hideWhenLoadingHTMLString:( NSString* )htmlString { if (!self.proxy) { self.proxy = [JUIWebViewDelegateProxy new]; @@ -60,7 +59,7 @@ -(void)hideWhenLoadingHTMLString:( NSString* )html_string_ } self.delegate = self.proxy; self.hidden = YES; - [self loadHTMLString:html_string_ baseURL:nil]; + [self loadHTMLString:htmlString baseURL:nil]; } @end diff --git a/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.h b/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.h index 267763c..5d5afe5 100755 --- a/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.h +++ b/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.h @@ -6,6 +6,6 @@ @property (nonatomic, copy) JFFSimpleBlock block; -- (id)initWithBlock:(JFFSimpleBlock)block; +- (instancetype)initWithBlock:(JFFSimpleBlock)block; @end diff --git a/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.m b/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.m index 5ca7147..3ba3a25 100644 --- a/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.m +++ b/lib/JFFUtils/Blocks/JFFOnDeallocBlockOwner.m @@ -2,7 +2,7 @@ @implementation JFFOnDeallocBlockOwner -- (id)initWithBlock:(JFFSimpleBlock)block +- (instancetype)initWithBlock:(JFFSimpleBlock)block { self = [super init]; diff --git a/lib/JFFUtils/Blocks/JFFSimpleBlockHolder.h b/lib/JFFUtils/Blocks/JFFSimpleBlockHolder.h index d9870c6..c9e6a54 100755 --- a/lib/JFFUtils/Blocks/JFFSimpleBlockHolder.h +++ b/lib/JFFUtils/Blocks/JFFSimpleBlockHolder.h @@ -4,7 +4,7 @@ @interface JFFSimpleBlockHolder : NSObject -@property ( nonatomic, copy ) JFFSimpleBlock simpleBlock; -@property ( nonatomic, copy, readonly ) JFFSimpleBlock onceSimpleBlock; +@property (nonatomic, copy) JFFSimpleBlock simpleBlock; +@property (nonatomic, copy, readonly) JFFSimpleBlock onceSimpleBlock; @end diff --git a/lib/JFFUtils/Blocks/JFFUtilsBlockDefinitions.h b/lib/JFFUtils/Blocks/JFFUtilsBlockDefinitions.h index 27a453b..27349eb 100644 --- a/lib/JFFUtils/Blocks/JFFUtilsBlockDefinitions.h +++ b/lib/JFFUtils/Blocks/JFFUtilsBlockDefinitions.h @@ -6,7 +6,6 @@ typedef void (^JFFSimpleBlock)(void); typedef BOOL (^JFFPredicateBlock)(id object); typedef BOOL (^JFFPredicateWithIndexBlock)(id object, NSUInteger index); -typedef BOOL (^JFFResultPredicateBlock)( id result_, NSError* error_ ); typedef id (^JFFAnalyzer)(id result, NSError **outError); #endif //JFF_UTILS_BLOCK_DEFINITIONS diff --git a/lib/JFFUtils/Blocks/JUContainersHelperBlocks.h b/lib/JFFUtils/Blocks/JUContainersHelperBlocks.h index 35fc38f..34e8fa8 100644 --- a/lib/JFFUtils/Blocks/JUContainersHelperBlocks.h +++ b/lib/JFFUtils/Blocks/JUContainersHelperBlocks.h @@ -14,7 +14,7 @@ typedef id (^JFFProducerBlock)(NSUInteger index); typedef NSArray* (^JFFFlattenBlock)(id object); typedef void (^JFFTransformBlock)(id firstObject, id secondObject); -typedef NSUInteger (^JFFElementIndexBlock)( id object_ ); -typedef BOOL (^JFFEqualityCheckerBlock)( id firstObject_, id secondObject_ ); +typedef NSUInteger (^JFFElementIndexBlock)(id object); +typedef BOOL (^JFFEqualityCheckerBlock)(id firstObject, id secondObject); #endif //__JU_ARRAY_HELPER_BLOCKS_H__ diff --git a/lib/JFFUtils/Extensions/NSData+ToString.h b/lib/JFFUtils/Categories/NSData+ToString.h similarity index 100% rename from lib/JFFUtils/Extensions/NSData+ToString.h rename to lib/JFFUtils/Categories/NSData+ToString.h diff --git a/lib/JFFUtils/Extensions/NSData+ToString.m b/lib/JFFUtils/Categories/NSData+ToString.m similarity index 55% rename from lib/JFFUtils/Extensions/NSData+ToString.m rename to lib/JFFUtils/Categories/NSData+ToString.m index 9e28741..b788e9e 100644 --- a/lib/JFFUtils/Extensions/NSData+ToString.m +++ b/lib/JFFUtils/Categories/NSData+ToString.m @@ -4,7 +4,7 @@ @implementation NSData (ToString) - (NSString *)toString { - return [[NSString alloc]initWithData:self encoding:NSUTF8StringEncoding]; + return [[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding]; } @end diff --git a/lib/JFFUtils/Extensions/NSDateFormatter+MultiThreading.h b/lib/JFFUtils/Categories/NSDateFormatter+MultiThreading.h similarity index 77% rename from lib/JFFUtils/Extensions/NSDateFormatter+MultiThreading.h rename to lib/JFFUtils/Categories/NSDateFormatter+MultiThreading.h index d811592..b9b8b1b 100644 --- a/lib/JFFUtils/Extensions/NSDateFormatter+MultiThreading.h +++ b/lib/JFFUtils/Categories/NSDateFormatter+MultiThreading.h @@ -1,6 +1,6 @@ #import -@interface NSDateFormatter (JFFMultiThreading) +@interface NSDateFormatter (MultiThreading) - (NSString *)synchronizedStringFromDate:(NSDate *)date; - (NSDate *)synchronizedDateFromString:(NSString *)string; diff --git a/lib/JFFUtils/Extensions/NSDateFormatter+MultiThreading.m b/lib/JFFUtils/Categories/NSDateFormatter+MultiThreading.m similarity index 88% rename from lib/JFFUtils/Extensions/NSDateFormatter+MultiThreading.m rename to lib/JFFUtils/Categories/NSDateFormatter+MultiThreading.m index e8be4f9..25882de 100644 --- a/lib/JFFUtils/Extensions/NSDateFormatter+MultiThreading.m +++ b/lib/JFFUtils/Categories/NSDateFormatter+MultiThreading.m @@ -1,6 +1,6 @@ #import "NSDateFormatter+MultiThreading.h" -@implementation NSDateFormatter (JFFMultiThreading) +@implementation NSDateFormatter (MultiThreading) //TODO remove this methods and create thread safe NSDateFormatter - (NSString *)synchronizedStringFromDate:(NSDate *)date diff --git a/lib/JFFUtils/Categories/NSDecimalNumber+Increment.h b/lib/JFFUtils/Categories/NSDecimalNumber+Increment.h new file mode 100644 index 0000000..1868bd7 --- /dev/null +++ b/lib/JFFUtils/Categories/NSDecimalNumber+Increment.h @@ -0,0 +1,10 @@ +#import + +@interface NSDecimalNumber( Increment ) + +- (instancetype)increment; +- (instancetype)decrement; + +- (instancetype)instanceOne; + +@end diff --git a/lib/JFFUtils/Categories/NSDecimalNumber+Increment.m b/lib/JFFUtils/Categories/NSDecimalNumber+Increment.m new file mode 100644 index 0000000..af22420 --- /dev/null +++ b/lib/JFFUtils/Categories/NSDecimalNumber+Increment.m @@ -0,0 +1,20 @@ +#import "NSDecimalNumber+Increment.h" + +@implementation NSDecimalNumber (Increment) + +- (instancetype)instanceOne +{ + return [[self class] one]; +} + +- (instancetype)increment +{ + return [self decimalNumberByAdding:[self instanceOne]]; +} + +- (instancetype)decrement +{ + return [self decimalNumberBySubtracting:[self instanceOne]]; +} + +@end diff --git a/lib/JFFUtils/Categories/NSNumber+FSStorable.h b/lib/JFFUtils/Categories/NSNumber+FSStorable.h new file mode 100644 index 0000000..4a3d037 --- /dev/null +++ b/lib/JFFUtils/Categories/NSNumber+FSStorable.h @@ -0,0 +1,10 @@ +#import + +@interface NSNumber (FSStorable) + ++ (instancetype)newLongLongNumberWithContentsOfFile:(NSString *)fileName; ++ (instancetype)newDoubleWithContentsOfFile:(NSString *)fileName; + +- (BOOL)saveNumberToFile:(NSString *)fileName; + +@end diff --git a/lib/JFFUtils/Categories/NSNumber+FSStorable.m b/lib/JFFUtils/Categories/NSNumber+FSStorable.m new file mode 100644 index 0000000..6fde912 --- /dev/null +++ b/lib/JFFUtils/Categories/NSNumber+FSStorable.m @@ -0,0 +1,69 @@ +#import "NSNumber+FSStorable.h" + +#import "NSString+PathExtensions.h" +#import "NSString+FileAttributes.h" + +@implementation NSNumber (FSStorable) + ++ (instancetype)newNumberWithDocumentContentsOfFile:(NSString *)fileName + scanner:(NSNumber *(^)(NSString *))scanner +{ + NSParameterAssert(fileName && scanner); + + NSString *path = [NSString documentsPathByAppendingPathComponent:fileName]; + + NSString *string = [[NSString alloc] initWithContentsOfFile:path + encoding:NSUTF8StringEncoding + error:NULL]; + + return string?scanner(string):nil; +} + ++ (instancetype)newLongLongNumberWithContentsOfFile:(NSString *)fileName +{ + NSNumber *(^scanner)(NSString *) = ^NSNumber *(NSString *string) { + + double scannedNumber = 0; + NSScanner *scanner = [NSScanner scannerWithString:string]; + [scanner scanDouble:&scannedNumber]; + NSNumber *result = @(scannedNumber); + return result; + }; + + return [self newNumberWithDocumentContentsOfFile:fileName + scanner:scanner]; +} + ++ (instancetype)newDoubleWithContentsOfFile:(NSString *)fileName +{ + NSNumber *(^scanner)(NSString *) = ^NSNumber *(NSString *string) { + + long long scannedNumber = 0; + NSScanner *scanner = [NSScanner scannerWithString:string]; + [scanner scanLongLong:&scannedNumber]; + NSNumber *result = @(scannedNumber); + return result; + }; + + return [self newNumberWithDocumentContentsOfFile:fileName + scanner:scanner]; +} + +- (BOOL)saveNumberToFile:(NSString *)fileName +{ + NSParameterAssert(fileName); + + NSString *string = [self description]; + + fileName = [NSString documentsPathByAppendingPathComponent:fileName]; + BOOL result = [string writeToFile:fileName + atomically:YES + encoding:NSUTF8StringEncoding + error:NULL]; + if (result) + [fileName addSkipBackupAttribute]; + + return result; +} + +@end diff --git a/lib/JFFUtils/Extensions/NSThread+AssertMainThread.h b/lib/JFFUtils/Categories/NSThread+AssertMainThread.h old mode 100755 new mode 100644 similarity index 75% rename from lib/JFFUtils/Extensions/NSThread+AssertMainThread.h rename to lib/JFFUtils/Categories/NSThread+AssertMainThread.h index 6d9efd9..176fb2e --- a/lib/JFFUtils/Extensions/NSThread+AssertMainThread.h +++ b/lib/JFFUtils/Categories/NSThread+AssertMainThread.h @@ -2,6 +2,6 @@ @interface NSThread (AssertMainThread) -+(void)assertMainThread; ++ (void)assertMainThread; @end diff --git a/lib/JFFUtils/Categories/NSThread+AssertMainThread.m b/lib/JFFUtils/Categories/NSThread+AssertMainThread.m new file mode 100644 index 0000000..3573ca4 --- /dev/null +++ b/lib/JFFUtils/Categories/NSThread+AssertMainThread.m @@ -0,0 +1,10 @@ +#import "NSThread+AssertMainThread.h" + +@implementation NSThread (AssertMainThread) + ++ (void)assertMainThread +{ + NSAssert([NSThread isMainThread], @"should be called only from main thread only"); +} + +@end diff --git a/lib/JFFUtils/Extensions/UIColor+ColorForHex.h b/lib/JFFUtils/Categories/UIColor+ColorForHex.h old mode 100755 new mode 100644 similarity index 56% rename from lib/JFFUtils/Extensions/UIColor+ColorForHex.h rename to lib/JFFUtils/Categories/UIColor+ColorForHex.h index eba7791..32e237e --- a/lib/JFFUtils/Extensions/UIColor+ColorForHex.h +++ b/lib/JFFUtils/Categories/UIColor+ColorForHex.h @@ -2,6 +2,6 @@ @interface UIColor (ColorForHex) -+ (UIColor *)colorForHex:(NSString *)hexColor; ++ (instancetype)colorForHex:(NSString *)hexColor; @end diff --git a/lib/JFFUtils/Extensions/UIColor+ColorForHex.m b/lib/JFFUtils/Categories/UIColor+ColorForHex.m old mode 100755 new mode 100644 similarity index 80% rename from lib/JFFUtils/Extensions/UIColor+ColorForHex.m rename to lib/JFFUtils/Categories/UIColor+ColorForHex.m index 9ed6fb9..45e4711 --- a/lib/JFFUtils/Extensions/UIColor+ColorForHex.m +++ b/lib/JFFUtils/Categories/UIColor+ColorForHex.m @@ -5,22 +5,22 @@ //source: http://iphonedevelopertips.com/general/using-nsscanner-to-convert-hex-to-rgb-color.html @implementation UIColor (ColorForHex) -+ (UIColor *)colorForHex:(NSString *)hexColor ++ (instancetype)colorForHex:(NSString *)hexColor { - hexColor = [[hexColor stringByTrimmingWhitespaces] uppercaseString]; + hexColor = [[hexColor stringByTrimmingWhitespaces] uppercaseString]; // String should be 6 or 7 characters if it includes '#' if ([hexColor length] < 6) - return [UIColor blackColor]; + return [UIColor blackColor]; // strip # if it appears if ([hexColor hasPrefix:@"#"]) - hexColor = [hexColor substringFromIndex:1]; + hexColor = [hexColor substringFromIndex:1]; // if the value isn't 6 characters at this point return // the color black if ([hexColor length] != 6) - return [UIColor blackColor]; + return [UIColor blackColor]; // Separate into r, g, b substrings NSRange range; @@ -35,8 +35,8 @@ + (UIColor *)colorForHex:(NSString *)hexColor range.location = 4; NSString *bString = [hexColor substringWithRange:range]; - // Scan values - unsigned int r, g, b; + // Scan values + unsigned int r, g, b; [[NSScanner scannerWithString:rString] scanHexInt:&r]; [[NSScanner scannerWithString:gString] scanHexInt:&g]; [[NSScanner scannerWithString:bString] scanHexInt:&b]; diff --git a/lib/JFFUtils/Extensions/UIDevice+PlatformName.h b/lib/JFFUtils/Categories/UIDevice+PlatformName.h similarity index 100% rename from lib/JFFUtils/Extensions/UIDevice+PlatformName.h rename to lib/JFFUtils/Categories/UIDevice+PlatformName.h diff --git a/lib/JFFUtils/Extensions/UIDevice+PlatformName.m b/lib/JFFUtils/Categories/UIDevice+PlatformName.m similarity index 83% rename from lib/JFFUtils/Extensions/UIDevice+PlatformName.m rename to lib/JFFUtils/Categories/UIDevice+PlatformName.m index b08d5c6..fbfb762 100644 --- a/lib/JFFUtils/Extensions/UIDevice+PlatformName.m +++ b/lib/JFFUtils/Categories/UIDevice+PlatformName.m @@ -7,7 +7,7 @@ @implementation UIDevice (PlatformName) -// http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk +// http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk + (NSString *)platformName { if (!__platformName) { @@ -22,7 +22,7 @@ + (NSString *)platformName machine = malloc(len); sysctl(mib, 2, machine, &len, NULL, 0); - NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding]; + NSString *platform = @(machine); free(machine); __platformName = platform; } diff --git a/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.h b/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.h index a8ba902..cba7def 100755 --- a/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.h +++ b/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.h @@ -4,10 +4,10 @@ @interface NSDictionary (BlocksAdditions) -- (NSDictionary*)map:(JFFDictMappingBlock)block; -- (NSDictionary*)mapKey:(JFFDictMappingBlock)block; +- (instancetype)map:(JFFDictMappingBlock)block; +- (instancetype)mapKey:(JFFDictMappingBlock)block; -- (NSDictionary *)map:(JFFDictMappingWithErrorBlock)block error:(NSError **)outError; +- (instancetype)map:(JFFDictMappingWithErrorBlock)block error:(NSError **)outError; - (NSUInteger)count:(JFFDictPredicateBlock)predicate; @@ -16,6 +16,6 @@ //Invokes the block passing in successive elements from self, //Creates a new NSDictionary containing those elements for which the block returns a YES value -- (NSDictionary*)select:(JFFDictPredicateBlock)predicate; +- (instancetype)select:(JFFDictPredicateBlock)predicate; @end diff --git a/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.m b/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.m index 431fa6e..ecda397 100644 --- a/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.m +++ b/lib/JFFUtils/Dictionary/NSDictionary+BlocksAdditions.m @@ -4,7 +4,7 @@ @implementation NSDictionary (BlocksAdditions) -- (NSDictionary *)map:(JFFDictMappingBlock)block +- (instancetype)map:(JFFDictMappingBlock)block { NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithCapacity:[self count]]; [self enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) { @@ -15,7 +15,7 @@ - (NSDictionary *)map:(JFFDictMappingBlock)block return [result copy]; } -- (NSDictionary *)map:(JFFDictMappingWithErrorBlock)block error:(NSError *__autoreleasing *)outError +- (instancetype)map:(JFFDictMappingWithErrorBlock)block error:(NSError *__autoreleasing *)outError { __block NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithCapacity:[self count]]; @@ -39,7 +39,7 @@ - (NSDictionary *)map:(JFFDictMappingWithErrorBlock)block error:(NSError *__auto return [result copy]; } --(NSDictionary*)mapKey:(JFFDictMappingBlock)block +- (instancetype)mapKey:(JFFDictMappingBlock)block { NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithCapacity:[self count]]; [self enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) { @@ -67,7 +67,7 @@ - (void)each:(JFFDictActionBlock)block }]; } -- (NSDictionary*)select:(JFFDictPredicateBlock)predicate +- (instancetype)select:(JFFDictPredicateBlock)predicate { NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithCapacity:[self count]]; diff --git a/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.h b/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.h index 5f36434..a5bf529 100755 --- a/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.h +++ b/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.h @@ -2,6 +2,6 @@ @interface NSDictionary (JFFExtendedDictionary) -- (NSDictionary *)dictionaryByAddingObjectsFromDictionary:(NSDictionary *)dictionary; +- (instancetype)dictionaryByAddingObjectsFromDictionary:(NSDictionary *)dictionary; @end diff --git a/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.m b/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.m index 75247a9..1ce415b 100644 --- a/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.m +++ b/lib/JFFUtils/Dictionary/NSDictionary+JFFExtendedDictionary.m @@ -4,7 +4,7 @@ @implementation NSDictionary (JFFExtendedDictionary) -- (NSDictionary *)dictionaryByAddingObjectsFromDictionary:(NSDictionary *)dictionary +- (instancetype)dictionaryByAddingObjectsFromDictionary:(NSDictionary *)dictionary { NSMutableDictionary *result = [self mutableCopy]; diff --git a/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.h b/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.h index 54291e0..aa1069d 100644 --- a/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.h +++ b/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.h @@ -11,7 +11,7 @@ - (NSNumber *)numberWithBoolForKey:(NSString *)key; - (NSNumber *)numberWithDoubleForKey:(NSString *)key; -- (NSDictionary *)dictionaryForKey:(NSString *)key; +- (instancetype)dictionaryForKey:(NSString *)key; - (NSArray *)arrayForKey:(NSString *)key; diff --git a/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.m b/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.m index e86cfe7..5e3d3f1 100644 --- a/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.m +++ b/lib/JFFUtils/Dictionary/NSDictionary+ValueWithType.m @@ -123,7 +123,7 @@ - (NSNumber *)numberWithDoubleForKey:(NSString *)key #pragma mark - Dict vlue for key -- (NSDictionary *)dictionaryForKey:(NSString *)key +- (instancetype)dictionaryForKey:(NSString *)key { id value = self[key]; diff --git a/lib/JFFUtils/Dictionary/NSMutableDictionary+IgnoringAddNilValue.h b/lib/JFFUtils/Dictionary/NSMutableDictionary+IgnoringAddNilValue.h deleted file mode 100644 index 7309c68..0000000 --- a/lib/JFFUtils/Dictionary/NSMutableDictionary+IgnoringAddNilValue.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface NSMutableDictionary (IgnoringAddNilValue) - -- (void)setObjectWithIgnoreNillValue:(id)anObject forKey:(id)aKey; - -@end diff --git a/lib/JFFUtils/Dictionary/NSMutableDictionary+IgnoringAddNilValue.m b/lib/JFFUtils/Dictionary/NSMutableDictionary+IgnoringAddNilValue.m deleted file mode 100644 index f8bb00a..0000000 --- a/lib/JFFUtils/Dictionary/NSMutableDictionary+IgnoringAddNilValue.m +++ /dev/null @@ -1,12 +0,0 @@ -#import "NSMutableDictionary+IgnoringAddNilValue.h" - -@implementation NSMutableDictionary (IgnoringAddNilValue) - -- (void)setObjectWithIgnoreNillValue:(id)anObject forKey:(id)aKey -{ - if (anObject) { - [self setObject:anObject forKey:aKey]; - } -} - -@end diff --git a/lib/JFFUtils/Errors/JFFError.h b/lib/JFFUtils/Errors/JFFError.h new file mode 100644 index 0000000..c61c2a2 --- /dev/null +++ b/lib/JFFUtils/Errors/JFFError.h @@ -0,0 +1,15 @@ +#import + +@interface JFFError : NSError + +- (instancetype)initWithDescription:(NSString *)description + domain:(NSString *)domain + code:(NSInteger)code; + +- (instancetype)initWithDescription:(NSString *)description; ++ (instancetype)newErrorWithDescription:(NSString *)description; + ++ (instancetype)newErrorWithDescription:(NSString *)description + code:(NSInteger)code; + +@end diff --git a/lib/JFFUtils/Errors/JFFError.m b/lib/JFFUtils/Errors/JFFError.m new file mode 100644 index 0000000..68da631 --- /dev/null +++ b/lib/JFFUtils/Errors/JFFError.m @@ -0,0 +1,44 @@ +#import "JFFError.h" + +@implementation JFFError + ++ (NSString *)jffErrorsDomain +{ + return @"com.just_for_fun.library"; +} + +- (instancetype)initWithDescription:(NSString *)description + domain:(NSString *)domain + code:(NSInteger)code +{ + NSDictionary *userInfo = @{NSLocalizedDescriptionKey : description}; + + return [super initWithDomain:domain + code:code + userInfo:userInfo]; +} + +- (instancetype)initWithDescription:(NSString *)description code:(NSInteger)code +{ + return [self initWithDescription:description + domain:[[self class] jffErrorsDomain] + code:code]; +} + +- (instancetype)initWithDescription:(NSString *)description +{ + return [self initWithDescription:description code:0]; +} + ++ (instancetype)newErrorWithDescription:(NSString *)description +{ + return [self newErrorWithDescription:description code:0]; +} + ++ (instancetype)newErrorWithDescription:(NSString *)description + code:(NSInteger)code +{ + return [[self alloc] initWithDescription:description code:code]; +} + +@end diff --git a/lib/JFFUtils/Errors/JFFSilentError.h b/lib/JFFUtils/Errors/JFFSilentError.h new file mode 100644 index 0000000..cc89e76 --- /dev/null +++ b/lib/JFFUtils/Errors/JFFSilentError.h @@ -0,0 +1,4 @@ +#import + +@interface JFFSilentError : JFFError +@end diff --git a/lib/JFFUtils/Errors/JFFSilentError.m b/lib/JFFUtils/Errors/JFFSilentError.m new file mode 100644 index 0000000..ee5803c --- /dev/null +++ b/lib/JFFUtils/Errors/JFFSilentError.m @@ -0,0 +1,12 @@ +#import "JFFSilentError.h" + +#import "NSError+WriteErrorToNSLog.h" + +@implementation JFFSilentError + +- (void)writeErrorWithJFFLogger +{ + [self writeErrorToNSLog]; +} + +@end diff --git a/lib/JFFUtils/Errors/NSError+IsNetworkError.h b/lib/JFFUtils/Errors/NSError+IsNetworkError.h new file mode 100644 index 0000000..26e0ad0 --- /dev/null +++ b/lib/JFFUtils/Errors/NSError+IsNetworkError.h @@ -0,0 +1,8 @@ +#import + +@interface NSError (IsNetworkError) + +- (BOOL)isNetworkError; +- (BOOL)isActiveCallError; + +@end diff --git a/lib/JFFUtils/Errors/NSError+IsNetworkError.m b/lib/JFFUtils/Errors/NSError+IsNetworkError.m new file mode 100644 index 0000000..51a4fb0 --- /dev/null +++ b/lib/JFFUtils/Errors/NSError+IsNetworkError.m @@ -0,0 +1,26 @@ +#import "NSError+IsNetworkError.h" + +@implementation NSError (IsNetworkError) + +- (BOOL)isNetworkError +{ + if (![[self domain] isEqualToString:NSURLErrorDomain]) + return NO; + + NSInteger code = [self code]; + return code == kCFURLErrorNotConnectedToInternet + || code == kCFURLErrorTimedOut + || code == kCFURLErrorCannotConnectToHost + || code == kCFURLErrorNetworkConnectionLost + || code == kCFURLErrorCannotFindHost; +} + +- (BOOL)isActiveCallError +{ + if (![[self domain] isEqualToString:NSURLErrorDomain]) + return NO; + + return kCFURLErrorCallIsActive == [self code]; +} + +@end diff --git a/lib/JFFUtils/Extensions/NSError+JSON.h b/lib/JFFUtils/Errors/NSError+JSON.h similarity index 75% rename from lib/JFFUtils/Extensions/NSError+JSON.h rename to lib/JFFUtils/Errors/NSError+JSON.h index b67c01d..cd39396 100644 --- a/lib/JFFUtils/Extensions/NSError+JSON.h +++ b/lib/JFFUtils/Errors/NSError+JSON.h @@ -2,6 +2,6 @@ @interface NSError (JSON) --(NSString*)toJson; +- (NSString *)toJson; @end diff --git a/lib/JFFUtils/Errors/NSError+JSON.m b/lib/JFFUtils/Errors/NSError+JSON.m new file mode 100644 index 0000000..510bc15 --- /dev/null +++ b/lib/JFFUtils/Errors/NSError+JSON.m @@ -0,0 +1,10 @@ +#import "NSError+JSON.h" + +@implementation NSError (JSON) + +- (NSString *)toJson +{ + return [NSString stringWithFormat: @"{ \"error\" : \"%@\", \"domain\" : \"%@\", \"code\" : \"%d\", \"localizedDescription\" : \"%@\" }", NSStringFromClass([self class]), self.domain, self.code, self.localizedDescription]; +} + +@end diff --git a/lib/JFFUtils/Extensions/NSError+setToPointer.h b/lib/JFFUtils/Errors/NSError+SetToPointer.h old mode 100755 new mode 100644 similarity index 74% rename from lib/JFFUtils/Extensions/NSError+setToPointer.h rename to lib/JFFUtils/Errors/NSError+SetToPointer.h index f7a147d..4c8d875 --- a/lib/JFFUtils/Extensions/NSError+setToPointer.h +++ b/lib/JFFUtils/Errors/NSError+SetToPointer.h @@ -1,6 +1,6 @@ #import -@interface NSError (setToPointer) +@interface NSError (SetToPointer) - (BOOL)setToPointer:(NSError *__autoreleasing *)outError; diff --git a/lib/JFFUtils/Extensions/NSError+setToPointer.m b/lib/JFFUtils/Errors/NSError+SetToPointer.m old mode 100755 new mode 100644 similarity index 69% rename from lib/JFFUtils/Extensions/NSError+setToPointer.m rename to lib/JFFUtils/Errors/NSError+SetToPointer.m index c7c9a6d..b521c68 --- a/lib/JFFUtils/Extensions/NSError+setToPointer.m +++ b/lib/JFFUtils/Errors/NSError+SetToPointer.m @@ -1,6 +1,6 @@ -#import "NSError+setToPointer.h" +#import "NSError+SetToPointer.h" -@implementation NSError (setToPointer) +@implementation NSError (SetToPointer) - (BOOL)setToPointer:(NSError *__autoreleasing *)outError { diff --git a/lib/JFFUtils/Extensions/NSError+WriteErrorToNSLog.h b/lib/JFFUtils/Errors/NSError+WriteErrorToNSLog.h similarity index 79% rename from lib/JFFUtils/Extensions/NSError+WriteErrorToNSLog.h rename to lib/JFFUtils/Errors/NSError+WriteErrorToNSLog.h index a8d6057..e99e9f7 100644 --- a/lib/JFFUtils/Extensions/NSError+WriteErrorToNSLog.h +++ b/lib/JFFUtils/Errors/NSError+WriteErrorToNSLog.h @@ -2,6 +2,8 @@ @interface NSError (WriteErrorToNSLog) +- (NSString *)errorLogDescription; + - (void)writeErrorToNSLog; - (void)writeErrorWithJFFLogger; diff --git a/lib/JFFUtils/Extensions/NSError+WriteErrorToNSLog.m b/lib/JFFUtils/Errors/NSError+WriteErrorToNSLog.m similarity index 74% rename from lib/JFFUtils/Extensions/NSError+WriteErrorToNSLog.m rename to lib/JFFUtils/Errors/NSError+WriteErrorToNSLog.m index 02387aa..365c03b 100644 --- a/lib/JFFUtils/Extensions/NSError+WriteErrorToNSLog.m +++ b/lib/JFFUtils/Errors/NSError+WriteErrorToNSLog.m @@ -6,10 +6,11 @@ @implementation NSError (WriteErrorToNSLog) - (NSString *)errorLogDescription { - return [[NSString alloc] initWithFormat:@"NSError : %@, domain : %@ code : %d", + return [[NSString alloc] initWithFormat:@"%@ : %@, domain : %@ code : %ld", + [self class], [self localizedDescription], [self domain], - [self code]]; + (long)[self code]]; } - (void)writeErrorToNSLog diff --git a/lib/JFFUtils/Extensions/NSDecimalNumber+Increment.h b/lib/JFFUtils/Extensions/NSDecimalNumber+Increment.h deleted file mode 100755 index 3afcbc4..0000000 --- a/lib/JFFUtils/Extensions/NSDecimalNumber+Increment.h +++ /dev/null @@ -1,10 +0,0 @@ -#import - -@interface NSDecimalNumber( Increment ) - --(NSDecimalNumber*)increment; --(NSDecimalNumber*)decrement; - --(NSDecimalNumber*)instanceOne; - -@end diff --git a/lib/JFFUtils/Extensions/NSDecimalNumber+Increment.m b/lib/JFFUtils/Extensions/NSDecimalNumber+Increment.m deleted file mode 100755 index 11c780a..0000000 --- a/lib/JFFUtils/Extensions/NSDecimalNumber+Increment.m +++ /dev/null @@ -1,20 +0,0 @@ -#import "NSDecimalNumber+Increment.h" - -@implementation NSDecimalNumber( Increment ) - --(NSDecimalNumber*)instanceOne -{ - return [ [ self class ] one ]; -} - --(NSDecimalNumber*)increment -{ - return [ self decimalNumberByAdding: [ self instanceOne ] ]; -} - --(NSDecimalNumber*)decrement -{ - return [ self decimalNumberBySubtracting: [ self instanceOne ] ]; -} - -@end diff --git a/lib/JFFUtils/Extensions/NSError+JSON.m b/lib/JFFUtils/Extensions/NSError+JSON.m deleted file mode 100644 index 2db7ceb..0000000 --- a/lib/JFFUtils/Extensions/NSError+JSON.m +++ /dev/null @@ -1,10 +0,0 @@ -#import "NSError+JSON.h" - -@implementation NSError (JSON) - --(NSString*)toJson -{ - return [ NSString stringWithFormat: @"{ \"error\" : \"%@\", \"domain\" : \"%@\", \"code\" : \"%d\", \"localizedDescription\" : \"%@\" }", NSStringFromClass( [ self class ] ), self.domain, self.code, self.localizedDescription ]; -} - -@end diff --git a/lib/JFFUtils/Extensions/NSNumber+FSStorable.h b/lib/JFFUtils/Extensions/NSNumber+FSStorable.h deleted file mode 100644 index 8f32f24..0000000 --- a/lib/JFFUtils/Extensions/NSNumber+FSStorable.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@interface NSNumber (FSStorable) - -+ (id)newLongLongNumberWithContentsOfFile:(NSString *)fileName; - -- (BOOL)saveNumberToFile:(NSString *)fileName; - -@end diff --git a/lib/JFFUtils/Extensions/NSNumber+FSStorable.m b/lib/JFFUtils/Extensions/NSNumber+FSStorable.m deleted file mode 100644 index 24ef5a0..0000000 --- a/lib/JFFUtils/Extensions/NSNumber+FSStorable.m +++ /dev/null @@ -1,43 +0,0 @@ -#import "NSNumber+FSStorable.h" - -#import "NSString+PathExtensions.h" -#import "NSString+FileAttributes.h" - -@implementation NSNumber (FSStorable) - -+ (id)newLongLongNumberWithContentsOfFile:(NSString *)fileName -{ - NSParameterAssert(fileName); - - fileName = [NSString documentsPathByAppendingPathComponent:fileName]; - NSString *string = [[NSString alloc] initWithContentsOfFile:fileName - encoding:NSUTF8StringEncoding - error:NULL]; - - long long scannedNumber = 0; - if (string) { - NSScanner *scanner = [NSScanner scannerWithString:string]; - [scanner scanLongLong:&scannedNumber]; - } - NSNumber *result = [[NSNumber alloc] initWithLongLong:scannedNumber]; - return result; -} - -- (BOOL)saveNumberToFile:(NSString *)fileName -{ - NSParameterAssert(fileName); - - NSString *string = [self description]; - - fileName = [NSString documentsPathByAppendingPathComponent:fileName]; - BOOL result = [string writeToFile:fileName - atomically:YES - encoding:NSUTF8StringEncoding - error:NULL]; - if (result) - [fileName addSkipBackupAttribute]; - - return result; -} - -@end diff --git a/lib/JFFUtils/Extensions/NSThread+AssertMainThread.m b/lib/JFFUtils/Extensions/NSThread+AssertMainThread.m deleted file mode 100755 index b3d0394..0000000 --- a/lib/JFFUtils/Extensions/NSThread+AssertMainThread.m +++ /dev/null @@ -1,10 +0,0 @@ -#import "NSThread+AssertMainThread.h" - -@implementation NSThread (AssertMainThread) - -+(void)assertMainThread -{ - NSAssert( [ NSThread isMainThread ], @"should be called only from main thread only" ); -} - -@end diff --git a/lib/JFFUtils/JFFAssignProxy.h b/lib/JFFUtils/JFFAssignProxy.h index 41b84f4..e44c43a 100755 --- a/lib/JFFUtils/JFFAssignProxy.h +++ b/lib/JFFUtils/JFFAssignProxy.h @@ -4,6 +4,6 @@ @property (nonatomic, unsafe_unretained, readonly) id target; -- (id)initWithTarget:(id)target; +- (instancetype)initWithTarget:(id)target; @end diff --git a/lib/JFFUtils/JFFAssignProxy.m b/lib/JFFUtils/JFFAssignProxy.m index 5f9ee55..09fc8ef 100755 --- a/lib/JFFUtils/JFFAssignProxy.m +++ b/lib/JFFUtils/JFFAssignProxy.m @@ -2,7 +2,7 @@ @implementation JFFAssignProxy -- (id)initWithTarget:(id)target +- (instancetype)initWithTarget:(id)target { _target = target; @@ -17,7 +17,7 @@ - (void)forwardInvocation:(NSInvocation *)invocation [invocation invokeWithTarget:_target]; } -- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector +- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector { return [_target methodSignatureForSelector:selector]; } diff --git a/lib/JFFUtils/JFFCastFunctions.hpp b/lib/JFFUtils/JFFCastFunctions.hpp index ba34782..eddf7b5 100755 --- a/lib/JFFUtils/JFFCastFunctions.hpp +++ b/lib/JFFUtils/JFFCastFunctions.hpp @@ -25,7 +25,7 @@ DESTINATION* objc_kind_of_cast(id nsObject) template < class DESTINATION > -DESTINATION* objc_member_of_cast( id nsObject ) +DESTINATION* objc_member_of_cast(id nsObject) { if (nil == nsObject) { return nil; diff --git a/lib/JFFUtils/JFFError.h b/lib/JFFUtils/JFFError.h deleted file mode 100755 index 60231ac..0000000 --- a/lib/JFFUtils/JFFError.h +++ /dev/null @@ -1,15 +0,0 @@ -#import - -@interface JFFError : NSError - -- (id)initWithDescription:(NSString *)description - domain:(NSString *)domain - code:(NSInteger)code; - -- (id)initWithDescription:(NSString *)description; -+ (id)newErrorWithDescription:(NSString *)description; - -+ (id)newErrorWithDescription:(NSString *)description - code:(NSInteger)code; - -@end diff --git a/lib/JFFUtils/JFFError.m b/lib/JFFUtils/JFFError.m deleted file mode 100755 index 10c5a25..0000000 --- a/lib/JFFUtils/JFFError.m +++ /dev/null @@ -1,44 +0,0 @@ -#import "JFFError.h" - -@implementation JFFError - -+ (NSString *)jffErrorsDomain -{ - return @"com.just_for_fun.library"; -} - -- (id)initWithDescription:(NSString *)description - domain:(NSString *)domain - code:(NSInteger)code -{ - NSDictionary *userInfo = @{NSLocalizedDescriptionKey : description}; - - return [super initWithDomain:domain - code:code - userInfo:userInfo]; -} - -- (id)initWithDescription:(NSString *)description code:(NSInteger)code -{ - return [self initWithDescription:description - domain:[[self class] jffErrorsDomain] - code:code]; -} - -- (id)initWithDescription:(NSString *)description -{ - return [self initWithDescription:description code:0]; -} - -+ (id)newErrorWithDescription:(NSString *)description -{ - return [self newErrorWithDescription:description code:0]; -} - -+ (id)newErrorWithDescription:(NSString *)description - code:(NSInteger)code -{ - return [[self alloc] initWithDescription:description code:code]; -} - -@end diff --git a/lib/JFFUtils/JFFMutableAssignArray.h b/lib/JFFUtils/JFFMutableAssignArray.h index 0a904e1..513ae5f 100644 --- a/lib/JFFUtils/JFFMutableAssignArray.h +++ b/lib/JFFUtils/JFFMutableAssignArray.h @@ -11,8 +11,11 @@ - (void)addObject:(id)object; - (BOOL)containsObject:(id)object; - (void)removeObject:(id)object; +- (void)removeObjectAtIndex:(NSUInteger)index; - (void)removeAllObjects; +- (NSUInteger)indexOfObject:(id)object; + - (NSUInteger)count; - (id)firstMatch:(JFFPredicateBlock)predicate; diff --git a/lib/JFFUtils/JFFMutableAssignArray.m b/lib/JFFUtils/JFFMutableAssignArray.m index 169ecf7..d027fb9 100644 --- a/lib/JFFUtils/JFFMutableAssignArray.m +++ b/lib/JFFUtils/JFFMutableAssignArray.m @@ -82,16 +82,18 @@ - (BOOL)containsObject:(id)object - (void)removeObject:(id)object { - NSUInteger index = [_mutableArray firstIndexOfObjectMatch:^BOOL(id element) { - JFFAutoRemoveAssignProxy *proxy = element; - return proxy.target == object; - }]; + NSUInteger index = [self indexOfObject:object]; if (index != NSNotFound) { - JFFAutoRemoveAssignProxy *proxy = _mutableArray[index]; - [proxy onRemoveFromMutableAssignArray:self]; - [_mutableArray removeObjectAtIndex:index]; + [self removeObjectAtIndex:index]; } +} + +- (void)removeObjectAtIndex:(NSUInteger)index +{ + JFFAutoRemoveAssignProxy *proxy = _mutableArray[index]; + [proxy onRemoveFromMutableAssignArray:self]; + [_mutableArray removeObjectAtIndex:index]; if (_onRemoveObject) { _onRemoveObject(); @@ -106,12 +108,22 @@ - (void)removeAllObjects [_mutableArray removeAllObjects]; } +- (NSUInteger)indexOfObject:(id)object +{ + NSUInteger index = [_mutableArray firstIndexOfObjectMatch:^BOOL(id element) { + JFFAutoRemoveAssignProxy *proxy = element; + return proxy.target == object; + }]; + + return index; +} + - (NSUInteger)count { return [_mutableArray count]; } -- (id)initWithObject:( id )anObject +- (instancetype)initWithObject:( id )anObject { self = [super init]; diff --git a/lib/JFFUtils/JFFMutableAssignDictionary.m b/lib/JFFUtils/JFFMutableAssignDictionary.m index a35fe28..9c681fc 100644 --- a/lib/JFFUtils/JFFMutableAssignDictionary.m +++ b/lib/JFFUtils/JFFMutableAssignDictionary.m @@ -28,7 +28,7 @@ - (void)onAddToMutableAssignDictionary:(JFFMutableAssignDictionary *)dict [self.target addOnDeallocBlock:self.onDeallocBlock]; } -- (void)onRemoveFromMutableAssignDictionary:(JFFMutableAssignDictionary *)array +- (void)onRemoveFromMutableAssignDictionary:(JFFMutableAssignDictionary *)dict { [self.target removeOnDeallocBlock:self.onDeallocBlock]; self.onDeallocBlock = nil; @@ -36,13 +36,10 @@ - (void)onRemoveFromMutableAssignDictionary:(JFFMutableAssignDictionary *)array @end -@interface JFFMutableAssignDictionary () - -@property (nonatomic) NSMutableDictionary *mutableDictionary; - -@end - @implementation JFFMutableAssignDictionary +{ + NSMutableDictionary *_mutableDictionary; +} - (void)dealloc { @@ -52,11 +49,12 @@ - (void)dealloc - (void)removeAllObjects { [_mutableDictionary enumerateKeysAndObjectsUsingBlock:^(id key, - JFFAutoRemoveFromDictAssignProxy *proxy, - BOOL *stop) { + JFFAutoRemoveFromDictAssignProxy *proxy, + BOOL *stop) { + [proxy onRemoveFromMutableAssignDictionary:self]; }]; - [_mutableDictionary removeAllObjects]; + _mutableDictionary = nil; } - (NSMutableDictionary *)mutableDictionary @@ -74,29 +72,30 @@ - (NSUInteger)count - (id)objectForKey:(id)key { - JFFAutoRemoveFromDictAssignProxy *proxy = _mutableDictionary[key]; - return proxy.target; + return [self objectForKeyedSubscript:key]; } - (id)objectForKeyedSubscript:(id)key { - return [self objectForKey:key]; + JFFAutoRemoveFromDictAssignProxy *proxy = _mutableDictionary[key]; + return proxy.target; } - (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block { [_mutableDictionary enumerateKeysAndObjectsUsingBlock:^(id key, - JFFAutoRemoveFromDictAssignProxy *proxy, - BOOL *stop) { + JFFAutoRemoveFromDictAssignProxy *proxy, + BOOL *stop) { block(key, proxy.target, stop); }]; } -- (NSDictionary*)map:(JFFDictMappingBlock)block +- (NSDictionary *)map:(JFFDictMappingBlock)block { return [_mutableDictionary map:^id(id key, JFFAutoRemoveFromDictAssignProxy *proxy) { + return block(key, proxy.target); - }]; + }]?:@{}; } - (void)removeObjectForKey:(id)key @@ -106,25 +105,25 @@ - (void)removeObjectForKey:(id)key [_mutableDictionary removeObjectForKey:key]; } -- (void)setObject:(id)object forKey:(id)key +- (void)setObject:(id)newValue forKey:(id)key +{ + [self setObject:newValue forKeyedSubscript:key]; +} + +- (void)setObject:(id)newValue forKeyedSubscript:(id)key { id previousObject = self[key]; if (previousObject) [self removeObjectForKey:key]; - JFFAutoRemoveFromDictAssignProxy *proxy = [[JFFAutoRemoveFromDictAssignProxy alloc] initWithTarget:object]; + JFFAutoRemoveFromDictAssignProxy *proxy = [[JFFAutoRemoveFromDictAssignProxy alloc] initWithTarget:newValue]; self.mutableDictionary[key] = proxy; [proxy onAddToMutableAssignDictionary:self key:key]; } -- (void)setObject:(id)newValue forKeyedSubscript:(id)key -{ - [self setObject:newValue forKey:key]; -} - - (NSString *)description { - return [_mutableDictionary description]; + return [_mutableDictionary?:@{} description]; } @end diff --git a/lib/JFFUtils/JFFMutableAssignKeyDictionary.h b/lib/JFFUtils/JFFMutableAssignKeyDictionary.h new file mode 100644 index 0000000..f417d76 --- /dev/null +++ b/lib/JFFUtils/JFFMutableAssignKeyDictionary.h @@ -0,0 +1,22 @@ +#import + +#import + +@interface JFFMutableAssignKeyDictionary : NSObject + +- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block; +- (NSDictionary *)map:(JFFDictMappingBlock)block; + +- (NSUInteger)count; + +- (id)objectForKey:(id)key; +- (id)objectForKeyedSubscript:(id)key; + +- (void)removeObjectForKey:(id)key; + +- (void)setObject:(id)object forKey:(id)key; +- (void)setObject:(id)newValue forKeyedSubscript:(id)key; + +- (void)removeAllObjects; + +@end diff --git a/lib/JFFUtils/JFFMutableAssignKeyDictionary.mm b/lib/JFFUtils/JFFMutableAssignKeyDictionary.mm new file mode 100644 index 0000000..dd983c2 --- /dev/null +++ b/lib/JFFUtils/JFFMutableAssignKeyDictionary.mm @@ -0,0 +1,227 @@ +#import "JFFMutableAssignKeyDictionary.h" + +#import "NSObject+OnDeallocBlock.h" +#include "JFFRuntimeAddiotions.h" + +#include + +@class JFFMutableAssignDictionaryKeyWrapper; + +typedef std::map<__unsafe_unretained id, JFFSimpleBlock> BlockByPtr; + +@interface JFFCPPMapONDeallocBlockByArrayPtrHolder : NSObject +{ +@public + BlockByPtr _map; +} + +@end + +@implementation JFFCPPMapONDeallocBlockByArrayPtrHolder +@end + +@interface NSObject (JFFMutableAssignKeyDictionary) + +@property (nonatomic) JFFCPPMapONDeallocBlockByArrayPtrHolder *mutableAssignKeyDictionaryOnDeallocBlock; + +@end + +@implementation NSObject (JFFMutableAssignKeyDictionary) + +@dynamic mutableAssignKeyDictionaryOnDeallocBlock; + ++ (void)load +{ + jClass_implementProperty(self, NSStringFromSelector(@selector(mutableAssignKeyDictionaryOnDeallocBlock))); +} + +- (JFFCPPMapONDeallocBlockByArrayPtrHolder *)lazyMutableAssignKeyDictionaryOnDeallocBlock +{ + JFFCPPMapONDeallocBlockByArrayPtrHolder *result = [self mutableAssignKeyDictionaryOnDeallocBlock]; + + if (!result) { + + result = [JFFCPPMapONDeallocBlockByArrayPtrHolder new]; + self.mutableAssignKeyDictionaryOnDeallocBlock = result; + } + + return result; +} + +- (void)onAddToMutableAssignKeyDictionary:(JFFMutableAssignKeyDictionary *)dict +{ + __unsafe_unretained JFFMutableAssignKeyDictionary *unretainedDict = dict; + __unsafe_unretained NSObject *unretainedSelf = self; + + [self onRemoveFromMutableAssignKeyDictionary:dict]; + + JFFSimpleBlock onDeallocBlock = [^void(void) { + + [unretainedDict removeObjectForKey:unretainedSelf]; + } copy]; + + self.lazyMutableAssignKeyDictionaryOnDeallocBlock->_map[dict] = onDeallocBlock; + + [self addOnDeallocBlock:onDeallocBlock]; +} + +- (void)onRemoveFromMutableAssignKeyDictionary:(JFFMutableAssignKeyDictionary *)dict +{ + JFFCPPMapONDeallocBlockByArrayPtrHolder *mutableAssignKeyDictionaryOnDeallocBlock = self.mutableAssignKeyDictionaryOnDeallocBlock; + + if (!mutableAssignKeyDictionaryOnDeallocBlock) + return; + + BlockByPtr::iterator it = mutableAssignKeyDictionaryOnDeallocBlock->_map.find(dict); + + if (it != mutableAssignKeyDictionaryOnDeallocBlock->_map.end()) { + + JFFSimpleBlock onDeallocBlock = it->second; + [self removeOnDeallocBlock:onDeallocBlock]; + + mutableAssignKeyDictionaryOnDeallocBlock->_map.erase(it); + } +} + +@end + +@interface JFFMutableAssignDictionaryKeyWrapper : NSObject + +@property (nonatomic, unsafe_unretained, readonly) NSObject *dictKeyObject; + +@end + +@implementation JFFMutableAssignDictionaryKeyWrapper + +- (BOOL)isEqual:(JFFMutableAssignDictionaryKeyWrapper *)object +{ + if (![object isKindOfClass:[self class]]) { + return NO; + } + + return _dictKeyObject == object->_dictKeyObject; +} + +- (NSUInteger)hash +{ + return (NSUInteger)((__bridge void*)_dictKeyObject); +} + +- (instancetype)copyWithZone:(NSZone *)zone +{ + JFFMutableAssignDictionaryKeyWrapper *copy = [[[self class] allocWithZone:zone] init]; + + if (copy) { + copy->_dictKeyObject = _dictKeyObject; + } + + return copy; +} + +- (instancetype)initWithDictKeyObject:(__unsafe_unretained id)object +{ + self = [super init]; + + if (self) { + + _dictKeyObject = object; + } + + return self; +} + +@end + +@implementation JFFMutableAssignKeyDictionary +{ + NSMutableDictionary *_mutableDictionary; +} + +- (void)dealloc +{ + [self removeAllObjects]; +} + +- (NSMutableDictionary *)mutableDictionary +{ + if (!_mutableDictionary) { + _mutableDictionary = [NSMutableDictionary new]; + } + return _mutableDictionary; +} + +- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block +{ + [_mutableDictionary enumerateKeysAndObjectsUsingBlock:^(JFFMutableAssignDictionaryKeyWrapper *key, id obj, BOOL *stop) { + + block(key.dictKeyObject, obj, stop); + }]; +} + +- (NSDictionary *)map:(JFFDictMappingBlock)block +{ + NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithCapacity:[self count]]; + + [_mutableDictionary enumerateKeysAndObjectsUsingBlock:^(JFFMutableAssignDictionaryKeyWrapper *internalKey, id object, BOOL *stop) { + + id key = internalKey.dictKeyObject; + id newObject = block(key, object); + NSParameterAssert(newObject); + result[key] = newObject; + }]; + + return [result copy]; +} + +- (NSUInteger)count +{ + return [_mutableDictionary count]; +} + +- (id)objectForKey:(id)key +{ + return [self objectForKeyedSubscript:key]; +} + +- (id)objectForKeyedSubscript:(id)key +{ + id internalKey = [[JFFMutableAssignDictionaryKeyWrapper alloc] initWithDictKeyObject:key]; + return _mutableDictionary[internalKey]; +} + +- (void)removeObjectForKey:(__unsafe_unretained id)key +{ + [key onRemoveFromMutableAssignKeyDictionary:self]; + + id internalKey = [[JFFMutableAssignDictionaryKeyWrapper alloc] initWithDictKeyObject:key]; + [_mutableDictionary removeObjectForKey:internalKey]; +} + +- (void)setObject:(id)newValue forKey:(id)key +{ + [self setObject:newValue forKeyedSubscript:key]; +} + +- (void)setObject:(id)newValue forKeyedSubscript:(id)key +{ + [key onAddToMutableAssignKeyDictionary:self]; + + id internalKey = [[JFFMutableAssignDictionaryKeyWrapper alloc] initWithDictKeyObject:key]; + self.mutableDictionary[internalKey] = newValue; +} + +- (void)removeAllObjects +{ + [_mutableDictionary enumerateKeysAndObjectsUsingBlock:^(JFFMutableAssignDictionaryKeyWrapper *key, id obj, BOOL *stop) { + + [key.dictKeyObject onRemoveFromMutableAssignKeyDictionary:self]; + }]; + _mutableDictionary = nil; +} + +- (NSString *)description +{ + return [_mutableDictionary?:@{} description]; +} + +@end diff --git a/lib/JFFUtils/JFFSingleThreadProxy.m b/lib/JFFUtils/JFFSingleThreadProxy.m index 65ed3f7..7359988 100644 --- a/lib/JFFUtils/JFFSingleThreadProxy.m +++ b/lib/JFFUtils/JFFSingleThreadProxy.m @@ -24,14 +24,12 @@ -(void)dealloc container.target = nil; }; dispatch_async(_dispatchQueue, releaseListener); - dispatch_release(_dispatchQueue); } - (id)initWithTargetFactory:(JFFObjectFactory)factory dispatchQueue:(dispatch_queue_t)dispatchQueue { _dispatchQueue = dispatchQueue; - dispatch_retain(_dispatchQueue); factory = [factory copy]; void (^releaseListener)(void) = ^ { diff --git a/lib/JFFUtils/JFFUtils.h b/lib/JFFUtils/JFFUtils.h index 7b8794c..c19fb9c 100644 --- a/lib/JFFUtils/JFFUtils.h +++ b/lib/JFFUtils/JFFUtils.h @@ -1,82 +1,85 @@ #import #import +#import #import #import #import #import +#import #import #import -#import #import #import #import +#import #import #import +#import #import #import +#import +#import +#import #import #import -#import #import #import -#import +#import #import +#import #import #import #import +#import #import -#import -#import +#import #import #import - #import #import #import #import -#import -#import -#import +#import +#import +#import +#import +#import +#import #import #import #import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import +#import +#import +#import +#import +#import +#import +#import #import #import #import -#import -#import +#import -#import #import #import #import -#import #import +#import #import #import +#import #import diff --git a/lib/JFFUtils/JFFUtils.xcodeproj/project.pbxproj b/lib/JFFUtils/JFFUtils.xcodeproj/project.pbxproj index ac90930..bf04605 100644 --- a/lib/JFFUtils/JFFUtils.xcodeproj/project.pbxproj +++ b/lib/JFFUtils/JFFUtils.xcodeproj/project.pbxproj @@ -11,8 +11,6 @@ 1B054D501521C6F4008E4B9E /* NSDictionary+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B054D4E1521C6F4008E4B9E /* NSDictionary+BlocksAdditions.m */; }; 1B054D531521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B054D511521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.h */; }; 1B054D541521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B054D521521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.m */; }; - 1B10109714ED598300B9E6F4 /* NSError+setToPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B10109514ED598300B9E6F4 /* NSError+setToPointer.h */; }; - 1B10109814ED598300B9E6F4 /* NSError+setToPointer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B10109614ED598300B9E6F4 /* NSError+setToPointer.m */; }; 1B104D8F1483C8410025FDDA /* JSignedRange.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B104D8D1483C8410025FDDA /* JSignedRange.m */; }; 1B104D921483C85A0025FDDA /* JSignedRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B104D911483C85A0025FDDA /* JSignedRange.h */; }; 1B14141E15DBCD3F00EFB2B8 /* NSDate+DateDifference.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B14141C15DBCD3F00EFB2B8 /* NSDate+DateDifference.h */; }; @@ -23,8 +21,6 @@ 1B14142315DBCD3F00EFB2B8 /* NSDate+DateDifference.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B14141D15DBCD3F00EFB2B8 /* NSDate+DateDifference.m */; }; 1B14142415DBCD3F00EFB2B8 /* NSDate+DateDifference.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B14141D15DBCD3F00EFB2B8 /* NSDate+DateDifference.m */; }; 1B14142515DBCD3F00EFB2B8 /* NSDate+DateDifference.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B14141D15DBCD3F00EFB2B8 /* NSDate+DateDifference.m */; }; - 1B16830F146AD4C800832839 /* NSString+UUIDCreation.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B16830D146AD4C800832839 /* NSString+UUIDCreation.h */; }; - 1B168310146AD4C800832839 /* NSString+UUIDCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B16830E146AD4C800832839 /* NSString+UUIDCreation.m */; }; 1B1B280814D825A700FA5388 /* NSString+IsEmailValid.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B1B280614D825A600FA5388 /* NSString+IsEmailValid.h */; }; 1B1B280914D825A700FA5388 /* NSString+IsEmailValid.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B1B280714D825A600FA5388 /* NSString+IsEmailValid.m */; }; 1B266C9D15627F7D0054E183 /* libc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B266C9C15627F7D0054E183 /* libc++.dylib */; }; @@ -55,12 +51,6 @@ 1B9C101015C802E600C20BCA /* JFFClangLiterals.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B9C100F15C802E600C20BCA /* JFFClangLiterals.h */; }; 1B9C101115C802E600C20BCA /* JFFClangLiterals.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B9C100F15C802E600C20BCA /* JFFClangLiterals.h */; }; 1B9C101215C802E600C20BCA /* JFFClangLiterals.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B9C100F15C802E600C20BCA /* JFFClangLiterals.h */; }; - 1BA30C2C151A384100329EA6 /* JFFRuntime.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA30C2A151A384100329EA6 /* JFFRuntime.h */; }; - 1BA30C2D151A384100329EA6 /* JFFRuntime.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA30C2B151A384100329EA6 /* JFFRuntime.m */; }; - 1BA676BB144C3FE900B14D49 /* UIWebView+UserAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676B9144C3FE900B14D49 /* UIWebView+UserAgent.h */; }; - 1BA676BC144C3FE900B14D49 /* UIWebView+UserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676BA144C3FE900B14D49 /* UIWebView+UserAgent.m */; }; - 1BA676BF144C409F00B14D49 /* NSThread+AssertMainThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676BD144C409E00B14D49 /* NSThread+AssertMainThread.h */; }; - 1BA676C0144C409F00B14D49 /* NSThread+AssertMainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676BE144C409F00B14D49 /* NSThread+AssertMainThread.m */; }; 1BA676CE144C474500B14D49 /* NSString+ToURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676CC144C474500B14D49 /* NSString+ToURL.h */; }; 1BA676CF144C474500B14D49 /* NSString+ToURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676CD144C474500B14D49 /* NSString+ToURL.m */; }; 1BA676D2144C476600B14D49 /* NSURL+ToURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676D0144C476600B14D49 /* NSURL+ToURL.h */; }; @@ -69,13 +59,8 @@ 1BBD97E115249C4200A34E64 /* NSObject+IsEqualTwoObjects.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BBD97DF15249C4200A34E64 /* NSObject+IsEqualTwoObjects.m */; }; 1BCDF9E514320B3200CEB6E7 /* NSMutableArray+ChangeCount.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BCDF9E314320B3200CEB6E7 /* NSMutableArray+ChangeCount.h */; }; 1BCDF9E614320B3200CEB6E7 /* NSMutableArray+ChangeCount.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCDF9E414320B3200CEB6E7 /* NSMutableArray+ChangeCount.m */; }; - 1BD01FB114447B7600A627B1 /* JFFSingleThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD01FAF14447B7600A627B1 /* JFFSingleThreadProxy.h */; }; - 1BD01FB214447B7600A627B1 /* JFFSingleThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD01FB014447B7600A627B1 /* JFFSingleThreadProxy.m */; }; 1BD1820D1467D71B0033BEFF /* JFFMutableAssignDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD1820B1467D71B0033BEFF /* JFFMutableAssignDictionary.h */; }; 1BD1820E1467D71B0033BEFF /* JFFMutableAssignDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD1820C1467D71B0033BEFF /* JFFMutableAssignDictionary.m */; }; - 1BE2ABEE14E524D0003097D3 /* UIColor+ColorForHex.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BE2ABEC14E524D0003097D3 /* UIColor+ColorForHex.h */; }; - 1BE2ABEF14E524D0003097D3 /* UIColor+ColorForHex.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE2ABED14E524D0003097D3 /* UIColor+ColorForHex.m */; }; - 1BE2ABF114E524DF003097D3 /* UIColor+ColorForHex.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE2ABED14E524D0003097D3 /* UIColor+ColorForHex.m */; }; 1BE75CFF1434B3450076E068 /* NSObject+Const0.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BE75CFD1434B3450076E068 /* NSObject+Const0.h */; }; 1BE75D001434B3450076E068 /* NSObject+Const0.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE75CFE1434B3450076E068 /* NSObject+Const0.m */; }; 37063C6715FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = 37063C6515FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.h */; }; @@ -88,25 +73,85 @@ 37497BD51600971C00AF0C29 /* NSDictionary+ValueWithType.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497BCF1600971C00AF0C29 /* NSDictionary+ValueWithType.m */; }; 37497BD61600971C00AF0C29 /* NSDictionary+ValueWithType.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497BCF1600971C00AF0C29 /* NSDictionary+ValueWithType.m */; }; 37497BD71600971C00AF0C29 /* NSDictionary+ValueWithType.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497BCF1600971C00AF0C29 /* NSDictionary+ValueWithType.m */; }; - 37497DF31601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 37497DF11601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h */; }; - 37497DF41601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 37497DF11601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h */; }; - 37497DF51601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 37497DF11601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h */; }; - 37497DF61601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 37497DF11601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h */; }; - 37497DF71601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497DF21601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m */; }; - 37497DF81601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497DF21601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m */; }; - 37497DF91601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497DF21601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m */; }; - 37497DFA1601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 37497DF21601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m */; }; 37805592164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 37805590164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.h */; }; 37805593164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 37805591164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.m */; }; + 4C27EDB11701C48500185768 /* libJFFTestTools.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C27EDAE1701C47300185768 /* libJFFTestTools.a */; }; + 4C3B63A21701C84700D5A8FD /* JFFMutableAssignKeyDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C3B63A01701C84700D5A8FD /* JFFMutableAssignKeyDictionary.h */; }; + 4C3B63A31701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C3B63A11701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm */; }; + 4C4E1E6D179D3529009E9C71 /* NSString+StringFromTemplateString.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C4E1E6B179D3529009E9C71 /* NSString+StringFromTemplateString.h */; }; + 4C4E1E6E179D3529009E9C71 /* NSString+StringFromTemplateString.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4E1E6C179D3529009E9C71 /* NSString+StringFromTemplateString.m */; }; + 4C4E1E72179D55AF009E9C71 /* StringFromTemplateString.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4E1E71179D55AF009E9C71 /* StringFromTemplateString.m */; }; + 4C4E1E77179D56D5009E9C71 /* NSString+StringFromTemplateString.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4E1E6C179D3529009E9C71 /* NSString+StringFromTemplateString.m */; }; + 4C5040C018112174003F4B12 /* JFFSingleThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5040BE18112174003F4B12 /* JFFSingleThreadProxy.h */; }; + 4C5040C118112174003F4B12 /* JFFSingleThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5040BF18112174003F4B12 /* JFFSingleThreadProxy.m */; }; + 4C5040C7181124A1003F4B12 /* NSString+JSEscape.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5040C3181124A1003F4B12 /* NSString+JSEscape.h */; }; + 4C5040C8181124A1003F4B12 /* NSString+JSEscape.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5040C4181124A1003F4B12 /* NSString+JSEscape.m */; }; + 4C5040C9181124A1003F4B12 /* NSString+UUIDCreation.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5040C5181124A1003F4B12 /* NSString+UUIDCreation.h */; }; + 4C5040CA181124A1003F4B12 /* NSString+UUIDCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5040C6181124A1003F4B12 /* NSString+UUIDCreation.m */; }; + 4C5040CD18112542003F4B12 /* NSError+JSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5040CB18112542003F4B12 /* NSError+JSON.h */; }; + 4C5040CE18112542003F4B12 /* NSError+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5040CC18112542003F4B12 /* NSError+JSON.m */; }; + 4C5040D118112601003F4B12 /* NSThread+AssertMainThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5040CF18112601003F4B12 /* NSThread+AssertMainThread.h */; }; + 4C5040D218112601003F4B12 /* NSThread+AssertMainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5040D018112601003F4B12 /* NSThread+AssertMainThread.m */; }; + 4C50BF59171D85B300251A16 /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DFB12171849D800D86975 /* JFFError.m */; }; + 4C50BF5A171D85B400251A16 /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DFB12171849D800D86975 /* JFFError.m */; }; + 4C50BF5B171D85B400251A16 /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DFB12171849D800D86975 /* JFFError.m */; }; + 4C50BF5C171D85B500251A16 /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DFB12171849D800D86975 /* JFFError.m */; }; + 4C6AFDFD177AD544009D09C3 /* NSString+MD5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C6AFDFB177AD544009D09C3 /* NSString+MD5.h */; }; + 4C6AFDFE177AD544009D09C3 /* NSString+MD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6AFDFC177AD544009D09C3 /* NSString+MD5.m */; }; + 4C6DFB13171849D800D86975 /* JFFError.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C6DFB11171849D800D86975 /* JFFError.h */; }; + 4C6DFB14171849D800D86975 /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DFB12171849D800D86975 /* JFFError.m */; }; + 4C6DFB1717184A0600D86975 /* JFFSilentError.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C6DFB1517184A0600D86975 /* JFFSilentError.h */; }; + 4C6DFB1817184A0600D86975 /* JFFSilentError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DFB1617184A0600D86975 /* JFFSilentError.m */; }; + 4C712E1917046A0300346F5E /* MethodObserverTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C712E1817046A0300346F5E /* MethodObserverTest.m */; }; + 4C8A22791705913B000539D2 /* TypeSignatureTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8A22781705913B000539D2 /* TypeSignatureTest.m */; }; + 4C8D176917870ED900DE7624 /* NSString+LocalizedPrice.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8D176717870ED900DE7624 /* NSString+LocalizedPrice.h */; }; + 4C8D176A17870ED900DE7624 /* NSString+LocalizedPrice.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8D176817870ED900DE7624 /* NSString+LocalizedPrice.m */; }; + 4C98FBA116E0B38D00B6EFD8 /* NSString+HTML.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C98FB9F16E0B38D00B6EFD8 /* NSString+HTML.h */; }; + 4C98FBA216E0B38D00B6EFD8 /* NSString+HTML.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C98FBA016E0B38D00B6EFD8 /* NSString+HTML.m */; }; + 4C98FBAC16E0B56D00B6EFD8 /* NSArray+Templates.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4C98FBAB16E0B56D00B6EFD8 /* NSArray+Templates.hpp */; }; + 4CAB2A571730097A001EB552 /* JFFRuntimeAddiotionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAB2A561730097A001EB552 /* JFFRuntimeAddiotionsTest.m */; }; + 4CB5CDEF174F55CB00F2B600 /* NSArray+ToURLsSkippingNils.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB5CDED174F55CA00F2B600 /* NSArray+ToURLsSkippingNils.h */; }; + 4CB5CDF0174F55CB00F2B600 /* NSArray+ToURLsSkippingNils.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB5CDEE174F55CA00F2B600 /* NSArray+ToURLsSkippingNils.m */; }; + 4CBBA1A317661FA5007317E6 /* NSArray+ArrayByRemovingObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CBBA1A117661FA5007317E6 /* NSArray+ArrayByRemovingObject.h */; }; + 4CBBA1A417661FA5007317E6 /* NSArray+ArrayByRemovingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBBA1A217661FA5007317E6 /* NSArray+ArrayByRemovingObject.m */; }; + 4CC01A921743836C003F1C88 /* NSError+WriteErrorToNSLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC01A901743836C003F1C88 /* NSError+WriteErrorToNSLog.h */; }; + 4CC01A931743836C003F1C88 /* NSError+WriteErrorToNSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC01A911743836C003F1C88 /* NSError+WriteErrorToNSLog.m */; }; + 4CC01A9617438408003F1C88 /* NSError+IsNetworkError.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC01A9417438408003F1C88 /* NSError+IsNetworkError.h */; }; + 4CC01A9717438408003F1C88 /* NSError+IsNetworkError.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC01A9517438408003F1C88 /* NSError+IsNetworkError.m */; }; + 4CC01A9A17438582003F1C88 /* NSError+SetToPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC01A9817438582003F1C88 /* NSError+SetToPointer.h */; }; + 4CC01A9B17438582003F1C88 /* NSError+SetToPointer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC01A9917438582003F1C88 /* NSError+SetToPointer.m */; }; + 4CC643BE1717009B000BF15A /* NSObject+ObjectMethodHook.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC643BC1717009B000BF15A /* NSObject+ObjectMethodHook.h */; }; + 4CC643BF1717009B000BF15A /* NSObject+ObjectMethodHook.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CC643BD1717009B000BF15A /* NSObject+ObjectMethodHook.mm */; }; + 4CC643C0171700BA000BF15A /* NSObject+ObjectMethodHook.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CC643BD1717009B000BF15A /* NSObject+ObjectMethodHook.mm */; }; + 4CC643C1171700BA000BF15A /* NSObject+ObjectMethodHook.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CC643BD1717009B000BF15A /* NSObject+ObjectMethodHook.mm */; }; + 4CC643C2171700BA000BF15A /* NSObject+ObjectMethodHook.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CC643BD1717009B000BF15A /* NSObject+ObjectMethodHook.mm */; }; + 4CC643C3171700CB000BF15A /* NSObject+ObjectMethodHook.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CC643BD1717009B000BF15A /* NSObject+ObjectMethodHook.mm */; }; + 4CC6BBEC17058D4200BD49E8 /* NSDecimalNumber+Increment.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC6BBEA17058D4200BD49E8 /* NSDecimalNumber+Increment.h */; }; + 4CC6BBED17058D4200BD49E8 /* NSDecimalNumber+Increment.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6BBEB17058D4200BD49E8 /* NSDecimalNumber+Increment.m */; }; + 4CC6BBF017058D5F00BD49E8 /* UIColor+ColorForHex.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC6BBEE17058D5F00BD49E8 /* UIColor+ColorForHex.h */; }; + 4CC6BBF117058D5F00BD49E8 /* UIColor+ColorForHex.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6BBEF17058D5F00BD49E8 /* UIColor+ColorForHex.m */; }; + 4CC6BBF817058DB100BD49E8 /* NSData+ToString.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC6BBF617058DB100BD49E8 /* NSData+ToString.h */; }; + 4CC6BBF917058DB100BD49E8 /* NSData+ToString.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6BBF717058DB100BD49E8 /* NSData+ToString.m */; }; + 4CC6BBFC17058DD000BD49E8 /* NSNumber+FSStorable.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC6BBFA17058DCF00BD49E8 /* NSNumber+FSStorable.h */; }; + 4CC6BBFD17058DD000BD49E8 /* NSNumber+FSStorable.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6BBFB17058DCF00BD49E8 /* NSNumber+FSStorable.m */; }; + 4CC6BC0017058DFF00BD49E8 /* NSDateFormatter+MultiThreading.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC6BBFE17058DFE00BD49E8 /* NSDateFormatter+MultiThreading.h */; }; + 4CC6BC0117058DFF00BD49E8 /* NSDateFormatter+MultiThreading.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6BBFF17058DFE00BD49E8 /* NSDateFormatter+MultiThreading.m */; }; + 4CC6BC0817058E3900BD49E8 /* UIDevice+PlatformName.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CC6BC0617058E3700BD49E8 /* UIDevice+PlatformName.h */; }; + 4CC6BC0917058E3900BD49E8 /* UIDevice+PlatformName.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6BC0717058E3800BD49E8 /* UIDevice+PlatformName.m */; }; + 4CEED6BB1701E236004CFCB3 /* JFFMutableAssignKeyDictionaryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CEED6B51701E0F5004CFCB3 /* JFFMutableAssignKeyDictionaryTest.m */; }; + 4CEED6BC1701E23C004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C3B63A11701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm */; }; + 4CEED6BD1701E23C004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C3B63A11701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm */; }; + 4CEED6BE1701E23C004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C3B63A11701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm */; }; + 4CEED6BF1701E23D004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C3B63A11701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm */; }; + 4CF0FFDC170602CC00282900 /* JFFRuntimeAddiotions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CF0FFDA170602CC00282900 /* JFFRuntimeAddiotions.h */; }; + 4CF0FFDD170602CC00282900 /* JFFRuntimeAddiotions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF0FFDB170602CC00282900 /* JFFRuntimeAddiotions.m */; }; + 4CF0FFDE1706038200282900 /* JFFRuntimeAddiotions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF0FFDB170602CC00282900 /* JFFRuntimeAddiotions.m */; }; + 4CF0FFDF1706038200282900 /* JFFRuntimeAddiotions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF0FFDB170602CC00282900 /* JFFRuntimeAddiotions.m */; }; + 4CF0FFE01706038300282900 /* JFFRuntimeAddiotions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF0FFDB170602CC00282900 /* JFFRuntimeAddiotions.m */; }; + 4CF0FFE11706038300282900 /* JFFRuntimeAddiotions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF0FFDB170602CC00282900 /* JFFRuntimeAddiotions.m */; }; 534CDFC214A8C2930068F4DF /* JFFCastFunctions.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 534CDFC014A8C2930068F4DF /* JFFCastFunctions.hpp */; }; 534CDFC314A8C2930068F4DF /* JFFCastFunctions.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 534CDFC014A8C2930068F4DF /* JFFCastFunctions.hpp */; }; 534CDFC414A8C2930068F4DF /* JFFCastFunctions.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 534CDFC014A8C2930068F4DF /* JFFCastFunctions.hpp */; }; - 538E1CAC14B32201006BD40A /* NSDecimalNumber+Increment.h in Headers */ = {isa = PBXBuildFile; fileRef = 538E1CAA14B32201006BD40A /* NSDecimalNumber+Increment.h */; }; - 538E1CAD14B32201006BD40A /* NSDecimalNumber+Increment.h in Headers */ = {isa = PBXBuildFile; fileRef = 538E1CAA14B32201006BD40A /* NSDecimalNumber+Increment.h */; }; - 538E1CAE14B32201006BD40A /* NSDecimalNumber+Increment.h in Headers */ = {isa = PBXBuildFile; fileRef = 538E1CAA14B32201006BD40A /* NSDecimalNumber+Increment.h */; }; - 538E1CAF14B32201006BD40A /* NSDecimalNumber+Increment.m in Sources */ = {isa = PBXBuildFile; fileRef = 538E1CAB14B32201006BD40A /* NSDecimalNumber+Increment.m */; }; - 538E1CB014B32201006BD40A /* NSDecimalNumber+Increment.m in Sources */ = {isa = PBXBuildFile; fileRef = 538E1CAB14B32201006BD40A /* NSDecimalNumber+Increment.m */; }; - 538E1CB114B32201006BD40A /* NSDecimalNumber+Increment.m in Sources */ = {isa = PBXBuildFile; fileRef = 538E1CAB14B32201006BD40A /* NSDecimalNumber+Increment.m */; }; 539103F414A88C04007315A3 /* JFFUtils_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* JFFUtils_Prefix.pch */; }; 539103F514A88C04007315A3 /* JFFUtilsBlockDefinitions.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE0A51390496200DD6890 /* JFFUtilsBlockDefinitions.h */; }; 539103F614A88C04007315A3 /* JFFSimpleBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE0A81390496200DD6890 /* JFFSimpleBlockHolder.h */; }; @@ -117,7 +162,6 @@ 539103FB14A88C04007315A3 /* NSObject+OnDeallocBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1CB1391A36800DD6890 /* NSObject+OnDeallocBlock.h */; }; 539103FC14A88C04007315A3 /* JFFUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE27B1391BD7800DD6890 /* JFFUtils.h */; }; 539103FD14A88C04007315A3 /* NSString+PropertyName.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648B7C13923EC4001E163C /* NSString+PropertyName.h */; }; - 539103FE14A88C04007315A3 /* JFFError.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648BDF13924326001E163C /* JFFError.h */; }; 539103FF14A88C04007315A3 /* NSObject+RuntimeExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1DE52913AB8269001FD56F /* NSObject+RuntimeExtensions.h */; }; 5391040014A88C04007315A3 /* JFFMulticastDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8DB67B1813E97FCF0024EA6C /* JFFMulticastDelegate.h */; }; 5391040114A88C04007315A3 /* JFFAssignProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 8DB67B1D13E980B70024EA6C /* JFFAssignProxy.h */; }; @@ -127,16 +171,12 @@ 5391040514A88C04007315A3 /* NSArray+RemoveDuplicates.h in Headers */ = {isa = PBXBuildFile; fileRef = 53BCF8DE143239D100E896B3 /* NSArray+RemoveDuplicates.h */; }; 5391040714A88C04007315A3 /* NSArray+IsEmpty.h in Headers */ = {isa = PBXBuildFile; fileRef = 53E366C61433760A002AB0B9 /* NSArray+IsEmpty.h */; }; 5391040814A88C04007315A3 /* NSObject+Const0.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BE75CFD1434B3450076E068 /* NSObject+Const0.h */; }; - 5391040A14A88C04007315A3 /* JFFSingleThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD01FAF14447B7600A627B1 /* JFFSingleThreadProxy.h */; }; 5391040C14A88C04007315A3 /* JGCDAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B7608981444912F0059E977 /* JGCDAdditions.h */; }; 5391041014A88C04007315A3 /* NSArray+NoThrowObjectAtIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B3CDDE31445DFD300733BE5 /* NSArray+NoThrowObjectAtIndex.h */; }; 5391041114A88C04007315A3 /* NSString+Trimm.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B6AAD8C1447039B00EA1D96 /* NSString+Trimm.h */; }; - 5391041214A88C04007315A3 /* UIWebView+UserAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676B9144C3FE900B14D49 /* UIWebView+UserAgent.h */; }; - 5391041314A88C04007315A3 /* NSThread+AssertMainThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676BD144C409E00B14D49 /* NSThread+AssertMainThread.h */; }; 5391041414A88C04007315A3 /* NSString+ToURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676CC144C474500B14D49 /* NSString+ToURL.h */; }; 5391041514A88C04007315A3 /* NSURL+ToURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676D0144C476600B14D49 /* NSURL+ToURL.h */; }; 5391041614A88C04007315A3 /* JFFMutableAssignDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD1820B1467D71B0033BEFF /* JFFMutableAssignDictionary.h */; }; - 5391041714A88C04007315A3 /* NSString+UUIDCreation.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B16830D146AD4C800832839 /* NSString+UUIDCreation.h */; }; 5391041814A88C04007315A3 /* JSignedRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B104D911483C85A0025FDDA /* JSignedRange.h */; }; 5391041914A88C04007315A3 /* NSObject+ExpandArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B3EE0341487D03A00BA6680 /* NSObject+ExpandArray.h */; }; 5391041B14A88C04007315A3 /* JFFSimpleBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE0A91390496200DD6890 /* JFFSimpleBlockHolder.m */; }; @@ -146,7 +186,6 @@ 5391041F14A88C04007315A3 /* JFFOnDeallocBlockOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1C21391A25500DD6890 /* JFFOnDeallocBlockOwner.m */; }; 5391042014A88C04007315A3 /* NSObject+OnDeallocBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1CC1391A36800DD6890 /* NSObject+OnDeallocBlock.m */; }; 5391042114A88C04007315A3 /* NSString+PropertyName.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648B7D13923EC4001E163C /* NSString+PropertyName.m */; }; - 5391042214A88C04007315A3 /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648BE013924326001E163C /* JFFError.m */; }; 5391042314A88C04007315A3 /* NSObject+RuntimeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1DE52A13AB8269001FD56F /* NSObject+RuntimeExtensions.m */; }; 5391042514A88C04007315A3 /* JFFMulticastDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1913E97FCF0024EA6C /* JFFMulticastDelegate.m */; }; 5391042614A88C04007315A3 /* JFFAssignProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1E13E980B70024EA6C /* JFFAssignProxy.m */; }; @@ -156,16 +195,12 @@ 5391042A14A88C04007315A3 /* NSArray+RemoveDuplicates.m in Sources */ = {isa = PBXBuildFile; fileRef = 53BCF8DF143239D100E896B3 /* NSArray+RemoveDuplicates.m */; }; 5391042B14A88C04007315A3 /* NSArray+IsEmpty.m in Sources */ = {isa = PBXBuildFile; fileRef = 53E366C71433760A002AB0B9 /* NSArray+IsEmpty.m */; }; 5391042C14A88C04007315A3 /* NSObject+Const0.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE75CFE1434B3450076E068 /* NSObject+Const0.m */; }; - 5391042E14A88C04007315A3 /* JFFSingleThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD01FB014447B7600A627B1 /* JFFSingleThreadProxy.m */; }; 5391043014A88C04007315A3 /* JGCDAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1B7608991444912F0059E977 /* JGCDAdditions.mm */; }; 5391043414A88C04007315A3 /* NSArray+NoThrowObjectAtIndex.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B3CDDE41445DFD300733BE5 /* NSArray+NoThrowObjectAtIndex.m */; }; 5391043514A88C04007315A3 /* NSString+Trimm.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B6AAD8D1447039B00EA1D96 /* NSString+Trimm.m */; }; - 5391043614A88C04007315A3 /* UIWebView+UserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676BA144C3FE900B14D49 /* UIWebView+UserAgent.m */; }; - 5391043714A88C04007315A3 /* NSThread+AssertMainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676BE144C409F00B14D49 /* NSThread+AssertMainThread.m */; }; 5391043814A88C04007315A3 /* NSString+ToURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676CD144C474500B14D49 /* NSString+ToURL.m */; }; 5391043914A88C04007315A3 /* NSURL+ToURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676D1144C476600B14D49 /* NSURL+ToURL.m */; }; 5391043A14A88C04007315A3 /* JFFMutableAssignDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD1820C1467D71B0033BEFF /* JFFMutableAssignDictionary.m */; }; - 5391043B14A88C04007315A3 /* NSString+UUIDCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B16830E146AD4C800832839 /* NSString+UUIDCreation.m */; }; 5391043C14A88C04007315A3 /* JSignedRange.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B104D8D1483C8410025FDDA /* JSignedRange.m */; }; 5391043D14A88C04007315A3 /* NSObject+ExpandArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B3EE0351487D03A00BA6680 /* NSObject+ExpandArray.m */; }; 5391043F14A88C04007315A3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; @@ -193,26 +228,20 @@ 655C20E815FE5A4000022B11 /* NSObject+DelegateProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 655C20E615FE5A4000022B11 /* NSObject+DelegateProxy.m */; }; 65648B7E13923EC4001E163C /* NSString+PropertyName.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648B7C13923EC4001E163C /* NSString+PropertyName.h */; }; 65648B7F13923EC4001E163C /* NSString+PropertyName.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648B7D13923EC4001E163C /* NSString+PropertyName.m */; }; - 65648BE113924326001E163C /* JFFError.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648BDF13924326001E163C /* JFFError.h */; }; - 65648BE213924326001E163C /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648BE013924326001E163C /* JFFError.m */; }; 65802A6B148BF2B10040A93A /* JFFUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE27B1391BD7800DD6890 /* JFFUtils.h */; }; 65802A6C148BF2B50040A93A /* JGCDAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1B7608991444912F0059E977 /* JGCDAdditions.mm */; }; 65802A6E148BF2BA0040A93A /* JFFMulticastDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1913E97FCF0024EA6C /* JFFMulticastDelegate.m */; }; 65802A6F148BF2BE0040A93A /* JFFMutableAssignDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD1820C1467D71B0033BEFF /* JFFMutableAssignDictionary.m */; }; 65802A70148BF2C10040A93A /* JFFMutableAssignArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D713C6C13F3F62B007268DF /* JFFMutableAssignArray.m */; }; - 65802A71148BF2C30040A93A /* JFFSingleThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD01FB014447B7600A627B1 /* JFFSingleThreadProxy.m */; }; 65802A72148BF2C80040A93A /* JFFAssignProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1E13E980B70024EA6C /* JFFAssignProxy.m */; }; - 65802A74148BF2CE0040A93A /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648BE013924326001E163C /* JFFError.m */; }; 65802A95148BF4610040A93A /* NSString+ToURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676CD144C474500B14D49 /* NSString+ToURL.m */; }; 65802A97148BF4640040A93A /* NSURL+ToURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676D1144C476600B14D49 /* NSURL+ToURL.m */; }; - 65802A98148BF4700040A93A /* NSThread+AssertMainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676BE144C409F00B14D49 /* NSThread+AssertMainThread.m */; }; 65802A9C148BF4800040A93A /* JFFSimpleBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE0A91390496200DD6890 /* JFFSimpleBlockHolder.m */; }; 65802A9D148BF4820040A93A /* JFFOnDeallocBlockOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1C21391A25500DD6890 /* JFFOnDeallocBlockOwner.m */; }; 65802A9E148BF4870040A93A /* NSString+Search.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE19C1391969A00DD6890 /* NSString+Search.m */; }; 65802A9F148BF4890040A93A /* NSString+PropertyName.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648B7D13923EC4001E163C /* NSString+PropertyName.m */; }; 65802AA0148BF48F0040A93A /* NSString+PathExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D713CC613F539A5007268DF /* NSString+PathExtensions.m */; }; 65802AA1148BF4920040A93A /* NSString+Trimm.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B6AAD8D1447039B00EA1D96 /* NSString+Trimm.m */; }; - 65802AA2148BF4960040A93A /* NSString+UUIDCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B16830E146AD4C800832839 /* NSString+UUIDCreation.m */; }; 65802AA3148BF49B0040A93A /* NSMutableArray+ChangeCount.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCDF9E414320B3200CEB6E7 /* NSMutableArray+ChangeCount.m */; }; 65802AA4148BF49D0040A93A /* NSArray+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE0AC1390496200DD6890 /* NSArray+BlocksAdditions.m */; }; 65802AA5148BF4A00040A93A /* NSArray+RemoveDuplicates.m in Sources */ = {isa = PBXBuildFile; fileRef = 53BCF8DF143239D100E896B3 /* NSArray+RemoveDuplicates.m */; }; @@ -222,17 +251,6 @@ 65802AA9148BF4AE0040A93A /* NSObject+OnDeallocBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1CC1391A36800DD6890 /* NSObject+OnDeallocBlock.m */; }; 65802AAA148BF4B00040A93A /* NSObject+RuntimeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1DE52A13AB8269001FD56F /* NSObject+RuntimeExtensions.m */; }; 65802AAB148BF4B20040A93A /* NSObject+Const0.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE75CFE1434B3450076E068 /* NSObject+Const0.m */; }; - 780EFB851712A55E0062FAAA /* NSString+JSEscape.h in Headers */ = {isa = PBXBuildFile; fileRef = 780EFB831712A55E0062FAAA /* NSString+JSEscape.h */; }; - 780EFB861712A55E0062FAAA /* NSString+JSEscape.m in Sources */ = {isa = PBXBuildFile; fileRef = 780EFB841712A55E0062FAAA /* NSString+JSEscape.m */; }; - 780EFB871712A56E0062FAAA /* NSString+JSEscape.m in Sources */ = {isa = PBXBuildFile; fileRef = 780EFB841712A55E0062FAAA /* NSString+JSEscape.m */; }; - 7E016681170477EE0073298E /* NSError+JSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E01667F170477EE0073298E /* NSError+JSON.h */; }; - 7E016682170477EE0073298E /* NSError+JSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E01667F170477EE0073298E /* NSError+JSON.h */; }; - 7E016683170477EE0073298E /* NSError+JSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E01667F170477EE0073298E /* NSError+JSON.h */; }; - 7E016684170477EE0073298E /* NSError+JSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E01667F170477EE0073298E /* NSError+JSON.h */; }; - 7E016685170477EE0073298E /* NSError+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016680170477EE0073298E /* NSError+JSON.m */; }; - 7E016686170477EE0073298E /* NSError+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016680170477EE0073298E /* NSError+JSON.m */; }; - 7E016687170477EE0073298E /* NSError+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016680170477EE0073298E /* NSError+JSON.m */; }; - 7E016688170477EE0073298E /* NSError+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016680170477EE0073298E /* NSError+JSON.m */; }; 7E44D666158F179400A2C11E /* NSURL+CPlusPlus.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E44D664158F179400A2C11E /* NSURL+CPlusPlus.h */; }; 7E44D667158F179400A2C11E /* NSURL+CPlusPlus.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E44D664158F179400A2C11E /* NSURL+CPlusPlus.h */; }; 7E44D668158F179400A2C11E /* NSURL+CPlusPlus.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E44D664158F179400A2C11E /* NSURL+CPlusPlus.h */; }; @@ -249,21 +267,10 @@ 7E44D676158F189F00A2C11E /* NSString+CPlusPlus.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7E44D670158F189F00A2C11E /* NSString+CPlusPlus.mm */; }; 7E44D677158F189F00A2C11E /* NSString+CPlusPlus.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7E44D670158F189F00A2C11E /* NSString+CPlusPlus.mm */; }; 7E44D678158F189F00A2C11E /* NSString+CPlusPlus.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7E44D670158F189F00A2C11E /* NSString+CPlusPlus.mm */; }; - 7E56B5F116E0EF68002960EE /* NSDate+Now.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E56B5EF16E0EF68002960EE /* NSDate+Now.h */; }; - 7E56B5F216E0EF68002960EE /* NSDate+Now.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E56B5EF16E0EF68002960EE /* NSDate+Now.h */; }; - 7E56B5F316E0EF68002960EE /* NSDate+Now.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E56B5EF16E0EF68002960EE /* NSDate+Now.h */; }; - 7E56B5F416E0EF68002960EE /* NSDate+Now.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E56B5EF16E0EF68002960EE /* NSDate+Now.h */; }; - 7E56B5F516E0EF68002960EE /* NSDate+Now.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56B5F016E0EF68002960EE /* NSDate+Now.m */; }; - 7E56B5F616E0EF68002960EE /* NSDate+Now.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56B5F016E0EF68002960EE /* NSDate+Now.m */; }; - 7E56B5F716E0EF68002960EE /* NSDate+Now.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56B5F016E0EF68002960EE /* NSDate+Now.m */; }; - 7E56B5F816E0EF68002960EE /* NSDate+Now.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56B5F016E0EF68002960EE /* NSDate+Now.m */; }; 7E57F42514F93738002D139B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; 7E57F42B14F93738002D139B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7E57F42914F93738002D139B /* InfoPlist.strings */; }; 7E57F43114F937E0002D139B /* NSString+ToURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676CD144C474500B14D49 /* NSString+ToURL.m */; }; 7E57F43314F937E0002D139B /* NSURL+ToURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676D1144C476600B14D49 /* NSURL+ToURL.m */; }; - 7E57F43514F937E0002D139B /* UIWebView+UserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676BA144C3FE900B14D49 /* UIWebView+UserAgent.m */; }; - 7E57F43714F937E0002D139B /* NSThread+AssertMainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BA676BE144C409F00B14D49 /* NSThread+AssertMainThread.m */; }; - 7E57F43914F937E0002D139B /* NSDecimalNumber+Increment.m in Sources */ = {isa = PBXBuildFile; fileRef = 538E1CAB14B32201006BD40A /* NSDecimalNumber+Increment.m */; }; 7E57F44214F937E0002D139B /* JFFSimpleBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE0A91390496200DD6890 /* JFFSimpleBlockHolder.m */; }; 7E57F44414F937E0002D139B /* JFFOnDeallocBlockOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1C21391A25500DD6890 /* JFFOnDeallocBlockOwner.m */; }; 7E57F44814F937E0002D139B /* NSString+Format.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A3BB2414DAB2BF008B71BE /* NSString+Format.m */; }; @@ -271,7 +278,6 @@ 7E57F44C14F937E0002D139B /* NSString+PropertyName.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648B7D13923EC4001E163C /* NSString+PropertyName.m */; }; 7E57F44E14F937E0002D139B /* NSString+PathExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D713CC613F539A5007268DF /* NSString+PathExtensions.m */; }; 7E57F45014F937E0002D139B /* NSString+Trimm.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B6AAD8D1447039B00EA1D96 /* NSString+Trimm.m */; }; - 7E57F45214F937E0002D139B /* NSString+UUIDCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B16830E146AD4C800832839 /* NSString+UUIDCreation.m */; }; 7E57F45414F937E0002D139B /* NSString+IsEmpty.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A3BB3E14DAB3CD008B71BE /* NSString+IsEmpty.m */; }; 7E57F45914F937E0002D139B /* NSMutableArray+ChangeCount.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCDF9E414320B3200CEB6E7 /* NSMutableArray+ChangeCount.m */; }; 7E57F45B14F937E0002D139B /* NSArray+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE0AC1390496200DD6890 /* NSArray+BlocksAdditions.m */; }; @@ -283,9 +289,7 @@ 7E57F46714F937E0002D139B /* NSObject+RuntimeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1DE52A13AB8269001FD56F /* NSObject+RuntimeExtensions.m */; }; 7E57F46914F937E0002D139B /* NSObject+Const0.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE75CFE1434B3450076E068 /* NSObject+Const0.m */; }; 7E57F46D14F937E0002D139B /* NSObject+ExpandArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B3EE0351487D03A00BA6680 /* NSObject+ExpandArray.m */; }; - 7E57F46F14F937E0002D139B /* JFFError.m in Sources */ = {isa = PBXBuildFile; fileRef = 65648BE013924326001E163C /* JFFError.m */; }; 7E57F47114F937E0002D139B /* JFFAssignProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1E13E980B70024EA6C /* JFFAssignProxy.m */; }; - 7E57F47314F937E0002D139B /* JFFSingleThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD01FB014447B7600A627B1 /* JFFSingleThreadProxy.m */; }; 7E57F47514F937E0002D139B /* JFFMutableAssignArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D713C6C13F3F62B007268DF /* JFFMutableAssignArray.m */; }; 7E57F47714F937E0002D139B /* JFFMutableAssignDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD1820C1467D71B0033BEFF /* JFFMutableAssignDictionary.m */; }; 7E57F47914F937E0002D139B /* JFFMulticastDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1913E97FCF0024EA6C /* JFFMulticastDelegate.m */; }; @@ -293,9 +297,6 @@ 7E57F47F14F937E0002D139B /* JSignedRange.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B104D8D1483C8410025FDDA /* JSignedRange.m */; }; 7E57F48314F93840002D139B /* NSString+ToURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676CC144C474500B14D49 /* NSString+ToURL.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F48514F93840002D139B /* NSURL+ToURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676D0144C476600B14D49 /* NSURL+ToURL.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E57F48714F93840002D139B /* UIWebView+UserAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676B9144C3FE900B14D49 /* UIWebView+UserAgent.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E57F48914F93840002D139B /* NSThread+AssertMainThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA676BD144C409E00B14D49 /* NSThread+AssertMainThread.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E57F48B14F93840002D139B /* NSDecimalNumber+Increment.h in Headers */ = {isa = PBXBuildFile; fileRef = 538E1CAA14B32201006BD40A /* NSDecimalNumber+Increment.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F49314F93840002D139B /* JFFUtilsBlockDefinitions.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE0A51390496200DD6890 /* JFFUtilsBlockDefinitions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F49414F93840002D139B /* JFFSimpleBlockHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE0A81390496200DD6890 /* JFFSimpleBlockHolder.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F49614F93840002D139B /* JFFOnDeallocBlockOwner.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE1C11391A25500DD6890 /* JFFOnDeallocBlockOwner.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -304,7 +305,6 @@ 7E57F49E14F93840002D139B /* NSString+PropertyName.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648B7C13923EC4001E163C /* NSString+PropertyName.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4A014F93840002D139B /* NSString+PathExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D713CC513F539A5007268DF /* NSString+PathExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4A214F93840002D139B /* NSString+Trimm.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B6AAD8C1447039B00EA1D96 /* NSString+Trimm.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E57F4A414F93840002D139B /* NSString+UUIDCreation.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B16830D146AD4C800832839 /* NSString+UUIDCreation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4A614F93840002D139B /* NSString+IsEmpty.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A3BB3D14DAB3CD008B71BE /* NSString+IsEmpty.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4AB14F93840002D139B /* NSMutableArray+ChangeCount.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BCDF9E314320B3200CEB6E7 /* NSMutableArray+ChangeCount.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4AD14F93840002D139B /* NSArray+BlocksAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE0AB1390496200DD6890 /* NSArray+BlocksAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -316,9 +316,7 @@ 7E57F4B914F93840002D139B /* NSObject+RuntimeExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1DE52913AB8269001FD56F /* NSObject+RuntimeExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4BB14F93840002D139B /* NSObject+Const0.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BE75CFD1434B3450076E068 /* NSObject+Const0.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4BF14F93840002D139B /* NSObject+ExpandArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B3EE0341487D03A00BA6680 /* NSObject+ExpandArray.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E57F4C114F93840002D139B /* JFFError.h in Headers */ = {isa = PBXBuildFile; fileRef = 65648BDF13924326001E163C /* JFFError.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4C314F93840002D139B /* JFFAssignProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 8DB67B1D13E980B70024EA6C /* JFFAssignProxy.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E57F4C514F93840002D139B /* JFFSingleThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD01FAF14447B7600A627B1 /* JFFSingleThreadProxy.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4C714F93840002D139B /* JFFMutableAssignArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D713C6B13F3F62B007268DF /* JFFMutableAssignArray.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4C914F93840002D139B /* JFFMutableAssignDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BD1820B1467D71B0033BEFF /* JFFMutableAssignDictionary.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4CB14F93840002D139B /* JFFMulticastDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8DB67B1813E97FCF0024EA6C /* JFFMulticastDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -326,62 +324,6 @@ 7E57F4D114F93840002D139B /* JSignedRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 1B104D911483C85A0025FDDA /* JSignedRange.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4D314F93840002D139B /* JFFUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 651BE27B1391BD7800DD6890 /* JFFUtils.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7E57F4D414F93840002D139B /* JFFCastFunctions.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 534CDFC014A8C2930068F4DF /* JFFCastFunctions.hpp */; settings = {ATTRIBUTES = (Public, ); }; }; - 7E99C70416EE3B7000E9B969 /* libJFFUtils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC07E0554694100DB518D /* libJFFUtils.a */; }; - 7E99C70716EE3B7B00E9B969 /* libJFFUtils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC07E0554694100DB518D /* libJFFUtils.a */; }; - 7E99C70916EE3B8A00E9B969 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E99C70816EE3B8A00E9B969 /* CoreGraphics.framework */; }; - 7E99C70A16EE3B8E00E9B969 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E99C70816EE3B8A00E9B969 /* CoreGraphics.framework */; }; - 7E99C72016EE3C1600E9B969 /* EmptyStringTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A45160860F300DD85B0 /* EmptyStringTest.m */; }; - 7E99C72116EE3C1600E9B969 /* DelegateProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE914E53160B71B300C89F37 /* DelegateProxyTest.m */; }; - 7E99C72216EE3C1600E9B969 /* NSObjectInstancesCountTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE03CAB1160CAD0500039011 /* NSObjectInstancesCountTest.m */; }; - 7E99C72316EE3C1600E9B969 /* DateDifferenceStringFromDateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8BA1611998D00124D90 /* DateDifferenceStringFromDateTest.m */; }; - 7E99C72416EE3C1600E9B969 /* NumberOfCharacterFromStringTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8BF1611A31F00124D90 /* NumberOfCharacterFromStringTest.m */; }; - 7E99C72516EE3C1600E9B969 /* NSObject_IsEqualTwoObjectsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8C31611A61E00124D90 /* NSObject_IsEqualTwoObjectsTest.m */; }; - 7E99C72616EE3C1600E9B969 /* ObjcDynamicCastTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBD71611F80800124D90 /* ObjcDynamicCastTest.mm */; }; - 7E99C72716EE3C1600E9B969 /* JFFMutableAssignArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE609CF116134405008259CF /* JFFMutableAssignArrayTest.m */; }; - 7E99C72816EE3C1600E9B969 /* JFFOnDeallocBlockOwnerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D21614502400C4D536 /* JFFOnDeallocBlockOwnerTest.m */; }; - 7E99C72916EE3C1600E9B969 /* JFFMulticastDelegateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D916145C0D00C4D536 /* JFFMulticastDelegateTest.m */; }; - 7E99C72A16EE3C1600E9B969 /* JFFAssignProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653DD16145D1900C4D536 /* JFFAssignProxyTest.m */; }; - 7E99C72B16EE3C1600E9B969 /* NSObject+OwnershipsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653E016145E6300C4D536 /* NSObject+OwnershipsTest.m */; }; - 7E99C72C16EE3C1600E9B969 /* JFFSimpleBlockHolderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653E31614669200C4D536 /* JFFSimpleBlockHolderTest.m */; }; - 7E99C72D16EE3C1600E9B969 /* NSObjectRuntimeExtensionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE6574516148DCC00C4D536 /* NSObjectRuntimeExtensionsTest.m */; }; - 7E99C72E16EE3C1600E9B969 /* JUArrayAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE6574916148F3000C4D536 /* JUArrayAdditionsTest.m */; }; - 7E99C72F16EE3C1600E9B969 /* JUMutableArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE2B32861617B55F003FB5F8 /* JUMutableArrayTest.m */; }; - 7E99C73016EE3C1600E9B969 /* JFFStringFormatTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE2B328B1617B5E9003FB5F8 /* JFFStringFormatTest.m */; }; - 7E99C73116EE3C1600E9B969 /* NSArray+ExpandArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1BC323161B33AB007DEC95 /* NSArray+ExpandArrayTest.m */; }; - 7E99C73216EE3C1600E9B969 /* JFFMutableAssignDictionaryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D51614512E00C4D536 /* JFFMutableAssignDictionaryTest.m */; }; - 7E99C73316EE3C1600E9B969 /* NSDictionary+BlocksAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1BC36D161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.m */; }; - 7E99C73416EE3C1600E9B969 /* JFFMeaningClassTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A4A1608636400DD85B0 /* JFFMeaningClassTest.m */; }; - 7E99C73516EE3C2400E9B969 /* JMParent.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBDC1611F8FC00124D90 /* JMParent.m */; }; - 7E99C73616EE3C2400E9B969 /* JMChild.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBDF1611F90900124D90 /* JMChild.m */; }; - 7E99C73716EE3C4000E9B969 /* JMParent.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBDC1611F8FC00124D90 /* JMParent.m */; }; - 7E99C73816EE3C4000E9B969 /* JMChild.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBDF1611F90900124D90 /* JMChild.m */; }; - 7E99C73916EE3C5300E9B969 /* EmptyStringTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A45160860F300DD85B0 /* EmptyStringTest.m */; }; - 7E99C73A16EE3C5300E9B969 /* DelegateProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE914E53160B71B300C89F37 /* DelegateProxyTest.m */; }; - 7E99C73B16EE3C5300E9B969 /* NSObjectInstancesCountTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE03CAB1160CAD0500039011 /* NSObjectInstancesCountTest.m */; }; - 7E99C73C16EE3C5300E9B969 /* DateDifferenceStringFromDateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8BA1611998D00124D90 /* DateDifferenceStringFromDateTest.m */; }; - 7E99C73D16EE3C5300E9B969 /* NumberOfCharacterFromStringTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8BF1611A31F00124D90 /* NumberOfCharacterFromStringTest.m */; }; - 7E99C73E16EE3C5300E9B969 /* NSObject_IsEqualTwoObjectsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8C31611A61E00124D90 /* NSObject_IsEqualTwoObjectsTest.m */; }; - 7E99C73F16EE3C5300E9B969 /* ObjcDynamicCastTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBD71611F80800124D90 /* ObjcDynamicCastTest.mm */; }; - 7E99C74016EE3C5300E9B969 /* JFFMutableAssignArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE609CF116134405008259CF /* JFFMutableAssignArrayTest.m */; }; - 7E99C74116EE3C5300E9B969 /* JFFOnDeallocBlockOwnerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D21614502400C4D536 /* JFFOnDeallocBlockOwnerTest.m */; }; - 7E99C74216EE3C5300E9B969 /* JFFMulticastDelegateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D916145C0D00C4D536 /* JFFMulticastDelegateTest.m */; }; - 7E99C74316EE3C5300E9B969 /* JFFAssignProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653DD16145D1900C4D536 /* JFFAssignProxyTest.m */; }; - 7E99C74416EE3C5300E9B969 /* NSObject+OwnershipsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653E016145E6300C4D536 /* NSObject+OwnershipsTest.m */; }; - 7E99C74516EE3C5300E9B969 /* JFFSimpleBlockHolderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653E31614669200C4D536 /* JFFSimpleBlockHolderTest.m */; }; - 7E99C74616EE3C5300E9B969 /* NSObjectRuntimeExtensionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE6574516148DCC00C4D536 /* NSObjectRuntimeExtensionsTest.m */; }; - 7E99C74716EE3C5300E9B969 /* JUArrayAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE6574916148F3000C4D536 /* JUArrayAdditionsTest.m */; }; - 7E99C74816EE3C5300E9B969 /* JUMutableArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE2B32861617B55F003FB5F8 /* JUMutableArrayTest.m */; }; - 7E99C74916EE3C5300E9B969 /* JFFStringFormatTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE2B328B1617B5E9003FB5F8 /* JFFStringFormatTest.m */; }; - 7E99C74A16EE3C5300E9B969 /* NSArray+ExpandArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1BC323161B33AB007DEC95 /* NSArray+ExpandArrayTest.m */; }; - 7E99C74B16EE3C5300E9B969 /* JFFMutableAssignDictionaryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D51614512E00C4D536 /* JFFMutableAssignDictionaryTest.m */; }; - 7E99C74C16EE3C5300E9B969 /* NSDictionary+BlocksAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1BC36D161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.m */; }; - 7E99C74D16EE3C5300E9B969 /* JFFMeaningClassTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A4A1608636400DD85B0 /* JFFMeaningClassTest.m */; }; - 7E99C75816EE3CEE00E9B969 /* libJFFTestTools.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E99C75316EE3CD500E9B969 /* libJFFTestTools.a */; }; - 7E99C75916EE3CF300E9B969 /* libJFFTestTools.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E99C75316EE3CD500E9B969 /* libJFFTestTools.a */; }; - 7ED3CB0B16E6387B00E5A00F /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE444A1D1608609100DD85B0 /* SenTestingKit.framework */; }; - 7ED3CB0C16E6387B00E5A00F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEC851AB15F4E20E0022F479 /* UIKit.framework */; }; - 7ED3CB0D16E6387B00E5A00F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; - 7ED3CB0F16E6387B00E5A00F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CE444A241608609100DD85B0 /* InfoPlist.strings */; }; 8D1DE52B13AB8269001FD56F /* NSObject+RuntimeExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1DE52913AB8269001FD56F /* NSObject+RuntimeExtensions.h */; }; 8D1DE52C13AB8269001FD56F /* NSObject+RuntimeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1DE52A13AB8269001FD56F /* NSObject+RuntimeExtensions.m */; }; 8D713C6D13F3F62B007268DF /* JFFMutableAssignArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D713C6B13F3F62B007268DF /* JFFMutableAssignArray.h */; }; @@ -394,24 +336,44 @@ 8DB67B2013E980B70024EA6C /* JFFAssignProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1E13E980B70024EA6C /* JFFAssignProxy.m */; }; AA747D9F0F9514B9006C5449 /* JFFUtils_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* JFFUtils_Prefix.pch */; }; AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; - CE0B00451626D9C1003802A0 /* NSDateFormatter+MultiThreading.h in Headers */ = {isa = PBXBuildFile; fileRef = CE0B00431626D9C1003802A0 /* NSDateFormatter+MultiThreading.h */; }; - CE0B00461626D9C1003802A0 /* NSDateFormatter+MultiThreading.m in Sources */ = {isa = PBXBuildFile; fileRef = CE0B00441626D9C1003802A0 /* NSDateFormatter+MultiThreading.m */; }; + CE03CAB2160CAD0500039011 /* NSObjectInstancesCountTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE03CAB1160CAD0500039011 /* NSObjectInstancesCountTest.m */; }; + CE1BC324161B33AB007DEC95 /* NSArray+ExpandArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1BC323161B33AB007DEC95 /* NSArray+ExpandArrayTest.m */; }; + CE1BC326161B349A007DEC95 /* NSObject+ExpandArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B3EE0351487D03A00BA6680 /* NSObject+ExpandArray.m */; }; + CE1BC36A161B38AF007DEC95 /* NSDictionary+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B054D4E1521C6F4008E4B9E /* NSDictionary+BlocksAdditions.m */; }; + CE1BC36E161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1BC36D161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.m */; }; + CE2B32871617B55F003FB5F8 /* JUMutableArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE2B32861617B55F003FB5F8 /* JUMutableArrayTest.m */; }; + CE2B32891617B5BF003FB5F8 /* NSMutableArray+ChangeCount.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCDF9E414320B3200CEB6E7 /* NSMutableArray+ChangeCount.m */; }; + CE2B328C1617B5E9003FB5F8 /* JFFStringFormatTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE2B328B1617B5E9003FB5F8 /* JFFStringFormatTest.m */; }; + CE2B328D1617B632003FB5F8 /* NSString+Format.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B909B8414EA919400B19283 /* NSString+Format.m */; }; CE444A1416085D5A00DD85B0 /* NSObject+JFFMeaningClass.h in Headers */ = {isa = PBXBuildFile; fileRef = CE444A1216085D5A00DD85B0 /* NSObject+JFFMeaningClass.h */; }; CE444A1516085D5A00DD85B0 /* NSObject+JFFMeaningClass.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A1316085D5A00DD85B0 /* NSObject+JFFMeaningClass.m */; }; CE444A1E1608609100DD85B0 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE444A1D1608609100DD85B0 /* SenTestingKit.framework */; }; CE444A1F1608609100DD85B0 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEC851AB15F4E20E0022F479 /* UIKit.framework */; }; CE444A201608609100DD85B0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; CE444A261608609100DD85B0 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CE444A241608609100DD85B0 /* InfoPlist.strings */; }; + CE444A46160860F300DD85B0 /* EmptyStringTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A45160860F300DD85B0 /* EmptyStringTest.m */; }; + CE444A481608634700DD85B0 /* NSObject+JFFMeaningClass.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A1316085D5A00DD85B0 /* NSObject+JFFMeaningClass.m */; }; + CE444A4B1608636400DD85B0 /* JFFMeaningClassTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE444A4A1608636400DD85B0 /* JFFMeaningClassTest.m */; }; + CE444A6E1608698600DD85B0 /* NSString+IsEmpty.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A3BB3E14DAB3CD008B71BE /* NSString+IsEmpty.m */; }; + CE57F8BB1611998D00124D90 /* DateDifferenceStringFromDateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8BA1611998D00124D90 /* DateDifferenceStringFromDateTest.m */; }; + CE57F8BD16119A5400124D90 /* NSDate+DateDifference.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B14141D15DBCD3F00EFB2B8 /* NSDate+DateDifference.m */; }; + CE57F8C01611A32000124D90 /* NumberOfCharacterFromStringTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8BF1611A31F00124D90 /* NumberOfCharacterFromStringTest.m */; }; + CE57F8C11611A3D500124D90 /* NSString+Search.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE19C1391969A00DD6890 /* NSString+Search.m */; }; + CE57F8C41611A61E00124D90 /* NSObject_IsEqualTwoObjectsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57F8C31611A61E00124D90 /* NSObject_IsEqualTwoObjectsTest.m */; }; + CE57F8C51611A6AA00124D90 /* NSObject+IsEqualTwoObjects.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BBD97DF15249C4200A34E64 /* NSObject+IsEqualTwoObjects.m */; }; CE57FBB81611EFFF00124D90 /* NSSet+BlocksAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = CE57FBB61611EFFF00124D90 /* NSSet+BlocksAdditions.h */; }; CE57FBB91611EFFF00124D90 /* NSSet+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBB71611EFFF00124D90 /* NSSet+BlocksAdditions.m */; }; CE57FBBD1611F0BF00124D90 /* NSMutableSet+StorableSet.h in Headers */ = {isa = PBXBuildFile; fileRef = CE57FBBB1611F0BF00124D90 /* NSMutableSet+StorableSet.h */; }; CE57FBBE1611F0BF00124D90 /* NSMutableSet+StorableSet.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBBC1611F0BF00124D90 /* NSMutableSet+StorableSet.m */; }; - CE7CF550161EBC4D008557D2 /* NSNumber+FSStorable.h in Headers */ = {isa = PBXBuildFile; fileRef = CE7CF54E161EBC4D008557D2 /* NSNumber+FSStorable.h */; }; - CE7CF551161EBC4D008557D2 /* NSNumber+FSStorable.m in Sources */ = {isa = PBXBuildFile; fileRef = CE7CF54F161EBC4D008557D2 /* NSNumber+FSStorable.m */; }; + CE57FBD81611F80800124D90 /* ObjcDynamicCastTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBD71611F80800124D90 /* ObjcDynamicCastTest.mm */; }; + CE57FBDD1611F8FC00124D90 /* JMParent.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBDC1611F8FC00124D90 /* JMParent.m */; }; + CE57FBE01611F90900124D90 /* JMChild.m in Sources */ = {isa = PBXBuildFile; fileRef = CE57FBDF1611F90900124D90 /* JMChild.m */; }; + CE609CF216134405008259CF /* JFFMutableAssignArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE609CF116134405008259CF /* JFFMutableAssignArrayTest.m */; }; + CE914E54160B71B300C89F37 /* DelegateProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE914E53160B71B300C89F37 /* DelegateProxyTest.m */; }; + CE914E5F160C4B0C00C89F37 /* JFFProxyDelegatesDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA097A715FF2E3E0080DEF7 /* JFFProxyDelegatesDispatcher.m */; }; + CE914E60160C4B1900C89F37 /* JFFDelegateProxyClassMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA097A315FF2C850080DEF7 /* JFFDelegateProxyClassMethods.m */; }; CE998C481626B988002D39FD /* NSOrderedSet+BlocksAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = CE998C461626B988002D39FD /* NSOrderedSet+BlocksAdditions.h */; }; CE998C491626B988002D39FD /* NSOrderedSet+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CE998C471626B988002D39FD /* NSOrderedSet+BlocksAdditions.m */; }; - CE9C273916AFDF3D0062C91E /* UIDevice+PlatformName.h in Headers */ = {isa = PBXBuildFile; fileRef = CE9C273716AFDF3D0062C91E /* UIDevice+PlatformName.h */; }; - CE9C273A16AFDF3D0062C91E /* UIDevice+PlatformName.m in Sources */ = {isa = PBXBuildFile; fileRef = CE9C273816AFDF3D0062C91E /* UIDevice+PlatformName.m */; }; CEA0979C15FF2ADE0080DEF7 /* DelegateProxyUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = CEA0979A15FF2ADE0080DEF7 /* DelegateProxyUtils.h */; }; CEA0979D15FF2ADE0080DEF7 /* DelegateProxyUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA0979B15FF2ADE0080DEF7 /* DelegateProxyUtils.m */; }; CEA097A015FF2C110080DEF7 /* NSString+DelegateProxySelectorsNames.h in Headers */ = {isa = PBXBuildFile; fileRef = CEA0979E15FF2C110080DEF7 /* NSString+DelegateProxySelectorsNames.h */; }; @@ -420,77 +382,49 @@ CEA097A515FF2C860080DEF7 /* JFFDelegateProxyClassMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA097A315FF2C850080DEF7 /* JFFDelegateProxyClassMethods.m */; }; CEA097A815FF2E3E0080DEF7 /* JFFProxyDelegatesDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = CEA097A615FF2E3D0080DEF7 /* JFFProxyDelegatesDispatcher.h */; }; CEA097A915FF2E3E0080DEF7 /* JFFProxyDelegatesDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA097A715FF2E3E0080DEF7 /* JFFProxyDelegatesDispatcher.m */; }; - CEB2D7691689A177004067F9 /* NSError+WriteErrorToNSLog.h in Headers */ = {isa = PBXBuildFile; fileRef = CEB2D7671689A177004067F9 /* NSError+WriteErrorToNSLog.h */; }; - CEB2D76A1689A177004067F9 /* NSError+WriteErrorToNSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = CEB2D7681689A177004067F9 /* NSError+WriteErrorToNSLog.m */; }; - CEC544891699D28A0019511A /* UIImage+WriteToTmpFile.h in Headers */ = {isa = PBXBuildFile; fileRef = CEC544871699D28A0019511A /* UIImage+WriteToTmpFile.h */; }; - CEC5448A1699D28A0019511A /* UIImage+WriteToTmpFile.m in Sources */ = {isa = PBXBuildFile; fileRef = CEC544881699D28A0019511A /* UIImage+WriteToTmpFile.m */; }; + CEB90821160C708300EFC230 /* NSArray+BlocksAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE0AC1390496200DD6890 /* NSArray+BlocksAdditions.m */; }; + CEB90823160C709D00EFC230 /* NSObject+DelegateProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 655C20E615FE5A4000022B11 /* NSObject+DelegateProxy.m */; }; + CEB90824160C70A300EFC230 /* DelegateProxyUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA0979B15FF2ADE0080DEF7 /* DelegateProxyUtils.m */; }; + CEB90825160C70A300EFC230 /* NSString+DelegateProxySelectorsNames.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA0979F15FF2C110080DEF7 /* NSString+DelegateProxySelectorsNames.m */; }; + CEB90826160C70B400EFC230 /* JFFMutableAssignArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D713C6C13F3F62B007268DF /* JFFMutableAssignArray.m */; }; + CEB90827160C711200EFC230 /* JFFAssignProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1E13E980B70024EA6C /* JFFAssignProxy.m */; }; + CEB90828160C712C00EFC230 /* NSObject+RuntimeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1DE52A13AB8269001FD56F /* NSObject+RuntimeExtensions.m */; }; + CEB90829160C73DE00EFC230 /* NSObject+Ownerships.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE138139107EA00DD6890 /* NSObject+Ownerships.m */; }; + CEB9082A160C73EC00EFC230 /* NSObject+OnDeallocBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1CC1391A36800DD6890 /* NSObject+OnDeallocBlock.m */; }; + CEB9082B160C740300EFC230 /* JFFOnDeallocBlockOwner.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE1C21391A25500DD6890 /* JFFOnDeallocBlockOwner.m */; }; CEC70F13169DBA8B006D63DE /* JFFLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = CEC70F0F169DBA8B006D63DE /* JFFLogger.h */; }; CEC70F14169DBA8B006D63DE /* JFFLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = CEC70F10169DBA8B006D63DE /* JFFLogger.m */; }; CEC8479616A98A6C00065745 /* NSObject+NsNullAsNil.h in Headers */ = {isa = PBXBuildFile; fileRef = CEC8479416A98A6C00065745 /* NSObject+NsNullAsNil.h */; }; CEC8479716A98A6C00065745 /* NSObject+NsNullAsNil.m in Sources */ = {isa = PBXBuildFile; fileRef = CEC8479516A98A6C00065745 /* NSObject+NsNullAsNil.m */; }; CEC851AC15F4E20E0022F479 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEC851AB15F4E20E0022F479 /* UIKit.framework */; }; - CEDB80ED1601F08F007577B2 /* NSData+ToString.h in Headers */ = {isa = PBXBuildFile; fileRef = CEDB80EB1601F08F007577B2 /* NSData+ToString.h */; }; - CEDB80EE1601F08F007577B2 /* NSData+ToString.m in Sources */ = {isa = PBXBuildFile; fileRef = CEDB80EC1601F08F007577B2 /* NSData+ToString.m */; }; CEE653CF16144C8900C4D536 /* JFFRuntimeInitializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B909B7E14EA918800B19283 /* JFFRuntimeInitializer.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - CEEAAD11167A0E4A00DD8A16 /* UIImage+ScaleToSize.h in Headers */ = {isa = PBXBuildFile; fileRef = CEEAAD0F167A0E4A00DD8A16 /* UIImage+ScaleToSize.h */; }; - CEEAAD12167A0E4A00DD8A16 /* UIImage+ScaleToSize.m in Sources */ = {isa = PBXBuildFile; fileRef = CEEAAD10167A0E4A00DD8A16 /* UIImage+ScaleToSize.m */; }; - CEEAAD15167A0E8D00DD8A16 /* UIImage+FixOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = CEEAAD13167A0E8D00DD8A16 /* UIImage+FixOrientation.h */; }; - CEEAAD16167A0E8D00DD8A16 /* UIImage+FixOrientation.m in Sources */ = {isa = PBXBuildFile; fileRef = CEEAAD14167A0E8D00DD8A16 /* UIImage+FixOrientation.m */; }; + CEE653D016144C8900C4D536 /* JFFRuntimeInitializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B909B7E14EA918800B19283 /* JFFRuntimeInitializer.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + CEE653D31614502400C4D536 /* JFFOnDeallocBlockOwnerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D21614502400C4D536 /* JFFOnDeallocBlockOwnerTest.m */; }; + CEE653D61614512E00C4D536 /* JFFMutableAssignDictionaryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D51614512E00C4D536 /* JFFMutableAssignDictionaryTest.m */; }; + CEE653D7161451BF00C4D536 /* JFFMutableAssignDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BD1820C1467D71B0033BEFF /* JFFMutableAssignDictionary.m */; }; + CEE653DA16145C0D00C4D536 /* JFFMulticastDelegateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653D916145C0D00C4D536 /* JFFMulticastDelegateTest.m */; }; + CEE653DB16145CED00C4D536 /* JFFMulticastDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB67B1913E97FCF0024EA6C /* JFFMulticastDelegate.m */; }; + CEE653DE16145D1900C4D536 /* JFFAssignProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653DD16145D1900C4D536 /* JFFAssignProxyTest.m */; }; + CEE653E116145E6300C4D536 /* NSObject+OwnershipsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653E016145E6300C4D536 /* NSObject+OwnershipsTest.m */; }; + CEE653E41614669500C4D536 /* JFFSimpleBlockHolderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE653E31614669200C4D536 /* JFFSimpleBlockHolderTest.m */; }; + CEE653E5161466DA00C4D536 /* JFFSimpleBlockHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 651BE0A91390496200DD6890 /* JFFSimpleBlockHolder.m */; }; + CEE6574616148DCC00C4D536 /* NSObjectRuntimeExtensionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE6574516148DCC00C4D536 /* NSObjectRuntimeExtensionsTest.m */; }; + CEE6574A16148F3000C4D536 /* JUArrayAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE6574916148F3000C4D536 /* JUArrayAdditionsTest.m */; }; + CEE6574B16148F7E00C4D536 /* NSArray+RemoveDuplicates.m in Sources */ = {isa = PBXBuildFile; fileRef = 53BCF8DF143239D100E896B3 /* NSArray+RemoveDuplicates.m */; }; + CEE6574C1614900000C4D536 /* NSArray+IsEmpty.m in Sources */ = {isa = PBXBuildFile; fileRef = 53E366C71433760A002AB0B9 /* NSArray+IsEmpty.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 7E99C70216EE3B6900E9B969 /* PBXContainerItemProxy */ = { + 4C27EDAD1701C47300185768 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; - proxyType = 1; - remoteGlobalIDString = D2AAC07D0554694100DB518D; - remoteInfo = JFFUtils; - }; - 7E99C70516EE3B7600E9B969 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; - proxyType = 1; - remoteGlobalIDString = D2AAC07D0554694100DB518D; - remoteInfo = JFFUtils; - }; - 7E99C75216EE3CD500E9B969 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E99C74E16EE3CD500E9B969 /* JFFTestTools.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1BE0542B154826DA00270B58; - remoteInfo = JFFTestTools; - }; - 7E99C75416EE3CE000E9B969 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E99C74E16EE3CD500E9B969 /* JFFTestTools.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 1BE0542A154826DA00270B58; - remoteInfo = JFFTestTools; - }; - 7E99C75616EE3CE700E9B969 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E99C74E16EE3CD500E9B969 /* JFFTestTools.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 1BE0542A154826DA00270B58; - remoteInfo = JFFTestTools; - }; - 7ED3CAD416E6387B00E5A00F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE914E56160C49C300C89F37 /* JFFTestTools.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 1BE0542A154826DA00270B58; - remoteInfo = JFFTestTools; - }; - CE914E5A160C49C400C89F37 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE914E56160C49C300C89F37 /* JFFTestTools.xcodeproj */; + containerPortal = 4C27EDA91701C47300185768 /* JFFTestTools.xcodeproj */; proxyType = 2; remoteGlobalIDString = 1BE0542B154826DA00270B58; remoteInfo = JFFTestTools; }; - CE914E5C160C49CB00C89F37 /* PBXContainerItemProxy */ = { + 4C27EDAF1701C48000185768 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = CE914E56160C49C300C89F37 /* JFFTestTools.xcodeproj */; + containerPortal = 4C27EDA91701C47300185768 /* JFFTestTools.xcodeproj */; proxyType = 1; remoteGlobalIDString = 1BE0542A154826DA00270B58; remoteInfo = JFFTestTools; @@ -502,14 +436,10 @@ 1B054D4E1521C6F4008E4B9E /* NSDictionary+BlocksAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+BlocksAdditions.m"; sourceTree = ""; }; 1B054D511521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+JFFExtendedDictionary.h"; sourceTree = ""; }; 1B054D521521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+JFFExtendedDictionary.m"; sourceTree = ""; }; - 1B10109514ED598300B9E6F4 /* NSError+setToPointer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+setToPointer.h"; sourceTree = ""; }; - 1B10109614ED598300B9E6F4 /* NSError+setToPointer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+setToPointer.m"; sourceTree = ""; }; 1B104D8D1483C8410025FDDA /* JSignedRange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSignedRange.m; sourceTree = ""; }; 1B104D911483C85A0025FDDA /* JSignedRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSignedRange.h; sourceTree = ""; }; 1B14141C15DBCD3F00EFB2B8 /* NSDate+DateDifference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+DateDifference.h"; sourceTree = ""; }; 1B14141D15DBCD3F00EFB2B8 /* NSDate+DateDifference.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+DateDifference.m"; sourceTree = ""; }; - 1B16830D146AD4C800832839 /* NSString+UUIDCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+UUIDCreation.h"; sourceTree = ""; }; - 1B16830E146AD4C800832839 /* NSString+UUIDCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+UUIDCreation.m"; sourceTree = ""; }; 1B1B280614D825A600FA5388 /* NSString+IsEmailValid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+IsEmailValid.h"; sourceTree = ""; }; 1B1B280714D825A600FA5388 /* NSString+IsEmailValid.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+IsEmailValid.m"; sourceTree = ""; }; 1B266C9C15627F7D0054E183 /* libc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libc++.dylib"; path = "usr/lib/libc++.dylib"; sourceTree = SDKROOT; }; @@ -533,12 +463,6 @@ 1B909B8314EA919400B19283 /* NSString+Format.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Format.h"; sourceTree = ""; }; 1B909B8414EA919400B19283 /* NSString+Format.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Format.m"; sourceTree = ""; }; 1B9C100F15C802E600C20BCA /* JFFClangLiterals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFClangLiterals.h; sourceTree = ""; }; - 1BA30C2A151A384100329EA6 /* JFFRuntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFRuntime.h; sourceTree = ""; }; - 1BA30C2B151A384100329EA6 /* JFFRuntime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFRuntime.m; sourceTree = ""; }; - 1BA676B9144C3FE900B14D49 /* UIWebView+UserAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIWebView+UserAgent.h"; sourceTree = ""; }; - 1BA676BA144C3FE900B14D49 /* UIWebView+UserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIWebView+UserAgent.m"; sourceTree = ""; }; - 1BA676BD144C409E00B14D49 /* NSThread+AssertMainThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSThread+AssertMainThread.h"; sourceTree = ""; }; - 1BA676BE144C409F00B14D49 /* NSThread+AssertMainThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSThread+AssertMainThread.m"; sourceTree = ""; }; 1BA676CC144C474500B14D49 /* NSString+ToURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+ToURL.h"; sourceTree = ""; }; 1BA676CD144C474500B14D49 /* NSString+ToURL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+ToURL.m"; sourceTree = ""; }; 1BA676D0144C476600B14D49 /* NSURL+ToURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+ToURL.h"; sourceTree = ""; }; @@ -548,25 +472,79 @@ 1BC8A7CD1536CCC900CF1859 /* JUDictionaryHelperBlocks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JUDictionaryHelperBlocks.h; sourceTree = ""; }; 1BCDF9E314320B3200CEB6E7 /* NSMutableArray+ChangeCount.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableArray+ChangeCount.h"; sourceTree = ""; }; 1BCDF9E414320B3200CEB6E7 /* NSMutableArray+ChangeCount.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableArray+ChangeCount.m"; sourceTree = ""; }; - 1BD01FAF14447B7600A627B1 /* JFFSingleThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSingleThreadProxy.h; sourceTree = ""; }; - 1BD01FB014447B7600A627B1 /* JFFSingleThreadProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSingleThreadProxy.m; sourceTree = ""; }; 1BD1820B1467D71B0033BEFF /* JFFMutableAssignDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFMutableAssignDictionary.h; sourceTree = ""; }; 1BD1820C1467D71B0033BEFF /* JFFMutableAssignDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFMutableAssignDictionary.m; sourceTree = ""; }; - 1BE2ABEC14E524D0003097D3 /* UIColor+ColorForHex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+ColorForHex.h"; sourceTree = ""; }; - 1BE2ABED14E524D0003097D3 /* UIColor+ColorForHex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+ColorForHex.m"; sourceTree = ""; }; 1BE75CFD1434B3450076E068 /* NSObject+Const0.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+Const0.h"; sourceTree = ""; }; 1BE75CFE1434B3450076E068 /* NSObject+Const0.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Const0.m"; sourceTree = ""; }; 37063C6515FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSOrderedSet+NoThrowObjectAtIndex.h"; sourceTree = ""; }; 37063C6615FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSOrderedSet+NoThrowObjectAtIndex.m"; sourceTree = ""; }; 37497BCE1600971C00AF0C29 /* NSDictionary+ValueWithType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+ValueWithType.h"; sourceTree = ""; }; 37497BCF1600971C00AF0C29 /* NSDictionary+ValueWithType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+ValueWithType.m"; sourceTree = ""; }; - 37497DF11601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableDictionary+IgnoringAddNilValue.h"; sourceTree = ""; }; - 37497DF21601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableDictionary+IgnoringAddNilValue.m"; sourceTree = ""; }; 37805590164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLocale+CurrentInterfaceLanguageCode.h"; sourceTree = ""; }; 37805591164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLocale+CurrentInterfaceLanguageCode.m"; sourceTree = ""; }; + 4C27EDA91701C47300185768 /* JFFTestTools.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFTestTools.xcodeproj; path = ../JFFTestTools/JFFTestTools.xcodeproj; sourceTree = ""; }; + 4C3B63A01701C84700D5A8FD /* JFFMutableAssignKeyDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFMutableAssignKeyDictionary.h; sourceTree = ""; }; + 4C3B63A11701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JFFMutableAssignKeyDictionary.mm; sourceTree = ""; }; + 4C4E1E6B179D3529009E9C71 /* NSString+StringFromTemplateString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+StringFromTemplateString.h"; sourceTree = ""; }; + 4C4E1E6C179D3529009E9C71 /* NSString+StringFromTemplateString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+StringFromTemplateString.m"; sourceTree = ""; }; + 4C4E1E70179D55AF009E9C71 /* StringFromTemplateString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringFromTemplateString.h; sourceTree = ""; }; + 4C4E1E71179D55AF009E9C71 /* StringFromTemplateString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StringFromTemplateString.m; sourceTree = ""; }; + 4C5040BE18112174003F4B12 /* JFFSingleThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSingleThreadProxy.h; sourceTree = ""; }; + 4C5040BF18112174003F4B12 /* JFFSingleThreadProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSingleThreadProxy.m; sourceTree = ""; }; + 4C5040C3181124A1003F4B12 /* NSString+JSEscape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+JSEscape.h"; sourceTree = ""; }; + 4C5040C4181124A1003F4B12 /* NSString+JSEscape.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+JSEscape.m"; sourceTree = ""; }; + 4C5040C5181124A1003F4B12 /* NSString+UUIDCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+UUIDCreation.h"; sourceTree = ""; }; + 4C5040C6181124A1003F4B12 /* NSString+UUIDCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+UUIDCreation.m"; sourceTree = ""; }; + 4C5040CB18112542003F4B12 /* NSError+JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+JSON.h"; sourceTree = ""; }; + 4C5040CC18112542003F4B12 /* NSError+JSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+JSON.m"; sourceTree = ""; }; + 4C5040CF18112601003F4B12 /* NSThread+AssertMainThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSThread+AssertMainThread.h"; sourceTree = ""; }; + 4C5040D018112601003F4B12 /* NSThread+AssertMainThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSThread+AssertMainThread.m"; sourceTree = ""; }; + 4C6AFDFB177AD544009D09C3 /* NSString+MD5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MD5.h"; sourceTree = ""; }; + 4C6AFDFC177AD544009D09C3 /* NSString+MD5.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MD5.m"; sourceTree = ""; }; + 4C6DFB11171849D800D86975 /* JFFError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFError.h; sourceTree = ""; }; + 4C6DFB12171849D800D86975 /* JFFError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFError.m; sourceTree = ""; }; + 4C6DFB1517184A0600D86975 /* JFFSilentError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFSilentError.h; sourceTree = ""; }; + 4C6DFB1617184A0600D86975 /* JFFSilentError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSilentError.m; sourceTree = ""; }; + 4C712E1717046A0300346F5E /* MethodObserverTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MethodObserverTest.h; sourceTree = ""; }; + 4C712E1817046A0300346F5E /* MethodObserverTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MethodObserverTest.m; sourceTree = ""; }; + 4C8A22771705913B000539D2 /* TypeSignatureTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeSignatureTest.h; sourceTree = ""; }; + 4C8A22781705913B000539D2 /* TypeSignatureTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TypeSignatureTest.m; sourceTree = ""; }; + 4C8D176717870ED900DE7624 /* NSString+LocalizedPrice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+LocalizedPrice.h"; sourceTree = ""; }; + 4C8D176817870ED900DE7624 /* NSString+LocalizedPrice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+LocalizedPrice.m"; sourceTree = ""; }; + 4C98FB9F16E0B38D00B6EFD8 /* NSString+HTML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+HTML.h"; sourceTree = ""; }; + 4C98FBA016E0B38D00B6EFD8 /* NSString+HTML.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+HTML.m"; sourceTree = ""; }; + 4C98FBAB16E0B56D00B6EFD8 /* NSArray+Templates.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "NSArray+Templates.hpp"; sourceTree = ""; }; + 4CAB2A551730097A001EB552 /* JFFRuntimeAddiotionsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFRuntimeAddiotionsTest.h; sourceTree = ""; }; + 4CAB2A561730097A001EB552 /* JFFRuntimeAddiotionsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFRuntimeAddiotionsTest.m; sourceTree = ""; }; + 4CB5CDED174F55CA00F2B600 /* NSArray+ToURLsSkippingNils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+ToURLsSkippingNils.h"; sourceTree = ""; }; + 4CB5CDEE174F55CA00F2B600 /* NSArray+ToURLsSkippingNils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+ToURLsSkippingNils.m"; sourceTree = ""; }; + 4CBBA1A117661FA5007317E6 /* NSArray+ArrayByRemovingObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+ArrayByRemovingObject.h"; sourceTree = ""; }; + 4CBBA1A217661FA5007317E6 /* NSArray+ArrayByRemovingObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+ArrayByRemovingObject.m"; sourceTree = ""; }; + 4CC01A901743836C003F1C88 /* NSError+WriteErrorToNSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+WriteErrorToNSLog.h"; sourceTree = ""; }; + 4CC01A911743836C003F1C88 /* NSError+WriteErrorToNSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+WriteErrorToNSLog.m"; sourceTree = ""; }; + 4CC01A9417438408003F1C88 /* NSError+IsNetworkError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+IsNetworkError.h"; sourceTree = ""; }; + 4CC01A9517438408003F1C88 /* NSError+IsNetworkError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+IsNetworkError.m"; sourceTree = ""; }; + 4CC01A9817438582003F1C88 /* NSError+SetToPointer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+SetToPointer.h"; sourceTree = ""; }; + 4CC01A9917438582003F1C88 /* NSError+SetToPointer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+SetToPointer.m"; sourceTree = ""; }; + 4CC643BC1717009B000BF15A /* NSObject+ObjectMethodHook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+ObjectMethodHook.h"; sourceTree = ""; }; + 4CC643BD1717009B000BF15A /* NSObject+ObjectMethodHook.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSObject+ObjectMethodHook.mm"; sourceTree = ""; }; + 4CC6BBEA17058D4200BD49E8 /* NSDecimalNumber+Increment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDecimalNumber+Increment.h"; sourceTree = ""; }; + 4CC6BBEB17058D4200BD49E8 /* NSDecimalNumber+Increment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDecimalNumber+Increment.m"; sourceTree = ""; }; + 4CC6BBEE17058D5F00BD49E8 /* UIColor+ColorForHex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+ColorForHex.h"; sourceTree = ""; }; + 4CC6BBEF17058D5F00BD49E8 /* UIColor+ColorForHex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+ColorForHex.m"; sourceTree = ""; }; + 4CC6BBF617058DB100BD49E8 /* NSData+ToString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+ToString.h"; sourceTree = ""; }; + 4CC6BBF717058DB100BD49E8 /* NSData+ToString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+ToString.m"; sourceTree = ""; }; + 4CC6BBFA17058DCF00BD49E8 /* NSNumber+FSStorable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNumber+FSStorable.h"; sourceTree = ""; }; + 4CC6BBFB17058DCF00BD49E8 /* NSNumber+FSStorable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSNumber+FSStorable.m"; sourceTree = ""; }; + 4CC6BBFE17058DFE00BD49E8 /* NSDateFormatter+MultiThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDateFormatter+MultiThreading.h"; sourceTree = ""; }; + 4CC6BBFF17058DFE00BD49E8 /* NSDateFormatter+MultiThreading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDateFormatter+MultiThreading.m"; sourceTree = ""; }; + 4CC6BC0617058E3700BD49E8 /* UIDevice+PlatformName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+PlatformName.h"; sourceTree = ""; }; + 4CC6BC0717058E3800BD49E8 /* UIDevice+PlatformName.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+PlatformName.m"; sourceTree = ""; }; + 4CEED6B41701E0F5004CFCB3 /* JFFMutableAssignKeyDictionaryTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFMutableAssignKeyDictionaryTest.h; sourceTree = ""; }; + 4CEED6B51701E0F5004CFCB3 /* JFFMutableAssignKeyDictionaryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFMutableAssignKeyDictionaryTest.m; sourceTree = ""; }; + 4CF0FFDA170602CC00282900 /* JFFRuntimeAddiotions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFRuntimeAddiotions.h; sourceTree = ""; }; + 4CF0FFDB170602CC00282900 /* JFFRuntimeAddiotions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFRuntimeAddiotions.m; sourceTree = ""; }; 534CDFC014A8C2930068F4DF /* JFFCastFunctions.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = JFFCastFunctions.hpp; sourceTree = ""; }; - 538E1CAA14B32201006BD40A /* NSDecimalNumber+Increment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDecimalNumber+Increment.h"; sourceTree = ""; }; - 538E1CAB14B32201006BD40A /* NSDecimalNumber+Increment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDecimalNumber+Increment.m"; sourceTree = ""; }; 5391044314A88C04007315A3 /* libJFFUtils-clang.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libJFFUtils-clang.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 53A3BB2314DAB2BE008B71BE /* NSString+Format.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Format.h"; sourceTree = ""; }; 53A3BB2414DAB2BF008B71BE /* NSString+Format.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Format.m"; sourceTree = ""; }; @@ -594,28 +572,16 @@ 655C20E615FE5A4000022B11 /* NSObject+DelegateProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+DelegateProxy.m"; sourceTree = ""; }; 65648B7C13923EC4001E163C /* NSString+PropertyName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+PropertyName.h"; sourceTree = ""; }; 65648B7D13923EC4001E163C /* NSString+PropertyName.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+PropertyName.m"; sourceTree = ""; }; - 65648BDF13924326001E163C /* JFFError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFError.h; sourceTree = ""; }; - 65648BE013924326001E163C /* JFFError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFError.m; sourceTree = ""; }; 65802A5B148BF2930040A93A /* libJFFUtilsMacOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFUtilsMacOS.a; sourceTree = BUILT_PRODUCTS_DIR; }; 65802A64148BF2930040A93A /* JFFUtilsMacOS-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JFFUtilsMacOS-Prefix.pch"; sourceTree = ""; }; - 780EFB831712A55E0062FAAA /* NSString+JSEscape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+JSEscape.h"; sourceTree = ""; }; - 780EFB841712A55E0062FAAA /* NSString+JSEscape.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+JSEscape.m"; sourceTree = ""; }; - 7E01667F170477EE0073298E /* NSError+JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+JSON.h"; sourceTree = ""; }; - 7E016680170477EE0073298E /* NSError+JSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+JSON.m"; sourceTree = ""; }; 7E44D664158F179400A2C11E /* NSURL+CPlusPlus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+CPlusPlus.h"; sourceTree = ""; }; 7E44D665158F179400A2C11E /* NSURL+CPlusPlus.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSURL+CPlusPlus.mm"; sourceTree = ""; }; 7E44D66F158F189F00A2C11E /* NSString+CPlusPlus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+CPlusPlus.h"; sourceTree = ""; }; 7E44D670158F189F00A2C11E /* NSString+CPlusPlus.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSString+CPlusPlus.mm"; sourceTree = ""; }; - 7E56B5EF16E0EF68002960EE /* NSDate+Now.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+Now.h"; sourceTree = ""; }; - 7E56B5F016E0EF68002960EE /* NSDate+Now.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+Now.m"; sourceTree = ""; }; 7E57F42414F93738002D139B /* JFFUtilsFW.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework.static; includeInIndex = 0; path = JFFUtilsFW.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7E57F42814F93738002D139B /* JFFUtilsFW-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JFFUtilsFW-Info.plist"; sourceTree = ""; }; 7E57F42A14F93738002D139B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 7E57F42C14F93738002D139B /* JFFUtilsFW-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JFFUtilsFW-Prefix.pch"; sourceTree = ""; }; - 7E99C70816EE3B8A00E9B969 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; - 7E99C74E16EE3CD500E9B969 /* JFFTestTools.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFTestTools.xcodeproj; path = ../JFFTestTools/JFFTestTools.xcodeproj; sourceTree = ""; }; - 7ED3CB1516E6387B00E5A00F /* JFFUtilsTest-CI.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "JFFUtilsTest-CI.octest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 7ED3CB1616E6387C00E5A00F /* JFFUtilsTest copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "JFFUtilsTest copy-Info.plist"; path = "/Volumes/NO NAME/Mobile/Mobile SDK/lib-third-party/JFFLibrary/lib/JFFUtils/JFFUtilsTest copy-Info.plist"; sourceTree = ""; }; 8D1DE52913AB8269001FD56F /* NSObject+RuntimeExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+RuntimeExtensions.h"; sourceTree = ""; }; 8D1DE52A13AB8269001FD56F /* NSObject+RuntimeExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+RuntimeExtensions.m"; sourceTree = ""; }; 8D713C6B13F3F62B007268DF /* JFFMutableAssignArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFMutableAssignArray.h; sourceTree = ""; }; @@ -630,8 +596,6 @@ AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; CE03CAB0160CAD0500039011 /* NSObjectInstancesCountTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSObjectInstancesCountTest.h; sourceTree = ""; }; CE03CAB1160CAD0500039011 /* NSObjectInstancesCountTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSObjectInstancesCountTest.m; sourceTree = ""; }; - CE0B00431626D9C1003802A0 /* NSDateFormatter+MultiThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDateFormatter+MultiThreading.h"; sourceTree = ""; }; - CE0B00441626D9C1003802A0 /* NSDateFormatter+MultiThreading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDateFormatter+MultiThreading.m"; sourceTree = ""; }; CE1BC322161B33AB007DEC95 /* NSArray+ExpandArrayTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+ExpandArrayTest.h"; sourceTree = ""; }; CE1BC323161B33AB007DEC95 /* NSArray+ExpandArrayTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+ExpandArrayTest.m"; sourceTree = ""; }; CE1BC36C161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+BlocksAdditionsTest.h"; sourceTree = ""; }; @@ -669,16 +633,11 @@ CE57FBDF1611F90900124D90 /* JMChild.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JMChild.m; sourceTree = ""; }; CE609CF016134405008259CF /* JFFMutableAssignArrayTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFMutableAssignArrayTest.h; sourceTree = ""; }; CE609CF116134405008259CF /* JFFMutableAssignArrayTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFMutableAssignArrayTest.m; sourceTree = ""; }; - CE7CF54E161EBC4D008557D2 /* NSNumber+FSStorable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNumber+FSStorable.h"; sourceTree = ""; }; - CE7CF54F161EBC4D008557D2 /* NSNumber+FSStorable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSNumber+FSStorable.m"; sourceTree = ""; }; CE914E52160B71B300C89F37 /* DelegateProxyTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DelegateProxyTest.h; sourceTree = ""; }; CE914E53160B71B300C89F37 /* DelegateProxyTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DelegateProxyTest.m; sourceTree = ""; }; - CE914E56160C49C300C89F37 /* JFFTestTools.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFTestTools.xcodeproj; path = "/Users/user/Sources/paparam.ru/HumanCloud/lib-third-party/iAsync/test/JFFUtilsTest/../../lib/JFFTestTools/JFFTestTools.xcodeproj"; sourceTree = ""; }; CE998C461626B988002D39FD /* NSOrderedSet+BlocksAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSOrderedSet+BlocksAdditions.h"; sourceTree = ""; }; CE998C471626B988002D39FD /* NSOrderedSet+BlocksAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSOrderedSet+BlocksAdditions.m"; sourceTree = ""; }; CE998C4B1626B9EB002D39FD /* JUContainersHelperBlocks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JUContainersHelperBlocks.h; sourceTree = ""; }; - CE9C273716AFDF3D0062C91E /* UIDevice+PlatformName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+PlatformName.h"; sourceTree = ""; }; - CE9C273816AFDF3D0062C91E /* UIDevice+PlatformName.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+PlatformName.m"; sourceTree = ""; }; CEA0979A15FF2ADE0080DEF7 /* DelegateProxyUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DelegateProxyUtils.h; sourceTree = ""; }; CEA0979B15FF2ADE0080DEF7 /* DelegateProxyUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DelegateProxyUtils.m; sourceTree = ""; }; CEA0979E15FF2C110080DEF7 /* NSString+DelegateProxySelectorsNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+DelegateProxySelectorsNames.h"; sourceTree = ""; }; @@ -687,17 +646,11 @@ CEA097A315FF2C850080DEF7 /* JFFDelegateProxyClassMethods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFDelegateProxyClassMethods.m; sourceTree = ""; }; CEA097A615FF2E3D0080DEF7 /* JFFProxyDelegatesDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFProxyDelegatesDispatcher.h; sourceTree = ""; }; CEA097A715FF2E3E0080DEF7 /* JFFProxyDelegatesDispatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFProxyDelegatesDispatcher.m; sourceTree = ""; }; - CEB2D7671689A177004067F9 /* NSError+WriteErrorToNSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+WriteErrorToNSLog.h"; sourceTree = ""; }; - CEB2D7681689A177004067F9 /* NSError+WriteErrorToNSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+WriteErrorToNSLog.m"; sourceTree = ""; }; - CEC544871699D28A0019511A /* UIImage+WriteToTmpFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+WriteToTmpFile.h"; sourceTree = ""; }; - CEC544881699D28A0019511A /* UIImage+WriteToTmpFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+WriteToTmpFile.m"; sourceTree = ""; }; CEC70F0F169DBA8B006D63DE /* JFFLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFLogger.h; sourceTree = ""; }; CEC70F10169DBA8B006D63DE /* JFFLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFLogger.m; sourceTree = ""; }; CEC8479416A98A6C00065745 /* NSObject+NsNullAsNil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+NsNullAsNil.h"; sourceTree = ""; }; CEC8479516A98A6C00065745 /* NSObject+NsNullAsNil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+NsNullAsNil.m"; sourceTree = ""; }; CEC851AB15F4E20E0022F479 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - CEDB80EB1601F08F007577B2 /* NSData+ToString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+ToString.h"; sourceTree = ""; }; - CEDB80EC1601F08F007577B2 /* NSData+ToString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+ToString.m"; sourceTree = ""; }; CEE653D11614502400C4D536 /* JFFOnDeallocBlockOwnerTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFOnDeallocBlockOwnerTest.h; sourceTree = ""; }; CEE653D21614502400C4D536 /* JFFOnDeallocBlockOwnerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFOnDeallocBlockOwnerTest.m; sourceTree = ""; }; CEE653D41614512E00C4D536 /* JFFMutableAssignDictionaryTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFFMutableAssignDictionaryTest.h; sourceTree = ""; }; @@ -714,10 +667,6 @@ CEE6574516148DCC00C4D536 /* NSObjectRuntimeExtensionsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSObjectRuntimeExtensionsTest.m; sourceTree = ""; }; CEE6574816148F3000C4D536 /* JUArrayAdditionsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JUArrayAdditionsTest.h; sourceTree = ""; }; CEE6574916148F3000C4D536 /* JUArrayAdditionsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JUArrayAdditionsTest.m; sourceTree = ""; }; - CEEAAD0F167A0E4A00DD8A16 /* UIImage+ScaleToSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ScaleToSize.h"; sourceTree = ""; }; - CEEAAD10167A0E4A00DD8A16 /* UIImage+ScaleToSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ScaleToSize.m"; sourceTree = ""; }; - CEEAAD13167A0E8D00DD8A16 /* UIImage+FixOrientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+FixOrientation.h"; sourceTree = ""; }; - CEEAAD14167A0E8D00DD8A16 /* UIImage+FixOrientation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+FixOrientation.m"; sourceTree = ""; }; D2AAC07E0554694100DB518D /* libJFFUtils.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJFFUtils.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -745,26 +694,11 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 7ED3CB0916E6387B00E5A00F /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 7E99C75916EE3CF300E9B969 /* libJFFTestTools.a in Frameworks */, - 7E99C70A16EE3B8E00E9B969 /* CoreGraphics.framework in Frameworks */, - 7E99C70716EE3B7B00E9B969 /* libJFFUtils.a in Frameworks */, - 7ED3CB0B16E6387B00E5A00F /* SenTestingKit.framework in Frameworks */, - 7ED3CB0C16E6387B00E5A00F /* UIKit.framework in Frameworks */, - 7ED3CB0D16E6387B00E5A00F /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; CE444A181608609100DD85B0 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E99C75816EE3CEE00E9B969 /* libJFFTestTools.a in Frameworks */, - 7E99C70916EE3B8A00E9B969 /* CoreGraphics.framework in Frameworks */, - 7E99C70416EE3B7000E9B969 /* libJFFUtils.a in Frameworks */, + 4C27EDB11701C48500185768 /* libJFFTestTools.a in Frameworks */, CE444A1E1608609100DD85B0 /* SenTestingKit.framework in Frameworks */, CE444A1F1608609100DD85B0 /* UIKit.framework in Frameworks */, CE444A201608609100DD85B0 /* Foundation.framework in Frameworks */, @@ -792,7 +726,6 @@ 5391044314A88C04007315A3 /* libJFFUtils-clang.a */, 7E57F42414F93738002D139B /* JFFUtilsFW.framework */, CE444A1C1608609100DD85B0 /* JFFUtilsTest.octest */, - 7ED3CB1516E6387B00E5A00F /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -808,7 +741,6 @@ 0867D69AFE84028FC02AAC07 /* Frameworks */, 034768DFFF38A50411DB9C8B /* Products */, CE914E55160C49A700C89F37 /* Dependencies */, - 7ED3CB1616E6387C00E5A00F /* JFFUtilsTest copy-Info.plist */, ); name = JFFUtils; sourceTree = ""; @@ -816,8 +748,6 @@ 0867D69AFE84028FC02AAC07 /* Frameworks */ = { isa = PBXGroup; children = ( - 7E99C74E16EE3CD500E9B969 /* JFFTestTools.xcodeproj */, - 7E99C70816EE3B8A00E9B969 /* CoreGraphics.framework */, 1B266C9C15627F7D0054E183 /* libc++.dylib */, CEC851AB15F4E20E0022F479 /* UIKit.framework */, AACBBE490F95108600F1A2B1 /* Foundation.framework */, @@ -836,8 +766,6 @@ 1B054D4E1521C6F4008E4B9E /* NSDictionary+BlocksAdditions.m */, 1B054D511521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.h */, 1B054D521521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.m */, - 37497DF11601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h */, - 37497DF21601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m */, ); path = Dictionary; sourceTree = ""; @@ -845,8 +773,6 @@ 1B14141115DBCCF100EFB2B8 /* NSDate */ = { isa = PBXGroup; children = ( - 7E56B5EF16E0EF68002960EE /* NSDate+Now.h */, - 7E56B5F016E0EF68002960EE /* NSDate+Now.m */, 1B14141C15DBCD3F00EFB2B8 /* NSDate+DateDifference.h */, 1B14141D15DBCD3F00EFB2B8 /* NSDate+DateDifference.m */, ); @@ -866,41 +792,12 @@ 1BA30C28151A383200329EA6 /* Runtime */ = { isa = PBXGroup; children = ( - 1BA30C2A151A384100329EA6 /* JFFRuntime.h */, - 1BA30C2B151A384100329EA6 /* JFFRuntime.m */, + 4CF0FFDA170602CC00282900 /* JFFRuntimeAddiotions.h */, + 4CF0FFDB170602CC00282900 /* JFFRuntimeAddiotions.m */, ); path = Runtime; sourceTree = ""; }; - 1BA676B7144C3FB600B14D49 /* Extensions */ = { - isa = PBXGroup; - children = ( - 1BA676B9144C3FE900B14D49 /* UIWebView+UserAgent.h */, - 1BA676BA144C3FE900B14D49 /* UIWebView+UserAgent.m */, - 1BA676BD144C409E00B14D49 /* NSThread+AssertMainThread.h */, - 1BA676BE144C409F00B14D49 /* NSThread+AssertMainThread.m */, - 538E1CAA14B32201006BD40A /* NSDecimalNumber+Increment.h */, - 538E1CAB14B32201006BD40A /* NSDecimalNumber+Increment.m */, - 1BE2ABEC14E524D0003097D3 /* UIColor+ColorForHex.h */, - 1BE2ABED14E524D0003097D3 /* UIColor+ColorForHex.m */, - 1B10109514ED598300B9E6F4 /* NSError+setToPointer.h */, - 1B10109614ED598300B9E6F4 /* NSError+setToPointer.m */, - 7E01667F170477EE0073298E /* NSError+JSON.h */, - 7E016680170477EE0073298E /* NSError+JSON.m */, - CEDB80EB1601F08F007577B2 /* NSData+ToString.h */, - CEDB80EC1601F08F007577B2 /* NSData+ToString.m */, - CE7CF54E161EBC4D008557D2 /* NSNumber+FSStorable.h */, - CE7CF54F161EBC4D008557D2 /* NSNumber+FSStorable.m */, - CE0B00431626D9C1003802A0 /* NSDateFormatter+MultiThreading.h */, - CE0B00441626D9C1003802A0 /* NSDateFormatter+MultiThreading.m */, - CEB2D7671689A177004067F9 /* NSError+WriteErrorToNSLog.h */, - CEB2D7681689A177004067F9 /* NSError+WriteErrorToNSLog.m */, - CE9C273716AFDF3D0062C91E /* UIDevice+PlatformName.h */, - CE9C273816AFDF3D0062C91E /* UIDevice+PlatformName.m */, - ); - path = Extensions; - sourceTree = ""; - }; 1BA676CB144C473500B14D49 /* ToURL */ = { isa = PBXGroup; children = ( @@ -925,10 +822,10 @@ 37063C6315FE0B7400B4B059 /* NSOrderedSet */ = { isa = PBXGroup; children = ( - 37063C6515FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.h */, - 37063C6615FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.m */, CE998C461626B988002D39FD /* NSOrderedSet+BlocksAdditions.h */, CE998C471626B988002D39FD /* NSOrderedSet+BlocksAdditions.m */, + 37063C6515FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.h */, + 37063C6615FE0C5700B4B059 /* NSOrderedSet+NoThrowObjectAtIndex.m */, ); path = NSOrderedSet; sourceTree = ""; @@ -942,6 +839,61 @@ path = NSLocale; sourceTree = ""; }; + 4C27EDAA1701C47300185768 /* Products */ = { + isa = PBXGroup; + children = ( + 4C27EDAE1701C47300185768 /* libJFFTestTools.a */, + ); + name = Products; + sourceTree = ""; + }; + 4C6DFB10171849C200D86975 /* Errors */ = { + isa = PBXGroup; + children = ( + 4C6DFB11171849D800D86975 /* JFFError.h */, + 4C6DFB12171849D800D86975 /* JFFError.m */, + 4C6DFB1517184A0600D86975 /* JFFSilentError.h */, + 4C6DFB1617184A0600D86975 /* JFFSilentError.m */, + 4CC01A9817438582003F1C88 /* NSError+SetToPointer.h */, + 4CC01A9917438582003F1C88 /* NSError+SetToPointer.m */, + 4CC01A901743836C003F1C88 /* NSError+WriteErrorToNSLog.h */, + 4CC01A911743836C003F1C88 /* NSError+WriteErrorToNSLog.m */, + 4CC01A9417438408003F1C88 /* NSError+IsNetworkError.h */, + 4CC01A9517438408003F1C88 /* NSError+IsNetworkError.m */, + 4C5040CB18112542003F4B12 /* NSError+JSON.h */, + 4C5040CC18112542003F4B12 /* NSError+JSON.m */, + ); + path = Errors; + sourceTree = ""; + }; + 4CAB2A5417300931001EB552 /* Developing */ = { + isa = PBXGroup; + children = ( + ); + path = Developing; + sourceTree = ""; + }; + 4CC6BBE517058CDE00BD49E8 /* Categories */ = { + isa = PBXGroup; + children = ( + 4CC6BBEA17058D4200BD49E8 /* NSDecimalNumber+Increment.h */, + 4CC6BBEB17058D4200BD49E8 /* NSDecimalNumber+Increment.m */, + 4CC6BBEE17058D5F00BD49E8 /* UIColor+ColorForHex.h */, + 4CC6BBEF17058D5F00BD49E8 /* UIColor+ColorForHex.m */, + 4CC6BBF617058DB100BD49E8 /* NSData+ToString.h */, + 4CC6BBF717058DB100BD49E8 /* NSData+ToString.m */, + 4CC6BBFA17058DCF00BD49E8 /* NSNumber+FSStorable.h */, + 4CC6BBFB17058DCF00BD49E8 /* NSNumber+FSStorable.m */, + 4CC6BBFE17058DFE00BD49E8 /* NSDateFormatter+MultiThreading.h */, + 4CC6BBFF17058DFE00BD49E8 /* NSDateFormatter+MultiThreading.m */, + 4CC6BC0617058E3700BD49E8 /* UIDevice+PlatformName.h */, + 4CC6BC0717058E3800BD49E8 /* UIDevice+PlatformName.m */, + 4C5040CF18112601003F4B12 /* NSThread+AssertMainThread.h */, + 4C5040D018112601003F4B12 /* NSThread+AssertMainThread.m */, + ); + path = Categories; + sourceTree = ""; + }; 651BE0A41390496200DD6890 /* Blocks */ = { isa = PBXGroup; children = ( @@ -968,6 +920,11 @@ 53E366C71433760A002AB0B9 /* NSArray+IsEmpty.m */, 1B3CDDE31445DFD300733BE5 /* NSArray+NoThrowObjectAtIndex.h */, 1B3CDDE41445DFD300733BE5 /* NSArray+NoThrowObjectAtIndex.m */, + 4C98FBAB16E0B56D00B6EFD8 /* NSArray+Templates.hpp */, + 4CB5CDED174F55CA00F2B600 /* NSArray+ToURLsSkippingNils.h */, + 4CB5CDEE174F55CA00F2B600 /* NSArray+ToURLsSkippingNils.m */, + 4CBBA1A117661FA5007317E6 /* NSArray+ArrayByRemovingObject.h */, + 4CBBA1A217661FA5007317E6 /* NSArray+ArrayByRemovingObject.m */, ); path = NSArray; sourceTree = ""; @@ -994,6 +951,8 @@ CE444A1316085D5A00DD85B0 /* NSObject+JFFMeaningClass.m */, CEC8479416A98A6C00065745 /* NSObject+NsNullAsNil.h */, CEC8479516A98A6C00065745 /* NSObject+NsNullAsNil.m */, + 4CC643BC1717009B000BF15A /* NSObject+ObjectMethodHook.h */, + 4CC643BD1717009B000BF15A /* NSObject+ObjectMethodHook.mm */, ); path = NSObject; sourceTree = ""; @@ -1001,8 +960,9 @@ 651BE0BF1390496700DD6890 /* Classes */ = { isa = PBXGroup; children = ( + 4C6DFB10171849C200D86975 /* Errors */, + 4CC6BBE517058CDE00BD49E8 /* Categories */, CEC70F0E169DBA8B006D63DE /* Logger */, - CEEAAD0D167A0E3400DD8A16 /* UIImage */, 3780558E164D42F100459BA7 /* NSLocale */, CE57FBB41611EFE100124D90 /* NSSet */, 37063C6315FE0B7400B4B059 /* NSOrderedSet */, @@ -1011,27 +971,26 @@ 1BA30C28151A383200329EA6 /* Runtime */, 1B909B7B14EA918800B19283 /* MemoryManagement */, 1BA676CB144C473500B14D49 /* ToURL */, - 1BA676B7144C3FB600B14D49 /* Extensions */, 651BE0A41390496200DD6890 /* Blocks */, 651BE19A1391969300DD6890 /* NSString */, 651BE0AA1390496200DD6890 /* NSArray */, 651BE0AD1390496200DD6890 /* NSObject */, - 65648BDF13924326001E163C /* JFFError.h */, - 65648BE013924326001E163C /* JFFError.m */, 8DB67B1D13E980B70024EA6C /* JFFAssignProxy.h */, 8DB67B1E13E980B70024EA6C /* JFFAssignProxy.m */, - 1BD01FAF14447B7600A627B1 /* JFFSingleThreadProxy.h */, - 1BD01FB014447B7600A627B1 /* JFFSingleThreadProxy.m */, 8D713C6B13F3F62B007268DF /* JFFMutableAssignArray.h */, 8D713C6C13F3F62B007268DF /* JFFMutableAssignArray.m */, 1BD1820B1467D71B0033BEFF /* JFFMutableAssignDictionary.h */, 1BD1820C1467D71B0033BEFF /* JFFMutableAssignDictionary.m */, + 4C3B63A01701C84700D5A8FD /* JFFMutableAssignKeyDictionary.h */, + 4C3B63A11701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm */, 8DB67B1813E97FCF0024EA6C /* JFFMulticastDelegate.h */, 8DB67B1913E97FCF0024EA6C /* JFFMulticastDelegate.m */, 1B7608981444912F0059E977 /* JGCDAdditions.h */, 1B7608991444912F0059E977 /* JGCDAdditions.mm */, 1B104D911483C85A0025FDDA /* JSignedRange.h */, 1B104D8D1483C8410025FDDA /* JSignedRange.m */, + 4C5040BE18112174003F4B12 /* JFFSingleThreadProxy.h */, + 4C5040BF18112174003F4B12 /* JFFSingleThreadProxy.m */, 534CDFC014A8C2930068F4DF /* JFFCastFunctions.hpp */, 1B9C100F15C802E600C20BCA /* JFFClangLiterals.h */, 651BE27B1391BD7800DD6890 /* JFFUtils.h */, @@ -1042,6 +1001,10 @@ 651BE19A1391969300DD6890 /* NSString */ = { isa = PBXGroup; children = ( + 4C5040C3181124A1003F4B12 /* NSString+JSEscape.h */, + 4C5040C4181124A1003F4B12 /* NSString+JSEscape.m */, + 4C5040C5181124A1003F4B12 /* NSString+UUIDCreation.h */, + 4C5040C6181124A1003F4B12 /* NSString+UUIDCreation.m */, 1B909B8314EA919400B19283 /* NSString+Format.h */, 1B909B8414EA919400B19283 /* NSString+Format.m */, 651BE19B1391969A00DD6890 /* NSString+Search.h */, @@ -1052,8 +1015,6 @@ 8D713CC613F539A5007268DF /* NSString+PathExtensions.m */, 1B6AAD8C1447039B00EA1D96 /* NSString+Trimm.h */, 1B6AAD8D1447039B00EA1D96 /* NSString+Trimm.m */, - 1B16830D146AD4C800832839 /* NSString+UUIDCreation.h */, - 1B16830E146AD4C800832839 /* NSString+UUIDCreation.m */, 1B5E1B9414D037EE0075049A /* NSString+StringWithCutPrefix.h */, 1B5E1B9514D037EE0075049A /* NSString+StringWithCutPrefix.m */, 53A3BB3D14DAB3CD008B71BE /* NSString+IsEmpty.h */, @@ -1066,8 +1027,14 @@ 7E44D670158F189F00A2C11E /* NSString+CPlusPlus.mm */, 1B2A4A9C15EF62A2004ABB2E /* NSString+FileAttributes.h */, 1B2A4A9D15EF62A3004ABB2E /* NSString+FileAttributes.m */, - 780EFB831712A55E0062FAAA /* NSString+JSEscape.h */, - 780EFB841712A55E0062FAAA /* NSString+JSEscape.m */, + 4C98FB9F16E0B38D00B6EFD8 /* NSString+HTML.h */, + 4C98FBA016E0B38D00B6EFD8 /* NSString+HTML.m */, + 4C6AFDFB177AD544009D09C3 /* NSString+MD5.h */, + 4C6AFDFC177AD544009D09C3 /* NSString+MD5.m */, + 4C8D176717870ED900DE7624 /* NSString+LocalizedPrice.h */, + 4C8D176817870ED900DE7624 /* NSString+LocalizedPrice.m */, + 4C4E1E6B179D3529009E9C71 /* NSString+StringFromTemplateString.h */, + 4C4E1E6C179D3529009E9C71 /* NSString+StringFromTemplateString.m */, ); path = NSString; sourceTree = ""; @@ -1106,19 +1073,20 @@ name = "Supporting Files"; sourceTree = ""; }; - 7E99C74F16EE3CD500E9B969 /* Products */ = { - isa = PBXGroup; - children = ( - 7E99C75316EE3CD500E9B969 /* libJFFTestTools.a */, - ); - name = Products; - sourceTree = ""; - }; CE444A211608609100DD85B0 /* JFFUtilsTest */ = { isa = PBXGroup; children = ( + 4C4E1E70179D55AF009E9C71 /* StringFromTemplateString.h */, + 4C4E1E71179D55AF009E9C71 /* StringFromTemplateString.m */, + 4CAB2A551730097A001EB552 /* JFFRuntimeAddiotionsTest.h */, + 4CAB2A561730097A001EB552 /* JFFRuntimeAddiotionsTest.m */, + 4CAB2A5417300931001EB552 /* Developing */, CE57FBDA1611F8E900124D90 /* mock */, CE444A221608609100DD85B0 /* Supporting Files */, + 4C712E1717046A0300346F5E /* MethodObserverTest.h */, + 4C712E1817046A0300346F5E /* MethodObserverTest.m */, + 4C8A22771705913B000539D2 /* TypeSignatureTest.h */, + 4C8A22781705913B000539D2 /* TypeSignatureTest.m */, CE444A44160860F300DD85B0 /* EmptyStringTest.h */, CE444A45160860F300DD85B0 /* EmptyStringTest.m */, CE914E52160B71B300C89F37 /* DelegateProxyTest.h */, @@ -1157,6 +1125,8 @@ CE1BC323161B33AB007DEC95 /* NSArray+ExpandArrayTest.m */, CEE653D41614512E00C4D536 /* JFFMutableAssignDictionaryTest.h */, CEE653D51614512E00C4D536 /* JFFMutableAssignDictionaryTest.m */, + 4CEED6B41701E0F5004CFCB3 /* JFFMutableAssignKeyDictionaryTest.h */, + 4CEED6B51701E0F5004CFCB3 /* JFFMutableAssignKeyDictionaryTest.m */, CE1BC36C161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.h */, CE1BC36D161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.m */, CE444A491608636400DD85B0 /* JFFMeaningClassTest.h */, @@ -1200,19 +1170,11 @@ CE914E55160C49A700C89F37 /* Dependencies */ = { isa = PBXGroup; children = ( - CE914E56160C49C300C89F37 /* JFFTestTools.xcodeproj */, + 4C27EDA91701C47300185768 /* JFFTestTools.xcodeproj */, ); name = Dependencies; sourceTree = ""; }; - CE914E57160C49C300C89F37 /* Products */ = { - isa = PBXGroup; - children = ( - CE914E5B160C49C400C89F37 /* libJFFTestTools.a */, - ); - name = Products; - sourceTree = ""; - }; CEA0979715FF2AAC0080DEF7 /* Details */ = { isa = PBXGroup; children = ( @@ -1245,19 +1207,6 @@ path = Logger; sourceTree = ""; }; - CEEAAD0D167A0E3400DD8A16 /* UIImage */ = { - isa = PBXGroup; - children = ( - CEEAAD0F167A0E4A00DD8A16 /* UIImage+ScaleToSize.h */, - CEEAAD10167A0E4A00DD8A16 /* UIImage+ScaleToSize.m */, - CEEAAD13167A0E8D00DD8A16 /* UIImage+FixOrientation.h */, - CEEAAD14167A0E8D00DD8A16 /* UIImage+FixOrientation.m */, - CEC544871699D28A0019511A /* UIImage+WriteToTmpFile.h */, - CEC544881699D28A0019511A /* UIImage+WriteToTmpFile.m */, - ); - path = UIImage; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -1275,7 +1224,6 @@ 539103FB14A88C04007315A3 /* NSObject+OnDeallocBlock.h in Headers */, 539103FC14A88C04007315A3 /* JFFUtils.h in Headers */, 539103FD14A88C04007315A3 /* NSString+PropertyName.h in Headers */, - 539103FE14A88C04007315A3 /* JFFError.h in Headers */, 539103FF14A88C04007315A3 /* NSObject+RuntimeExtensions.h in Headers */, 5391040014A88C04007315A3 /* JFFMulticastDelegate.h in Headers */, 5391040114A88C04007315A3 /* JFFAssignProxy.h in Headers */, @@ -1285,29 +1233,21 @@ 5391040514A88C04007315A3 /* NSArray+RemoveDuplicates.h in Headers */, 5391040714A88C04007315A3 /* NSArray+IsEmpty.h in Headers */, 5391040814A88C04007315A3 /* NSObject+Const0.h in Headers */, - 5391040A14A88C04007315A3 /* JFFSingleThreadProxy.h in Headers */, 5391040C14A88C04007315A3 /* JGCDAdditions.h in Headers */, 5391041014A88C04007315A3 /* NSArray+NoThrowObjectAtIndex.h in Headers */, 5391041114A88C04007315A3 /* NSString+Trimm.h in Headers */, - 5391041214A88C04007315A3 /* UIWebView+UserAgent.h in Headers */, - 5391041314A88C04007315A3 /* NSThread+AssertMainThread.h in Headers */, 5391041414A88C04007315A3 /* NSString+ToURL.h in Headers */, 5391041514A88C04007315A3 /* NSURL+ToURL.h in Headers */, 5391041614A88C04007315A3 /* JFFMutableAssignDictionary.h in Headers */, - 5391041714A88C04007315A3 /* NSString+UUIDCreation.h in Headers */, 5391041814A88C04007315A3 /* JSignedRange.h in Headers */, 5391041914A88C04007315A3 /* NSObject+ExpandArray.h in Headers */, 534CDFC414A8C2930068F4DF /* JFFCastFunctions.hpp in Headers */, - 538E1CAE14B32201006BD40A /* NSDecimalNumber+Increment.h in Headers */, 7E44D668158F179400A2C11E /* NSURL+CPlusPlus.h in Headers */, 7E44D673158F189F00A2C11E /* NSString+CPlusPlus.h in Headers */, 1B9C101215C802E600C20BCA /* JFFClangLiterals.h in Headers */, 1B14142015DBCD3F00EFB2B8 /* NSDate+DateDifference.h in Headers */, 1B2A4AA015EF62A3004ABB2E /* NSString+FileAttributes.h in Headers */, 37497BD21600971C00AF0C29 /* NSDictionary+ValueWithType.h in Headers */, - 37497DF51601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */, - 7E56B5F316E0EF68002960EE /* NSDate+Now.h in Headers */, - 7E016683170477EE0073298E /* NSError+JSON.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1317,16 +1257,12 @@ files = ( 65802A6B148BF2B10040A93A /* JFFUtils.h in Headers */, 534CDFC314A8C2930068F4DF /* JFFCastFunctions.hpp in Headers */, - 538E1CAD14B32201006BD40A /* NSDecimalNumber+Increment.h in Headers */, 7E44D667158F179400A2C11E /* NSURL+CPlusPlus.h in Headers */, 7E44D672158F189F00A2C11E /* NSString+CPlusPlus.h in Headers */, 1B9C101115C802E600C20BCA /* JFFClangLiterals.h in Headers */, 1B14141F15DBCD3F00EFB2B8 /* NSDate+DateDifference.h in Headers */, 1B2A4A9F15EF62A3004ABB2E /* NSString+FileAttributes.h in Headers */, 37497BD11600971C00AF0C29 /* NSDictionary+ValueWithType.h in Headers */, - 37497DF41601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */, - 7E56B5F216E0EF68002960EE /* NSDate+Now.h in Headers */, - 7E016682170477EE0073298E /* NSError+JSON.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1336,9 +1272,6 @@ files = ( 7E57F48314F93840002D139B /* NSString+ToURL.h in Headers */, 7E57F48514F93840002D139B /* NSURL+ToURL.h in Headers */, - 7E57F48714F93840002D139B /* UIWebView+UserAgent.h in Headers */, - 7E57F48914F93840002D139B /* NSThread+AssertMainThread.h in Headers */, - 7E57F48B14F93840002D139B /* NSDecimalNumber+Increment.h in Headers */, 7E57F49314F93840002D139B /* JFFUtilsBlockDefinitions.h in Headers */, 7E57F49414F93840002D139B /* JFFSimpleBlockHolder.h in Headers */, 7E57F49614F93840002D139B /* JFFOnDeallocBlockOwner.h in Headers */, @@ -1347,7 +1280,6 @@ 7E57F49E14F93840002D139B /* NSString+PropertyName.h in Headers */, 7E57F4A014F93840002D139B /* NSString+PathExtensions.h in Headers */, 7E57F4A214F93840002D139B /* NSString+Trimm.h in Headers */, - 7E57F4A414F93840002D139B /* NSString+UUIDCreation.h in Headers */, 7E57F4A614F93840002D139B /* NSString+IsEmpty.h in Headers */, 7E57F4AB14F93840002D139B /* NSMutableArray+ChangeCount.h in Headers */, 7E57F4AD14F93840002D139B /* NSArray+BlocksAdditions.h in Headers */, @@ -1359,9 +1291,7 @@ 7E57F4B914F93840002D139B /* NSObject+RuntimeExtensions.h in Headers */, 7E57F4BB14F93840002D139B /* NSObject+Const0.h in Headers */, 7E57F4BF14F93840002D139B /* NSObject+ExpandArray.h in Headers */, - 7E57F4C114F93840002D139B /* JFFError.h in Headers */, 7E57F4C314F93840002D139B /* JFFAssignProxy.h in Headers */, - 7E57F4C514F93840002D139B /* JFFSingleThreadProxy.h in Headers */, 7E57F4C714F93840002D139B /* JFFMutableAssignArray.h in Headers */, 7E57F4C914F93840002D139B /* JFFMutableAssignDictionary.h in Headers */, 7E57F4CB14F93840002D139B /* JFFMulticastDelegate.h in Headers */, @@ -1374,9 +1304,6 @@ 1B14142115DBCD3F00EFB2B8 /* NSDate+DateDifference.h in Headers */, 1B2A4AA115EF62A3004ABB2E /* NSString+FileAttributes.h in Headers */, 37497BD31600971C00AF0C29 /* NSDictionary+ValueWithType.h in Headers */, - 37497DF61601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */, - 7E56B5F416E0EF68002960EE /* NSDate+Now.h in Headers */, - 7E016684170477EE0073298E /* NSError+JSON.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1394,39 +1321,32 @@ 651BE1CD1391A36800DD6890 /* NSObject+OnDeallocBlock.h in Headers */, 651BE27C1391BD7800DD6890 /* JFFUtils.h in Headers */, 65648B7E13923EC4001E163C /* NSString+PropertyName.h in Headers */, - 65648BE113924326001E163C /* JFFError.h in Headers */, 8D1DE52B13AB8269001FD56F /* NSObject+RuntimeExtensions.h in Headers */, 8DB67B1A13E97FCF0024EA6C /* JFFMulticastDelegate.h in Headers */, 8DB67B1F13E980B70024EA6C /* JFFAssignProxy.h in Headers */, 8D713C6D13F3F62B007268DF /* JFFMutableAssignArray.h in Headers */, 8D713CC713F539A5007268DF /* NSString+PathExtensions.h in Headers */, 1BCDF9E514320B3200CEB6E7 /* NSMutableArray+ChangeCount.h in Headers */, + 4C5040D118112601003F4B12 /* NSThread+AssertMainThread.h in Headers */, 53BCF8E0143239D100E896B3 /* NSArray+RemoveDuplicates.h in Headers */, + 4C5040C7181124A1003F4B12 /* NSString+JSEscape.h in Headers */, 53E366C81433760A002AB0B9 /* NSArray+IsEmpty.h in Headers */, 1BE75CFF1434B3450076E068 /* NSObject+Const0.h in Headers */, - 1BD01FB114447B7600A627B1 /* JFFSingleThreadProxy.h in Headers */, 1B76089A1444912F0059E977 /* JGCDAdditions.h in Headers */, 1B3CDDE51445DFD300733BE5 /* NSArray+NoThrowObjectAtIndex.h in Headers */, 1B6AAD8E1447039B00EA1D96 /* NSString+Trimm.h in Headers */, - 1BA676BB144C3FE900B14D49 /* UIWebView+UserAgent.h in Headers */, - 1BA676BF144C409F00B14D49 /* NSThread+AssertMainThread.h in Headers */, 1BA676CE144C474500B14D49 /* NSString+ToURL.h in Headers */, 1BA676D2144C476600B14D49 /* NSURL+ToURL.h in Headers */, 1BD1820D1467D71B0033BEFF /* JFFMutableAssignDictionary.h in Headers */, - 1B16830F146AD4C800832839 /* NSString+UUIDCreation.h in Headers */, 1B104D921483C85A0025FDDA /* JSignedRange.h in Headers */, 1B3EE0361487D03A00BA6680 /* NSObject+ExpandArray.h in Headers */, 534CDFC214A8C2930068F4DF /* JFFCastFunctions.hpp in Headers */, - 538E1CAC14B32201006BD40A /* NSDecimalNumber+Increment.h in Headers */, 53A3BB3F14DAB3CD008B71BE /* NSString+IsEmpty.h in Headers */, 1B5E1B9614D037EE0075049A /* NSString+StringWithCutPrefix.h in Headers */, 1B1B280814D825A700FA5388 /* NSString+IsEmailValid.h in Headers */, - 1BE2ABEE14E524D0003097D3 /* UIColor+ColorForHex.h in Headers */, 1B90996B14EA4D9500B19283 /* NSString+Base64.h in Headers */, 1B909B7F14EA918800B19283 /* JFFMemoryMgmt.h in Headers */, 1B909B8514EA919400B19283 /* NSString+Format.h in Headers */, - 1B10109714ED598300B9E6F4 /* NSError+setToPointer.h in Headers */, - 1BA30C2C151A384100329EA6 /* JFFRuntime.h in Headers */, 1B054D4F1521C6F4008E4B9E /* NSDictionary+BlocksAdditions.h in Headers */, 1B054D531521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.h in Headers */, 1BBD97E015249C4200A34E64 /* NSObject+IsEqualTwoObjects.h in Headers */, @@ -1441,26 +1361,38 @@ CEA097A015FF2C110080DEF7 /* NSString+DelegateProxySelectorsNames.h in Headers */, CEA097A415FF2C860080DEF7 /* JFFDelegateProxyClassMethods.h in Headers */, CEA097A815FF2E3E0080DEF7 /* JFFProxyDelegatesDispatcher.h in Headers */, - CEDB80ED1601F08F007577B2 /* NSData+ToString.h in Headers */, 37497BD01600971C00AF0C29 /* NSDictionary+ValueWithType.h in Headers */, - 37497DF31601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.h in Headers */, CE444A1416085D5A00DD85B0 /* NSObject+JFFMeaningClass.h in Headers */, CE57FBB81611EFFF00124D90 /* NSSet+BlocksAdditions.h in Headers */, CE57FBBD1611F0BF00124D90 /* NSMutableSet+StorableSet.h in Headers */, - CE7CF550161EBC4D008557D2 /* NSNumber+FSStorable.h in Headers */, CE998C481626B988002D39FD /* NSOrderedSet+BlocksAdditions.h in Headers */, - CE0B00451626D9C1003802A0 /* NSDateFormatter+MultiThreading.h in Headers */, 37805592164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.h in Headers */, - CEEAAD11167A0E4A00DD8A16 /* UIImage+ScaleToSize.h in Headers */, - CEEAAD15167A0E8D00DD8A16 /* UIImage+FixOrientation.h in Headers */, - CEB2D7691689A177004067F9 /* NSError+WriteErrorToNSLog.h in Headers */, - CEC544891699D28A0019511A /* UIImage+WriteToTmpFile.h in Headers */, CEC70F13169DBA8B006D63DE /* JFFLogger.h in Headers */, CEC8479616A98A6C00065745 /* NSObject+NsNullAsNil.h in Headers */, - CE9C273916AFDF3D0062C91E /* UIDevice+PlatformName.h in Headers */, - 7E56B5F116E0EF68002960EE /* NSDate+Now.h in Headers */, - 7E016681170477EE0073298E /* NSError+JSON.h in Headers */, - 780EFB851712A55E0062FAAA /* NSString+JSEscape.h in Headers */, + 4C5040C018112174003F4B12 /* JFFSingleThreadProxy.h in Headers */, + 4C98FBA116E0B38D00B6EFD8 /* NSString+HTML.h in Headers */, + 4C98FBAC16E0B56D00B6EFD8 /* NSArray+Templates.hpp in Headers */, + 4C5040C9181124A1003F4B12 /* NSString+UUIDCreation.h in Headers */, + 4C3B63A21701C84700D5A8FD /* JFFMutableAssignKeyDictionary.h in Headers */, + 4CC6BBEC17058D4200BD49E8 /* NSDecimalNumber+Increment.h in Headers */, + 4CC6BBF017058D5F00BD49E8 /* UIColor+ColorForHex.h in Headers */, + 4CC6BBF817058DB100BD49E8 /* NSData+ToString.h in Headers */, + 4CC6BBFC17058DD000BD49E8 /* NSNumber+FSStorable.h in Headers */, + 4CC6BC0017058DFF00BD49E8 /* NSDateFormatter+MultiThreading.h in Headers */, + 4CC6BC0817058E3900BD49E8 /* UIDevice+PlatformName.h in Headers */, + 4CF0FFDC170602CC00282900 /* JFFRuntimeAddiotions.h in Headers */, + 4CC643BE1717009B000BF15A /* NSObject+ObjectMethodHook.h in Headers */, + 4C6DFB13171849D800D86975 /* JFFError.h in Headers */, + 4C6DFB1717184A0600D86975 /* JFFSilentError.h in Headers */, + 4CC01A921743836C003F1C88 /* NSError+WriteErrorToNSLog.h in Headers */, + 4CC01A9617438408003F1C88 /* NSError+IsNetworkError.h in Headers */, + 4CC01A9A17438582003F1C88 /* NSError+SetToPointer.h in Headers */, + 4CB5CDEF174F55CB00F2B600 /* NSArray+ToURLsSkippingNils.h in Headers */, + 4CBBA1A317661FA5007317E6 /* NSArray+ArrayByRemovingObject.h in Headers */, + 4C5040CD18112542003F4B12 /* NSError+JSON.h in Headers */, + 4C6AFDFD177AD544009D09C3 /* NSString+MD5.h in Headers */, + 4C8D176917870ED900DE7624 /* NSString+LocalizedPrice.h in Headers */, + 4C4E1E6D179D3529009E9C71 /* NSString+StringFromTemplateString.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1522,27 +1454,6 @@ productReference = 7E57F42414F93738002D139B /* JFFUtilsFW.framework */; productType = "com.apple.product-type.framework.static"; }; - 7ED3CAD216E6387B00E5A00F /* JFFUtilsTest-CI */ = { - isa = PBXNativeTarget; - buildConfigurationList = 7ED3CB1116E6387B00E5A00F /* Build configuration list for PBXNativeTarget "JFFUtilsTest-CI" */; - buildPhases = ( - 7ED3CAD516E6387B00E5A00F /* Sources */, - 7ED3CB0916E6387B00E5A00F /* Frameworks */, - 7ED3CB0E16E6387B00E5A00F /* Resources */, - 7ED3CB1016E6387B00E5A00F /* ShellScript */, - ); - buildRules = ( - ); - dependencies = ( - 7E99C75516EE3CE000E9B969 /* PBXTargetDependency */, - 7E99C70616EE3B7600E9B969 /* PBXTargetDependency */, - 7ED3CAD316E6387B00E5A00F /* PBXTargetDependency */, - ); - name = "JFFUtilsTest-CI"; - productName = JFFUtilsTest; - productReference = 7ED3CB1516E6387B00E5A00F /* JFFUtilsTest-CI.octest */; - productType = "com.apple.product-type.bundle"; - }; CE444A1B1608609100DD85B0 /* JFFUtilsTest */ = { isa = PBXNativeTarget; buildConfigurationList = CE444A2B1608609100DD85B0 /* Build configuration list for PBXNativeTarget "JFFUtilsTest" */; @@ -1555,9 +1466,7 @@ buildRules = ( ); dependencies = ( - 7E99C75716EE3CE700E9B969 /* PBXTargetDependency */, - 7E99C70316EE3B6900E9B969 /* PBXTargetDependency */, - CE914E5D160C49CB00C89F37 /* PBXTargetDependency */, + 4C27EDB01701C48000185768 /* PBXTargetDependency */, ); name = JFFUtilsTest; productName = JFFUtilsTest; @@ -1587,7 +1496,7 @@ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0440; + LastUpgradeCheck = 0500; }; buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "JFFUtils" */; compatibilityVersion = "Xcode 3.2"; @@ -1605,12 +1514,8 @@ projectDirPath = ""; projectReferences = ( { - ProductGroup = 7E99C74F16EE3CD500E9B969 /* Products */; - ProjectRef = 7E99C74E16EE3CD500E9B969 /* JFFTestTools.xcodeproj */; - }, - { - ProductGroup = CE914E57160C49C300C89F37 /* Products */; - ProjectRef = CE914E56160C49C300C89F37 /* JFFTestTools.xcodeproj */; + ProductGroup = 4C27EDAA1701C47300185768 /* Products */; + ProjectRef = 4C27EDA91701C47300185768 /* JFFTestTools.xcodeproj */; }, ); projectRoot = ""; @@ -1620,24 +1525,16 @@ 539103F214A88C04007315A3 /* JFFUtils-clang */, 7E57F42314F93738002D139B /* JFFUtilsFW */, CE444A1B1608609100DD85B0 /* JFFUtilsTest */, - 7ED3CAD216E6387B00E5A00F /* JFFUtilsTest-CI */, ); }; /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 7E99C75316EE3CD500E9B969 /* libJFFTestTools.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFTestTools.a; - remoteRef = 7E99C75216EE3CD500E9B969 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CE914E5B160C49C400C89F37 /* libJFFTestTools.a */ = { + 4C27EDAE1701C47300185768 /* libJFFTestTools.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; path = libJFFTestTools.a; - remoteRef = CE914E5A160C49C400C89F37 /* PBXContainerItemProxy */; + remoteRef = 4C27EDAD1701C47300185768 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ @@ -1651,14 +1548,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 7ED3CB0E16E6387B00E5A00F /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 7ED3CB0F16E6387B00E5A00F /* InfoPlist.strings in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; CE444A191608609100DD85B0 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1712,19 +1601,6 @@ shellPath = /bin/sh; shellScript = "set -e\n\nset +u\nif [[ $UFW_MASTER_SCRIPT_RUNNING ]]\nthen\n # Nothing for the slave script to do\n exit 0\nfi\nset -u\nexport UFW_MASTER_SCRIPT_RUNNING=1\n\n\n# Functions\n\n## List files in the specified directory, storing to the specified array.\n#\n# @param $1 The path to list\n# @param $2 The name of the array to fill\n#\n##\nlist_files ()\n{\n filelist=$(ls \"$1\")\n while read line\n do\n eval \"$2[\\${#$2[*]}]=\\\"\\$line\\\"\"\n done <<< \"$filelist\"\n}\n\n\n# Sanity check\n\nif [[ ! -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]]\nthen\n echo \"Framework target \\\"${TARGET_NAME}\\\" had no source files to build from. Make sure your source files have the correct target membership\"\n exit 1\nfi\n\n\n# Gather information\n\nif [[ \"$SDK_NAME\" =~ ([A-Za-z]+) ]]\nthen\n UFW_SDK_PLATFORM=${BASH_REMATCH[1]}\nelse\n echo \"Could not find platform name from SDK_NAME: $SDK_NAME\"\n exit 1\nfi\n\nif [[ \"$SDK_NAME\" =~ ([0-9]+.*$) ]]\nthen\n UFW_SDK_VERSION=${BASH_REMATCH[1]}\nelse\n echo \"Could not find sdk version from SDK_NAME: $SDK_NAME\"\n exit 1\nfi\n\nif [[ \"$UFW_SDK_PLATFORM\" = \"iphoneos\" ]]\nthen\n UFW_OTHER_PLATFORM=iphonesimulator\nelse\n UFW_OTHER_PLATFORM=iphoneos\nfi\n\nif [[ \"$BUILT_PRODUCTS_DIR\" =~ (.*)$UFW_SDK_PLATFORM$ ]]\nthen\n UFW_OTHER_BUILT_PRODUCTS_DIR=\"${BASH_REMATCH[1]}${UFW_OTHER_PLATFORM}\"\nelse\n echo \"Could not find $UFW_SDK_PLATFORM in $BUILT_PRODUCTS_DIR\"\n exit 1\nfi\n\nONLY_ACTIVE_PLATFORM=${ONLY_ACTIVE_PLATFORM:-$ONLY_ACTIVE_ARCH}\n\n# Short-circuit if all binaries are up to date.\n# We already checked the other platform in the prerun script.\n\nif [[ -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && [[ -f \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && [[ ! \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\nthen\n exit 0\nfi\n\nif [ \"${ONLY_ACTIVE_PLATFORM}\" == \"YES\" ]\nthen\n echo \"ONLY_ACTIVE_PLATFORM=${ONLY_ACTIVE_PLATFORM}: Skipping other platform build\"\nelse\n # Make sure the other platform gets built\n \n echo \"Build other platform\"\n \n echo xcodebuild -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\n xcodebuild -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\n \n \n # Build the fat static library binary\n \n echo \"Create universal static library\"\n \n echo \"$PLATFORM_DEVELOPER_BIN_DIR/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n \"$PLATFORM_DEVELOPER_BIN_DIR/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n \n echo mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\nfi\n\n# Build embedded framework structure\n\necho \"Build Embedded Framework\"\n\necho rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\nrm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\necho mkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/Resources\"\nmkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/Resources\"\necho cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\ncp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\n\ndeclare -a UFW_FILE_LIST\nlist_files \"${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\" UFW_FILE_LIST\nfor filename in \"${UFW_FILE_LIST[@]}\"\ndo\n if [[ \"${filename}\" != \"Info.plist\" ]] && [[ ! \"${filename}\" =~ .*\\.lproj$ ]]\n then\n echo ln -sf \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/Resources/${filename}\"\n ln -sf \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/Resources/${filename}\"\n fi\ndone\n\n\nif [ \"${ONLY_ACTIVE_PLATFORM}\" != \"YES\" ]\nthen\n # Replace other platform's framework with a copy of this one (so that both have the same universal binary)\n \n echo \"Copy from $UFW_SDK_PLATFORM to $UFW_OTHER_PLATFORM\"\n \n echo rm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\n rm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\n echo cp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\n cp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\nfi\n"; }; - 7ED3CB1016E6387B00E5A00F /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; - }; CE444A1A1608609100DD85B0 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -1752,7 +1628,6 @@ 5391041F14A88C04007315A3 /* JFFOnDeallocBlockOwner.m in Sources */, 5391042014A88C04007315A3 /* NSObject+OnDeallocBlock.m in Sources */, 5391042114A88C04007315A3 /* NSString+PropertyName.m in Sources */, - 5391042214A88C04007315A3 /* JFFError.m in Sources */, 5391042314A88C04007315A3 /* NSObject+RuntimeExtensions.m in Sources */, 5391042514A88C04007315A3 /* JFFMulticastDelegate.m in Sources */, 5391042614A88C04007315A3 /* JFFAssignProxy.m in Sources */, @@ -1762,28 +1637,23 @@ 5391042A14A88C04007315A3 /* NSArray+RemoveDuplicates.m in Sources */, 5391042B14A88C04007315A3 /* NSArray+IsEmpty.m in Sources */, 5391042C14A88C04007315A3 /* NSObject+Const0.m in Sources */, - 5391042E14A88C04007315A3 /* JFFSingleThreadProxy.m in Sources */, 5391043014A88C04007315A3 /* JGCDAdditions.mm in Sources */, 5391043414A88C04007315A3 /* NSArray+NoThrowObjectAtIndex.m in Sources */, 5391043514A88C04007315A3 /* NSString+Trimm.m in Sources */, - 5391043614A88C04007315A3 /* UIWebView+UserAgent.m in Sources */, - 5391043714A88C04007315A3 /* NSThread+AssertMainThread.m in Sources */, 5391043814A88C04007315A3 /* NSString+ToURL.m in Sources */, 5391043914A88C04007315A3 /* NSURL+ToURL.m in Sources */, 5391043A14A88C04007315A3 /* JFFMutableAssignDictionary.m in Sources */, - 5391043B14A88C04007315A3 /* NSString+UUIDCreation.m in Sources */, 5391043C14A88C04007315A3 /* JSignedRange.m in Sources */, 5391043D14A88C04007315A3 /* NSObject+ExpandArray.m in Sources */, - 538E1CB114B32201006BD40A /* NSDecimalNumber+Increment.m in Sources */, - 1BE2ABF114E524DF003097D3 /* UIColor+ColorForHex.m in Sources */, 7E44D66C158F179400A2C11E /* NSURL+CPlusPlus.mm in Sources */, 7E44D677158F189F00A2C11E /* NSString+CPlusPlus.mm in Sources */, 1B14142415DBCD3F00EFB2B8 /* NSDate+DateDifference.m in Sources */, 1B2A4AA415EF62A3004ABB2E /* NSString+FileAttributes.m in Sources */, 37497BD61600971C00AF0C29 /* NSDictionary+ValueWithType.m in Sources */, - 37497DF91601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */, - 7E56B5F716E0EF68002960EE /* NSDate+Now.m in Sources */, - 7E016687170477EE0073298E /* NSError+JSON.m in Sources */, + 4CEED6BE1701E23C004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */, + 4CF0FFDF1706038200282900 /* JFFRuntimeAddiotions.m in Sources */, + 4CC643C1171700BA000BF15A /* NSObject+ObjectMethodHook.mm in Sources */, + 4C50BF5B171D85B400251A16 /* JFFError.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1795,19 +1665,15 @@ 65802A6E148BF2BA0040A93A /* JFFMulticastDelegate.m in Sources */, 65802A6F148BF2BE0040A93A /* JFFMutableAssignDictionary.m in Sources */, 65802A70148BF2C10040A93A /* JFFMutableAssignArray.m in Sources */, - 65802A71148BF2C30040A93A /* JFFSingleThreadProxy.m in Sources */, 65802A72148BF2C80040A93A /* JFFAssignProxy.m in Sources */, - 65802A74148BF2CE0040A93A /* JFFError.m in Sources */, 65802A95148BF4610040A93A /* NSString+ToURL.m in Sources */, 65802A97148BF4640040A93A /* NSURL+ToURL.m in Sources */, - 65802A98148BF4700040A93A /* NSThread+AssertMainThread.m in Sources */, 65802A9C148BF4800040A93A /* JFFSimpleBlockHolder.m in Sources */, 65802A9D148BF4820040A93A /* JFFOnDeallocBlockOwner.m in Sources */, 65802A9E148BF4870040A93A /* NSString+Search.m in Sources */, 65802A9F148BF4890040A93A /* NSString+PropertyName.m in Sources */, 65802AA0148BF48F0040A93A /* NSString+PathExtensions.m in Sources */, 65802AA1148BF4920040A93A /* NSString+Trimm.m in Sources */, - 65802AA2148BF4960040A93A /* NSString+UUIDCreation.m in Sources */, 65802AA3148BF49B0040A93A /* NSMutableArray+ChangeCount.m in Sources */, 65802AA4148BF49D0040A93A /* NSArray+BlocksAdditions.m in Sources */, 65802AA5148BF4A00040A93A /* NSArray+RemoveDuplicates.m in Sources */, @@ -1817,15 +1683,15 @@ 65802AA9148BF4AE0040A93A /* NSObject+OnDeallocBlock.m in Sources */, 65802AAA148BF4B00040A93A /* NSObject+RuntimeExtensions.m in Sources */, 65802AAB148BF4B20040A93A /* NSObject+Const0.m in Sources */, - 538E1CB014B32201006BD40A /* NSDecimalNumber+Increment.m in Sources */, 7E44D66B158F179400A2C11E /* NSURL+CPlusPlus.mm in Sources */, 7E44D676158F189F00A2C11E /* NSString+CPlusPlus.mm in Sources */, 1B14142315DBCD3F00EFB2B8 /* NSDate+DateDifference.m in Sources */, 1B2A4AA315EF62A3004ABB2E /* NSString+FileAttributes.m in Sources */, 37497BD51600971C00AF0C29 /* NSDictionary+ValueWithType.m in Sources */, - 37497DF81601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */, - 7E56B5F616E0EF68002960EE /* NSDate+Now.m in Sources */, - 7E016686170477EE0073298E /* NSError+JSON.m in Sources */, + 4CEED6BF1701E23D004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */, + 4CF0FFDE1706038200282900 /* JFFRuntimeAddiotions.m in Sources */, + 4CC643C0171700BA000BF15A /* NSObject+ObjectMethodHook.mm in Sources */, + 4C50BF5A171D85B400251A16 /* JFFError.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1835,9 +1701,6 @@ files = ( 7E57F43114F937E0002D139B /* NSString+ToURL.m in Sources */, 7E57F43314F937E0002D139B /* NSURL+ToURL.m in Sources */, - 7E57F43514F937E0002D139B /* UIWebView+UserAgent.m in Sources */, - 7E57F43714F937E0002D139B /* NSThread+AssertMainThread.m in Sources */, - 7E57F43914F937E0002D139B /* NSDecimalNumber+Increment.m in Sources */, 7E57F44214F937E0002D139B /* JFFSimpleBlockHolder.m in Sources */, 7E57F44414F937E0002D139B /* JFFOnDeallocBlockOwner.m in Sources */, 7E57F44814F937E0002D139B /* NSString+Format.m in Sources */, @@ -1845,7 +1708,6 @@ 7E57F44C14F937E0002D139B /* NSString+PropertyName.m in Sources */, 7E57F44E14F937E0002D139B /* NSString+PathExtensions.m in Sources */, 7E57F45014F937E0002D139B /* NSString+Trimm.m in Sources */, - 7E57F45214F937E0002D139B /* NSString+UUIDCreation.m in Sources */, 7E57F45414F937E0002D139B /* NSString+IsEmpty.m in Sources */, 7E57F45914F937E0002D139B /* NSMutableArray+ChangeCount.m in Sources */, 7E57F45B14F937E0002D139B /* NSArray+BlocksAdditions.m in Sources */, @@ -1857,9 +1719,7 @@ 7E57F46714F937E0002D139B /* NSObject+RuntimeExtensions.m in Sources */, 7E57F46914F937E0002D139B /* NSObject+Const0.m in Sources */, 7E57F46D14F937E0002D139B /* NSObject+ExpandArray.m in Sources */, - 7E57F46F14F937E0002D139B /* JFFError.m in Sources */, 7E57F47114F937E0002D139B /* JFFAssignProxy.m in Sources */, - 7E57F47314F937E0002D139B /* JFFSingleThreadProxy.m in Sources */, 7E57F47514F937E0002D139B /* JFFMutableAssignArray.m in Sources */, 7E57F47714F937E0002D139B /* JFFMutableAssignDictionary.m in Sources */, 7E57F47914F937E0002D139B /* JFFMulticastDelegate.m in Sources */, @@ -1870,40 +1730,10 @@ 1B14142515DBCD3F00EFB2B8 /* NSDate+DateDifference.m in Sources */, 1B2A4AA515EF62A3004ABB2E /* NSString+FileAttributes.m in Sources */, 37497BD71600971C00AF0C29 /* NSDictionary+ValueWithType.m in Sources */, - 37497DFA1601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */, - 7E56B5F816E0EF68002960EE /* NSDate+Now.m in Sources */, - 7E016688170477EE0073298E /* NSError+JSON.m in Sources */, - 780EFB871712A56E0062FAAA /* NSString+JSEscape.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 7ED3CAD516E6387B00E5A00F /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 7E99C73716EE3C4000E9B969 /* JMParent.m in Sources */, - 7E99C73816EE3C4000E9B969 /* JMChild.m in Sources */, - 7E99C73916EE3C5300E9B969 /* EmptyStringTest.m in Sources */, - 7E99C73A16EE3C5300E9B969 /* DelegateProxyTest.m in Sources */, - 7E99C73B16EE3C5300E9B969 /* NSObjectInstancesCountTest.m in Sources */, - 7E99C73C16EE3C5300E9B969 /* DateDifferenceStringFromDateTest.m in Sources */, - 7E99C73D16EE3C5300E9B969 /* NumberOfCharacterFromStringTest.m in Sources */, - 7E99C73E16EE3C5300E9B969 /* NSObject_IsEqualTwoObjectsTest.m in Sources */, - 7E99C73F16EE3C5300E9B969 /* ObjcDynamicCastTest.mm in Sources */, - 7E99C74016EE3C5300E9B969 /* JFFMutableAssignArrayTest.m in Sources */, - 7E99C74116EE3C5300E9B969 /* JFFOnDeallocBlockOwnerTest.m in Sources */, - 7E99C74216EE3C5300E9B969 /* JFFMulticastDelegateTest.m in Sources */, - 7E99C74316EE3C5300E9B969 /* JFFAssignProxyTest.m in Sources */, - 7E99C74416EE3C5300E9B969 /* NSObject+OwnershipsTest.m in Sources */, - 7E99C74516EE3C5300E9B969 /* JFFSimpleBlockHolderTest.m in Sources */, - 7E99C74616EE3C5300E9B969 /* NSObjectRuntimeExtensionsTest.m in Sources */, - 7E99C74716EE3C5300E9B969 /* JUArrayAdditionsTest.m in Sources */, - 7E99C74816EE3C5300E9B969 /* JUMutableArrayTest.m in Sources */, - 7E99C74916EE3C5300E9B969 /* JFFStringFormatTest.m in Sources */, - 7E99C74A16EE3C5300E9B969 /* NSArray+ExpandArrayTest.m in Sources */, - 7E99C74B16EE3C5300E9B969 /* JFFMutableAssignDictionaryTest.m in Sources */, - 7E99C74C16EE3C5300E9B969 /* NSDictionary+BlocksAdditionsTest.m in Sources */, - 7E99C74D16EE3C5300E9B969 /* JFFMeaningClassTest.m in Sources */, + 4CEED6BD1701E23C004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */, + 4CF0FFE01706038300282900 /* JFFRuntimeAddiotions.m in Sources */, + 4CC643C2171700BA000BF15A /* NSObject+ObjectMethodHook.mm in Sources */, + 4C50BF5C171D85B500251A16 /* JFFError.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1911,29 +1741,66 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 7E99C72016EE3C1600E9B969 /* EmptyStringTest.m in Sources */, - 7E99C72116EE3C1600E9B969 /* DelegateProxyTest.m in Sources */, - 7E99C72216EE3C1600E9B969 /* NSObjectInstancesCountTest.m in Sources */, - 7E99C72316EE3C1600E9B969 /* DateDifferenceStringFromDateTest.m in Sources */, - 7E99C72416EE3C1600E9B969 /* NumberOfCharacterFromStringTest.m in Sources */, - 7E99C72516EE3C1600E9B969 /* NSObject_IsEqualTwoObjectsTest.m in Sources */, - 7E99C72616EE3C1600E9B969 /* ObjcDynamicCastTest.mm in Sources */, - 7E99C72716EE3C1600E9B969 /* JFFMutableAssignArrayTest.m in Sources */, - 7E99C72816EE3C1600E9B969 /* JFFOnDeallocBlockOwnerTest.m in Sources */, - 7E99C72916EE3C1600E9B969 /* JFFMulticastDelegateTest.m in Sources */, - 7E99C72A16EE3C1600E9B969 /* JFFAssignProxyTest.m in Sources */, - 7E99C72B16EE3C1600E9B969 /* NSObject+OwnershipsTest.m in Sources */, - 7E99C72C16EE3C1600E9B969 /* JFFSimpleBlockHolderTest.m in Sources */, - 7E99C72D16EE3C1600E9B969 /* NSObjectRuntimeExtensionsTest.m in Sources */, - 7E99C72E16EE3C1600E9B969 /* JUArrayAdditionsTest.m in Sources */, - 7E99C72F16EE3C1600E9B969 /* JUMutableArrayTest.m in Sources */, - 7E99C73016EE3C1600E9B969 /* JFFStringFormatTest.m in Sources */, - 7E99C73116EE3C1600E9B969 /* NSArray+ExpandArrayTest.m in Sources */, - 7E99C73216EE3C1600E9B969 /* JFFMutableAssignDictionaryTest.m in Sources */, - 7E99C73316EE3C1600E9B969 /* NSDictionary+BlocksAdditionsTest.m in Sources */, - 7E99C73416EE3C1600E9B969 /* JFFMeaningClassTest.m in Sources */, - 7E99C73516EE3C2400E9B969 /* JMParent.m in Sources */, - 7E99C73616EE3C2400E9B969 /* JMChild.m in Sources */, + CE444A46160860F300DD85B0 /* EmptyStringTest.m in Sources */, + CE444A481608634700DD85B0 /* NSObject+JFFMeaningClass.m in Sources */, + CE444A4B1608636400DD85B0 /* JFFMeaningClassTest.m in Sources */, + CE444A6E1608698600DD85B0 /* NSString+IsEmpty.m in Sources */, + CE914E54160B71B300C89F37 /* DelegateProxyTest.m in Sources */, + CE914E5F160C4B0C00C89F37 /* JFFProxyDelegatesDispatcher.m in Sources */, + CE914E60160C4B1900C89F37 /* JFFDelegateProxyClassMethods.m in Sources */, + CEB90821160C708300EFC230 /* NSArray+BlocksAdditions.m in Sources */, + CEB90823160C709D00EFC230 /* NSObject+DelegateProxy.m in Sources */, + CEB90824160C70A300EFC230 /* DelegateProxyUtils.m in Sources */, + CEB90825160C70A300EFC230 /* NSString+DelegateProxySelectorsNames.m in Sources */, + CEB90826160C70B400EFC230 /* JFFMutableAssignArray.m in Sources */, + CEB90827160C711200EFC230 /* JFFAssignProxy.m in Sources */, + CEB90828160C712C00EFC230 /* NSObject+RuntimeExtensions.m in Sources */, + CEB90829160C73DE00EFC230 /* NSObject+Ownerships.m in Sources */, + CEB9082A160C73EC00EFC230 /* NSObject+OnDeallocBlock.m in Sources */, + CEB9082B160C740300EFC230 /* JFFOnDeallocBlockOwner.m in Sources */, + CE03CAB2160CAD0500039011 /* NSObjectInstancesCountTest.m in Sources */, + CE57F8BB1611998D00124D90 /* DateDifferenceStringFromDateTest.m in Sources */, + CE57F8BD16119A5400124D90 /* NSDate+DateDifference.m in Sources */, + CE57F8C01611A32000124D90 /* NumberOfCharacterFromStringTest.m in Sources */, + CE57F8C11611A3D500124D90 /* NSString+Search.m in Sources */, + CE57F8C41611A61E00124D90 /* NSObject_IsEqualTwoObjectsTest.m in Sources */, + CE57F8C51611A6AA00124D90 /* NSObject+IsEqualTwoObjects.m in Sources */, + CE57FBD81611F80800124D90 /* ObjcDynamicCastTest.mm in Sources */, + CE57FBDD1611F8FC00124D90 /* JMParent.m in Sources */, + CE57FBE01611F90900124D90 /* JMChild.m in Sources */, + CE609CF216134405008259CF /* JFFMutableAssignArrayTest.m in Sources */, + CEE653D016144C8900C4D536 /* JFFRuntimeInitializer.m in Sources */, + CEE653D31614502400C4D536 /* JFFOnDeallocBlockOwnerTest.m in Sources */, + CEE653D61614512E00C4D536 /* JFFMutableAssignDictionaryTest.m in Sources */, + CEE653D7161451BF00C4D536 /* JFFMutableAssignDictionary.m in Sources */, + CEE653DA16145C0D00C4D536 /* JFFMulticastDelegateTest.m in Sources */, + CEE653DB16145CED00C4D536 /* JFFMulticastDelegate.m in Sources */, + CEE653DE16145D1900C4D536 /* JFFAssignProxyTest.m in Sources */, + CEE653E116145E6300C4D536 /* NSObject+OwnershipsTest.m in Sources */, + CEE653E41614669500C4D536 /* JFFSimpleBlockHolderTest.m in Sources */, + CEE653E5161466DA00C4D536 /* JFFSimpleBlockHolder.m in Sources */, + CEE6574616148DCC00C4D536 /* NSObjectRuntimeExtensionsTest.m in Sources */, + CEE6574A16148F3000C4D536 /* JUArrayAdditionsTest.m in Sources */, + CEE6574B16148F7E00C4D536 /* NSArray+RemoveDuplicates.m in Sources */, + CEE6574C1614900000C4D536 /* NSArray+IsEmpty.m in Sources */, + CE2B32871617B55F003FB5F8 /* JUMutableArrayTest.m in Sources */, + CE2B32891617B5BF003FB5F8 /* NSMutableArray+ChangeCount.m in Sources */, + CE2B328C1617B5E9003FB5F8 /* JFFStringFormatTest.m in Sources */, + CE2B328D1617B632003FB5F8 /* NSString+Format.m in Sources */, + CE1BC324161B33AB007DEC95 /* NSArray+ExpandArrayTest.m in Sources */, + CE1BC326161B349A007DEC95 /* NSObject+ExpandArray.m in Sources */, + CE1BC36A161B38AF007DEC95 /* NSDictionary+BlocksAdditions.m in Sources */, + CE1BC36E161B3A51007DEC95 /* NSDictionary+BlocksAdditionsTest.m in Sources */, + 4CEED6BB1701E236004CFCB3 /* JFFMutableAssignKeyDictionaryTest.m in Sources */, + 4CEED6BC1701E23C004CFCB3 /* JFFMutableAssignKeyDictionary.mm in Sources */, + 4C712E1917046A0300346F5E /* MethodObserverTest.m in Sources */, + 4C8A22791705913B000539D2 /* TypeSignatureTest.m in Sources */, + 4CF0FFE11706038300282900 /* JFFRuntimeAddiotions.m in Sources */, + 4CC643C3171700CB000BF15A /* NSObject+ObjectMethodHook.mm in Sources */, + 4C50BF59171D85B300251A16 /* JFFError.m in Sources */, + 4CAB2A571730097A001EB552 /* JFFRuntimeAddiotionsTest.m in Sources */, + 4C4E1E72179D55AF009E9C71 /* StringFromTemplateString.m in Sources */, + 4C4E1E77179D56D5009E9C71 /* NSString+StringFromTemplateString.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1948,42 +1815,37 @@ 651BE1C41391A25500DD6890 /* JFFOnDeallocBlockOwner.m in Sources */, 651BE1CE1391A36800DD6890 /* NSObject+OnDeallocBlock.m in Sources */, 65648B7F13923EC4001E163C /* NSString+PropertyName.m in Sources */, - 65648BE213924326001E163C /* JFFError.m in Sources */, 8D1DE52C13AB8269001FD56F /* NSObject+RuntimeExtensions.m in Sources */, 8DB67B1B13E97FCF0024EA6C /* JFFMulticastDelegate.m in Sources */, 8DB67B2013E980B70024EA6C /* JFFAssignProxy.m in Sources */, 8D713C6E13F3F62B007268DF /* JFFMutableAssignArray.m in Sources */, + 4C5040C8181124A1003F4B12 /* NSString+JSEscape.m in Sources */, 8D713CC813F539A5007268DF /* NSString+PathExtensions.m in Sources */, 1BCDF9E614320B3200CEB6E7 /* NSMutableArray+ChangeCount.m in Sources */, 53BCF8E1143239D100E896B3 /* NSArray+RemoveDuplicates.m in Sources */, 53E366C91433760A002AB0B9 /* NSArray+IsEmpty.m in Sources */, 1BE75D001434B3450076E068 /* NSObject+Const0.m in Sources */, - 1BD01FB214447B7600A627B1 /* JFFSingleThreadProxy.m in Sources */, 1B76089B1444912F0059E977 /* JGCDAdditions.mm in Sources */, 1B3CDDE61445DFD300733BE5 /* NSArray+NoThrowObjectAtIndex.m in Sources */, 1B6AAD8F1447039B00EA1D96 /* NSString+Trimm.m in Sources */, - 1BA676BC144C3FE900B14D49 /* UIWebView+UserAgent.m in Sources */, - 1BA676C0144C409F00B14D49 /* NSThread+AssertMainThread.m in Sources */, 1BA676CF144C474500B14D49 /* NSString+ToURL.m in Sources */, 1BA676D3144C476600B14D49 /* NSURL+ToURL.m in Sources */, 1BD1820E1467D71B0033BEFF /* JFFMutableAssignDictionary.m in Sources */, - 1B168310146AD4C800832839 /* NSString+UUIDCreation.m in Sources */, 1B104D8F1483C8410025FDDA /* JSignedRange.m in Sources */, 1B3EE0371487D03A00BA6680 /* NSObject+ExpandArray.m in Sources */, - 538E1CAF14B32201006BD40A /* NSDecimalNumber+Increment.m in Sources */, + 4C5040CE18112542003F4B12 /* NSError+JSON.m in Sources */, 53A3BB4214DAB3CD008B71BE /* NSString+IsEmpty.m in Sources */, 1B5E1B9714D037EE0075049A /* NSString+StringWithCutPrefix.m in Sources */, 1B1B280914D825A700FA5388 /* NSString+IsEmailValid.m in Sources */, - 1BE2ABEF14E524D0003097D3 /* UIColor+ColorForHex.m in Sources */, 1B90996C14EA4D9500B19283 /* NSString+Base64.m in Sources */, - 1B10109814ED598300B9E6F4 /* NSError+setToPointer.m in Sources */, 1B909B8014EA918800B19283 /* JFFMemoryMgmt.m in Sources */, + 4C5040CA181124A1003F4B12 /* NSString+UUIDCreation.m in Sources */, 1B909B8614EA919400B19283 /* NSString+Format.m in Sources */, - 1BA30C2D151A384100329EA6 /* JFFRuntime.m in Sources */, 1B054D501521C6F4008E4B9E /* NSDictionary+BlocksAdditions.m in Sources */, 1B054D541521C739008E4B9E /* NSDictionary+JFFExtendedDictionary.m in Sources */, 1BBD97E115249C4200A34E64 /* NSObject+IsEqualTwoObjects.m in Sources */, 7E44D66A158F179400A2C11E /* NSURL+CPlusPlus.mm in Sources */, + 4C5040D218112601003F4B12 /* NSThread+AssertMainThread.m in Sources */, 7E44D675158F189F00A2C11E /* NSString+CPlusPlus.mm in Sources */, 1B14142215DBCD3F00EFB2B8 /* NSDate+DateDifference.m in Sources */, 1B2A4AA215EF62A3004ABB2E /* NSString+FileAttributes.m in Sources */, @@ -1993,62 +1855,46 @@ CEA097A115FF2C110080DEF7 /* NSString+DelegateProxySelectorsNames.m in Sources */, CEA097A515FF2C860080DEF7 /* JFFDelegateProxyClassMethods.m in Sources */, CEA097A915FF2E3E0080DEF7 /* JFFProxyDelegatesDispatcher.m in Sources */, - CEDB80EE1601F08F007577B2 /* NSData+ToString.m in Sources */, 37497BD41600971C00AF0C29 /* NSDictionary+ValueWithType.m in Sources */, - 37497DF71601FAB200AF0C29 /* NSMutableDictionary+IgnoringAddNilValue.m in Sources */, CE444A1516085D5A00DD85B0 /* NSObject+JFFMeaningClass.m in Sources */, CE57FBB91611EFFF00124D90 /* NSSet+BlocksAdditions.m in Sources */, CE57FBBE1611F0BF00124D90 /* NSMutableSet+StorableSet.m in Sources */, CEE653CF16144C8900C4D536 /* JFFRuntimeInitializer.m in Sources */, - CE7CF551161EBC4D008557D2 /* NSNumber+FSStorable.m in Sources */, CE998C491626B988002D39FD /* NSOrderedSet+BlocksAdditions.m in Sources */, - CE0B00461626D9C1003802A0 /* NSDateFormatter+MultiThreading.m in Sources */, 37805593164D432700459BA7 /* NSLocale+CurrentInterfaceLanguageCode.m in Sources */, - CEEAAD12167A0E4A00DD8A16 /* UIImage+ScaleToSize.m in Sources */, - CEEAAD16167A0E8D00DD8A16 /* UIImage+FixOrientation.m in Sources */, - CEB2D76A1689A177004067F9 /* NSError+WriteErrorToNSLog.m in Sources */, - CEC5448A1699D28A0019511A /* UIImage+WriteToTmpFile.m in Sources */, CEC70F14169DBA8B006D63DE /* JFFLogger.m in Sources */, CEC8479716A98A6C00065745 /* NSObject+NsNullAsNil.m in Sources */, - CE9C273A16AFDF3D0062C91E /* UIDevice+PlatformName.m in Sources */, - 7E56B5F516E0EF68002960EE /* NSDate+Now.m in Sources */, - 7E016685170477EE0073298E /* NSError+JSON.m in Sources */, - 780EFB861712A55E0062FAAA /* NSString+JSEscape.m in Sources */, + 4C5040C118112174003F4B12 /* JFFSingleThreadProxy.m in Sources */, + 4C98FBA216E0B38D00B6EFD8 /* NSString+HTML.m in Sources */, + 4C3B63A31701C84700D5A8FD /* JFFMutableAssignKeyDictionary.mm in Sources */, + 4CC6BBED17058D4200BD49E8 /* NSDecimalNumber+Increment.m in Sources */, + 4CC6BBF117058D5F00BD49E8 /* UIColor+ColorForHex.m in Sources */, + 4CC6BBF917058DB100BD49E8 /* NSData+ToString.m in Sources */, + 4CC6BBFD17058DD000BD49E8 /* NSNumber+FSStorable.m in Sources */, + 4CC6BC0117058DFF00BD49E8 /* NSDateFormatter+MultiThreading.m in Sources */, + 4CC6BC0917058E3900BD49E8 /* UIDevice+PlatformName.m in Sources */, + 4CF0FFDD170602CC00282900 /* JFFRuntimeAddiotions.m in Sources */, + 4CC643BF1717009B000BF15A /* NSObject+ObjectMethodHook.mm in Sources */, + 4C6DFB14171849D800D86975 /* JFFError.m in Sources */, + 4C6DFB1817184A0600D86975 /* JFFSilentError.m in Sources */, + 4CC01A931743836C003F1C88 /* NSError+WriteErrorToNSLog.m in Sources */, + 4CC01A9717438408003F1C88 /* NSError+IsNetworkError.m in Sources */, + 4CC01A9B17438582003F1C88 /* NSError+SetToPointer.m in Sources */, + 4CB5CDF0174F55CB00F2B600 /* NSArray+ToURLsSkippingNils.m in Sources */, + 4CBBA1A417661FA5007317E6 /* NSArray+ArrayByRemovingObject.m in Sources */, + 4C6AFDFE177AD544009D09C3 /* NSString+MD5.m in Sources */, + 4C8D176A17870ED900DE7624 /* NSString+LocalizedPrice.m in Sources */, + 4C4E1E6E179D3529009E9C71 /* NSString+StringFromTemplateString.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 7E99C70316EE3B6900E9B969 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = D2AAC07D0554694100DB518D /* JFFUtils */; - targetProxy = 7E99C70216EE3B6900E9B969 /* PBXContainerItemProxy */; - }; - 7E99C70616EE3B7600E9B969 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = D2AAC07D0554694100DB518D /* JFFUtils */; - targetProxy = 7E99C70516EE3B7600E9B969 /* PBXContainerItemProxy */; - }; - 7E99C75516EE3CE000E9B969 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFTestTools; - targetProxy = 7E99C75416EE3CE000E9B969 /* PBXContainerItemProxy */; - }; - 7E99C75716EE3CE700E9B969 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFTestTools; - targetProxy = 7E99C75616EE3CE700E9B969 /* PBXContainerItemProxy */; - }; - 7ED3CAD316E6387B00E5A00F /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFTestTools; - targetProxy = 7ED3CAD416E6387B00E5A00F /* PBXContainerItemProxy */; - }; - CE914E5D160C49CB00C89F37 /* PBXTargetDependency */ = { + 4C27EDB01701C48000185768 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = JFFTestTools; - targetProxy = CE914E5C160C49CB00C89F37 /* PBXContainerItemProxy */; + targetProxy = 4C27EDAF1701C48000185768 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -2076,7 +1922,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; DSTROOT = /tmp/JFFUtils.dst; @@ -2098,7 +1943,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; DSTROOT = /tmp/JFFUtils.dst; GCC_MODEL_TUNING = G5; @@ -2115,17 +1959,17 @@ 1DEB922308733DC00010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_ENABLE_MODULES = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ../, - ../JFFCache, - ); + HEADER_SEARCH_PATHS = ../; IPHONEOS_DEPLOYMENT_TARGET = 5.0; + LLVM_VECTORIZE_LOOPS = YES; + ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; @@ -2134,16 +1978,15 @@ 1DEB922408733DC00010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_ENABLE_MODULES = YES; + CLANG_X86_VECTOR_INSTRUCTIONS = avx2; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ../, - ../JFFCache, - ); + HEADER_SEARCH_PATHS = ../; IPHONEOS_DEPLOYMENT_TARGET = 5.0; + LLVM_VECTORIZE_LOOPS = YES; OTHER_LDFLAGS = "-ObjC"; SDKROOT = iphoneos; }; @@ -2153,7 +1996,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; DSTROOT = /tmp/JFFUtils.dst; @@ -2176,7 +2018,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; DSTROOT = /tmp/JFFUtils.dst; GCC_MODEL_TUNING = G5; @@ -2195,7 +2036,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; @@ -2226,7 +2066,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; @@ -2462,118 +2301,6 @@ }; name = Coverage; }; - 7ED3CB1216E6387B00E5A00F /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SDKROOT)/Developer/Library/Frameworks\"", - "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", - ); - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "JFFUtilsTest/JFFUtilsTest-Prefix.pch"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - HEADER_SEARCH_PATHS = ( - ../, - ../JFFTestTools, - ); - INFOPLIST_FILE = "JFFUtilsTest copy-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; - OTHER_LDFLAGS = ( - "-ObjC", - "-all_load", - ); - PRODUCT_NAME = "JFFUtilsTest-CI"; - TEST_AFTER_BUILD = YES; - WRAPPER_EXTENSION = octest; - }; - name = Debug; - }; - 7ED3CB1316E6387B00E5A00F /* Coverage */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SDKROOT)/Developer/Library/Frameworks\"", - "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", - ); - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "JFFUtilsTest/JFFUtilsTest-Prefix.pch"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - HEADER_SEARCH_PATHS = ( - ../, - ../JFFTestTools, - ); - INFOPLIST_FILE = "JFFUtilsTest copy-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; - OTHER_LDFLAGS = ( - "-ObjC", - "-all_load", - ); - PRODUCT_NAME = "JFFUtilsTest-CI"; - TEST_AFTER_BUILD = YES; - WRAPPER_EXTENSION = octest; - }; - name = Coverage; - }; - 7ED3CB1416E6387B00E5A00F /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SDKROOT)/Developer/Library/Frameworks\"", - "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", - ); - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "JFFUtilsTest/JFFUtilsTest-Prefix.pch"; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - HEADER_SEARCH_PATHS = ( - ../, - ../JFFTestTools, - ); - INFOPLIST_FILE = "JFFUtilsTest copy-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; - OTHER_LDFLAGS = ( - "-ObjC", - "-all_load", - ); - PRODUCT_NAME = "JFFUtilsTest-CI"; - TEST_AFTER_BUILD = YES; - VALIDATE_PRODUCT = YES; - WRAPPER_EXTENSION = octest; - }; - name = Release; - }; CE444A2C1608609100DD85B0 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -2698,16 +2425,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 7ED3CB1116E6387B00E5A00F /* Build configuration list for PBXNativeTarget "JFFUtilsTest-CI" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 7ED3CB1216E6387B00E5A00F /* Debug */, - 7ED3CB1316E6387B00E5A00F /* Coverage */, - 7ED3CB1416E6387B00E5A00F /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; CE444A2B1608609100DD85B0 /* Build configuration list for PBXNativeTarget "JFFUtilsTest" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/lib/JFFUtils/JFFUtilsTest/JFFMulticastDelegateTest.m b/lib/JFFUtils/JFFUtilsTest/JFFMulticastDelegateTest.m index 970bd7c..4b49b8d 100644 --- a/lib/JFFUtils/JFFUtilsTest/JFFMulticastDelegateTest.m +++ b/lib/JFFUtils/JFFUtilsTest/JFFMulticastDelegateTest.m @@ -3,7 +3,7 @@ @protocol TestMulticastDelegateInterface < NSObject > @required --(NSUInteger)justReturnFiveNumber; +- (NSUInteger)justReturnFiveNumber; @end @@ -17,7 +17,7 @@ @implementation TestClassForMulticast @synthesize initialState; --(NSUInteger)justReturnFiveNumber +- (NSUInteger)justReturnFiveNumber { return self.initialState++; } @@ -26,7 +26,7 @@ -(NSUInteger)justReturnFiveNumber @implementation JFFMulticastDelegateTest --(void)testMutableAssignArrayAssignIssue +- (void)testMutableAssignArrayAssignIssue { __block BOOL delegateDeallocated = NO; @@ -51,7 +51,7 @@ -(void)testMutableAssignArrayAssignIssue STAssertTrue( 0 == [ multicast justReturnFiveNumber ], @"Empty array" ); } --(void)testMulticastDelegateFirstRelease +- (void)testMulticastDelegateFirstRelease { __block BOOL multicast_deallocated_ = NO; { @@ -69,7 +69,7 @@ -(void)testMulticastDelegateFirstRelease STAssertTrue( multicast_deallocated_, @"Target should be dealloced" ); } --(void)testAddDelegateTwice +- (void)testAddDelegateTwice { JFFMulticastDelegate< TestMulticastDelegateInterface > *multicast = (JFFMulticastDelegate< TestMulticastDelegateInterface >*)[JFFMulticastDelegate new]; diff --git a/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignArrayTest.m b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignArrayTest.m index 104774b..b1181fb 100644 --- a/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignArrayTest.m +++ b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignArrayTest.m @@ -27,7 +27,7 @@ - (void)testMutableAssignArrayAssignIssue - (void)testMutableAssignArrayFirstRelease { - __weak JFFMutableAssignArray* weakArray; + __weak JFFMutableAssignArray *weakArray; { JFFMutableAssignArray *array = [JFFMutableAssignArray new]; diff --git a/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignDictionaryTest.m b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignDictionaryTest.m index 8f16a15..acecfba 100644 --- a/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignDictionaryTest.m +++ b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignDictionaryTest.m @@ -2,9 +2,10 @@ @implementation JFFMutableAssignDictionaryTest --(void)testMutableAssignDictionaryAssignIssue +- (void)testMutableAssignDictionaryAssignIssue { - JFFMutableAssignDictionary *dict; + JFFMutableAssignDictionary *dict1; + JFFMutableAssignDictionary *dict2; __block BOOL targetDeallocated = NO; { @@ -12,33 +13,54 @@ -(void)testMutableAssignDictionaryAssignIssue [target addOnDeallocBlock:^void(void) { targetDeallocated = YES; - } ]; + }]; + + dict1 = [JFFMutableAssignDictionary new]; + [dict1 setObject:target forKey:@"1"]; - dict = [JFFMutableAssignDictionary new]; - [dict setObject:target forKey:@"1"]; + dict2 = [JFFMutableAssignDictionary new]; + [dict2 setObject:target forKey:@"1"]; + [dict2 setObject:target forKey:@"2"]; - STAssertTrue(1 == [dict count], @"Contains 1 object"); + STAssertTrue(1 == [dict1 count], @"Contains 1 object"); + STAssertTrue(2 == [dict2 count], @"Contains 1 object"); } STAssertTrue(targetDeallocated, @"Target should be dealloced"); - STAssertTrue(0 == [dict count], @"Empty array"); + STAssertTrue(0 == [dict1 count], @"Empty array"); + STAssertTrue(0 == [dict2 count], @"Empty array"); } --(void)testMutableAssignDictionaryFirstRelease +- (void)testMutableAssignDictionaryFirstRelease { - __block BOOL dict_deallocated_ = NO; { - JFFMutableAssignDictionary* dict_ = [ JFFMutableAssignDictionary new ]; + __block BOOL dictDeallocated1 = NO; + __block BOOL dictDeallocated2 = NO; + NSObject *target = [NSObject new]; - [dict_ addOnDeallocBlock:^void(void) { - dict_deallocated_ = YES; - }]; + { + JFFMutableAssignDictionary *dict1 = [JFFMutableAssignDictionary new]; + + [dict1 addOnDeallocBlock:^void(void) { + dictDeallocated1 = YES; + }]; + + dict1[@"1"] = target; + + // + + JFFMutableAssignDictionary *dict2 = [JFFMutableAssignDictionary new]; + + [dict2 addOnDeallocBlock:^void(void) { + dictDeallocated2 = YES; + }]; + + dict2[@"2"] = target; + } - NSObject *target_ = [NSObject new]; - [ dict_ setObject: target_ forKey: @"1" ]; + STAssertTrue(dictDeallocated1, @"Target should be dealloced"); + STAssertTrue(dictDeallocated2, @"Target should be dealloced"); } - - STAssertTrue( dict_deallocated_, @"Target should be dealloced" ); } -(void)testObjectForKey @@ -62,21 +84,21 @@ -(void)testObjectForKey STAssertTrue(dict[@"2" ] == object2, @"Dict contains object_"); STAssertTrue(dict[@"3" ] == nil, @"Dict no contains object for key \"2\""); - __block NSUInteger count_ = 0; + __block NSUInteger count = 0; [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - if ( [ key isEqualToString: @"1" ] ) { + if ([ key isEqualToString:@"1"]) { STAssertTrue(obj == object1, nil); - ++count_; + ++count; } else if ([key isEqualToString:@"2"]) { STAssertTrue(obj == object2, nil); - ++count_; + ++count; } else { STFail( @"should not be reached" ); } } ]; - STAssertTrue( count_ == 2, @"Dict no contains object for key \"2\"" ); + STAssertTrue( count == 2, @"Dict no contains object for key \"2\"" ); } STAssertTrue(target_deallocated, @"Target should be dealloced"); diff --git a/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignKeyDictionaryTest.h b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignKeyDictionaryTest.h new file mode 100644 index 0000000..ed74fc7 --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignKeyDictionaryTest.h @@ -0,0 +1,7 @@ +#import + +#import + +@interface JFFMutableAssignKeyDictionaryTest : SenTestCase + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignKeyDictionaryTest.m b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignKeyDictionaryTest.m new file mode 100644 index 0000000..ae05b0f --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/JFFMutableAssignKeyDictionaryTest.m @@ -0,0 +1,205 @@ +#import "JFFMutableAssignKeyDictionaryTest.h" + +@interface NSTestKeyObject : NSObject +@end + +@implementation NSTestKeyObject +@end + +@implementation JFFMutableAssignKeyDictionaryTest + +-(void)testMutableAssignDictionaryAssignIssue +{ + JFFMutableAssignKeyDictionary *dict1; + JFFMutableAssignKeyDictionary *dict2; + __block BOOL targetDeallocated = NO; + + { + NSObject *target = [NSTestKeyObject new]; + + [target addOnDeallocBlock:^void(void) { + targetDeallocated = YES; + }]; + + dict1 = [JFFMutableAssignKeyDictionary new]; + dict2 = [JFFMutableAssignKeyDictionary new]; + + dict1[target] = [NSObject new]; + + dict2[target] = [NSObject new]; + dict2[target] = [NSObject new]; + + STAssertTrue(1 == [dict1 count], @"Contains 1 object"); + STAssertTrue(1 == [dict2 count], @"Contains 1 object"); + } + + STAssertTrue(targetDeallocated, @"Target should be dealloced"); + STAssertTrue(0 == [dict1 count], @"Empty array"); + STAssertTrue(0 == [dict2 count], @"Empty array"); +} + +- (void)testMutableAssignDictionaryFirstRelease +{ + { + NSObject *target = [NSObject new]; + + __block BOOL dictDeallocated1 = NO; + __block BOOL dictDeallocated2 = NO; + { + JFFMutableAssignKeyDictionary *dict1 = [JFFMutableAssignKeyDictionary new]; + + [dict1 addOnDeallocBlock:^void(void) { + dictDeallocated1 = YES; + }]; + + dict1[target] = [NSObject new]; + + //// + + JFFMutableAssignKeyDictionary *dict2 = [JFFMutableAssignKeyDictionary new]; + + [dict2 addOnDeallocBlock:^void(void) { + dictDeallocated2 = YES; + }]; + + dict2[target] = [NSObject new]; + dict2[target] = [NSObject new]; + } + + STAssertTrue(dictDeallocated1, @"Target should be dealloced"); + STAssertTrue(dictDeallocated2, @"Target should be dealloced"); + } +} + +-(void)testObjectForKey +{ + @autoreleasepool { + + JFFMutableAssignKeyDictionary *dict = [JFFMutableAssignKeyDictionary new]; + + __block BOOL targetDeallocated = NO; + @autoreleasepool { + + NSObject *object1 = [NSObject new]; + NSObject *object2 = [NSObject new]; + + NSObject *key1 = [NSObject new]; + NSObject *key2 = [NSObject new]; + NSObject *key3 = [NSObject new]; + + [key1 addOnDeallocBlock: ^void( void ) { + targetDeallocated = YES; + }]; + + dict[key1] = object1; + [dict setObject:object2 forKey:key2]; + + STAssertTrue(dict[key1] == object1, @"Dict contains object_"); + STAssertTrue(dict[key2] == object2, @"Dict contains object_"); + STAssertTrue(dict[key3] == nil, @"Dict no contains object for key \"2\""); + + __block NSUInteger count = 0; + + [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + if ([key isEqual:key1]) { + STAssertTrue(obj == object1, nil); + ++count; + } else if ([key isEqual:key2]) { + STAssertTrue(obj == object2, nil); + ++count; + } else { + STFail( @"should not be reached" ); + } + }]; + + STAssertTrue(count == 2, @"Dict no contains object for key \"2\""); + } + + STAssertTrue(targetDeallocated, @"Target should be dealloced"); + STAssertTrue(0 == [dict count], @"Empty dict"); + } +} + +- (void)testMapMethod +{ + JFFMutableAssignKeyDictionary *dict = [JFFMutableAssignKeyDictionary new]; + + NSString *key1 = @"1"; + NSString *key2 = @"2"; + NSString *key3 = @"3"; + + dict[key1] = @1; + dict[key2] = @2; + dict[key3] = @3; + + NSDictionary *result = [dict map:^id(id key, id object) { + + NSUInteger num = [object unsignedIntegerValue]; + return @(num * [key integerValue]); + }]; + + STAssertTrue([result count] == 3, nil); + + if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 6.) { + STAssertFalse([result isKindOfClass:[NSMutableDictionary class]], nil); + } + + STAssertTrue([result isKindOfClass:[NSDictionary class]], nil); + + STAssertEqualObjects(@1, result[key1], nil); + STAssertEqualObjects(@4, result[key2], nil); + STAssertEqualObjects(@9, result[key3], nil); + + STAssertThrows({ + [dict map:^id(id key, id object) { + NSUInteger num = [object unsignedIntegerValue]; + if (num == 3) + return nil; + return @(num * 2); + }]; + }, nil); +} + +- (void)testEnumerateKeysAndObjectsUsingBlock +{ + NSString *key1 = @"1"; + NSString *key2 = @"2"; + NSString *key3 = @"3"; + + NSDictionary *patternDict = + @{ + key1 : @1, + key2 : @2, + key3 : @3, + }; + + JFFMutableAssignKeyDictionary *dict = [JFFMutableAssignKeyDictionary new]; + + [patternDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + dict[key] = obj; + }]; + + __block NSUInteger count = 0; + NSMutableDictionary *resultDict = [NSMutableDictionary new]; + + [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + ++count; + resultDict[key] = obj; + STAssertEqualObjects(obj, patternDict[key], nil); + }]; + + STAssertTrue(count == 3, nil); + STAssertEqualObjects(resultDict, patternDict, nil); + + count = 0; + + [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + ++count; + if (count == 2) + *stop = YES; + }]; + + STAssertTrue(count == 2, nil); +} + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/JFFRuntimeAddiotionsTest.h b/lib/JFFUtils/JFFUtilsTest/JFFRuntimeAddiotionsTest.h new file mode 100644 index 0000000..5abc5cb --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/JFFRuntimeAddiotionsTest.h @@ -0,0 +1,5 @@ +#import + +@interface JFFRuntimeAddiotionsTest : SenTestCase + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/JFFRuntimeAddiotionsTest.m b/lib/JFFUtils/JFFUtilsTest/JFFRuntimeAddiotionsTest.m new file mode 100644 index 0000000..7ff87c3 --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/JFFRuntimeAddiotionsTest.m @@ -0,0 +1,64 @@ +#import "JFFRuntimeAddiotionsTest.h" + +#include "JFFRuntimeAddiotions.h" + +@interface TestWeakOwnerClass : NSObject + +@property (weak, nonatomic) id dynamicWeakOwnedObject; +@property (weak, nonatomic) id normalWeakOwnedObject; + +@end + +@implementation TestWeakOwnerClass + +@dynamic dynamicWeakOwnedObject; + ++ (void)load +{ + jClass_implementProperty([self class], NSStringFromSelector(@selector(dynamicWeakOwnedObject))); +} + +@end + +@implementation JFFRuntimeAddiotionsTest + +- (void)testWeakOwnerDynamicProperty +{ + @autoreleasepool + { + TestWeakOwnerClass *owner = [TestWeakOwnerClass new]; + + STAssertNil(owner.dynamicWeakOwnedObject, nil); + + @autoreleasepool + { + NSObject *owned = [NSObject new]; + NSObject *owned2 = [NSObject new]; + + owner.dynamicWeakOwnedObject = owned; + STAssertNotNil(owner.dynamicWeakOwnedObject, nil); + + owner.normalWeakOwnedObject = owned2; + STAssertNotNil(owner.normalWeakOwnedObject, nil); + } + + STAssertNil(owner.dynamicWeakOwnedObject, nil); + STAssertNil(owner.normalWeakOwnedObject, nil); + } + + @autoreleasepool + { + NSObject *owned = [NSObject new]; + + @autoreleasepool + { + TestWeakOwnerClass *owner = [TestWeakOwnerClass new]; + STAssertNil(owner.dynamicWeakOwnedObject, nil); + + owner.dynamicWeakOwnedObject = owned; + STAssertNotNil(owner.dynamicWeakOwnedObject, nil); + } + } +} + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/JFFSimpleBlockHolderTest.m b/lib/JFFUtils/JFFUtilsTest/JFFSimpleBlockHolderTest.m index 2169ac4..c3914f7 100644 --- a/lib/JFFUtils/JFFUtilsTest/JFFSimpleBlockHolderTest.m +++ b/lib/JFFUtils/JFFUtilsTest/JFFSimpleBlockHolderTest.m @@ -10,35 +10,35 @@ -(void)setUp -(void)testSimpleBlockHolderBehavior { @autoreleasepool { - JFFSimpleBlockHolder* holder_ = [ JFFSimpleBlockHolder new ]; + JFFSimpleBlockHolder* holder = [ JFFSimpleBlockHolder new ]; STAssertTrue( 0 != [ JFFSimpleBlockHolder instancesCount ], @"Block holder should exists" ); - __block BOOL blockContextDeallocated_ = NO; - __block NSUInteger performBlockCount_ = 0; + __block BOOL blockContextDeallocated = NO; + __block NSUInteger performBlockCount = 0; @autoreleasepool { - NSObject *blockContext_ = [NSObject new]; - [ blockContext_ addOnDeallocBlock: ^void( void ) + NSObject *blockContext = [NSObject new]; + [ blockContext addOnDeallocBlock: ^void( void ) { - blockContextDeallocated_ = YES; + blockContextDeallocated = YES; } ]; - holder_.simpleBlock = ^void( void ) + holder.simpleBlock = ^void( void ) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-retain-cycles" - if ( [ blockContext_ class ] && [ holder_ class ] ) - ++performBlockCount_; + if ([blockContext class] && [holder class]) + ++performBlockCount; #pragma clang diagnostic pop }; - holder_.onceSimpleBlock(); - holder_.onceSimpleBlock(); + holder.onceSimpleBlock(); + holder.onceSimpleBlock(); } - STAssertTrue( blockContextDeallocated_, @"Block context should be dealloced" ); - STAssertTrue( 1 == performBlockCount_, @"Block was called once" ); - STAssertTrue( nil == holder_.simpleBlock, @"Block is nil after call" ); + STAssertTrue(blockContextDeallocated, @"Block context should be dealloced"); + STAssertTrue(1 == performBlockCount, @"Block was called once"); + STAssertTrue(nil == holder.simpleBlock, @"Block is nil after call"); } STAssertTrue( 0 == [ JFFSimpleBlockHolder instancesCount ], @"Block holder should be dealloced" ); diff --git a/lib/JFFUtils/JFFUtilsTest/JFFUtilsTest-Prefix.pch b/lib/JFFUtils/JFFUtilsTest/JFFUtilsTest-Prefix.pch index 3d865aa..2451aaa 100644 --- a/lib/JFFUtils/JFFUtilsTest/JFFUtilsTest-Prefix.pch +++ b/lib/JFFUtils/JFFUtilsTest/JFFUtilsTest-Prefix.pch @@ -1,3 +1,7 @@ +// +// Prefix header for all source files of the 'JFFUtilsTest' target in the 'JFFUtilsTest' project +// + #ifdef __OBJC__ #import #import diff --git a/lib/JFFUtils/JFFUtilsTest/JUArrayAdditionsTest.m b/lib/JFFUtils/JFFUtilsTest/JUArrayAdditionsTest.m index 7ac3bf5..972d5f4 100644 --- a/lib/JFFUtils/JFFUtilsTest/JUArrayAdditionsTest.m +++ b/lib/JFFUtils/JFFUtilsTest/JUArrayAdditionsTest.m @@ -73,11 +73,11 @@ -(void)testBlockVersionWorksCorrectly JFFEqualityCheckerBlock predicate_ = ^( id left_, id right_ ) { - NSComparisonResult result1_ = [ left_ caseInsensitiveCompare: right_ ]; - NSComparisonResult result2_ = [ right_ caseInsensitiveCompare: left_ ]; + NSComparisonResult result1 = [ left_ caseInsensitiveCompare: right_ ]; + NSComparisonResult result2 = [ right_ caseInsensitiveCompare: left_ ]; - BOOL resultEqual_ = ( result1_ == result2_ ); - BOOL resultSame_ = ( NSOrderedSame == result2_ ); + BOOL resultEqual_ = ( result1 == result2 ); + BOOL resultSame_ = ( NSOrderedSame == result2 ); return (BOOL)( resultSame_ && resultEqual_ ); }; diff --git a/lib/JFFUtils/JFFUtilsTest/JUMutableArrayTest.m b/lib/JFFUtils/JFFUtilsTest/JUMutableArrayTest.m index 3788cb8..c2a12dd 100644 --- a/lib/JFFUtils/JFFUtilsTest/JUMutableArrayTest.m +++ b/lib/JFFUtils/JFFUtilsTest/JUMutableArrayTest.m @@ -58,10 +58,10 @@ -(void)testArrayDoesNotGrowOnShrinks -(void)testArrayShrinksCorrectly { - NSMutableArray* items_ = nil; + NSMutableArray* items = nil; { - items_ = [ @[ @"one" + items = [ @[ @"one" , @"two" , @"three" , @"four" @@ -69,18 +69,18 @@ -(void)testArrayShrinksCorrectly , @"six" , @"seven" ] mutableCopy ]; - STAssertNotNil( items_ , @"Array should be valid" ); - STAssertTrue ( 7 == [ items_ count ], @"Array should have 7 items" ); + STAssertNotNil( items , @"Array should be valid" ); + STAssertTrue ( 7 == [ items count ], @"Array should have 7 items" ); - [ items_ shrinkToSize: 3 ]; - STAssertNotNil( items_ , @"Array should be valid" ); - STAssertTrue ( 3 == [ items_ count ], @"Array should have 3 items" ); + [items shrinkToSize:3]; + STAssertNotNil( items , @"Array should be valid" ); + STAssertTrue ( 3 == [ items count ], @"Array should have 3 items" ); - STAssertTrue( [ [ items_ lastObject ] isEqualToString: @"three" ], @"Last item mismatch" ); + STAssertTrue( [ [ items lastObject ] isEqualToString: @"three" ], @"Last item mismatch" ); } { - items_ = [ @[ @"one" + items = [ @[ @"one" , @"two" , @"three" , @"four" @@ -88,14 +88,14 @@ -(void)testArrayShrinksCorrectly , @"six" , @"seven" ] mutableCopy ]; - STAssertNotNil( items_ , @"Array should be valid" ); - STAssertTrue ( 7 == [ items_ count ], @"Array should have 7 items" ); + STAssertNotNil( items , @"Array should be valid" ); + STAssertTrue ( 7 == [ items count ], @"Array should have 7 items" ); - [ items_ shrinkToSize: 5 ]; - STAssertNotNil( items_ , @"Array should be valid" ); - STAssertTrue ( 5 == [ items_ count ], @"Array should have 5 items" ); + [ items shrinkToSize: 5 ]; + STAssertNotNil( items , @"Array should be valid" ); + STAssertTrue ( 5 == [ items count ], @"Array should have 5 items" ); - STAssertTrue( [ [ items_ lastObject ] isEqualToString: @"five" ], @"Last item mismatch" ); + STAssertTrue( [ [ items lastObject ] isEqualToString: @"five" ], @"Last item mismatch" ); } } diff --git a/lib/JFFUtils/JFFUtilsTest/MethodObserverTest.h b/lib/JFFUtils/JFFUtilsTest/MethodObserverTest.h new file mode 100644 index 0000000..95b6944 --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/MethodObserverTest.h @@ -0,0 +1,5 @@ +#import + +@interface MethodObserverTest : SenTestCase + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/MethodObserverTest.m b/lib/JFFUtils/JFFUtilsTest/MethodObserverTest.m new file mode 100644 index 0000000..6f76650 --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/MethodObserverTest.m @@ -0,0 +1,1724 @@ +#import "MethodObserverTest.h" + +#import "JFFRuntimeAddiotions.h" +#import "NSObject+ObjectMethodHook.h" + +#include "JFFMemoryMgmt.h" + +#include + +@protocol TestClassToTestHooks + +@optional +- (NSString *)returnObjectForIntegerPoint2:(NSRange)point + arg:(NSUInteger)arg; + +@end + +@interface TestClassToTestHooks : NSObject + +@property (nonatomic) NSUInteger state; + +@property (nonatomic) CGPoint point; +@property (nonatomic) UIEvent *event; + +@end + +@implementation TestClassToTestHooks + +- (NSString *)returnObjectForIntegerArg:(NSUInteger)arg + point:(NSRange)point +{ + return [@(arg * _state) stringValue]; +} + +- (NSNumber *)returnObjectForIntegerPoint:(NSRange)point + arg:(NSUInteger)arg +{ + return @(arg * _state); +} + +- (NSNumber *)returnObjectForIntegerPoint:(NSRange)point + point:(NSRange)point2 +{ + return @(point.length); +} + +- (NSString *)returnObjectForArg1:(NSRange)arg1 + arg2:(CGPoint)arg2 + arg3:(float)arg3 + arg4:(double)arg4 +{ + return [[NSString alloc] initWithFormat:@"arg1: %@ arg2: %@ arg3: %f arg4: %f", + NSStringFromRange(arg1), + NSStringFromCGPoint(arg2), + arg3, + arg4 + ]; +} + +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event +{ + _point = point; + _event = event; + return YES; +} + +@end + +//Case table +//case 1 - parent has no method, child has no method +//case 2 - parent has no method, child has method +//case 3 - parent has method, child has no method +//case 3 - parent has method, child has method + +//case a - hook child, case b - hook parent + +//case 1_a - parent has no method, child has no method and hook child +@protocol ParentTestClassCase1_a + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase1_a : NSObject +@end + +@implementation ParentTestClassCase1_a +@end + +@interface ChildTestClassCase1_a : ParentTestClassCase1_a +@end + +@implementation ChildTestClassCase1_a +@end + +//case 1_b - parent has no method, child has no method and hook parent +@protocol ParentTestClassCase1_b + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase1_b : NSObject +@end + +@implementation ParentTestClassCase1_b +@end + +@interface ChildTestClassCase1_b : ParentTestClassCase1_b +@end + +@implementation ChildTestClassCase1_b +@end + +//case 2_a - parent has no method, child has method and hook child first +@protocol ParentTestClassCase2_a + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase2_a : NSObject +@end + +@implementation ParentTestClassCase2_a +@end + +@interface ChildTestClassCase2_a : ParentTestClassCase2_a +@end + +@implementation ChildTestClassCase2_a + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg) stringValue]; +} + +@end + +//case 2_b - parent has no method, child has method and hook parent first +@protocol ParentTestClassCase2_b + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase2_b : NSObject +@end + +@implementation ParentTestClassCase2_b +@end + +@interface ChildTestClassCase2_b : ParentTestClassCase2_b +@end + +@implementation ChildTestClassCase2_b + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg) stringValue]; +} + +@end + +//case 3_a - parent has method, child has no method and hook child first +@protocol ParentTestClassCase3_a + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase3_a : NSObject +@end + +@implementation ParentTestClassCase3_a + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg) stringValue]; +} + +@end + +@interface ChildTestClassCase3_a : ParentTestClassCase3_a +@end + +@implementation ChildTestClassCase3_a +@end + +//case 3_b - parent has method, child has no method and hook parent first +@protocol ParentTestClassCase3_b + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase3_b : NSObject +@end + +@implementation ParentTestClassCase3_b + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg) stringValue]; +} + +@end + +//case 4_a - parent has method, child has method and hook child first +@protocol ParentTestClassCase4_a + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase4_a : NSObject +@end + +@implementation ParentTestClassCase4_a + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg) stringValue]; +} + +@end + +@interface ChildTestClassCase4_a : ParentTestClassCase4_a +@end + +@implementation ChildTestClassCase4_a + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg*2) stringValue]; +} + +@end + +//case 4_b - parent has method, child has method and hook parent first +@protocol ParentTestClassCase4_b + +@optional +- (NSString *)returnObjectForArg:(NSUInteger)arg; + +@end + +@interface ParentTestClassCase4_b : NSObject +@end + +@implementation ParentTestClassCase4_b + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg) stringValue]; +} + +@end + +@interface ChildTestClassCase4_b : ParentTestClassCase4_b +@end + +@implementation ChildTestClassCase4_b + +- (NSString *)returnObjectForArg:(NSUInteger)arg +{ + return [@(arg*2) stringValue]; +} + +@end + +@interface SimpleHookExampleClass : NSObject + +@property (nonatomic) NSUInteger state; + +@end + +@implementation SimpleHookExampleClass + +- (NSUInteger)mutStateOnArg:(NSUInteger)arg +{ + return _state * arg; +} + +- (void)mutStateOnArgPtr:(NSUInteger *)arg str:(NSString *)str +{ + *arg = _state * *arg; +} + +@end + +@implementation MethodObserverTest + +//test method- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event +- (void)testPointInsideWithEventMethod +{ + UIEvent *originalEvent = [UIEvent new]; + CGPoint originalPoint = CGPointMake(2.f, 3.f); + __block __weak TestClassToTestHooks *weakTestObject; + + //test observing existing method + @autoreleasepool + { + __block BOOL hookWasCalled = NO; + + typedef BOOL(^BlockObserver)(id _self, CGPoint point, UIEvent *event); + + id observer = ^BlockObserver(BlockObserver(^previousImplementationGetter)(void)) { + + return ^BOOL(id _self, CGPoint point, UIEvent *event) { + + STAssertEqualObjects(NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(point), nil); + STAssertTrue(originalEvent == event, nil); + + hookWasCalled = YES; + + BlockObserver previousImplementation = previousImplementationGetter(); + + BOOL previousResult = previousImplementation(_self, point, event); + + STAssertEqualObjects(NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(weakTestObject.point), nil); + STAssertTrue(originalEvent == weakTestObject.event, nil); + + STAssertTrue(previousResult, nil); + + return NO; + }; + }; + + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(pointInside:withEvent:)]; + + BOOL result = [testObject pointInside:originalPoint withEvent:originalEvent]; + + STAssertFalse(result, nil); + + STAssertTrue(hookWasCalled, nil); + } + + //test normal call + { + @autoreleasepool + { + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + BOOL result = [testObject pointInside:originalPoint withEvent:originalEvent]; + + STAssertTrue(result, nil); + } + STAssertNil(weakTestObject, nil); + } +} + +- (void)testVoidReturnTypeCall +{ + //test observing existing method + { + __block BOOL hookWasCalled = NO; + + typedef void(^BlockObserver)(id _self, NSUInteger *arg, NSString *str); + + id observer = ^BlockObserver(BlockObserver(^previousImplementationGetter)(void)) { + + return ^void(id _self, NSUInteger *arg, NSString *str) { + + hookWasCalled = YES; + + BlockObserver previousImplementation = previousImplementationGetter(); + + previousImplementation(_self, arg, str); + + STAssertEquals((NSUInteger)24, *arg, nil); + STAssertEqualObjects(@"32", str, nil); + + *arg = 11; + }; + }; + + SimpleHookExampleClass *testObject = [SimpleHookExampleClass new]; + + testObject.state = 2; + + [testObject addMethodHook:observer + selector:@selector(mutStateOnArgPtr:str:)]; + + NSUInteger originalArg = 12; + + [testObject mutStateOnArgPtr:&originalArg str:@"32"]; + + STAssertEquals((NSUInteger)11, originalArg, nil); + + STAssertTrue(hookWasCalled, nil); + } + + //test normal call + { + NSUInteger originalArg = 10; + NSUInteger originalState = 3; + + __weak TestClassToTestHooks *weakTestObject; + @autoreleasepool + { + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + testObject.state = originalState; + + id result = [testObject returnObjectForIntegerPoint:NSMakeRange(2, 3) arg:originalArg]; + + STAssertEqualObjects(@(originalArg * originalState), result, nil); + } + STAssertNil(weakTestObject, nil); + } +} + +- (void)testSimpleExample +{ + //test observing existing method + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger originalState = 2; + + typedef NSUInteger(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousImplementationGetter)(void)) { + + return ^NSUInteger(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousImplementation = previousImplementationGetter(); + + NSUInteger previousResult = previousImplementation(_self, arg); + + STAssertEquals((NSUInteger)24, previousResult, nil); + + STAssertEquals((NSUInteger)12, arg, nil); + return 11; + }; + }; + + SimpleHookExampleClass *testObject = [SimpleHookExampleClass new]; + + testObject.state = originalState; + + [testObject addMethodHook:observer + selector:@selector(mutStateOnArg:)]; + + NSUInteger result = [testObject mutStateOnArg:originalArg]; + + STAssertEquals((NSUInteger)11, result, nil); + + STAssertTrue(hookWasCalled, nil); + } + + //test normal call + { + NSUInteger originalArg = 10; + NSUInteger originalState = 3; + + __weak id weakTestObject; + @autoreleasepool + { + SimpleHookExampleClass *testObject = [SimpleHookExampleClass new]; + weakTestObject = testObject; + + testObject.state = originalState; + + NSUInteger result = [testObject mutStateOnArg:originalArg]; + + STAssertEquals((NSUInteger)30, result, nil); + } + STAssertNil(weakTestObject, nil); + } +} + +- (void)testSignatures +{ + id block = ^NSObject *(id _self, NSUInteger arg, NSRange point) { + + return nil; + }; + + const char *methodSinature = method_getTypeEncoding(class_getInstanceMethod([TestClassToTestHooks class], @selector(returnObjectForIntegerArg:point:))); + const char *blockSinature = block_getTypeEncoding(block); + + NSMethodSignature *methodSig = [NSMethodSignature signatureWithObjCTypes:methodSinature]; + NSMethodSignature *blockSig = [NSMethodSignature signatureWithObjCTypes:blockSinature ]; + + STAssertTrue(strcmp(methodSig.methodReturnType, blockSig.methodReturnType) == 0, nil); + STAssertTrue(methodSig.numberOfArguments == blockSig.numberOfArguments, nil); + STAssertTrue(methodSig.frameLength == blockSig.frameLength, nil); + + for (NSUInteger index = 2; index < methodSig.numberOfArguments; ++index) { + + STAssertTrue(strcmp([methodSig getArgumentTypeAtIndex:index], [blockSig getArgumentTypeAtIndex:index]) == 0, @"parameter mismatch"); + } +} + +- (void)testDynamicBlockInvocation_DynamicArgumentsOrder +{ + NSRange originalRange1 = NSMakeRange(11, 12); + NSRange originalRange2 = NSMakeRange(13, 14); + + NSObject *(^block)(id _self, NSRange point, NSRange point2) = ^NSObject *(id _self, NSRange point, NSRange point2) { + + STAssertEquals(originalRange1.length, point.length, nil); + STAssertEquals(originalRange1.location, point.location, nil); + + STAssertEquals(originalRange2.length, point2.length, nil); + STAssertEquals(originalRange2.location, point2.location, nil); + + //return (__bridge NSObject *)(CFRetain((__bridge_retained CFTypeRef)@3)); + return @"12"; + }; + + NSObject *(^generalBlock)(id _self, ...) = ^NSObject *(id _self, ...) { + + va_list args; + va_start(args, _self); + + NSObject *retValue; + + const char *blockSinature = block_getTypeEncoding(block); + + invokeMethosBlockWithArgsAndReturnValue(block, + blockSinature, + NULL, + args, + &_self, + &retValue); + + va_end(args); + + return retValue; + }; + + TestClassToTestHooks *obj = [TestClassToTestHooks new]; + + const char *blockSinature = block_getTypeEncoding(block); + + class_replaceMethod([TestClassToTestHooks class], + @selector(returnObjectForIntegerPoint:point:), + imp_implementationWithBlock(generalBlock), + blockSinature); + + id result = [obj returnObjectForIntegerPoint:originalRange1 point:originalRange2]; + + STAssertEqualObjects(@"12", result, nil); +} + +//- (NSObject *)returnObjectForIntegerPoint:(NSRange)point +// arg:(NSUInteger)arg +//{ +// return @(arg); +//} + +//TODO fix number types + +- (void)testHookExistedMethodWithLotOfArgs +{ + //test observing existing method + __block BOOL hookWasCalled = NO; + + NSUInteger originalState = 2; + + typedef NSObject *(^BlockObserver)(id _self, NSRange arg1, CGPoint arg2, float arg3, double arg4); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSRange arg1, CGPoint arg2, float arg3, double arg4) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg1, arg2, arg3, arg4); + + STAssertEqualObjects(@"arg1: {7, 8} arg2: {4.5, 6.7} arg3: 3.200000 arg4: 2.300000", previousResult, nil); + } + + return @"1"; + }; + }; + + __weak TestClassToTestHooks *weakTestObject; + @autoreleasepool + { + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + testObject.state = originalState; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg1:arg2:arg3:arg4:)]; + + id result = [testObject returnObjectForArg1:NSMakeRange(7, 8) + arg2:CGPointMake(4.5, 6.7) + arg3:3.2 + arg4:2.3]; + + STAssertEqualObjects(@"1", result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); +} + +- (void)testHookExistedMethodWithObjectPointerReturnType +{ + //test observing existing method + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger originalState = 2; + + typedef NSObject *(^BlockObserver)(id _self, NSRange point, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSRange point, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, point, arg); + + STAssertEqualObjects(@(originalArg * originalState), previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return @(originalArg); + }; + }; + + __weak TestClassToTestHooks *weakTestObject; + @autoreleasepool + { + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + testObject.state = originalState; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForIntegerPoint:arg:)]; + + id result = [testObject returnObjectForIntegerPoint:NSMakeRange(2, 3) arg:originalArg]; + + STAssertEqualObjects(@(originalArg), result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + //test normal call + { + NSUInteger originalArg = 10; + NSUInteger originalState = 3; + + __weak TestClassToTestHooks *weakTestObject; + @autoreleasepool + { + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + testObject.state = originalState; + + id result = [testObject returnObjectForIntegerPoint:NSMakeRange(2, 3) arg:originalArg]; + + STAssertEqualObjects(@(originalArg * originalState), result, nil); + } + STAssertNil(weakTestObject, nil); + } +} + +- (void)testHookNotExistedMethodWithObjectPointerReturnType +{ + //test observing not existing method + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSRange point, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSRange point, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + STAssertNil(previousBlock, @"no original method"); + + STAssertEquals(originalArg, arg, nil); + return [@(originalArg) stringValue]; + }; + }; + + __weak TestClassToTestHooks *weakTestObject; + @autoreleasepool + { + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForIntegerPoint2:arg:)]; + + id result = [testObject returnObjectForIntegerPoint2:NSMakeRange(2, 3) arg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + //test normal call + { + NSUInteger originalArg = 10; + NSUInteger originalState = 3; + + __weak TestClassToTestHooks *weakTestObject; + @autoreleasepool + { + TestClassToTestHooks *testObject = [TestClassToTestHooks new]; + weakTestObject = testObject; + + testObject.state = originalState; + + //todo fix? + STAssertTrue([testObject respondsToSelector:@selector(returnObjectForIntegerPoint2:arg:)], nil); + + STAssertThrows({ + + [testObject returnObjectForIntegerPoint2:NSMakeRange(2, 3) arg:originalArg]; + }, nil); + + //STAssertEqualObjects([@(originalArg * originalState) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } +} + +//case 1_a - c - parent has no method, child has no method and hook child +- (void)testCase1_a +{ + //test observing not existing method + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + STAssertNil(previousBlock, @"no original method"); + + STAssertEquals(originalArg, arg, nil); + return [@(originalArg) stringValue]; + }; + }; + + __weak ChildTestClassCase1_a *weakTestObject; + @autoreleasepool + { + ChildTestClassCase1_a *testObject = [ChildTestClassCase1_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + //test normal call for child + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase1_a *testObject = [ChildTestClassCase1_a new]; + weakTestObject = testObject; + + //todo fix? + STAssertTrue([testObject respondsToSelector:@selector(returnObjectForArg:)], nil); + + STAssertThrows({ + + [testObject returnObjectForArg:originalArg]; + }, nil); + + //STAssertEqualObjects([@(originalArg * originalState) stringValue], result, nil); + } + } + + //test normal call for child + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase1_a *testObject = [ParentTestClassCase1_a new]; + weakTestObject = testObject; + + STAssertFalse([testObject respondsToSelector:@selector(returnObjectForArg:)], nil); + + STAssertThrows({ + + [testObject returnObjectForArg:originalArg]; + }, nil); + + //STAssertEqualObjects([@(originalArg * originalState) stringValue], result, nil); + } + } +} + +//case 1_b - c - parent has no method, child has no method and hook parent +- (void)testCase1_b +{ + //test observing not existing method + JFFSimpleBlock hookTest = ^() + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + STAssertNil(previousBlock, @"no original method"); + + STAssertEquals(originalArg, arg, nil); + return [@(originalArg) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase1_b *testObject = [ParentTestClassCase1_b new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + }; + + hookTest(); + hookTest(); + + //test normal call for child + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase1_b *testObject = [ChildTestClassCase1_b new]; + weakTestObject = testObject; + + //todo fix? + STAssertTrue([testObject respondsToSelector:@selector(returnObjectForArg:)], nil); + + STAssertThrows({ + + [testObject returnObjectForArg:originalArg]; + }, nil); + } + } + + //test normal call for child + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase1_b *testObject = [ParentTestClassCase1_b new]; + weakTestObject = testObject; + + //todo fix? + STAssertTrue([testObject respondsToSelector:@selector(returnObjectForArg:)], nil); + + STAssertThrows({ + + [testObject returnObjectForArg:originalArg]; + }, nil); + } + } +} + +//case 2_a - parent has no method, child has method and hook child first +- (void)testCase2_a +{ + //test observing existing method + JFFSimpleBlock firstHookTest = ^() + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger internalResult = 100; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(internalResult) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase2_a *testObject = [ChildTestClassCase2_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(internalResult) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + }; + firstHookTest(); + + //test normal call + { + NSUInteger originalArg = 10; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase2_a *testObject = [ChildTestClassCase2_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + //test normal call + { + NSUInteger originalArg = 10; + + __weak ParentTestClassCase2_a *weakTestObject; + @autoreleasepool + { + ParentTestClassCase2_a *testObject = [ParentTestClassCase2_a new]; + weakTestObject = testObject; + + STAssertThrows({ + + [testObject returnObjectForArg:originalArg]; + }, nil); + } + STAssertNil(weakTestObject, nil); + } + + //hook parent + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + STAssertNil(previousBlock, nil); + + STAssertEquals(originalArg, arg, nil); + return [@(arg) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase2_a *testObject = [ParentTestClassCase2_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + firstHookTest(); +} + +//case 2_b - parent has no method, child has method and hook parent first +- (void)testCase2_b +{ + //test observing existing method + JFFSimpleBlock firstHookTest = ^() + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger internalResult = 100; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + STAssertNil(previousBlock, nil); + + STAssertEquals(originalArg, arg, nil); + return [@(internalResult) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase2_a *testObject = [ParentTestClassCase2_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(internalResult) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + }; + firstHookTest(); + + //test normal call + { + NSUInteger originalArg = 10; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase2_a *testObject = [ChildTestClassCase2_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + //test normal call + { + NSUInteger originalArg = 10; + + __weak ParentTestClassCase2_a *weakTestObject; + @autoreleasepool + { + ParentTestClassCase2_a *testObject = [ParentTestClassCase2_a new]; + weakTestObject = testObject; + + STAssertThrows({ + + [testObject returnObjectForArg:originalArg]; + }, nil); + } + STAssertNil(weakTestObject, nil); + } + + //hook child + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(arg) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase2_a *testObject = [ChildTestClassCase2_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + firstHookTest(); +} + +//case 3_a - parent has method, child has no method and hook child first +- (void)testCase3_a +{ + //test observing existing method + JFFSimpleBlock firstHookTest = ^() + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger internalResult = 100; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(internalResult) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase3_a *testObject = [ChildTestClassCase3_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(internalResult) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + }; + firstHookTest(); + + //test normal call + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase3_a *testObject = [ChildTestClassCase3_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + //test normal call + { + NSUInteger originalArg = 10; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase3_a *testObject = [ParentTestClassCase3_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + + //hook parent + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(arg) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase3_a *testObject = [ParentTestClassCase3_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + firstHookTest(); +} + +//case 3_b - parent has method, child has no method and hook parent first +- (void)testCase3_b +{ + //test observing existing method + JFFSimpleBlock firstHookTest = ^() + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger internalResult = 100; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(internalResult) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase3_a *testObject = [ParentTestClassCase3_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(internalResult) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + }; + firstHookTest(); + + //test normal call + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase3_a *testObject = [ChildTestClassCase3_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + //test normal call + { + NSUInteger originalArg = 10; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase3_a *testObject = [ParentTestClassCase3_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + + //hook parent + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(arg) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase3_a *testObject = [ChildTestClassCase3_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + firstHookTest(); +} + +//case 4_a - parent has method, child has method and hook child first +- (void)testCase4_a +{ + //test observing existing method + JFFSimpleBlock firstHookTest = ^() + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger internalResult = 100; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg * 2) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(internalResult) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase4_a *testObject = [ChildTestClassCase4_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(internalResult) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + }; + firstHookTest(); + + //test normal call + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase4_a *testObject = [ChildTestClassCase4_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg * 2) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + //test normal call + { + NSUInteger originalArg = 10; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase4_a *testObject = [ParentTestClassCase4_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + + //hook child + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(arg) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase4_a *testObject = [ParentTestClassCase4_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + firstHookTest(); +} + +//case 4_b - parent has method, child has method and hook parent first +- (void)testCase4_b +{ + //test observing existing method + JFFSimpleBlock firstHookTest = ^() + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 12; + NSUInteger internalResult = 100; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(internalResult) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase4_a *testObject = [ParentTestClassCase4_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(internalResult) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + }; + firstHookTest(); + + //test normal call + { + NSUInteger originalArg = 11; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase4_a *testObject = [ChildTestClassCase4_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg * 2) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + //test normal call + { + NSUInteger originalArg = 10; + + __weak id weakTestObject; + @autoreleasepool + { + ParentTestClassCase4_a *testObject = [ParentTestClassCase4_a new]; + weakTestObject = testObject; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + STAssertNil(weakTestObject, nil); + } + + //hook child + { + __block BOOL hookWasCalled = NO; + + NSUInteger originalArg = 13; + + typedef NSObject *(^BlockObserver)(id _self, NSUInteger arg); + + id observer = ^BlockObserver(BlockObserver(^previousBlockGetter)(void)) { + + return ^NSObject *(id _self, NSUInteger arg) { + + hookWasCalled = YES; + + BlockObserver previousBlock = previousBlockGetter(); + + { + id previousResult = previousBlock(_self, arg); + + STAssertEqualObjects([@(originalArg * 2) stringValue], previousResult, nil); + } + + STAssertEquals(originalArg, arg, nil); + return [@(arg) stringValue]; + }; + }; + + __weak id weakTestObject; + @autoreleasepool + { + ChildTestClassCase4_a *testObject = [ChildTestClassCase4_a new]; + weakTestObject = testObject; + + [testObject addMethodHook:observer + selector:@selector(returnObjectForArg:)]; + + id result = [testObject returnObjectForArg:originalArg]; + + STAssertEqualObjects([@(originalArg) stringValue], result, nil); + } + + STAssertNil(weakTestObject, nil); + STAssertTrue(hookWasCalled, nil); + } + + firstHookTest(); +} + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/NSObjectRuntimeExtensionsTest.m b/lib/JFFUtils/JFFUtilsTest/NSObjectRuntimeExtensionsTest.m index b1d089d..abe0064 100644 --- a/lib/JFFUtils/JFFUtilsTest/NSObjectRuntimeExtensionsTest.m +++ b/lib/JFFUtils/JFFUtilsTest/NSObjectRuntimeExtensionsTest.m @@ -2,8 +2,8 @@ #include -static const NSUInteger testClassMethodResult_ = 34;//just rendomize number -static const NSUInteger testInstanceMethodResult_ = 35;//just rendomize number +static const NSUInteger testClassMethodResult_ = 34;//just rendomize number +static const NSUInteger testInstanceMethodResult = 35;//just rendomize number @interface NSTestClass : NSObject @end @@ -27,7 +27,7 @@ + (NSUInteger)classMethodWithLongNameForUniquenessPurposes - (NSUInteger)instanceMethodWithLongNameForUniquenessPurposes { - return testInstanceMethodResult_; + return testInstanceMethodResult; } @end @@ -54,7 +54,7 @@ + (NSUInteger)classMethodWithLongNameForUniquenessPurposes - (NSUInteger)instanceMethodWithLongNameForUniquenessPurposes { - return testInstanceMethodResult_; + return testInstanceMethodResult; } @end @@ -145,7 +145,7 @@ -(void)testHookInstanceMethod NSTestClass* instance_ = [ NSTestClass new ]; - STAssertEquals( testInstanceMethodResult_ + STAssertEquals( testInstanceMethodResult , [ instance_ instanceMethodWithLongNameForUniquenessPurposes ] , @"result mismatch" ); @@ -154,7 +154,7 @@ -(void)testHookInstanceMethod prototypeMethodSelector: @selector( prototypeMethod ) hookMethodSelector: @selector( hookMethod ) ]; - STAssertEquals( testInstanceMethodResult_ * 2 + STAssertEquals( testInstanceMethodResult * 2 , [ instance_ instanceMethodWithLongNameForUniquenessPurposes ] , @"result mismatch" ); } @@ -245,26 +245,26 @@ -(void)testAddClassMethodIfNeedWithSelector -(void)testAddInstanceMethodIfNeedWithSelector { - static BOOL firstTestRun_ = YES; + static BOOL firstTestRun = YES; - if ( firstTestRun_ ) - { - SEL newMethodSelector_ = @selector( instanceMethodWithLongNameForUniquenessPurposes2 ); - SEL selector_ = @selector( instanceMethodWithLongNameForUniquenessPurposes ); - BOOL result_ = [ NSTestClass addInstanceMethodIfNeedWithSelector: selector_ - toClass: [ NSTestClass class ] - newMethodSelector: newMethodSelector_ ]; + if (firstTestRun) { - STAssertTrue( result_, @"method added" ); + SEL newMethodSelector = @selector(instanceMethodWithLongNameForUniquenessPurposes2); + SEL selector = @selector(instanceMethodWithLongNameForUniquenessPurposes); + BOOL result = [NSTestClass addInstanceMethodIfNeedWithSelector:selector + toClass:[NSTestClass class] + newMethodSelector:newMethodSelector]; - STAssertTrue( [ NSTestClass hasInstanceMethodWithSelector: newMethodSelector_ ] + STAssertTrue(result, @"method added"); + + STAssertTrue( [ NSTestClass hasInstanceMethodWithSelector:newMethodSelector] , @"NSTestClass has instanceMethodWithLongNameForUniquenessPurposes2 method" ); - NSTestClass* instance_ = [ NSTestClass new ]; - NSUInteger method_result_ = (NSUInteger)objc_msgSend( instance_, newMethodSelector_ ); - STAssertTrue( testInstanceMethodResult_ == method_result_, @"check implementation of new method" ); + NSTestClass *instance = [NSTestClass new]; + NSUInteger methodResult = (NSUInteger)objc_msgSend(instance, newMethodSelector); + STAssertTrue(testInstanceMethodResult == methodResult, @"check implementation of new method" ); - firstTestRun_ = NO; + firstTestRun = NO; } } @@ -277,7 +277,7 @@ -(void)testTwiceHookInstanceMethod NSTwiceTestClass* instance_ = [ NSTwiceTestClass new ]; - STAssertEquals( testInstanceMethodResult_ + STAssertEquals( testInstanceMethodResult , [ instance_ instanceMethodWithLongNameForUniquenessPurposes ] , @"result mismatch" ); @@ -286,16 +286,16 @@ -(void)testTwiceHookInstanceMethod prototypeMethodSelector: @selector( twicePrototypeMethod ) hookMethodSelector: @selector( twiceHookMethod ) ]; - STAssertEquals( testInstanceMethodResult_ * 2 + STAssertEquals( testInstanceMethodResult * 2 , [ instance_ instanceMethodWithLongNameForUniquenessPurposes ] , @"result mismatch" ); STAssertThrows( { - [ [ TwiceHookMethodsClass class ] hookInstanceMethodForClass: [ NSTwiceTestClass class ] - withSelector: @selector( instanceMethodWithLongNameForUniquenessPurposes ) - prototypeMethodSelector: @selector( twicePrototypeMethod ) - hookMethodSelector: @selector( twiceHookMethod ) ]; - }, @"twice hook forbidden" ); + [ [ TwiceHookMethodsClass class ] hookInstanceMethodForClass: [ NSTwiceTestClass class ] + withSelector: @selector( instanceMethodWithLongNameForUniquenessPurposes ) + prototypeMethodSelector: @selector( twicePrototypeMethod ) + hookMethodSelector: @selector( twiceHookMethod ) ]; + }, @"twice hook forbidden" ); } -(void)testTwiceHookClassMethod diff --git a/lib/JFFUtils/JFFUtilsTest/StringFromTemplateString.h b/lib/JFFUtils/JFFUtilsTest/StringFromTemplateString.h new file mode 100644 index 0000000..ea05c64 --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/StringFromTemplateString.h @@ -0,0 +1,5 @@ +#import + +@interface StringFromTemplateString : SenTestCase + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/StringFromTemplateString.m b/lib/JFFUtils/JFFUtilsTest/StringFromTemplateString.m new file mode 100644 index 0000000..e026375 --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/StringFromTemplateString.m @@ -0,0 +1,78 @@ +#import "StringFromTemplateString.h" + +@implementation StringFromTemplateString + +- (void)testStringFromTemplateString +{ + { + NSString *templateString = @"${monthCount} months for ${price}/month"; + + NSString *resultString = [templateString localizedTemplateStringWithVariables: + @{ + @"monthCount" : @3, + @"price" : @"$23", + }]; + + STAssertEqualObjects(@"3 months for $23/month", resultString, nil); + } + + { + NSString *templateString = @"${price} months for ${monthCount}/month"; + + NSString *resultString = [templateString localizedTemplateStringWithVariables: + @{ + @"monthCount" : @3, + @"price" : @"$23", + }]; + + STAssertEqualObjects(@"$23 months for 3/month", resultString, nil); + } + + { + NSString *templateString = @"cc ${monthCount} months for ${price}"; + + NSString *resultString = [templateString localizedTemplateStringWithVariables: + @{ + @"monthCount" : @3, + @"price" : @"$23", + }]; + + STAssertEqualObjects(@"cc 3 months for $23", resultString, nil); + } + + { + NSString *templateString = @"${monthCount}${price}"; + + NSString *resultString = [templateString localizedTemplateStringWithVariables: + @{ + @"monthCount" : @3, + @"price" : @"$23", + }]; + + STAssertEqualObjects(@"3$23", resultString, nil); + } + + { + NSString *templateString = @"${monthCount"; + + NSString *resultString = [templateString localizedTemplateStringWithVariables: + @{ + @"monthCount" : @3, + }]; + + STAssertEqualObjects(@"${monthCount", resultString, nil); + } + + { + NSString *templateString = @"${monthCount}"; + + NSString *resultString = [templateString localizedTemplateStringWithVariables: + @{ + @"monthCount2" : @3, + }]; + + STAssertEqualObjects(@"${monthCount}", resultString, nil); + } +} + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/TypeSignatureTest.h b/lib/JFFUtils/JFFUtilsTest/TypeSignatureTest.h new file mode 100644 index 0000000..6e08bb6 --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/TypeSignatureTest.h @@ -0,0 +1,5 @@ +#import + +@interface TypeSignatureTest : SenTestCase + +@end diff --git a/lib/JFFUtils/JFFUtilsTest/TypeSignatureTest.m b/lib/JFFUtils/JFFUtilsTest/TypeSignatureTest.m new file mode 100644 index 0000000..cd98e6a --- /dev/null +++ b/lib/JFFUtils/JFFUtilsTest/TypeSignatureTest.m @@ -0,0 +1,159 @@ +#import "TypeSignatureTest.h" + +#include "JFFRuntimeAddiotions.h" + +@implementation TypeSignatureTest + +static NSArray *typeEncodingOffsets(const char *signature) +{ + NSCParameterAssert(signature != NULL); + + NSMutableArray *result = [NSMutableArray new]; + + while (strlen(signature) != 0) { + + signature = NSGetSizeAndAlignment(signature, NULL, NULL); + + if (strlen(signature) == 0) + break; + + long long value; + sscanf(signature, "%lld", &value); + + [result addObject:@(value)]; + } + + return result; +} + +- (void)testGetReturnType +{ + const char *typeSignatureScanFormat = "%[@^vcI]"; + + //"NSObject *" return type + { + id block = ^NSObject *(id _self, NSUInteger arg, CGPoint point) { + + return nil; + }; + [block description]; + + const char *sinature = "@20@?0@4I8{CGPoint=ff}12"; + //block_getTypeEncoding(block); + + NSMethodSignature *sig = [NSMethodSignature signatureWithObjCTypes:sinature]; + + char returnType[strlen(sinature) + 1]; + sscanf(sinature, typeSignatureScanFormat, returnType); + + STAssertTrue(strcmp(returnType, sig.methodReturnType) == 0, nil); + } + + //"void *" return type + { + id block = ^void *(id _self, NSUInteger arg, CGPoint point) { + + return nil; + }; + [block description]; + + const char *sinature = "^v20@?0@4I8{CGPoint=ff}12"; + //block_getTypeEncoding(block); + + NSMethodSignature *sig = [NSMethodSignature signatureWithObjCTypes:sinature]; + + char returnType[strlen(sinature) + 1]; + sscanf(sinature, typeSignatureScanFormat, returnType); + + STAssertTrue(strcmp(returnType, sig.methodReturnType) == 0, nil); + } + + //"BOOL" return type + { + id block = ^BOOL(id _self, NSUInteger arg, CGPoint point) { + + return YES; + }; + [block description]; + + const char *sinature = "c20@?0@4I8{CGPoint=ff}12"; + //block_getTypeEncoding(block); + + NSMethodSignature *sig = [NSMethodSignature signatureWithObjCTypes:sinature]; + + char returnType[strlen(sinature) + 1]; + sscanf(sinature, typeSignatureScanFormat, returnType); + + STAssertTrue(strcmp(returnType, sig.methodReturnType) == 0, nil); + } + + //"NSUInteger" return type + { + id block = ^NSUInteger(id _self, NSUInteger arg, CGPoint point) { + + return 1; + }; + [block description]; + + const char *sinature = "I20@?0@4I8{CGPoint=ff}12"; + +// NSLog(@"sinature: %s", sinature); + + NSMethodSignature *sig = [NSMethodSignature signatureWithObjCTypes:sinature]; + + char returnType[strlen(sinature) + 1]; + sscanf(sinature, typeSignatureScanFormat, returnType); + +// NSLog(@"ret1: %s", returnType); +// NSLog(@"ret2: %s", sig.methodReturnType); + + STAssertTrue(strcmp(returnType, sig.methodReturnType) == 0, nil); + } +} + +- (void)testGetOffsets +{ + { + id block = ^NSObject *(id _self, NSUInteger arg, CGPoint point) { + + return nil; + }; + [block description]; + const char *sinature = "@20@?0@4I8{CGPoint=ff}12"; + //block_getTypeEncoding(block); + + NSArray *arr = @[@20, @0, @4, @8, @12]; + + STAssertEqualObjects(arr, typeEncodingOffsets(sinature), nil); + } + + { + id block = ^NSNumber *(id _self, float arg) { + + return nil; + }; + [block description]; + const char *sinature = "@12@?0@4f8";//block_getTypeEncoding(block); + //block_getTypeEncoding(block); + + NSArray *arr = @[@12, @0, @4, @8]; + + STAssertEqualObjects(arr, typeEncodingOffsets(sinature), nil); + } + + { + id block = ^(id _self, NSUInteger arg, CGPoint point) { + + return nil; + }; + [block description]; + const char *sinature = "^v20@?0@4I8{CGPoint=ff}12";//block_getTypeEncoding(block); + NSLog(@"blockSinature: %s", sinature); + + NSArray *arr = @[@20, @0, @4, @8, @12]; + + STAssertEqualObjects(arr, typeEncodingOffsets(sinature), nil); + } +} + +@end diff --git a/lib/JFFUtils/JGCDAdditions.mm b/lib/JFFUtils/JGCDAdditions.mm index c9af495..badca47 100644 --- a/lib/JFFUtils/JGCDAdditions.mm +++ b/lib/JFFUtils/JGCDAdditions.mm @@ -3,6 +3,9 @@ #include #include +#include +#include + static std::map dispatchByLabel; static NSString *const lockObject = @"0524a0b0-4bc8-47da-a1f5-6073ba5b59d9"; @@ -42,14 +45,7 @@ dispatch_queue_t dispatch_queue_get_or_create(const char *label, dispatch_queue_ void dispatch_queue_release_by_label(const char *label) { @synchronized(lockObject) { - const std::string labelStr(label); - auto position = dispatchByLabel.find(labelStr); - if (position != dispatchByLabel.end()) { - dispatch_queue_t queue = position->second; - dispatch_release(queue); - - dispatchByLabel.erase(position); - } + dispatchByLabel.erase(label); } } diff --git a/lib/JFFUtils/MemoryManagement/JFFRuntimeInitializer.m b/lib/JFFUtils/MemoryManagement/JFFRuntimeInitializer.m index 4629eac..288e5f7 100755 --- a/lib/JFFUtils/MemoryManagement/JFFRuntimeInitializer.m +++ b/lib/JFFUtils/MemoryManagement/JFFRuntimeInitializer.m @@ -10,24 +10,24 @@ @interface JFFRuntimeInitializer : NSObject @implementation JFFRuntimeInitializer --(void)deallocRemoveAssociatedObjectsHook +- (void)deallocRemoveAssociatedObjectsHook { - [ self doesNotRecognizeSelector: _cmd ]; + [self doesNotRecognizeSelector:_cmd]; } --(void)deallocRemoveAssociatedObjectsPrototype +- (void)deallocRemoveAssociatedObjectsPrototype { - objc_removeAssociatedObjects( self ); - - [ self deallocRemoveAssociatedObjectsHook ]; + objc_removeAssociatedObjects(self); + + [self deallocRemoveAssociatedObjectsHook]; } -+(void)load ++ (void)load { - [ self hookInstanceMethodForClass: [ NSObject class ] - withSelector: @selector( dealloc ) - prototypeMethodSelector: @selector( deallocRemoveAssociatedObjectsPrototype ) - hookMethodSelector: @selector( deallocRemoveAssociatedObjectsHook ) ]; + [self hookInstanceMethodForClass:[NSObject class] + withSelector:@selector(dealloc) + prototypeMethodSelector:@selector(deallocRemoveAssociatedObjectsPrototype) + hookMethodSelector:@selector(deallocRemoveAssociatedObjectsHook)]; } @end diff --git a/lib/JFFUtils/NSArray/JUArrayHelperBlocks.h b/lib/JFFUtils/NSArray/JUArrayHelperBlocks.h deleted file mode 100644 index 2eabb4b..0000000 --- a/lib/JFFUtils/NSArray/JUArrayHelperBlocks.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __JU_ARRAY_HELPER_BLOCKS_H__ -#define __JU_ARRAY_HELPER_BLOCKS_H__ - -#import - -#import - -typedef void (^JFFActionBlock)( id object_ ); -typedef id (^JFFMappingBlock)( id object_ ); -typedef id (^JFFMappingWithErrorBlock)( id object_, NSError** outError_ ); -typedef void (^JFFMappingDictBlock)( id object_, id* key_, id* value_ ); -typedef id (^JFFProducerBlock)( NSUInteger index_ ); -typedef NSArray* (^JFFFlattenBlock)( id object_ ); - -typedef void (^JFFTransformBlock)( id first_object_, id second_object_ ); -typedef BOOL (^JFFEqualityCheckerBlock)( id first_object_, id second_object_ ); - -#endif //__JU_ARRAY_HELPER_BLOCKS_H__ diff --git a/lib/JFFUtils/NSArray/NSArray+ArrayByRemovingObject.h b/lib/JFFUtils/NSArray/NSArray+ArrayByRemovingObject.h new file mode 100644 index 0000000..51743a8 --- /dev/null +++ b/lib/JFFUtils/NSArray/NSArray+ArrayByRemovingObject.h @@ -0,0 +1,9 @@ +#import + +@interface NSArray (ArrayByRemovingObject) + +- (instancetype)arrayByRemovingObjectAtIndex:(NSUInteger)index; + +- (instancetype)arrayByRemovingObject:(id)objectToRemove; + +@end diff --git a/lib/JFFUtils/NSArray/NSArray+ArrayByRemovingObject.m b/lib/JFFUtils/NSArray/NSArray+ArrayByRemovingObject.m new file mode 100644 index 0000000..529a332 --- /dev/null +++ b/lib/JFFUtils/NSArray/NSArray+ArrayByRemovingObject.m @@ -0,0 +1,22 @@ +#import "NSArray+ArrayByRemovingObject.h" + +#import "NSArray+BlocksAdditions.h" + +@implementation NSArray (ArrayByRemovingObject) + +- (instancetype)arrayByRemovingObjectAtIndex:(NSUInteger)index +{ + id objectToRemove = self[index]; + + return [self arrayByRemovingObject:objectToRemove]; +} + +- (instancetype)arrayByRemovingObject:(id)objectToRemove +{ + return [self select:^BOOL(id object) { + + return objectToRemove != object; + }]; +} + +@end diff --git a/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.h b/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.h index d8f9087..5d25082 100644 --- a/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.h +++ b/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.h @@ -8,51 +8,52 @@ #pragma mark BlocksAdditions //Calls block once for number from 0(zero) to (size_ - 1) //Creates a new NSArray containing the values returned by the block. -+ (id)arrayWithSize:(NSUInteger)size - producer:(JFFProducerBlock)block; ++ (instancetype)arrayWithSize:(NSUInteger)size + producer:(JFFProducerBlock)block; //Calls block once for number from 0(zero) to (size_ - 1) //Creates a new NSArray containing the values returned by the block. -+ (id)arrayWithCapacity:(NSUInteger)size - ignoringNilsProducer:(JFFProducerBlock)block; ++ (instancetype)arrayWithCapacity:(NSUInteger)size + ignoringNilsProducer:(JFFProducerBlock)block; //Calls block once for each element in self, passing that element as a parameter. - (void)each:(JFFActionBlock)block; //Invokes block once for each element of self. //Creates a new NSArray containing the values returned by the block. -- (NSArray*)map:(JFFMappingBlock)block; +- (instancetype)map:(JFFMappingBlock)block; //Invokes block once for each element of self. //Creates a new NSArray containing the values returned by the block. //if error happens it is suppressed -- (NSArray*)forceMap:(JFFMappingBlock)block; +- (instancetype)forceMap:(JFFMappingBlock)block; //Invokes block once for each element of self. //Creates a new NSArray containing the values returned by the block. //or return nil if error happens --(NSArray*)map:( JFFMappingWithErrorBlock )block_ error:( NSError** )outError_; --(NSArray*)mapIgnoringNilError:( JFFMappingWithErrorBlock )block_ error:( NSError** )outError_; +- (instancetype)map:(JFFMappingWithErrorBlock)block + error:(NSError *__autoreleasing *)outError; +- (instancetype)mapIgnoringNilError:(JFFMappingWithErrorBlock)block error:(NSError **)outError; //Invokes block once for each element of self. //Creates a new NSArray containing the values returned by the block. Passes index of element in block as argument. //or return nil if error happens -- (NSArray*)mapWithIndex:(JFFMappingWithErrorAndIndexBlock)block - error:(NSError *__autoreleasing *)outError; +- (instancetype)mapWithIndex:(JFFMappingWithErrorAndIndexBlock)block + error:(NSError *__autoreleasing *)outError; //Invokes block once for each element of self. //Creates a new NSDictionary containing the values and keys returned by the block. -- (NSDictionary*)mapDict:(JFFMappingDictBlock)block; +- (NSDictionary *)mapDict:(JFFMappingDictBlock)block; //Invokes the block passing in successive elements from self, //Creates a new NSArray containing those elements for which the block returns a YES value -- (NSArray*)select:(JFFPredicateBlock)predicate; +- (instancetype)select:(JFFPredicateBlock)predicate; -- (NSArray*)selectWithIndex:(JFFPredicateWithIndexBlock)predicate; +- (instancetype)selectWithIndex:(JFFPredicateWithIndexBlock)predicate; //Invokes the block passing in successive elements from self, //Creates a new NSArray containing all elements of all arrays returned the block -- (NSArray*)flatten:(JFFFlattenBlock)block; +- (instancetype)flatten:(JFFFlattenBlock)block; //Invokes the block passing in successive elements from self, //returning a count of those elements for which the block returns a YES value @@ -62,6 +63,10 @@ //returning the first element for which the block returns a YES value - (id)firstMatch:(JFFPredicateBlock)predicate; +//Invokes the block passing in successive elements from self, +//returning the last element for which the block returns a YES value +- (id)lastMatch:(JFFPredicateBlock)predicate; + - (NSUInteger)firstIndexOfObjectMatch:(JFFPredicateBlock)predicate; //Invokes the block passing parallel in successive elements from self and other NSArray, @@ -69,8 +74,8 @@ withBlock:(JFFTransformBlock)block; //Invokes the block passing parallel in successive elements from self and other NSArray, -- (NSArray*)devideIntoArrayWithSize:(NSUInteger)size - elementIndexBlock:(JFFElementIndexBlock)block; +- (instancetype)devideIntoArrayWithSize:(NSUInteger)size + elementIndexBlock:(JFFElementIndexBlock)block; - (BOOL)any:(JFFPredicateBlock)predicate; diff --git a/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.m b/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.m index e8c4f46..9015816 100644 --- a/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.m +++ b/lib/JFFUtils/NSArray/NSArray+BlocksAdditions.m @@ -4,7 +4,7 @@ @implementation NSMutableArray (BlocksAdditions) -+ (id)converToCurrentTypeMutableArray:(NSMutableArray *)array ++ (instancetype)converToCurrentTypeMutableArray:(NSMutableArray *)array { return array; } @@ -13,34 +13,34 @@ + (id)converToCurrentTypeMutableArray:(NSMutableArray *)array @implementation NSArray (BlocksAdditions) -+ (id)converToCurrentTypeMutableArray:(NSMutableArray *)array ++ (instancetype)converToCurrentTypeMutableArray:(NSMutableArray *)array { return [array copy]; } -+ (id)arrayWithSize:(NSUInteger)size - producer:(JFFProducerBlock)block ++ (instancetype)arrayWithSize:(NSUInteger)size + producer:(JFFProducerBlock)block { NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:size]; - - for ( NSUInteger index = 0; index < size; ++index ) { + + for (NSUInteger index = 0; index < size; ++index) { [result addObject:block(index)]; } - + return [self converToCurrentTypeMutableArray:result]; } -+ (id)arrayWithCapacity:(NSUInteger)capacity - ignoringNilsProducer:(JFFProducerBlock)block ++ (instancetype)arrayWithCapacity:(NSUInteger)capacity + ignoringNilsProducer:(JFFProducerBlock)block { - NSMutableArray* result = [[NSMutableArray alloc] initWithCapacity:capacity]; - - for ( NSUInteger index = 0; index < capacity; ++index ) { + NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:capacity]; + + for (NSUInteger index = 0; index < capacity; ++index) { id object = block(index); if (object) [result addObject:object]; } - + return [self converToCurrentTypeMutableArray:result]; } @@ -51,14 +51,14 @@ - (void)each:(JFFActionBlock)block }]; } -- (NSArray *)select:(JFFPredicateBlock)predicate +- (instancetype)select:(JFFPredicateBlock)predicate { return [self selectWithIndex:^(id obj, NSUInteger idx) { return predicate(obj); }]; } -- (NSArray *)selectWithIndex:(JFFPredicateWithIndexBlock)predicate +- (instancetype)selectWithIndex:(JFFPredicateWithIndexBlock)predicate { NSIndexSet *indexes = [self indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { return predicate(obj, idx); @@ -66,7 +66,7 @@ - (NSArray *)selectWithIndex:(JFFPredicateWithIndexBlock)predicate return [self objectsAtIndexes:indexes]; } -- (NSArray *)map:(JFFMappingBlock)block +- (instancetype)map:(JFFMappingBlock)block { NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[self count]]; @@ -79,7 +79,7 @@ - (NSArray *)map:(JFFMappingBlock)block return [result copy]; } -- (NSArray *)map:(JFFMappingWithErrorBlock)block error:(NSError **)outError +- (instancetype)map:(JFFMappingWithErrorBlock)block error:(NSError **)outError { NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[self count]]; @@ -95,29 +95,25 @@ - (NSArray *)map:(JFFMappingWithErrorBlock)block error:(NSError **)outError return [result copy]; } - --(NSArray*)mapIgnoringNilError:( JFFMappingWithErrorBlock )block_ error:( NSError** )outError_ +- (instancetype)mapIgnoringNilError:(JFFMappingWithErrorBlock)block_ error:(NSError **)outError_ { - NSParameterAssert( NULL != outError_ ); - NSMutableArray* result_ = [ [ NSMutableArray alloc ] initWithCapacity: [ self count ] ]; - - for ( id object_ in self ) - { - id newObject_ = block_( object_, outError_ ); - if ( newObject_ ) - { - [ result_ addObject: newObject_ ]; - } - else if ( nil != *outError_ ) - { + NSParameterAssert(NULL != outError_); + NSMutableArray *result_ = [[NSMutableArray alloc] initWithCapacity:[self count]]; + + for (id object_ in self) { + + id newObject_ = block_(object_, outError_); + if (newObject_) { + [result_ addObject:newObject_]; + } else if (nil != *outError_) { return nil; } } - - return [ result_ copy ]; + + return [result_ copy]; } -- (NSArray *)forceMap:(JFFMappingBlock)block +- (instancetype)forceMap:(JFFMappingBlock)block { NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[self count]]; @@ -131,7 +127,7 @@ - (NSArray *)forceMap:(JFFMappingBlock)block return [result copy]; } -- (NSArray *)mapWithIndex:(JFFMappingWithErrorAndIndexBlock)block error:(NSError **)outError +- (instancetype)mapWithIndex:(JFFMappingWithErrorAndIndexBlock)block error:(NSError **)outError { __block NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[self count]]; @@ -162,15 +158,15 @@ - (NSDictionary *)mapDict:(JFFMappingDictBlock)block id key; id value; block(object, &key, &value); - [keys addObject: key ]; - [values addObject: value]; + [keys addObject:key ]; + [values addObject:value]; } - return [[NSDictionary alloc] initWithObjects: values - forKeys: keys]; + return [[NSDictionary alloc] initWithObjects:values + forKeys:keys]; } -- (NSArray *)flatten:(JFFFlattenBlock)block +- (instancetype)flatten:(JFFFlattenBlock)block { NSMutableArray *result = [NSMutableArray new]; @@ -203,6 +199,17 @@ - (id)firstMatch:(JFFPredicateBlock)predicate return nil; } +- (id)lastMatch:(JFFPredicateBlock)predicate +{ + NSEnumerator *enumerator = [self reverseObjectEnumerator]; + for (id object in enumerator) { + + if (predicate(object)) + return object; + } + return nil; +} + - (NSUInteger)firstIndexOfObjectMatch:(JFFPredicateBlock)predicate { NSUInteger result = 0; @@ -225,8 +232,8 @@ - (void)transformWithArray:(NSArray *)other } } -- (NSArray *)devideIntoArrayWithSize:(NSUInteger)size - elementIndexBlock:(JFFElementIndexBlock)block +- (instancetype)devideIntoArrayWithSize:(NSUInteger)size + elementIndexBlock:(JFFElementIndexBlock)block { NSParameterAssert(size > 0); NSParameterAssert(block ); @@ -236,12 +243,12 @@ - (NSArray *)devideIntoArrayWithSize:(NSUInteger)size return [NSMutableArray new]; }]; - [self enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { + [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSUInteger inserIndex = block(obj); [mResult[inserIndex] addObject: obj]; }]; - NSArray *result = [mResult map: ^id(id object) { + NSArray *result = [mResult map:^id(id object) { return [object copy]; }]; diff --git a/lib/JFFUtils/NSArray/NSArray+IsEmpty.h b/lib/JFFUtils/NSArray/NSArray+IsEmpty.h index 6610725..3c79fdf 100755 --- a/lib/JFFUtils/NSArray/NSArray+IsEmpty.h +++ b/lib/JFFUtils/NSArray/NSArray+IsEmpty.h @@ -1,7 +1,7 @@ #import -@interface NSArray ( IsEmpty ) +@interface NSArray (IsEmpty) --(BOOL)hasElements; +- (BOOL)hasElements; @end diff --git a/lib/JFFUtils/NSArray/NSArray+IsEmpty.m b/lib/JFFUtils/NSArray/NSArray+IsEmpty.m index 6e754ea..cb02fa3 100755 --- a/lib/JFFUtils/NSArray/NSArray+IsEmpty.m +++ b/lib/JFFUtils/NSArray/NSArray+IsEmpty.m @@ -1,11 +1,11 @@ #import "NSArray+IsEmpty.h" -@implementation NSArray ( IsEmpty ) +@implementation NSArray (IsEmpty) --(BOOL)hasElements +- (BOOL)hasElements { // Apple recommends checking "lastObject" instead of comparing "count" with zero - return ( nil != [ self lastObject ] ); + return (nil != [self lastObject]); } @end diff --git a/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.h b/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.h index bcee0eb..34b2532 100755 --- a/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.h +++ b/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.h @@ -4,4 +4,6 @@ - (id)noThrowObjectAtIndex:(NSUInteger)index; +- (id)firstObject; + @end diff --git a/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.m b/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.m index a74545d..d2c7afd 100755 --- a/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.m +++ b/lib/JFFUtils/NSArray/NSArray+NoThrowObjectAtIndex.m @@ -12,4 +12,9 @@ - (id)noThrowObjectAtIndex:(NSUInteger)index return self[index]; } +- (id)firstObject +{ + return [self noThrowObjectAtIndex:0]; +} + @end diff --git a/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.h b/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.h index 59d6da5..12ffa45 100755 --- a/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.h +++ b/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.h @@ -3,11 +3,11 @@ @interface NSArray( RemoveDuplicates ) -- (NSArray *)arrayByRemovingDuplicates; //uses @selector(isEual:) -- (NSArray *)arrayByRemovingDuplicatesUsingIsEqualBlock:(JFFEqualityCheckerBlock)predicate; +- (instancetype)arrayByRemovingDuplicates; //uses @selector(isEual:) +- (instancetype)arrayByRemovingDuplicatesUsingIsEqualBlock:(JFFEqualityCheckerBlock)predicate; //Same methods using functional programming notation -- (NSArray *)unique; //uses @selector(isEual:) -- (NSArray *)uniqueBy:(JFFEqualityCheckerBlock)predicate; +- (instancetype)unique; //uses @selector(isEual:) +- (instancetype)uniqueBy:(JFFEqualityCheckerBlock)predicate; @end diff --git a/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.m b/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.m index a4a75bd..65c488e 100755 --- a/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.m +++ b/lib/JFFUtils/NSArray/NSArray+RemoveDuplicates.m @@ -6,17 +6,17 @@ @implementation NSArray( RemoveDuplicates ) -- (NSArray *)arrayByRemovingDuplicates +- (instancetype)arrayByRemovingDuplicates { return [self unique]; } -- (NSArray *)arrayByRemovingDuplicatesUsingIsEqualBlock:(JFFEqualityCheckerBlock)predicate +- (instancetype)arrayByRemovingDuplicatesUsingIsEqualBlock:(JFFEqualityCheckerBlock)predicate { return [self uniqueBy:predicate]; } -- (NSArray *)unique +- (instancetype)unique { NSUInteger itemsCount = [self count]; @@ -34,7 +34,7 @@ - (NSArray *)unique return [result copy]; } -- (NSArray *)uniqueBy:(JFFEqualityCheckerBlock)predicate +- (instancetype)uniqueBy:(JFFEqualityCheckerBlock)predicate { NSMutableArray *myCopy = [self mutableCopy]; @@ -49,14 +49,14 @@ - (NSArray *)uniqueBy:(JFFEqualityCheckerBlock)predicate searchPredicate = ^BOOL(id itemObject) { return predicate(firstItem, itemObject); }; - filtered = [myCopy select: searchPredicate]; + filtered = [myCopy select:searchPredicate]; [result addObject:firstItem]; [myCopy removeObjectsInArray:filtered]; } //Shrink the capacity - return [result copy ]; + return [result copy]; } @end diff --git a/lib/JFFUtils/NSArray/NSArray+ToURLsSkippingNils.h b/lib/JFFUtils/NSArray/NSArray+ToURLsSkippingNils.h new file mode 100644 index 0000000..fccef74 --- /dev/null +++ b/lib/JFFUtils/NSArray/NSArray+ToURLsSkippingNils.h @@ -0,0 +1,7 @@ +#import + +@interface NSArray (ToURLsSkippingNils) + +- (instancetype)toURLsSkippingNils; + +@end diff --git a/lib/JFFUtils/NSArray/NSArray+ToURLsSkippingNils.m b/lib/JFFUtils/NSArray/NSArray+ToURLsSkippingNils.m new file mode 100644 index 0000000..536a4e4 --- /dev/null +++ b/lib/JFFUtils/NSArray/NSArray+ToURLsSkippingNils.m @@ -0,0 +1,17 @@ +#import "NSArray+ToURLsSkippingNils.h" + +#import "NSString+ToURL.h" +#import "NSObject+NsNullAsNil.h" +#import "NSArray+BlocksAdditions.h" + +@implementation NSArray (ToURLsSkippingNils) + +- (instancetype)toURLsSkippingNils +{ + return [self forceMap:^id(id object) { + + return [[object nsNullAsNil] toURL]; + }]; +} + +@end diff --git a/lib/JFFUtils/NSDate/NSDate+DateDifference.m b/lib/JFFUtils/NSDate/NSDate+DateDifference.m index d990645..cc82f66 100644 --- a/lib/JFFUtils/NSDate/NSDate+DateDifference.m +++ b/lib/JFFUtils/NSDate/NSDate+DateDifference.m @@ -55,7 +55,7 @@ - (NSString *)dateDifferenceStringFromDate:(NSDate *)fromDate : NSLocalizedString(@"SECONDS", nil); } - NSString *numberStr = [[NSString alloc] initWithFormat:@"%d ", dateComponent]; + NSString *numberStr = [[NSString alloc] initWithFormat:@"%lu ", (unsigned long)dateComponent]; result = [numberStr stringByAppendingString:result]; return result; diff --git a/lib/JFFUtils/NSLocale/NSLocale+CurrentInterfaceLanguageCode.m b/lib/JFFUtils/NSLocale/NSLocale+CurrentInterfaceLanguageCode.m index 7958003..2e918d8 100644 --- a/lib/JFFUtils/NSLocale/NSLocale+CurrentInterfaceLanguageCode.m +++ b/lib/JFFUtils/NSLocale/NSLocale+CurrentInterfaceLanguageCode.m @@ -6,7 +6,7 @@ @implementation NSLocale (CurrentInterfaceLanguageCode) + (NSString *)currentInterfaceLanguageCode { - NSString *languageCode = [[self preferredLanguages] noThrowObjectAtIndex:0]; + NSString *languageCode = [[self preferredLanguages] firstObject]; return languageCode; } @@ -14,7 +14,7 @@ + (NSString *)currentInterfaceISO2LanguageCode { NSString *languageCode = [self currentInterfaceLanguageCode]; - return [[languageCode componentsSeparatedByString:@"_"] noThrowObjectAtIndex:0]; + return [[languageCode componentsSeparatedByString:@"_"] firstObject]; } @end diff --git a/lib/JFFUtils/NSNotificationCenter/NSNotificationCenterNewFeaturesRuntime.m b/lib/JFFUtils/NSNotificationCenter/NSNotificationCenterNewFeaturesRuntime.m deleted file mode 100644 index 8236523..0000000 --- a/lib/JFFUtils/NSNotificationCenter/NSNotificationCenterNewFeaturesRuntime.m +++ /dev/null @@ -1,118 +0,0 @@ -//#import "JFFSimpleBlockHolder.h" -#import "NSObject+Ownerships.h" -#import "NSObject+RuntimeExtensions.h" - -#include - -typedef void (^JFFNotificationCenterBlock)( NSNotification* notification_ ); - -@interface JFFNotificationCenterBlockHolder : NSObject - -@property ( nonatomic, copy ) JFFNotificationCenterBlock block; -@property ( nonatomic, retain ) NSOperationQueue* queue; - -@end - -@implementation JFFNotificationCenterBlockHolder - --(void)dealloc -{ - [ self->_block release ]; - [ self->_queue release ]; - - [ super dealloc ]; -} - --(void)notifyBlockWithNotification:( NSNotification* )notification_ -{ - if ( self.queue ) - { - NSOperationQueue* queue_ = self.queue; - [ queue_ addOperationWithBlock: ^void( void ) - { - self.block( notification_ ); - } ]; - return; - } - - self.block( notification_ ); -} - --(void)removeSelfFromNotificationCenter:( NSObject* )notification_center_ -{ - [ notification_center_.ownerships removeObject: self ]; -} - -@end - -@interface NSNotificationCenterNewFeaturesRuntime : NSObject -@end - -@implementation NSNotificationCenterNewFeaturesRuntime - --(void)addObserver:( id )observer_ selector:( SEL )selector_ name:( NSString* )name_ object:( id )object_ -{ - [ self doesNotRecognizeSelector: _cmd ]; -} - --(id)addObserverForName:( NSString* )name_ - object:( id )object_ - queue:( NSOperationQueue* )queue_ - usingBlock:( void (^)(NSNotification*) )block_ -{ - JFFNotificationCenterBlockHolder* observer_ = [ JFFNotificationCenterBlockHolder new ]; - observer_.block = block_; - observer_.queue = queue_; - - [ self.ownerships addObject: observer_ ]; - - [ self addObserver: observer_ - selector: @selector( notifyBlockWithNotification: ) - name: name_ - object: object_ ]; - - return [ observer_ autorelease ]; -} - --(void)removeObserverWithBlockHolder:( id )observer_ -{ - if ( [ observer_ isKindOfClass: [ JFFNotificationCenterBlockHolder class ] ] ) - { - JFFNotificationCenterBlockHolder* block_holder_ = observer_; - [ block_holder_ removeSelfFromNotificationCenter: self ]; - } - - objc_msgSend( self, @selector( removeObserverWithBlockHolderNativeMethod: ), observer_ ); -} - --(void)removeObserverWithBlockHolder:( id )observer_ - name:( NSString* )name_ - object:( id )object_ -{ - if ( [ observer_ isKindOfClass: [ JFFNotificationCenterBlockHolder class ] ] ) - { - JFFNotificationCenterBlockHolder* block_holder_ = observer_; - [ block_holder_ removeSelfFromNotificationCenter: self ]; - } - - objc_msgSend( self, @selector( removeObserverWithBlockHolderNativeMethod:name:object: ), observer_, name_, object_ ); -} - -+(void)load -{ - //for ios less then 5.x only - [ self addInstanceMethodIfNeedWithSelector: @selector( addObserverForName:object:queue:usingBlock: ) - toClass: [ NSURL class ] ]; - - [ self hookInstanceMethodForClass: [ NSNotificationCenter class ] - withSelector: @selector( removeObserver: ) - prototypeMethodSelector: @selector( removeObserverWithBlockHolder: ) - hookMethodSelector: @selector( removeObserverWithBlockHolderNativeMethod: ) ]; - - [ self hookInstanceMethodForClass: [ NSNotificationCenter class ] - withSelector: @selector( removeObserver:name:object: ) - prototypeMethodSelector: @selector( removeObserverWithBlockHolder:name:object: ) - hookMethodSelector: @selector( removeObserverWithBlockHolderNativeMethod:name:object: ) ]; -} - -@end diff --git a/lib/JFFUtils/NSObject/Details/DelegateProxy/DelegateProxyUtils.m b/lib/JFFUtils/NSObject/Details/DelegateProxy/DelegateProxyUtils.m index 6286e36..92808a5 100644 --- a/lib/JFFUtils/NSObject/Details/DelegateProxy/DelegateProxyUtils.m +++ b/lib/JFFUtils/NSObject/Details/DelegateProxy/DelegateProxyUtils.m @@ -9,12 +9,12 @@ void jff_validateSeteDelegateProxyMethodArguments(id proxy, NSString *delegateName, id targetObject) { //JDOTO assert that property is weak or unsafe_unretained - assert([delegateName length]>0); - assert(proxy); - assert(targetObject); + NSCParameterAssert([delegateName length]>0); + NSCParameterAssert(proxy); + NSCParameterAssert(targetObject); //should has a property getter - assert([[targetObject class] hasInstanceMethodWithSelector:NSSelectorFromString(delegateName)]); + NSCParameterAssert([[targetObject class] hasInstanceMethodWithSelector:NSSelectorFromString(delegateName)]); } void hookDelegateSetterAndGetterMethodsForProxyDelegate(NSString *delegateName, @@ -30,6 +30,7 @@ void hookDelegateSetterAndGetterMethodsForProxyDelegate(NSString *delegateName, if ([prototypeClass addInstanceMethodIfNeedWithSelector:@selector(delegateGetterHookMethod) toClass:prototypeClass newMethodSelector:NSSelectorFromString(prototypeMethodName)]) { + [prototypeClass hookInstanceMethodForClass:targetClass withSelector:NSSelectorFromString(delegateName) prototypeMethodSelector:NSSelectorFromString(prototypeMethodName) diff --git a/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFDelegateProxyClassMethods.h b/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFDelegateProxyClassMethods.h index aa41776..fa9db72 100644 --- a/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFDelegateProxyClassMethods.h +++ b/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFDelegateProxyClassMethods.h @@ -1,4 +1,7 @@ #import @interface JFFDelegateProxyClassMethods : NSObject + +- (id)delegateGetterHookMethod; + @end diff --git a/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.h b/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.h index 9c437f2..4bef337 100644 --- a/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.h +++ b/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.h @@ -4,7 +4,7 @@ @interface JFFProxyDelegatesDispatcher : NSObject -+ (id)newProxyDelegatesDispatcherWithRealDelegate:(id)realDelegate - delegates:(JFFMutableAssignArray *)delegates; ++ (instancetype)newProxyDelegatesDispatcherWithRealDelegate:(id)realDelegate + delegates:(JFFMutableAssignArray *)delegates; @end diff --git a/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.m b/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.m index 42bd85a..43ca0af 100644 --- a/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.m +++ b/lib/JFFUtils/NSObject/Details/DelegateProxy/JFFProxyDelegatesDispatcher.m @@ -10,13 +10,13 @@ @implementation JFFProxyDelegatesDispatcher id _realDelegate; } -+ (id)newProxyDelegatesDispatcherWithRealDelegate:(id)realDelegate - delegates:(JFFMutableAssignArray *)delegates ++ (instancetype)newProxyDelegatesDispatcherWithRealDelegate:(id)realDelegate + delegates:(JFFMutableAssignArray *)delegates { JFFProxyDelegatesDispatcher *result = [JFFProxyDelegatesDispatcher new]; - if (result) - { + if (result) { + result->_delegates = delegates; result->_realDelegate = realDelegate; } @@ -37,11 +37,11 @@ - (void)forwardInvocation:(NSInvocation *)invocation [invocation invokeWithTarget:_realDelegate]; } -- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector +- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector { __block NSMethodSignature *result; - [[_delegates array] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) - { + [[_delegates array] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + result = [obj methodSignatureForSelector:selector]; if (result) *stop = YES; diff --git a/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.h b/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.h index cc55738..54e2460 100644 --- a/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.h +++ b/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.h @@ -2,6 +2,6 @@ @interface NSString (DelegateProxySelectorsNames) -- (NSString*)hookedGetterMethodNameForClass:(Class)targetClass; +- (instancetype)hookedGetterMethodNameForClass:(Class)targetClass; @end diff --git a/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.m b/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.m index d8b3ecb..a792994 100644 --- a/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.m +++ b/lib/JFFUtils/NSObject/Details/DelegateProxy/NSString+DelegateProxySelectorsNames.m @@ -2,7 +2,7 @@ @implementation NSString (DelegateProxySelectorsNames) -- (NSString*)hookedGetterMethodNameForClass:(Class)targetClass +- (instancetype)hookedGetterMethodNameForClass:(Class)targetClass { NSString *result = [[NSString alloc]initWithFormat:@"hookedDelegateGetterName_%@_%@", targetClass, diff --git a/lib/JFFUtils/NSObject/NSObject+Const0.h b/lib/JFFUtils/NSObject/NSObject+Const0.h index 6780648..aaba6a5 100755 --- a/lib/JFFUtils/NSObject/NSObject+Const0.h +++ b/lib/JFFUtils/NSObject/NSObject+Const0.h @@ -2,6 +2,6 @@ @interface NSObject (Const0) -+(id)objectThatAlwaysReturnsZeroForAnyMethod; ++ (id)objectThatAlwaysReturnsZeroForAnyMethod; @end diff --git a/lib/JFFUtils/NSObject/NSObject+Const0.m b/lib/JFFUtils/NSObject/NSObject+Const0.m index 22bc011..3a14ede 100755 --- a/lib/JFFUtils/NSObject/NSObject+Const0.m +++ b/lib/JFFUtils/NSObject/NSObject+Const0.m @@ -9,7 +9,7 @@ - (void)forwardInvocation:(NSInvocation *)invocation { } -- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector +- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector { return [[self class] instanceMethodSignatureForSelector:@selector(doNothing)]; } @@ -23,7 +23,7 @@ - (NSUInteger)doNothing @implementation NSObject (Const0) -+(id)objectThatAlwaysReturnsZeroForAnyMethod ++ (id)objectThatAlwaysReturnsZeroForAnyMethod { static dispatch_once_t once; static id instance; diff --git a/lib/JFFUtils/NSObject/NSObject+DelegateProxy.m b/lib/JFFUtils/NSObject/NSObject+DelegateProxy.m index 0c29cbe..c74be19 100644 --- a/lib/JFFUtils/NSObject/NSObject+DelegateProxy.m +++ b/lib/JFFUtils/NSObject/NSObject+DelegateProxy.m @@ -14,7 +14,7 @@ @implementation NSObject (DelegateProxy) -- (NSMutableDictionary*)lazyProxyDelegatesDictionary +- (NSMutableDictionary *)lazyProxyDelegatesDictionary { NSMutableDictionary *result = objc_getAssociatedObject(self, &proxyDelegatesKey); @@ -26,7 +26,7 @@ - (NSMutableDictionary*)lazyProxyDelegatesDictionary return result; } -- (JFFMutableAssignArray*)proxyDelegatesForDelegateWithName:(NSString *)delegateName +- (JFFMutableAssignArray *)proxyDelegatesForDelegateWithName:(NSString *)delegateName { NSMutableDictionary *arrayByDelegateName = [self lazyProxyDelegatesDictionary]; @@ -34,7 +34,7 @@ - (JFFMutableAssignArray*)proxyDelegatesForDelegateWithName:(NSString *)delegate return delegates; } -- (JFFMutableAssignArray*)lazyProxyDelegatesForDelegateWithName:(NSString *)delegateName +- (JFFMutableAssignArray *)lazyProxyDelegatesForDelegateWithName:(NSString *)delegateName { NSMutableDictionary *arrayByDelegateName = [self lazyProxyDelegatesDictionary]; diff --git a/lib/JFFUtils/NSObject/NSObject+ExpandArray.h b/lib/JFFUtils/NSObject/NSObject+ExpandArray.h index 6f98241..408a2da 100755 --- a/lib/JFFUtils/NSObject/NSObject+ExpandArray.h +++ b/lib/JFFUtils/NSObject/NSObject+ExpandArray.h @@ -2,6 +2,6 @@ @interface NSArray (ExpandArray) -- (id)expandArray; +- (instancetype)expandArray; @end diff --git a/lib/JFFUtils/NSObject/NSObject+ExpandArray.m b/lib/JFFUtils/NSObject/NSObject+ExpandArray.m index dedc682..43aed83 100755 --- a/lib/JFFUtils/NSObject/NSObject+ExpandArray.m +++ b/lib/JFFUtils/NSObject/NSObject+ExpandArray.m @@ -4,7 +4,7 @@ @implementation NSArray (ExpandArray) -- (id)expandArray +- (instancetype)expandArray { NSMutableArray *result = [NSMutableArray new]; for (id object in self) { diff --git a/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.h b/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.h index 6fb90dd..a65deda 100755 --- a/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.h +++ b/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.h @@ -1,6 +1,6 @@ #import -typedef NS_ENUM( NSInteger, JUncertainLogicStates ) +typedef NS_ENUM(NSInteger, JUncertainLogicStates) { ULFalse = 0, ULTrue = 1, @@ -13,13 +13,13 @@ typedef NS_ENUM( NSInteger, JUncertainLogicStates ) isEqualTo:(NSObject *)object2; -+(JUncertainLogicStates)quickCheckObject:( id )first - isEqualTo:( id )second; ++ (JUncertainLogicStates)quickCheckObject:(id)first + isEqualTo:(id)second; -+(BOOL)objcBoolean:( BOOL )first - xorWith:( BOOL )second; ++ (BOOL)objcBoolean:(BOOL)first + xorWith:(BOOL)second; -+(BOOL)objcBoolean:( BOOL )first - isEqualTo:( BOOL )second; ++ (BOOL)objcBoolean:(BOOL)first + isEqualTo:(BOOL)second; @end diff --git a/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.m b/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.m index 243bb92..d1c1a72 100755 --- a/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.m +++ b/lib/JFFUtils/NSObject/NSObject+IsEqualTwoObjects.m @@ -2,49 +2,43 @@ @implementation NSObject (IsEqualTwoObjects) -+(BOOL)object:(NSObject *)object1 ++ (BOOL)object:(NSObject *)object1 isEqualTo:(NSObject *)object2 { - JUncertainLogicStates pointerCheckResult = [ self quickCheckObject: object1 - isEqualTo: object2 ]; - if ( ULMaybe != pointerCheckResult ) - { + JUncertainLogicStates pointerCheckResult = [self quickCheckObject:object1 + isEqualTo:object2]; + if (ULMaybe != pointerCheckResult) { return (BOOL)pointerCheckResult; } - + return [object1 isEqual:object2]; } -+(BOOL)objcBoolean:( BOOL )first - xorWith:( BOOL )second ++ (BOOL)objcBoolean:(BOOL)first + xorWith:(BOOL)second { - return ![ self objcBoolean: first - isEqualTo: second ]; + return ![self objcBoolean:first + isEqualTo:second]; } -+(BOOL)objcBoolean:( BOOL )first - isEqualTo:( BOOL )second ++ (BOOL)objcBoolean:(BOOL)first + isEqualTo:(BOOL)second { - return ( first && second ) || ( !first && !second ); + return (first && second) || (!first && !second); } -+(JUncertainLogicStates)quickCheckObject:( id )first - isEqualTo:( id )second ++ (JUncertainLogicStates)quickCheckObject:(id)first + isEqualTo:(id)second { - BOOL isBothNil = ( nil == first ) && ( nil == second ); - BOOL isAnyNil = ( nil == first ) || ( nil == second ); + BOOL isBothNil = (nil == first) && (nil == second); + BOOL isAnyNil = (nil == first) || (nil == second); - if ( isBothNil ) - { + if (isBothNil) { return ULTrue; - } - else if ( first == second ) - { + } else if (first == second) { return ULTrue; - } - else if ( isAnyNil ) - { + } else if (isAnyNil) { return ULFalse; } diff --git a/lib/JFFUtils/NSObject/NSObject+JFFMeaningClass.m b/lib/JFFUtils/NSObject/NSObject+JFFMeaningClass.m index c833bee..7fd9ec2 100644 --- a/lib/JFFUtils/NSObject/NSObject+JFFMeaningClass.m +++ b/lib/JFFUtils/NSObject/NSObject+JFFMeaningClass.m @@ -137,7 +137,7 @@ + (Class)jffMeaningClass return self; } -- (id)jffMeaningClass +- (Class)jffMeaningClass { return [[self class] jffMeaningClass]; } diff --git a/lib/JFFUtils/NSObject/NSObject+ObjectMethodHook.h b/lib/JFFUtils/NSObject/NSObject+ObjectMethodHook.h new file mode 100644 index 0000000..4655928 --- /dev/null +++ b/lib/JFFUtils/NSObject/NSObject+ObjectMethodHook.h @@ -0,0 +1,16 @@ +#import + +typedef id(^JFFPreviousObserverBlockGetter)(); + +typedef id(^JFFMethodObserverBlock)(JFFPreviousObserverBlockGetter previousBlockGetter); + +@interface NSObject (ObjectMethodHook) + +//- no thread safe method, use only from one thread +//- works only for instance methods + +//TODO add static version of method +- (void)addMethodHook:(JFFMethodObserverBlock)observer + selector:(SEL)selector; + +@end diff --git a/lib/JFFUtils/NSObject/NSObject+ObjectMethodHook.mm b/lib/JFFUtils/NSObject/NSObject+ObjectMethodHook.mm new file mode 100644 index 0000000..714f524 --- /dev/null +++ b/lib/JFFUtils/NSObject/NSObject+ObjectMethodHook.mm @@ -0,0 +1,369 @@ +#import "NSObject+ObjectMethodHook.h" + +#include "JFFRuntimeAddiotions.h" + +#include + +#include + +static char ownershipsKey; + +@interface NSObject (ObjectMethodHook_Private) + +- (NSMutableArray *)lazyObserversBlocksForSelectorName:(NSString *)selectorName; + +@end + +static void callBlockWithInvocation(NSInvocation *invocation, id block) +{ + [invocation invokeWithTarget:block]; +} + +static id lastBlockObserver(id _self, SEL selector) +{ + NSString *selectorStr = NSStringFromSelector(selector); + NSMutableArray *methodObservers = [_self lazyObserversBlocksForSelectorName:selectorStr]; + return [methodObservers lastObject]; +} + +inline static BOOL isVoidReturnType(NSMethodSignature *sig) +{ + return *sig.methodReturnType == @encode(void)[0]; +} + +static SEL originalMethodHolderSelector(SEL selectorToHook) +{ + SEL result = NULL; + + NSString *oroginalMethodHolderStr = NSStringFromSelector(selectorToHook); + oroginalMethodHolderStr = [[NSString alloc] initWithFormat:@"originalMethodHolder_%@", oroginalMethodHolderStr]; + result = NSSelectorFromString(oroginalMethodHolderStr); + + return result; +} + +static void self_invokeMethosBlockWithArgsAndReturnValue(id targetObjectOrBlock, + const char *signature, + SEL selectorOrNullForBlock, + va_list args, + id *selfArgumentPtr, + void *returnValuePtr, + SEL originalSelector) +{ + BOOL isBlockCall = selectorOrNullForBlock == NULL; + + if (isBlockCall && !targetObjectOrBlock) { + + SEL originalMethodHolder = originalMethodHolderSelector(originalSelector); + + //TODO check exectly for self class, no for parent class + Method hookHolderMethod = class_getInstanceMethod([*selfArgumentPtr class], originalMethodHolder); + + if (hookHolderMethod != NULL) { + + invokeMethosBlockWithArgsAndReturnValue(*selfArgumentPtr, + method_getTypeEncoding(hookHolderMethod), + originalMethodHolder, + args, + selfArgumentPtr, + returnValuePtr); + return; + } + + [*selfArgumentPtr doesNotRecognizeSelector:originalMethodHolder]; + return; + } + + invokeMethosBlockWithArgsAndReturnValue(targetObjectOrBlock, + signature, + selectorOrNullForBlock, + args, + selfArgumentPtr, + returnValuePtr); +} + +template +id generalHookBlock(const char *methodReturnType, + SEL originalSelector, + id(^targetGetter)(id _self, const char**, SEL*) + ) +{ + if (strcmp(@encode(T), methodReturnType) != 0) + return nil; + + targetGetter = [targetGetter copy]; + + return ^T(id _self, ...) { + + const char *signature = NULL; + SEL selector = NULL; + id target = targetGetter(_self, &signature, &selector); + + va_list args; + va_start(args, _self); + + T retValue; + + self_invokeMethosBlockWithArgsAndReturnValue(target, + signature, + selector, + args, + &_self, + &retValue, + originalSelector); + + va_end(args); + + return retValue; + }; +} + +template <> +id generalHookBlock(const char *methodReturnType, + SEL originalSelector, + id(^targetGetter)(id _self, const char**, SEL*) + ) +{ + if (strcmp(@encode(void), methodReturnType) != 0) + return nil; + + targetGetter = [targetGetter copy]; + + return ^void(id _self, ...) { + + const char *signature = NULL; + SEL selector = NULL; + id target = targetGetter(_self, &signature, &selector); + + va_list args; + va_start(args, _self); + + self_invokeMethosBlockWithArgsAndReturnValue(target, + signature, + selector, + args, + &_self, + NULL, + originalSelector); + + va_end(args); + }; +} + +static id generalHookBlockForSignature(const char *prototypeSinature, + SEL originalSelector, + id(^targetGetter)(id _self, const char**, SEL*) + ) +{ + id resultBlock; + + NSCParameterAssert(strlen(prototypeSinature) != 0); + char returnType[strlen(prototypeSinature) + 1]; + const char *typeSignatureScanFormat = "%[@^vcI]";//check it for new added types + sscanf(prototypeSinature, typeSignatureScanFormat, returnType); + + const char *methodReturnType = returnType; + if (strcmp(@encode(id), returnType) == 0) + methodReturnType = @encode(void *); + + resultBlock = resultBlock?:generalHookBlock(methodReturnType, originalSelector, targetGetter); + resultBlock = resultBlock?:generalHookBlock(methodReturnType, originalSelector, targetGetter); + resultBlock = resultBlock?:generalHookBlock(methodReturnType, originalSelector, targetGetter); + resultBlock = resultBlock?:generalHookBlock(methodReturnType, originalSelector, targetGetter); + + if (!resultBlock) { + + NSCAssert(0, @"typeSignatureScanFormat - check it for new added types"); + } + + //originalBlock = resultBlock; + + return resultBlock; +} + +static NSMutableDictionary *lazyHookedClassesAndMethod() +{ + static NSMutableDictionary *result; + + if (!result) { + + result = [NSMutableDictionary new]; + } + return result; +} + +//TODO do not use ARC for this class +//returns a block with original implementation +static void hookMehodWithGeneralBlock(const char *prototypeSinature, SEL selectorToHook, Class classToHook) +{ + id generalHook = generalHookBlockForSignature(prototypeSinature, selectorToHook, ^id(id _localSelf, const char** sinature, SEL* selector) { + + id block = lastBlockObserver(_localSelf, selectorToHook); + + if (block) + *sinature = block_getTypeEncoding(block); + + return block; + }); + + Method hookedMethod = class_getInstanceMethod(classToHook, selectorToHook); + + if (hookedMethod != NULL) { + + SEL originalMethodHolder = originalMethodHolderSelector(selectorToHook); + + BOOL added = class_addMethod(classToHook, + originalMethodHolder, + imp_implementationWithBlock(generalHook), + prototypeSinature); + + { + NSString *errorDescription = [[NSString alloc] initWithFormat:@"camn not add method: %@", NSStringFromSelector(originalMethodHolder)]; + NSCAssert(added, errorDescription); + } + + Method hookHolderMethod = class_getInstanceMethod(classToHook, originalMethodHolder); + + method_exchangeImplementations(hookHolderMethod, hookedMethod); + + } else { + + BOOL added = class_addMethod(classToHook, + selectorToHook, + imp_implementationWithBlock(generalHook), + prototypeSinature); + + { + NSString *errorDescription = [[NSString alloc] initWithFormat:@"camn not add method: %@", NSStringFromSelector(selectorToHook)]; + NSCAssert(added, errorDescription); + } + } + + //save flag that method hooked + { + NSMutableDictionary *hookedClassesAndMethod = lazyHookedClassesAndMethod(); + + NSString *className = [classToHook description]; + NSMutableSet *methods = hookedClassesAndMethod[className]; + + if (!methods) { + + methods = [NSMutableSet new]; + hookedClassesAndMethod[className] = methods; + } + + [methods addObject:NSStringFromSelector(selectorToHook)]; + } +} + +@implementation NSObject (ObjectMethodHook) + +- (NSMutableArray *)lazyObserversBlocksForSelectorName:(NSString *)selectorName +{ + NSMutableDictionary *dict = objc_getAssociatedObject(self, &ownershipsKey); + + if (!dict) { + + dict = [NSMutableDictionary new]; + objc_setAssociatedObject(self, &ownershipsKey, dict, OBJC_ASSOCIATION_RETAIN); + } + + NSMutableArray *result = dict[selectorName]; + + if (!result) { + + result = [NSMutableArray new]; + dict[selectorName] = result; + } + + return result; +} + +static id hookedMethodBlockHolder(SEL selectorToHook, id _self) +{ + SEL originalMethodHolder = originalMethodHolderSelector(selectorToHook); + + Method hookHolderMethod = class_getInstanceMethod([_self class], originalMethodHolder); + + if (hookHolderMethod == NULL) + return nil; + + const char *prototypeSinature = method_getTypeEncoding(hookHolderMethod); + + return generalHookBlockForSignature(prototypeSinature, selectorToHook, ^id(id _localSelf, const char** sinature, SEL* selector) { + + *sinature = prototypeSinature; + *selector = originalMethodHolder; + + return _localSelf; + }); +} + +static Class findClassForHook(SEL selectorToHook, id _self) +{ + Class result = [_self class]; + + Method method = class_getInstanceMethod(result, selectorToHook); + Class resultSuper = [result superclass]; + + while (resultSuper && method == class_getInstanceMethod(resultSuper, selectorToHook)) { + + method = class_getInstanceMethod(resultSuper, selectorToHook); + result = resultSuper; + resultSuper = [result superclass]; + } + + if (method == NULL) + result = [_self class]; + + return result; +} + +static Class findClassForHookIfNotHooked(SEL selectorToHook, id _self) +{ + Class result = findClassForHook(selectorToHook, _self); + + NSMutableDictionary *hookedClassesAndMethod = lazyHookedClassesAndMethod(); + + NSString *className = [result description]; + NSMutableSet *methods = hookedClassesAndMethod[className]; + + if ([methods containsObject:NSStringFromSelector(selectorToHook)]) { + return Nil; + } + + return result; +} + +//TODO try to hook retain method +- (void)addMethodHook:(JFFMethodObserverBlock)observer + selector:(SEL)selectorToHook +{ + NSString *selectorStr = NSStringFromSelector(selectorToHook); + + NSMutableArray *methodObservers = [self lazyObserversBlocksForSelectorName:selectorStr]; + Class classToHook = findClassForHookIfNotHooked(selectorToHook, self); + + __block id previousObserver = [methodObservers lastObject]; + + __unsafe_unretained id unsafeUnretainedSelf = self; + + id hook = observer(^id() { + + if (!previousObserver) { + + return hookedMethodBlockHolder(selectorToHook, unsafeUnretainedSelf); + } + return previousObserver; + }); + + if (classToHook != NULL) { + + const char *prototypeSinature = block_getTypeEncoding(hook); + hookMehodWithGeneralBlock(prototypeSinature, selectorToHook, classToHook); + } + + [methodObservers addObject:hook]; +} + +@end diff --git a/lib/JFFUtils/NSObject/NSObject+RuntimeExtensions.m b/lib/JFFUtils/NSObject/NSObject+RuntimeExtensions.m index 4837aae..dec8f29 100755 --- a/lib/JFFUtils/NSObject/NSObject+RuntimeExtensions.m +++ b/lib/JFFUtils/NSObject/NSObject+RuntimeExtensions.m @@ -95,12 +95,11 @@ + (void)hookMethodForClass:(Class)class NSParameterAssert(prototypeMethod); const char *typeEncoding = method_getTypeEncoding(prototypeMethod); -// BOOL methodAdded = - class_addMethod(targetClass, - hookSelector, - method_getImplementation(prototypeMethod), - typeEncoding); - //NSAssert(methodAdded, @"should be added"); + BOOL methodAdded = class_addMethod(targetClass, + hookSelector, + method_getImplementation(prototypeMethod), + typeEncoding); + NSAssert(methodAdded, @"should be added"); Method hookMethod = methodGetter(class, hookSelector); method_exchangeImplementations(targetMethod, hookMethod); @@ -122,6 +121,17 @@ + (void)hookInstanceMethodForClass:(Class)class methodGetter:methodGetter]; } ++ (void)unHookInstanceMethodForClass:(Class)targetClass + withSelector:(SEL)targetSelector + prototypeMethodSelector:(SEL)prototypeSelector + hookMethodSelector:(SEL)hookSelector +{ + [self unHookInstanceMethodForClass:targetClass + withSelector:targetSelector + prototypeMethodSelector:targetSelector + hookMethodSelector:prototypeSelector]; +} + + (void)hookClassMethodForClass:(Class)class withSelector:(SEL)targetSelector prototypeMethodSelector:(SEL)prototypeSelector @@ -145,10 +155,6 @@ + (BOOL)hasMethodForMethodGetter:(JFFMethodGetterForClass)methodGetter if (!method) return NO; - //TODO ? -// if (![self superclass]) -// return NO; - Method superMethod = methodGetter([self superclass]); return method != superMethod; } @@ -169,16 +175,15 @@ + (BOOL)hasClassMethodWithSelector:(SEL)methodSelector #pragma mark - #pragma mark Unhook -+ (void)unHookInstanceMethodForClass:(Class)targetClass ++ (void)unHookClassMethodForClass:(Class)targetClass withSelector:(SEL)targetSelector prototypeMethodSelector:(SEL)prototypeSelector hookMethodSelector:(SEL)hookSelector { - [ self hookInstanceMethodForClass: targetClass - withSelector: targetSelector - prototypeMethodSelector: hookSelector - hookMethodSelector: prototypeSelector ]; + [self hookClassMethodForClass:targetClass + withSelector:targetSelector + prototypeMethodSelector:hookSelector + hookMethodSelector:prototypeSelector]; } - @end diff --git a/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.h b/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.h index ced0d94..3f9daea 100644 --- a/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.h +++ b/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.h @@ -4,11 +4,16 @@ @interface NSOrderedSet (BlocksAdditions) +//Calls block once for number from 0(zero) to (size_ - 1) +//Creates a new NSOrderedSet containing the values returned by the block. ++ (instancetype)setWithSize:(NSUInteger)size + producer:(JFFProducerBlock)block; + //Invokes block once for each element of self. //Creates a new NSOrderedSet containing the values returned by the block. -- (NSOrderedSet*)map:(JFFMappingBlock)block; +- (instancetype)map:(JFFMappingBlock)block; -- (NSOrderedSet *)forceMap:(JFFMappingBlock)block; +- (instancetype)forceMap:(JFFMappingBlock)block; - (id)firstMatch:(JFFPredicateBlock)predicate; - (BOOL)any:(JFFPredicateBlock)predicate; @@ -16,6 +21,6 @@ //Invokes the block passing in successive elements from self, //Creates a new NSSet containing those elements for which the block returns a YES value -- (NSOrderedSet *)select:(JFFPredicateBlock)predicate; +- (instancetype)select:(JFFPredicateBlock)predicate; @end diff --git a/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.m b/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.m index 5541d06..23dbc26 100644 --- a/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.m +++ b/lib/JFFUtils/NSOrderedSet/NSOrderedSet+BlocksAdditions.m @@ -1,10 +1,36 @@ #import "NSOrderedSet+BlocksAdditions.h" +@implementation NSMutableOrderedSet (BlocksAdditions) + ++ (instancetype)converToCurrentTypeMutableOrderedSet:(NSMutableOrderedSet *)set +{ + return set; +} + +@end + @implementation NSOrderedSet (BlocksAdditions) ++ (instancetype)converToCurrentTypeMutableOrderedSet:(NSMutableOrderedSet *)set +{ + return [set copy]; +} + ++ (instancetype)setWithSize:(NSUInteger)size + producer:(JFFProducerBlock)block +{ + NSMutableOrderedSet *result = [[NSMutableOrderedSet alloc] initWithCapacity:size]; + + for (NSUInteger index = 0; index < size; ++index) { + [result addObject:block(index)]; + } + + return [self converToCurrentTypeMutableOrderedSet:result]; +} + //TODO test //TODO remove code duplicate -- (NSOrderedSet *)map:(JFFMappingBlock)block +- (instancetype)map:(JFFMappingBlock)block { NSMutableOrderedSet *result = [[NSMutableOrderedSet alloc] initWithCapacity:[self count]]; @@ -17,7 +43,7 @@ - (NSOrderedSet *)map:(JFFMappingBlock)block return [result copy]; } -- (NSOrderedSet *)forceMap:(JFFMappingBlock)block +- (instancetype)forceMap:(JFFMappingBlock)block { NSMutableOrderedSet *result = [[NSMutableOrderedSet alloc] initWithCapacity:[self count]]; @@ -54,7 +80,7 @@ - (BOOL)all:(JFFPredicateBlock)predicate return ![self any:notPredicate]; } -- (NSOrderedSet *)select:(JFFPredicateBlock)predicate +- (instancetype)select:(JFFPredicateBlock)predicate { NSIndexSet *indexes = [self indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { diff --git a/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.h b/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.h index 9476260..5dcaf94 100644 --- a/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.h +++ b/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.h @@ -2,7 +2,7 @@ @interface NSMutableSet (StorableSet) -+ (id)newStorableSetWithContentsOfFile:(NSString *)fileName; ++ (instancetype)newStorableSetWithContentsOfFile:(NSString *)fileName; - (BOOL)addAndSaveObject:(id)object; - (BOOL)removeAndSaveObject:(id)object; diff --git a/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.m b/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.m index 295ff3f..20982bb 100644 --- a/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.m +++ b/lib/JFFUtils/NSSet/NSMutableSet+StorableSet.m @@ -3,25 +3,28 @@ #import "NSString+PathExtensions.h" #import "NSString+FileAttributes.h" -#include +#include "JFFRuntimeAddiotions.h" -static char propertyKey; +@interface NSMutableSet (StorableSet_Internal) -@implementation NSMutableSet (StorableSet) +@property (nonatomic) NSString *storeFilePath; -- (void)setStoreFilePath:(NSString *)path -{ - objc_setAssociatedObject(self, &propertyKey, path, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} +@end + +@implementation NSMutableSet (StorableSet_Internal) + +@dynamic storeFilePath; -- (NSString *)storeFilePath ++ (void)load { - NSString *result = objc_getAssociatedObject(self, &propertyKey); - - return result; + jClass_implementProperty(self, NSStringFromSelector(@selector(storeFilePath))); } -+ (id)newStorableSetWithContentsOfFile:(NSString *)fileName +@end + +@implementation NSMutableSet (StorableSet) + ++ (instancetype)newStorableSetWithContentsOfFile:(NSString *)fileName { NSParameterAssert(fileName); diff --git a/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.h b/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.h index b049115..79adcbd 100644 --- a/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.h +++ b/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.h @@ -4,18 +4,23 @@ @interface NSSet (BlocksAdditions) +//Calls block once for number from 0(zero) to (size_ - 1) +//Creates a new NSArray containing the values returned by the block. ++ (instancetype)setWithSize:(NSUInteger)size + producer:(JFFProducerBlock)block; + //Invokes block once for each element of self. //Creates a new NSSet containing the values returned by the block. -- (NSSet*)map:(JFFMappingBlock)block; +- (instancetype)map:(JFFMappingBlock)block; //Invokes block once for each element of self. //Creates a new NSSet containing the values returned by the block. //if error happens it is suppressed -- (NSSet*)forceMap:(JFFMappingBlock)block; +- (instancetype)forceMap:(JFFMappingBlock)block; //Invokes the block passing in successive elements from self, //Creates a new NSSet containing those elements for which the block returns a YES value -- (NSSet *)select:(JFFPredicateBlock)predicate; +- (instancetype)select:(JFFPredicateBlock)predicate; //Invokes the block passing in successive elements from self, //Creates a new NSArray containing those elements for which the block returns a YES value diff --git a/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.m b/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.m index a0c09d0..87fd6fb 100644 --- a/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.m +++ b/lib/JFFUtils/NSSet/NSSet+BlocksAdditions.m @@ -2,21 +2,47 @@ #import "NSArray+BlocksAdditions.h" +@implementation NSMutableSet (BlocksAdditions) + ++ (instancetype)converToCurrentTypeMutableSet:(NSMutableSet *)set +{ + return set; +} + +@end + @implementation NSSet (BlocksAdditions) -- (NSSet *)map:(JFFMappingBlock)block ++ (instancetype)converToCurrentTypeMutableSet:(NSMutableSet *)set +{ + return [set copy]; +} + ++ (instancetype)setWithSize:(NSUInteger)size + producer:(JFFProducerBlock)block +{ + NSMutableSet *result = [[NSMutableSet alloc] initWithCapacity:size]; + + for (NSUInteger index = 0; index < size; ++index) { + [result addObject:block(index)]; + } + + return [self converToCurrentTypeMutableSet:result]; +} + +- (instancetype)map:(JFFMappingBlock)block { NSArray *arrray = [[self allObjects] map:block]; return [NSSet setWithArray:arrray]; } -- (NSSet *)forceMap:(JFFMappingBlock)block +- (instancetype)forceMap:(JFFMappingBlock)block { NSArray *arrray = [[self allObjects] forceMap:block]; return [NSSet setWithArray:arrray]; } -- (NSSet *)select:(JFFPredicateBlock)predicate +- (instancetype)select:(JFFPredicateBlock)predicate { return [self objectsPassingTest:^BOOL(id obj, BOOL *stop) { return predicate(obj); diff --git a/lib/JFFUtils/NSString/NSString+Base64.h b/lib/JFFUtils/NSString/NSString+Base64.h index cff7dc0..73cf80a 100755 --- a/lib/JFFUtils/NSString/NSString+Base64.h +++ b/lib/JFFUtils/NSString/NSString+Base64.h @@ -2,6 +2,6 @@ @interface NSString (Base64) -+(NSString*)base64StringFromData:( NSData* )data length:( int )length; ++ (instancetype)base64StringFromData:(NSData *)data length:(int)length; @end diff --git a/lib/JFFUtils/NSString/NSString+Base64.m b/lib/JFFUtils/NSString/NSString+Base64.m index af3e5f2..cd50404 100755 --- a/lib/JFFUtils/NSString/NSString+Base64.m +++ b/lib/JFFUtils/NSString/NSString+Base64.m @@ -9,7 +9,7 @@ @implementation NSString (Base64) -+(NSString*)base64StringFromData:( NSData* )data length:( int )length ++ (instancetype)base64StringFromData:(NSData *)data length:(int)length { unsigned long ixtext, lentext; long ctremaining; diff --git a/lib/JFFUtils/NSString/NSString+CPlusPlus.h b/lib/JFFUtils/NSString/NSString+CPlusPlus.h index 9947bcb..972ebc7 100755 --- a/lib/JFFUtils/NSString/NSString+CPlusPlus.h +++ b/lib/JFFUtils/NSString/NSString+CPlusPlus.h @@ -3,7 +3,7 @@ @interface NSString (CPlusPlus) --(std::string)toStlString; -+(id)stringWithStlStringNoCopy:( const std::string& )stlString_; +- (std::string)toStlString; ++ (instancetype)stringWithStlStringNoCopy:( const std::string& )stlString_; @end diff --git a/lib/JFFUtils/NSString/NSString+CPlusPlus.mm b/lib/JFFUtils/NSString/NSString+CPlusPlus.mm index 6e2141e..6a4e197 100755 --- a/lib/JFFUtils/NSString/NSString+CPlusPlus.mm +++ b/lib/JFFUtils/NSString/NSString+CPlusPlus.mm @@ -17,7 +17,7 @@ @implementation NSString (CPlusPlus) return urlCppString; } -+ (id)stringWithStlStringNoCopy:(const std::string&)stlString ++ (instancetype)stringWithStlStringNoCopy:(const std::string&)stlString { if (stlString.empty()) { return nil; diff --git a/lib/JFFUtils/NSString/NSString+FileAttributes.h b/lib/JFFUtils/NSString/NSString+FileAttributes.h index d9e7de8..c242124 100644 --- a/lib/JFFUtils/NSString/NSString+FileAttributes.h +++ b/lib/JFFUtils/NSString/NSString+FileAttributes.h @@ -2,6 +2,6 @@ @interface NSString (FileAttributes) --(void)addSkipBackupAttribute; +- (void)addSkipBackupAttribute; @end diff --git a/lib/JFFUtils/NSString/NSString+Format.h b/lib/JFFUtils/NSString/NSString+Format.h index cf9db0f..c8d9d19 100755 --- a/lib/JFFUtils/NSString/NSString+Format.h +++ b/lib/JFFUtils/NSString/NSString+Format.h @@ -1,9 +1,9 @@ #import -@interface NSString (Format) +@interface NSString (Format) -+ (id)stringWithFormatCheckNill:(NSString *)format, ...; ++ (instancetype)stringWithFormatCheckNill:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2); --(NSString*)singleQuotedString; +- (instancetype)singleQuotedString; @end diff --git a/lib/JFFUtils/NSString/NSString+Format.m b/lib/JFFUtils/NSString/NSString+Format.m index a71a298..11ecea3 100755 --- a/lib/JFFUtils/NSString/NSString+Format.m +++ b/lib/JFFUtils/NSString/NSString+Format.m @@ -2,7 +2,7 @@ @implementation NSString (Format) -+ (id)stringWithFormatCheckNill:(NSString *)format, ... ++ (instancetype)stringWithFormatCheckNill:(NSString *)format, ... { if ([format length] == 0) { return nil; @@ -31,9 +31,9 @@ + (id)stringWithFormatCheckNill:(NSString *)format, ... arguments:argumentList]; } --(NSString*)singleQuotedString +- (instancetype)singleQuotedString { - return [ NSString stringWithFormat: @"'%@'", self ]; + return [[NSString alloc] initWithFormat:@"'%@'", self]; } @end diff --git a/lib/JFFUtils/NSString/NSString+HTML.h b/lib/JFFUtils/NSString/NSString+HTML.h index d750d75..40cbaa8 100644 --- a/lib/JFFUtils/NSString/NSString+HTML.h +++ b/lib/JFFUtils/NSString/NSString+HTML.h @@ -1,5 +1,7 @@ #import @interface NSString (HTML) --(NSString *)stringByTrimmingHTMLTags; + +- (instancetype)stringByTrimmingHTMLTags; + @end diff --git a/lib/JFFUtils/NSString/NSString+HTML.m b/lib/JFFUtils/NSString/NSString+HTML.m index bf3aab8..46007e5 100644 --- a/lib/JFFUtils/NSString/NSString+HTML.m +++ b/lib/JFFUtils/NSString/NSString+HTML.m @@ -2,43 +2,43 @@ @implementation NSString (HTML) -- (NSString*)convertEntities +- (instancetype)convertEntities { - NSString *returnStr_ = self; + __block NSString *result = self; - NSDictionary *listOfReplaces_ = @{ - @"&": @"&", - @""": @"\"", - @"’": @"'", - @"'": @"'", - @"9": @"'", - @"’": @"'", - @"–": @"'", - @">": @">", - @"<": @"<", - @" ": @" ", - }; + NSDictionary *listOfReplaces = + @{ + @"&" : @"&", + @""" : @"\"", + @"’" : @"'", + @"'" : @"'", + @"9" : @"'", + @"’" : @"'", + @"–" : @"'", + @">" : @">", + @"<" : @"<", + @" " : @" ", + }; - for (NSString *elem_ in [listOfReplaces_ allKeys]) - { - NSString *correctString = [ listOfReplaces_ objectForKey:elem_ ]; - returnStr_ = [ returnStr_ stringByReplacingOccurrencesOfString:elem_ withString:correctString ]; - } + [listOfReplaces enumerateKeysAndObjectsUsingBlock:^(NSString *elem, NSString *correctString, BOOL *stop) { + + result = [result stringByReplacingOccurrencesOfString:elem withString:correctString]; + }]; - return returnStr_; + return result; } --(NSString *)stringByTrimmingHTMLTags +- (instancetype)stringByTrimmingHTMLTags { - NSRange r; - NSString *result_ = self; + NSRange range; + NSString *result = self; - while ((r = [result_ rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound) - result_ = [result_ stringByReplacingCharactersInRange:r withString:@""]; + while ((range = [result rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound) + result = [result stringByReplacingCharactersInRange:range withString:@""]; - result_ = [result_ convertEntities]; + result = [result convertEntities]; - return result_; - } + return result; +} -@end +@end \ No newline at end of file diff --git a/lib/JFFUtils/NSString/NSString+IsEmailValid.h b/lib/JFFUtils/NSString/NSString+IsEmailValid.h index 09bfac2..cb50f78 100755 --- a/lib/JFFUtils/NSString/NSString+IsEmailValid.h +++ b/lib/JFFUtils/NSString/NSString+IsEmailValid.h @@ -2,6 +2,6 @@ @interface NSString (IsEmailValid) --(BOOL)isEmailValid; +- (BOOL)isEmailValid; @end diff --git a/lib/JFFUtils/NSString/NSString+IsEmailValid.m b/lib/JFFUtils/NSString/NSString+IsEmailValid.m index cf842d4..be38550 100644 --- a/lib/JFFUtils/NSString/NSString+IsEmailValid.m +++ b/lib/JFFUtils/NSString/NSString+IsEmailValid.m @@ -13,9 +13,9 @@ - (BOOL)isEmailValid @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-" @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21" @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"; - + NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; - + return [emailTest evaluateWithObject:self]; } diff --git a/lib/JFFUtils/NSString/NSString+IsEmpty.h b/lib/JFFUtils/NSString/NSString+IsEmpty.h index 6e5a211..55bffc9 100755 --- a/lib/JFFUtils/NSString/NSString+IsEmpty.h +++ b/lib/JFFUtils/NSString/NSString+IsEmpty.h @@ -2,7 +2,7 @@ @interface NSString (IsEmpty) --(BOOL)hasSymbols; --(BOOL)hasNonWhitespaceSymbols; +- (BOOL)hasSymbols; +- (BOOL)hasNonWhitespaceSymbols; @end diff --git a/lib/JFFUtils/NSString/NSString+IsEmpty.m b/lib/JFFUtils/NSString/NSString+IsEmpty.m index 6425c84..832fe0a 100755 --- a/lib/JFFUtils/NSString/NSString+IsEmpty.m +++ b/lib/JFFUtils/NSString/NSString+IsEmpty.m @@ -2,17 +2,17 @@ @implementation NSString (IsEmpty) --(BOOL)hasSymbols +- (BOOL)hasSymbols { - return ![ self isEqualToString: @"" ]; + return ![self isEqualToString:@""]; } --(BOOL)hasNonWhitespaceSymbols +- (BOOL)hasNonWhitespaceSymbols { - NSCharacterSet *whiteSpaces_ = [ NSCharacterSet whitespaceAndNewlineCharacterSet ]; - NSString *stringWithoutWhiteSpaces_ = [ self stringByTrimmingCharactersInSet: whiteSpaces_ ]; - - return [ stringWithoutWhiteSpaces_ hasSymbols]; + NSCharacterSet *whiteSpaces = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + NSString *stringWithoutWhiteSpaces = [self stringByTrimmingCharactersInSet:whiteSpaces]; + + return [stringWithoutWhiteSpaces hasSymbols]; } @end diff --git a/lib/JFFUtils/NSString/NSString+JSEscape.h b/lib/JFFUtils/NSString/NSString+JSEscape.h index f74678d..e5e7464 100644 --- a/lib/JFFUtils/NSString/NSString+JSEscape.h +++ b/lib/JFFUtils/NSString/NSString+JSEscape.h @@ -2,6 +2,6 @@ @interface NSString (JSEscape) --(NSString *)stringByReplacingJSEscapes; +- (instancetype)stringByReplacingJSEscapes; @end diff --git a/lib/JFFUtils/NSString/NSString+JSEscape.m b/lib/JFFUtils/NSString/NSString+JSEscape.m index 7cedee0..56e69c6 100644 --- a/lib/JFFUtils/NSString/NSString+JSEscape.m +++ b/lib/JFFUtils/NSString/NSString+JSEscape.m @@ -2,10 +2,10 @@ @implementation NSString (JSEscape) --(NSString *)stringByReplacingJSEscapes +- (instancetype)stringByReplacingJSEscapes { NSString *result = [ self stringByReplacingOccurrencesOfString:@"'" withString:@"\\'" ]; - + return result; } diff --git a/lib/JFFUtils/NSString/NSString+LocalizedPrice.h b/lib/JFFUtils/NSString/NSString+LocalizedPrice.h new file mode 100644 index 0000000..a3c8a9b --- /dev/null +++ b/lib/JFFUtils/NSString/NSString+LocalizedPrice.h @@ -0,0 +1,10 @@ +#import + +typedef double(^JFFCurrencyChanger)(double); + +@interface NSString (LocalizedPrice) + ++ (instancetype)localizedPrice:(NSNumber *)price + priceLocale:(NSLocale *)priceLocale; + +@end diff --git a/lib/JFFUtils/NSString/NSString+LocalizedPrice.m b/lib/JFFUtils/NSString/NSString+LocalizedPrice.m new file mode 100644 index 0000000..86f013c --- /dev/null +++ b/lib/JFFUtils/NSString/NSString+LocalizedPrice.m @@ -0,0 +1,18 @@ +#import "NSString+LocalizedPrice.h" + +#import "NSString+Search.h" + +@implementation NSString (LocalizedPrice) + ++ (instancetype)localizedPrice:(NSNumber *)price + priceLocale:(NSLocale *)priceLocale +{ + NSNumberFormatter *numberFormatter = [NSNumberFormatter new]; + [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; + [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; + [numberFormatter setLocale:priceLocale]; + NSString *result = [numberFormatter stringFromNumber:price]; + return result; +} + +@end diff --git a/lib/JFFUtils/NSString/NSString+MD5.h b/lib/JFFUtils/NSString/NSString+MD5.h new file mode 100644 index 0000000..5db86bd --- /dev/null +++ b/lib/JFFUtils/NSString/NSString+MD5.h @@ -0,0 +1,7 @@ +#import + +@interface NSString (MD5) + +- (instancetype)md5Digest; + +@end diff --git a/lib/JFFUtils/NSString/NSString+MD5.m b/lib/JFFUtils/NSString/NSString+MD5.m new file mode 100644 index 0000000..9144dda --- /dev/null +++ b/lib/JFFUtils/NSString/NSString+MD5.m @@ -0,0 +1,21 @@ +#import "NSString+MD5.h" + +#import + +@implementation NSString(MD5) + +- (instancetype)md5Digest +{ + const char *cStr = [self UTF8String]; + unsigned char result[16]; + CC_MD5(cStr, (CC_LONG)strlen(cStr), result); // This is the md5 call + return [[NSString alloc] initWithFormat: + @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + result[0], result[1], result[2], result[3], + result[4], result[5], result[6], result[7], + result[8], result[9], result[10], result[11], + result[12], result[13], result[14], result[15] + ]; +} + +@end \ No newline at end of file diff --git a/lib/JFFUtils/NSString/NSString+PathExtensions.h b/lib/JFFUtils/NSString/NSString+PathExtensions.h index c8f3e29..6ba7f4f 100755 --- a/lib/JFFUtils/NSString/NSString+PathExtensions.h +++ b/lib/JFFUtils/NSString/NSString+PathExtensions.h @@ -2,8 +2,8 @@ @interface NSString (PathExtensions) -+ (NSString *)documentsPathByAppendingPathComponent:(NSString *)str; ++ (instancetype)documentsPathByAppendingPathComponent:(NSString *)str; -+ (NSString *)cachesPathByAppendingPathComponent:(NSString *)str; ++ (instancetype)cachesPathByAppendingPathComponent:(NSString *)str; @end diff --git a/lib/JFFUtils/NSString/NSString+PathExtensions.m b/lib/JFFUtils/NSString/NSString+PathExtensions.m index 8644429..4dd2c4f 100755 --- a/lib/JFFUtils/NSString/NSString+PathExtensions.m +++ b/lib/JFFUtils/NSString/NSString+PathExtensions.m @@ -2,36 +2,36 @@ @implementation NSString (PathExtensions) -+(NSString*)pathForDirectory:(NSSearchPathDirectory)directory ++ (instancetype)pathForDirectory:(NSSearchPathDirectory)directory { NSArray *pathes = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES); return [pathes lastObject]; } -+ (NSString *)documentsPathByAppendingPathComponent:(NSString *)str ++ (instancetype)documentsPathByAppendingPathComponent:(NSString *)str { - static NSString* documentsDirectory = nil; + static NSString *documentsDirectory = nil; static dispatch_once_t onceToken; - dispatch_once(&onceToken, - ^{ - documentsDirectory = [ self pathForDirectory: NSDocumentDirectory ]; + dispatch_once(&onceToken, ^{ + + documentsDirectory = [self pathForDirectory:NSDocumentDirectory]; }); return [ documentsDirectory stringByAppendingPathComponent: str ]; } -+ (NSString *)cachesPathByAppendingPathComponent:(NSString *)str ++ (instancetype)cachesPathByAppendingPathComponent:(NSString *)str { - static NSString* cachesDirectory = nil; + static NSString *cachesDirectory = nil; static dispatch_once_t onceToken; - dispatch_once(&onceToken, - ^{ - cachesDirectory = [ self pathForDirectory: NSCachesDirectory ]; + dispatch_once(&onceToken, ^{ + + cachesDirectory = [self pathForDirectory:NSCachesDirectory]; }); - return [ cachesDirectory stringByAppendingPathComponent: str ]; + return [cachesDirectory stringByAppendingPathComponent:str]; } @end diff --git a/lib/JFFUtils/NSString/NSString+PropertyName.h b/lib/JFFUtils/NSString/NSString+PropertyName.h index 14897f5..117484a 100755 --- a/lib/JFFUtils/NSString/NSString+PropertyName.h +++ b/lib/JFFUtils/NSString/NSString+PropertyName.h @@ -2,8 +2,8 @@ @interface NSString (PropertyName) -- (id)propertyGetNameFromPropertyName; +- (instancetype)propertyGetNameFromPropertyName; -- (id)propertySetNameForPropertyName; +- (instancetype)propertySetNameForPropertyName; @end diff --git a/lib/JFFUtils/NSString/NSString+PropertyName.m b/lib/JFFUtils/NSString/NSString+PropertyName.m index 827301f..f410906 100755 --- a/lib/JFFUtils/NSString/NSString+PropertyName.m +++ b/lib/JFFUtils/NSString/NSString+PropertyName.m @@ -5,12 +5,12 @@ @implementation NSString (PropertyName) --(id)propertyGetNameFromPropertyName +- (instancetype)propertyGetNameFromPropertyName { NSUInteger stringLength = [self length]; if (stringLength <= 4 - || [self characterAtIndex:stringLength - 1] != ':' - || ![self hasPrefix:setterPreffix] ) + || ![self hasSuffix:setterSuffix] + || ![self hasPrefix:setterPreffix]) return nil; NSRange range1 = {3, 1}; @@ -21,9 +21,9 @@ -(id)propertyGetNameFromPropertyName return [[namePart1 lowercaseString] stringByAppendingString:namePart2]; } --(id)propertySetNameForPropertyName +- (instancetype)propertySetNameForPropertyName { - if ([self hasSuffix: setterSuffix]) + if ([self hasSuffix:setterSuffix]) return nil; NSUInteger stringLength = [self length]; diff --git a/lib/JFFUtils/NSString/NSString+Search.m b/lib/JFFUtils/NSString/NSString+Search.m index 1991a00..8cbd1ba 100755 --- a/lib/JFFUtils/NSString/NSString+Search.m +++ b/lib/JFFUtils/NSString/NSString+Search.m @@ -14,7 +14,7 @@ - (NSUInteger)numberofOccurencesWithRangeSearcher:(NSRange(^)(NSRange))rangeSear ++result; searchRange.location = range.location + step; - searchRange.length = [ self length ] - searchRange.location; + searchRange.length = [self length] - searchRange.location; if (searchRange.location >= [self length]) break; diff --git a/lib/JFFUtils/NSString/NSString+StringFromTemplateString.h b/lib/JFFUtils/NSString/NSString+StringFromTemplateString.h new file mode 100644 index 0000000..6746330 --- /dev/null +++ b/lib/JFFUtils/NSString/NSString+StringFromTemplateString.h @@ -0,0 +1,7 @@ +#import + +@interface NSString (StringFromTemplateString) + +- (instancetype)localizedTemplateStringWithVariables:(NSDictionary *)variables; + +@end diff --git a/lib/JFFUtils/NSString/NSString+StringFromTemplateString.m b/lib/JFFUtils/NSString/NSString+StringFromTemplateString.m new file mode 100644 index 0000000..ca5d5de --- /dev/null +++ b/lib/JFFUtils/NSString/NSString+StringFromTemplateString.m @@ -0,0 +1,64 @@ +#import "NSString+StringFromTemplateString.h" + +//source: http://stackoverflow.com/questions/2841553/how-to-create-a-formatted-localized-string + +static NSString *specialStringBegin = @"${"; +static NSString *specialStringEnd = @"}"; + +@implementation NSString (StringFromTemplateString) + +- (instancetype)localizedTemplateStringWithVariables:(NSDictionary *)variables +{ + NSMutableString *result = [NSMutableString new]; + // Create scanner with the localized string + NSString *scannedString = NSLocalizedString(self, nil); + + while ([scannedString length] != 0) { + // Find ${variable} templates + + NSRange range = [scannedString rangeOfString:specialStringBegin]; + + if (range.location != NSNotFound) { + + if (range.location > 0) { + [result appendString:[scannedString substringToIndex:range.location]]; + } + + // Skip "@{" syntax + range.location += 2; + + NSRange rangeEnd = [scannedString rangeOfString:specialStringEnd]; + + if (rangeEnd.location != NSNotFound) { + + id variableName = [scannedString substringWithRange:NSMakeRange(range.location, rangeEnd.location - range.location)]; + id variableValue = variables[variableName]; + + // Check for the variable + if (variableValue) { + if ([variableValue isKindOfClass:[NSString class]]) { + // NSString, append + [result appendString:variableValue]; + } else { + // Not a NSString, but can handle description, append + [result appendString:[NSString localizedStringWithFormat:@"%@", variableValue]]; + } + } else { + // Not found, localize the template key and append + [result appendString:[[NSString alloc] initWithFormat:@"%@%@%@", specialStringBegin, variableName, specialStringEnd]]; + } + // Skip syntax + // + scannedString = [scannedString substringFromIndex:rangeEnd.location + rangeEnd.length]; + continue; + } + } + + [result appendString:scannedString]; + scannedString = nil; + } + + return result; +} + +@end diff --git a/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.h b/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.h index 4fbe94c..edf47fa 100755 --- a/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.h +++ b/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.h @@ -2,6 +2,6 @@ @interface NSString (StringWithCutPrefix) --(id)stringWithCutPrefix:( NSString* )prefix_; +- (instancetype)stringWithCutPrefix:(NSString *)prefix; @end diff --git a/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.m b/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.m index 5212263..e659e4a 100755 --- a/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.m +++ b/lib/JFFUtils/NSString/NSString+StringWithCutPrefix.m @@ -2,11 +2,11 @@ @implementation NSString (StringWithCutPrefix) -- (id)stringWithCutPrefix:(NSString *)prefix +- (instancetype)stringWithCutPrefix:(NSString *)prefix { return [self hasPrefix:prefix] - ? [self substringFromIndex:[prefix length]] - : self; + ?[self substringFromIndex:[prefix length]] + :self; } @end diff --git a/lib/JFFUtils/NSString/NSString+Trimm.h b/lib/JFFUtils/NSString/NSString+Trimm.h index 53279ac..785b015 100755 --- a/lib/JFFUtils/NSString/NSString+Trimm.h +++ b/lib/JFFUtils/NSString/NSString+Trimm.h @@ -2,9 +2,9 @@ @interface NSString (Trimm) --(NSString*)stringByTrimmingWhitespaces; --(NSString*)stringByTrimmingPunctuation; +- (instancetype)stringByTrimmingWhitespaces; +- (instancetype)stringByTrimmingPunctuation; --(NSString*)stringByTrimmingQuotes; +- (instancetype)stringByTrimmingQuotes; @end diff --git a/lib/JFFUtils/NSString/NSString+Trimm.m b/lib/JFFUtils/NSString/NSString+Trimm.m index eccab6f..e2a29b1 100755 --- a/lib/JFFUtils/NSString/NSString+Trimm.m +++ b/lib/JFFUtils/NSString/NSString+Trimm.m @@ -2,7 +2,7 @@ @implementation NSString (Trimm) --(NSRange)rangeForQuotesRemoval +- (NSRange)rangeForQuotesRemoval { NSString *quotedString = self; @@ -14,19 +14,19 @@ -(NSRange)rangeForQuotesRemoval return result; } -- (NSString *)stringByTrimmingWhitespaces +- (instancetype)stringByTrimmingWhitespaces { NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet]; return [self stringByTrimmingCharactersInSet:set]; } -- (NSString *)stringByTrimmingPunctuation +- (instancetype)stringByTrimmingPunctuation { NSCharacterSet *set = [NSCharacterSet punctuationCharacterSet]; return [self stringByTrimmingCharactersInSet:set]; } -- (NSString *)stringByTrimmingQuotes +- (instancetype)stringByTrimmingQuotes { NSRange rangeWithoutQuotes = [self rangeForQuotesRemoval]; NSString *result = [self substringWithRange:rangeWithoutQuotes]; diff --git a/lib/JFFUtils/NSString/NSString+UUIDCreation.h b/lib/JFFUtils/NSString/NSString+UUIDCreation.h index 422b810..9ec4585 100755 --- a/lib/JFFUtils/NSString/NSString+UUIDCreation.h +++ b/lib/JFFUtils/NSString/NSString+UUIDCreation.h @@ -2,6 +2,6 @@ @interface NSString (UUIDCreation) -+(NSString*)createUuid; ++ (instancetype)createUuid; @end diff --git a/lib/JFFUtils/NSString/NSString+UUIDCreation.m b/lib/JFFUtils/NSString/NSString+UUIDCreation.m index 1cd1d97..2777f50 100755 --- a/lib/JFFUtils/NSString/NSString+UUIDCreation.m +++ b/lib/JFFUtils/NSString/NSString+UUIDCreation.m @@ -2,12 +2,12 @@ @implementation NSString (UUIDCreation) -+ (NSString *)createUuid ++ (instancetype)createUuid { CFUUIDRef uuid = CFUUIDCreate( NULL ); - NSString* result = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuid); - CFRelease( uuid ); - + NSString *result = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuid); + CFRelease(uuid); + return result; } diff --git a/lib/JFFUtils/Runtime/JFFRuntime.h b/lib/JFFUtils/Runtime/JFFRuntime.h deleted file mode 100755 index cb3b4fa..0000000 --- a/lib/JFFUtils/Runtime/JFFRuntime.h +++ /dev/null @@ -1,3 +0,0 @@ -#import - -void enumerateAllClassesWithBlock(void(^)(Class)); diff --git a/lib/JFFUtils/Runtime/JFFRuntime.m b/lib/JFFUtils/Runtime/JFFRuntime.m deleted file mode 100755 index 09d6949..0000000 --- a/lib/JFFUtils/Runtime/JFFRuntime.m +++ /dev/null @@ -1,23 +0,0 @@ -#import "JFFRuntime.h" - -#include - -void enumerateAllClassesWithBlock(void(^block)(Class)) -{ - assert(block); - - int numClasses = objc_getClassList(NULL, 0); - Class classes[sizeof(Class) * numClasses]; - - numClasses = objc_getClassList(classes, numClasses); - - for (int index = 0; index < numClasses; ++index) { - - @autoreleasepool { - - Class class = classes[index]; - if (class_getClassMethod(class, @selector(conformsToProtocol:))) - block(class); - } - } -} diff --git a/lib/JFFUtils/Runtime/JFFRuntimeAddiotions.h b/lib/JFFUtils/Runtime/JFFRuntimeAddiotions.h new file mode 100644 index 0000000..f8ab78b --- /dev/null +++ b/lib/JFFUtils/Runtime/JFFRuntimeAddiotions.h @@ -0,0 +1,32 @@ +#ifndef JFFUtils_JFFBlockRuntimeAddiotions_h +#define JFFUtils_JFFBlockRuntimeAddiotions_h + +#include +#include + +@class +NSArray, +NSString; + +#ifdef __cplusplus +extern "C" { +#endif + + void enumerateAllClassesWithBlock(void(^)(Class)); + + const char *block_getTypeEncoding(id block); + + void invokeMethosBlockWithArgsAndReturnValue(id targetObjectOrBlock, + const char *signature, + SEL selectorOrNullForBlock, + va_list args, + id *selfArgumentPtr, + void *returnValuePtr); + + void jClass_implementProperty(Class cls, NSString *propertyName); + +#ifdef __cplusplus +} /* closing brace for extern "C" */ +#endif + +#endif //JFFUtils_JFFBlockRuntimeAddiotions_h diff --git a/lib/JFFUtils/Runtime/JFFRuntimeAddiotions.m b/lib/JFFUtils/Runtime/JFFRuntimeAddiotions.m new file mode 100644 index 0000000..9d17f17 --- /dev/null +++ b/lib/JFFUtils/Runtime/JFFRuntimeAddiotions.m @@ -0,0 +1,343 @@ +#include "JFFRuntimeAddiotions.h" + +#include + +void enumerateAllClassesWithBlock(void(^block)(Class)) +{ + NSCParameterAssert(block && "block is undefined"); + + int numClasses = objc_getClassList(NULL, 0); + Class classes[numClasses]; + + numClasses = objc_getClassList(classes, numClasses); + + for (int index = 0; index < numClasses; ++index) { + + @autoreleasepool { + + Class class = classes[index]; + if (class_getClassMethod(class, @selector(conformsToProtocol:))) + block(class); + } + } +} + +const char *block_getTypeEncoding(id block) +{ + //http://clang.llvm.org/docs/Block-ABI-Apple.html + //https://github.com/ebf/CTObjectiveCRuntimeAdditions/blob/master/CTObjectiveCRuntimeAdditions/CTObjectiveCRuntimeAdditions/CTBlockDescription.h + // + struct JFF_Block_literal_1 { + void *isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock + int flags; + int reserved; + void (*invoke)(void *, ...); + struct Block_descriptor_1 { + unsigned long int reserved; // NULL + unsigned long int size; // sizeof(struct Block_literal_1) + // optional helper functions + void (*copy_helper)(void *dst, void *src); // IFF (1<<25) + void (*dispose_helper)(void *src); // IFF (1<<25) + // required ABI.2010.3.16 + const char *signature; // IFF (1<<30) + } *descriptor; + // imported variables + }; + + typedef NS_OPTIONS(uint32_t, CTBlockDescriptionFlags) + { + CTBlockDescriptionFlagsHasCopyDispose = (1 << 25), + CTBlockDescriptionFlagsHasCtor = (1 << 26), // helpers have C++ code + CTBlockDescriptionFlagsIsGlobal = (1 << 28), + CTBlockDescriptionFlagsHasStret = (1 << 29), // IFF BLOCK_HAS_SIGNATURE + CTBlockDescriptionFlagsHasSignature = (1 << 30) + }; + + struct JFF_Block_literal_1 *blockRef = (__bridge struct JFF_Block_literal_1 *)block; + + int flags = blockRef->flags; + //unsigned long int size = blockRef->descriptor->size; + + if (flags & CTBlockDescriptionFlagsHasSignature) { + size_t signatureLocation = (size_t)blockRef->descriptor; + signatureLocation += sizeof(unsigned long int); + signatureLocation += sizeof(unsigned long int); + + if (flags & CTBlockDescriptionFlagsHasCopyDispose) { + signatureLocation += sizeof(void(*)(void *dst, void *src)); + signatureLocation += sizeof(void (*)(void *src)); + } + + const char *signature = (*(const char **)signatureLocation); + + return signature; + } + + return NULL; +} + +void invokeMethosBlockWithArgsAndReturnValue(id targetObjectOrBlock, + const char *signature, + SEL selectorOrNullForBlock, + va_list args, + id *selfArgumentPtr, + void *returnValuePtr) +{ + NSMethodSignature *signatureObj = [NSMethodSignature signatureWithObjCTypes:signature]; + + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signatureObj]; + //[invocation retainArguments]; + + if (selectorOrNullForBlock != NULL) { + + invocation.selector = selectorOrNullForBlock; + } else { + + //for block call + [invocation setArgument:selfArgumentPtr atIndex:1]; + } + + const char *signaturePtr = signature; + signaturePtr = NSGetSizeAndAlignment(signaturePtr, NULL, NULL); + signaturePtr = NSGetSizeAndAlignment(signaturePtr, NULL, NULL); + signaturePtr = NSGetSizeAndAlignment(signaturePtr, NULL, NULL); + + { + NSString *errorDescription = [[NSString alloc] initWithFormat:@"invalid signature: %s", signature]; + NSCAssert(strlen(signaturePtr) != 0, errorDescription); + } + long long value; + sscanf(signaturePtr, "%lld", &value); + + size_t startAddress = (size_t)args - value * 2; + + /*for (NSUInteger indx = 0; indx < 40; ++indx) { + + NSUInteger *ptr = (NSUInteger *)(startAddress + indx * 4); + NSLog(@"ptr: %p val: %d", ptr, *ptr); + }*/ + + for (NSUInteger index = 2; index < signatureObj.numberOfArguments; ++index) { + + signaturePtr = NSGetSizeAndAlignment(signaturePtr, NULL, NULL); + + { + NSString *errorDescription = [[NSString alloc] initWithFormat:@"invalid signature: %s", signaturePtr]; + NSCAssert(strlen(signaturePtr) != 0, errorDescription); + } + long long value; + sscanf(signaturePtr, "%lld", &value); + + size_t currAddress = startAddress + value; + + [invocation setArgument:currAddress + atIndex:index]; + } + + [invocation invokeWithTarget:targetObjectOrBlock]; + + if (returnValuePtr != NULL) + [invocation getReturnValue:returnValuePtr]; +} + +@interface JFFWeakGetterProxy : NSObject + +@property (weak, nonatomic) id targetObject; + +@end + +@implementation JFFWeakGetterProxy +@end + +typedef NS_ENUM(NSUInteger, MemoryManagement) +{ + MemoryManagementAssign, + MemoryManagementCopy, + MemoryManagementRetain, + MemoryManagementWeak +}; + +typedef id(^WeakGetterBlock)(id self_); + +inline static IMP getGetterImplementation(const MemoryManagement memoryManagement, SEL getter) +{ + if (memoryManagement == MemoryManagementWeak) { + + return imp_implementationWithBlock(^id(id self_) { + + JFFWeakGetterProxy *proxy = objc_getAssociatedObject(self_, getter); + + id result = proxy.targetObject; + + if (result) + return result; + + if (proxy) + objc_setAssociatedObject(self_, getter, nil, OBJC_ASSOCIATION_RETAIN); + + return nil; + }); + } + + return imp_implementationWithBlock(^id(id self_) { + return objc_getAssociatedObject(self_, getter); + }); +} + +inline static IMP getSetterImplementation(const MemoryManagement memoryManagement, + SEL getter, + objc_AssociationPolicy associationPolicy) +{ + if (memoryManagement == MemoryManagementWeak) { + + return imp_implementationWithBlock(^(id self_, id object) { + + JFFWeakGetterProxy *proxy = objc_getAssociatedObject(self_, getter); + + if (!object) { + + if (proxy) + objc_setAssociatedObject(self_, getter, nil, OBJC_ASSOCIATION_RETAIN); + return; + } + + if (!proxy) { + + proxy = [JFFWeakGetterProxy new]; + objc_setAssociatedObject(self_, getter, proxy, OBJC_ASSOCIATION_RETAIN); + } + + proxy.targetObject = object; + }); + } + + return imp_implementationWithBlock(^(id self_, id object) { + + objc_setAssociatedObject(self_, getter, object, associationPolicy); + }); +} + +//based on https://github.com/ebf/CTObjectiveCRuntimeAdditions/blob/master/CTObjectiveCRuntimeAdditions/CTObjectiveCRuntimeAdditions/CTObjectiveCRuntimeAdditions.m + +void jClass_implementProperty(Class cls, NSString *propertyName) +{ + NSCAssert(cls != Nil, @"class is required"); + NSCAssert(propertyName != nil, @"propertyName is required"); + + objc_property_t property = class_getProperty(cls, propertyName.UTF8String); + + unsigned int count = 0; + objc_property_attribute_t *attributes = property_copyAttributeList(property, &count); + + MemoryManagement memoryManagement = MemoryManagementAssign; + BOOL isNonatomic = NO; + + NSString *getterName = nil; + NSString *setterName = nil; + NSString *encoding = nil; + + for (int i = 0; i < count; i++) { + objc_property_attribute_t attribute = attributes[i]; + + switch (attribute.name[0]) { + case 'N': + isNonatomic = YES; + break; + case '&': + memoryManagement = MemoryManagementRetain; + break; + case 'C': + memoryManagement = MemoryManagementCopy; + break; + case 'G': + getterName = [[NSString alloc] initWithFormat:@"%s", attribute.value]; + break; + case 'S': + setterName = [[NSString alloc] initWithFormat:@"%s", attribute.value]; + break; + case 'T': + encoding = [[NSString alloc] initWithFormat:@"%s", attribute.value]; + break; + case 'W': + memoryManagement = MemoryManagementWeak; + break; + default: + break; + } + } + + NSCAssert([encoding length] != 0, @"encoding is required"); + + if (!getterName) { + getterName = propertyName; + } + + if (!setterName) { + NSString *firstLetter = [propertyName substringToIndex:1]; + setterName = [propertyName stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[NSString stringWithFormat:@"set%@", firstLetter.uppercaseString]]; + setterName = [setterName stringByAppendingString:@":"]; + } + + NSCAssert([encoding characterAtIndex:0] != '{', @"structs are not supported"); + NSCAssert([encoding characterAtIndex:0] != '(', @"unions are not supported"); + + SEL getter = NSSelectorFromString(getterName); + SEL setter = NSSelectorFromString(setterName); + + if (encoding.UTF8String[0] == @encode(id)[0]) { + + IMP getterImplementation = getGetterImplementation(memoryManagement, getter); + + objc_AssociationPolicy associationPolicy = 0; + + if (memoryManagement == MemoryManagementCopy) { + associationPolicy = isNonatomic?OBJC_ASSOCIATION_COPY_NONATOMIC:OBJC_ASSOCIATION_COPY; + } else { + associationPolicy = isNonatomic?OBJC_ASSOCIATION_RETAIN_NONATOMIC:OBJC_ASSOCIATION_RETAIN; + } + + IMP setterImplementation = getSetterImplementation(memoryManagement, getter, associationPolicy); + + BOOL added1 = class_addMethod(cls, getter, getterImplementation, "@8@0:4");//was "@@:" + BOOL added2 = class_addMethod(cls, setter, setterImplementation, "v@:@"); + + NSCAssert(added1 && added2, @"encoding is required"); + + return; + } + + objc_AssociationPolicy associationPolicy = isNonatomic ? OBJC_ASSOCIATION_RETAIN_NONATOMIC : OBJC_ASSOCIATION_RETAIN; + +#define CASE(type, selectorpart) if (encoding.UTF8String[0] == @encode(type)[0]) {\ +IMP getterImplementation = imp_implementationWithBlock(^type(id self) {\ +return [objc_getAssociatedObject(self, getter) selectorpart##Value];\ +});\ +\ +IMP setterImplementation = imp_implementationWithBlock(^(id self, type object) {\ +objc_setAssociatedObject(self, getter, @(object), associationPolicy);\ +});\ +\ +class_addMethod(cls, getter, getterImplementation, "@@:");\ +class_addMethod(cls, setter, setterImplementation, "v@:@");\ +\ +return;\ +} + + CASE(char, char); + CASE(unsigned char, unsignedChar); + CASE(short, short); + CASE(unsigned short, unsignedShort); + CASE(int, int); + CASE(unsigned int, unsignedInt); + CASE(long, long); + CASE(unsigned long, unsignedLong); + CASE(long long, longLong); + CASE(unsigned long long, unsignedLongLong); + CASE(float, float); + CASE(double, double); + CASE(BOOL, bool); + +#undef CASE + + NSCAssert(NO, @"encoding %@ in not supported", encoding); +} diff --git a/lib/JFFUtils/ToURL/NSString+ToURL.h b/lib/JFFUtils/ToURL/NSString+ToURL.h index 89923d2..71ad5e5 100755 --- a/lib/JFFUtils/ToURL/NSString+ToURL.h +++ b/lib/JFFUtils/ToURL/NSString+ToURL.h @@ -2,6 +2,6 @@ @interface NSString (ToURL) -- (NSURL*)toURL; +- (NSURL *)toURL; @end diff --git a/lib/JFFUtils/ToURL/NSString+ToURL.m b/lib/JFFUtils/ToURL/NSString+ToURL.m index 656c1d9..338a255 100755 --- a/lib/JFFUtils/ToURL/NSString+ToURL.m +++ b/lib/JFFUtils/ToURL/NSString+ToURL.m @@ -2,9 +2,9 @@ @implementation NSString (ToURL) -- (NSURL*)toURL +- (NSURL *)toURL { - return [[NSURL alloc]initWithString:self]; + return [[NSURL alloc] initWithString:self]; } @end diff --git a/lib/JFFUtils/ToURL/NSURL+CPlusPlus.h b/lib/JFFUtils/ToURL/NSURL+CPlusPlus.h index e195eec..77560dd 100755 --- a/lib/JFFUtils/ToURL/NSURL+CPlusPlus.h +++ b/lib/JFFUtils/ToURL/NSURL+CPlusPlus.h @@ -4,6 +4,6 @@ @interface NSURL (CPlusPlus) --(std::string)toStlString; +- (std::string)toStlString; @end diff --git a/lib/JFFUtils/ToURL/NSURL+CPlusPlus.mm b/lib/JFFUtils/ToURL/NSURL+CPlusPlus.mm index 5e68f81..845148d 100755 --- a/lib/JFFUtils/ToURL/NSURL+CPlusPlus.mm +++ b/lib/JFFUtils/ToURL/NSURL+CPlusPlus.mm @@ -3,9 +3,9 @@ @implementation NSURL (CPlusPlus) --(std::string)toStlString +- (std::string)toStlString { - return [ [ self absoluteString ] toStlString ]; + return [[self absoluteString] toStlString]; } @end diff --git a/lib/JFFUtils/ToURL/NSURL+ToURL.h b/lib/JFFUtils/ToURL/NSURL+ToURL.h index 5eb84a2..0eade7d 100755 --- a/lib/JFFUtils/ToURL/NSURL+ToURL.h +++ b/lib/JFFUtils/ToURL/NSURL+ToURL.h @@ -2,6 +2,6 @@ @interface NSURL (ToURL) --(NSURL*)toURL; +- (NSURL *)toURL; @end diff --git a/lib/JFFUtils/ToURL/NSURL+ToURL.m b/lib/JFFUtils/ToURL/NSURL+ToURL.m index ef2814e..2802f0c 100755 --- a/lib/JFFUtils/ToURL/NSURL+ToURL.m +++ b/lib/JFFUtils/ToURL/NSURL+ToURL.m @@ -2,7 +2,7 @@ @implementation NSURL (ToURL) --(NSURL*)toURL +- (NSURL *)toURL { return self; } diff --git a/lib/JFFUtils/UIImage/UIImage+ScaleToSize.h b/lib/JFFUtils/UIImage/UIImage+ScaleToSize.h deleted file mode 100644 index 74c236f..0000000 --- a/lib/JFFUtils/UIImage/UIImage+ScaleToSize.h +++ /dev/null @@ -1,8 +0,0 @@ -#import - -@interface UIImage (ScaleToSize) - -- (UIImage *)imageScaledToSize:(CGSize)targetSize - contentMode:(UIViewContentMode)contentMode; - -@end diff --git a/lib/TouchXmlHelper/TouchXmlHelper.xcodeproj/project.pbxproj b/lib/TouchXmlHelper/TouchXmlHelper.xcodeproj/project.pbxproj index 3847336..bad42d0 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper.xcodeproj/project.pbxproj +++ b/lib/TouchXmlHelper/TouchXmlHelper.xcodeproj/project.pbxproj @@ -37,13 +37,6 @@ remoteGlobalIDString = 451E6E311152EB4A0024ABA5; remoteInfo = Validator; }; - 7E25B3F215860ED300469187 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E25B3E215860ED300469187 /* TouchXML.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1B0E823A1563882000825E3C; - remoteInfo = TouchXMLiOS; - }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -138,7 +131,6 @@ children = ( 7E25B3EF15860ED300469187 /* TouchXML_UnitTests.octest */, 7E25B3F115860ED300469187 /* Validator.app */, - 7E25B3F315860ED300469187 /* libTouchXMLiOS.a */, ); name = Products; sourceTree = ""; @@ -185,7 +177,7 @@ 7E25B3AF15860D2600469187 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = Sitecore; }; buildConfigurationList = 7E25B3B215860D2600469187 /* Build configuration list for PBXProject "TouchXmlHelper" */; @@ -226,13 +218,6 @@ remoteRef = 7E25B3F015860ED300469187 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7E25B3F315860ED300469187 /* libTouchXMLiOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libTouchXMLiOS.a; - remoteRef = 7E25B3F215860ED300469187 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; /* End PBXReferenceProxy section */ /* Begin PBXSourcesBuildPhase section */ @@ -256,7 +241,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -276,7 +260,8 @@ "$SDKROOT/usr/include/libxml2/**", .., ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; @@ -285,7 +270,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -298,7 +282,7 @@ "$SDKROOT/usr/include/libxml2/**", .., ); - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; diff --git a/lib/TouchXmlHelper/TouchXmlHelper/CXMLElement+Custom.m b/lib/TouchXmlHelper/TouchXmlHelper/CXMLElement+Custom.m index 8f73d31..8726c9b 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper/CXMLElement+Custom.m +++ b/lib/TouchXmlHelper/TouchXmlHelper/CXMLElement+Custom.m @@ -2,50 +2,49 @@ @implementation CXMLElement (Custom) --(CXMLElement*)firstElementIfExistsForName:( NSString* )name_ - logMessageEnabled:( BOOL )logMessageEnabled_ - shouldFail:( BOOL )shouldFail_ +- (CXMLElement *)firstElementIfExistsForName:(NSString *)name + logMessageEnabled:(BOOL)logMessageEnabled + shouldFail:(BOOL)shouldFail { - NSArray* elements_ = [ self elementsForName: name_ ]; - if ( [ elements_ count ] == 0 ) - { - if ( logMessageEnabled_ ) - { - NSLog( @"[!!! WARNING !!!] - No elements for name: %@", name_ ); - NSLog( @"In node : "); - NSLog( @"%@", self ); + NSArray *elements = [self elementsForName:name]; + if ([elements count] == 0) { + + if (logMessageEnabled) { + + NSLog(@"[!!! WARNING !!!] - No elements for name: %@", name); + NSLog(@"In node : "); + NSLog(@"%@", self); } - if ( shouldFail_ ) - { - NSAssert1( NO, @"[!!! ERROR !!!] - No elements for name: %@", name_ ); + if (shouldFail) { + NSAssert1(NO, @"[!!! ERROR !!!] - No elements for name: %@", name); } - + return nil; } - - return [ elements_ objectAtIndex: 0 ]; + + return elements[0]; } --(CXMLElement*)firstElementForName:( NSString* )name_ +- (CXMLElement *)firstElementForName:(NSString *)name { - return [ self firstElementIfExistsForName: name_ - logMessageEnabled: YES - shouldFail: YES ]; + return [self firstElementIfExistsForName:name + logMessageEnabled:YES + shouldFail:YES]; } --(CXMLElement*)firstElementForNameNoThrow:( NSString* )name_ +- (CXMLElement *)firstElementForNameNoThrow:(NSString *)name { - return [ self firstElementIfExistsForName: name_ - logMessageEnabled: YES - shouldFail: NO ]; + return [self firstElementIfExistsForName:name + logMessageEnabled:YES + shouldFail:NO]; } --(CXMLElement*)firstElementIfExistsForName:( NSString* )name_ +- (CXMLElement *)firstElementIfExistsForName:(NSString *)name { - return [ self firstElementIfExistsForName: name_ - logMessageEnabled: NO - shouldFail: NO ]; + return [self firstElementIfExistsForName:name + logMessageEnabled:NO + shouldFail:NO]; } @end diff --git a/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.h b/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.h index 8011508..bef0c95 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.h +++ b/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.h @@ -2,13 +2,13 @@ @interface CXMLNode (Custom) --(CXMLNode*)firstNodeIfExistsForXPath:( NSString* )xpath_ - namespaceMappings:( NSDictionary* )namespaceMappings_; +- (CXMLNode *)firstNodeIfExistsForXPath:(NSString *)xpath + namespaceMappings:(NSDictionary *)namespaceMappings; --(CXMLNode*)firstNodeForXPath:( NSString* )xpath_ - namespaceMappings:( NSDictionary* )namespaceMappings_; +- (CXMLNode *)firstNodeForXPath:(NSString *)xpath + namespaceMappings:(NSDictionary *)namespaceMappings; --(NSArray*)nodesForXPath:( NSString* )xpath_ - namespaceMappings:( NSDictionary* )namespaceMappings_; +- (NSArray *)nodesForXPath:(NSString *)xpath + namespaceMappings:(NSDictionary *)namespaceMappings; @end diff --git a/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.m b/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.m index 7c63df0..a95232a 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.m +++ b/lib/TouchXmlHelper/TouchXmlHelper/CXMLNode+Custom.m @@ -2,53 +2,51 @@ @implementation CXMLNode (Custom) --(CXMLNode*)firstNodeIfExistsForXPath:( NSString* )xpath_ - namespaceMappings:( NSDictionary* )namespaceMappings_ - logMessageEnabled:( BOOL )logMessageEnabled_ - shouldFail:( BOOL )shouldFail_ +- (CXMLNode *)firstNodeIfExistsForXPath:(NSString *)xpath + namespaceMappings:(NSDictionary *)namespaceMappings + logMessageEnabled:(BOOL)logMessageEnabled + shouldFail:(BOOL)shouldFail { - NSArray* nodes_ = [ self nodesForXPath: xpath_ namespaceMappings: namespaceMappings_ ]; - if ( [ nodes_ count ] == 0 ) - { - if ( logMessageEnabled_ ) - { - NSLog( @"[!!! WARNING !!!] - No elements for path: %@", xpath_ ); - NSLog( @"In node : "); - NSLog( @"%@", self ); + NSArray *nodes = [self nodesForXPath:xpath namespaceMappings:namespaceMappings]; + if ([nodes count] == 0) { + + if (logMessageEnabled) { + NSLog(@"[!!! WARNING !!!] - No elements for path: %@", xpath); + NSLog(@"In node : "); + NSLog(@"%@", self ); } - if ( shouldFail_ ) - { - NSAssert1( NO, @"[!!! ERROR !!!] - No elements for path: %@", xpath_ ); + if (shouldFail) { + NSAssert1(NO, @"[!!! ERROR !!!] - No elements for path: %@", xpath); } - + return nil; } - - return [ nodes_ objectAtIndex: 0 ]; + + return nodes[0]; } --(CXMLNode*)firstNodeIfExistsForXPath:( NSString* )xpath_ - namespaceMappings:( NSDictionary* )namespaceMappings_ +- (CXMLNode *)firstNodeIfExistsForXPath:(NSString *)xpath + namespaceMappings:(NSDictionary *)namespaceMappings { - return [self firstNodeIfExistsForXPath: xpath_ - namespaceMappings: namespaceMappings_ - logMessageEnabled: NO - shouldFail: NO ]; + return [self firstNodeIfExistsForXPath:xpath + namespaceMappings:namespaceMappings + logMessageEnabled:NO + shouldFail:NO]; } --(CXMLNode*)firstNodeForXPath:( NSString* )xpath_ - namespaceMappings:( NSDictionary* )namespaceMappings_ +- (CXMLNode *)firstNodeForXPath:(NSString *)xpath + namespaceMappings:(NSDictionary *)namespaceMappings { - return [ self firstNodeIfExistsForXPath: xpath_ - namespaceMappings: namespaceMappings_ - logMessageEnabled: YES - shouldFail: YES ]; + return [self firstNodeIfExistsForXPath:xpath + namespaceMappings:namespaceMappings + logMessageEnabled:YES + shouldFail:YES]; } --(NSArray*)nodesForXPath:( NSString* )xpath_ - namespaceMappings:( NSDictionary* )namespace_mappings_ +- (NSArray *)nodesForXPath:(NSString *)xpath + namespaceMappings:(NSDictionary *)namespaceMappings { - return [ self nodesForXPath: xpath_ namespaceMappings: namespace_mappings_ error: 0 ]; + return [self nodesForXPath:xpath namespaceMappings:namespaceMappings error:0]; } @end diff --git a/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseEmptyXMLError.m b/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseEmptyXMLError.m index ee562c7..893eabc 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseEmptyXMLError.m +++ b/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseEmptyXMLError.m @@ -2,9 +2,9 @@ @implementation JFFRestKitParseEmptyXMLError --(id)init +- (instancetype)init { - return [ self initWithDescription: NSLocalizedString( @"JFF_RESTKIT_PARSE_EMPTY_XML_ERROR", nil ) ]; + return [self initWithDescription:NSLocalizedString(@"JFF_RESTKIT_PARSE_EMPTY_XML_ERROR", nil)]; } @end diff --git a/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseInvalidXMLError.m b/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseInvalidXMLError.m index 4c1b15a..1cd39ba 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseInvalidXMLError.m +++ b/lib/TouchXmlHelper/TouchXmlHelper/JFFRestKitParseInvalidXMLError.m @@ -2,9 +2,9 @@ @implementation JFFRestKitParseInvalidXMLError --(id)init +- (instancetype)init { - return [ self initWithDescription: NSLocalizedString( @"JFF_RESTKIT_PARSE_INVALID_XML_ERROR", nil ) ]; + return [self initWithDescription:NSLocalizedString(@"JFF_RESTKIT_PARSE_INVALID_XML_ERROR", nil)]; } @end diff --git a/lib/TouchXmlHelper/TouchXmlHelper/asyncXMLParsers.m b/lib/TouchXmlHelper/TouchXmlHelper/asyncXMLParsers.m index 5402b7c..d20c41d 100644 --- a/lib/TouchXmlHelper/TouchXmlHelper/asyncXMLParsers.m +++ b/lib/TouchXmlHelper/TouchXmlHelper/asyncXMLParsers.m @@ -1,22 +1,23 @@ #import "asyncXMLParsers.h" #import "jRestKitXMLTools.h" + #import //JTODO test JFFAsyncOperationBinder xmlDocumentWithDataAsyncBinder( void ) { - return ^JFFAsyncOperation( NSData* data_ ) { - return ^JFFCancelAsyncOperation( JFFAsyncOperationProgressHandler progressCallback_ - , JFFCancelAsyncOperationHandler cancelCallback_ - , JFFDidFinishAsyncOperationHandler doneCallback_ ) - { - NSError* parseError_ = nil; + return ^JFFAsyncOperation(NSData *data) { + return ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { + + NSError *parseError = nil; //STODO parse on separate thread and test - CXMLDocument* document_ = xmlDocumentWithData( data_, &parseError_ ); + CXMLDocument *document = xmlDocumentWithData(data, &parseError); - if ( doneCallback_ ) - doneCallback_( document_, parseError_ ); + if (doneCallback) + doneCallback(document, parseError); return JFFStubCancelAsyncOperationBlock; }; diff --git a/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.h b/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.h index 59a19e2..c76abeb 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.h +++ b/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.h @@ -2,5 +2,4 @@ @class CXMLDocument; -CXMLDocument* xmlDocumentWithData( NSData* data_, NSError** outError_ ); - +CXMLDocument *xmlDocumentWithData(NSData *data, NSError **outError); diff --git a/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.m b/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.m index ea7d1eb..7ff386a 100755 --- a/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.m +++ b/lib/TouchXmlHelper/TouchXmlHelper/jRestKitXMLTools.m @@ -3,33 +3,34 @@ #import "JFFRestKitParseEmptyXMLError.h" #import "JFFRestKitParseInvalidXMLError.h" - -CXMLDocument* xmlDocumentWithData( NSData* data_, NSError** outError_ ) +CXMLDocument *xmlDocumentWithData(NSData *data, NSError **outError) { - if ( [ data_ length ] == 0 ) - { - [ [ JFFRestKitParseEmptyXMLError new ] setToPointer: outError_ ]; + if ([data length] == 0) { + + if (NULL != outError) { + *outError = [JFFRestKitParseEmptyXMLError new]; + } return nil; } - - NSError* parseError_ = nil; - - CXMLDocument* document_ = [ [ CXMLDocument alloc ] initWithData: data_ - options: 0 - error: &parseError_ ]; - - xmlErrorPtr xmlError_ = nil; - if ( document_ ) - xmlError_ = xmlCtxtGetLastError( document_->xmlCtxt ); - - if ( !parseError_ && xmlError_ ) - { - NSString* errorDescription_ = @( xmlError_->message ); - parseError_ = [ JFFRestKitParseInvalidXMLError newErrorWithDescription: errorDescription_ ]; - document_ = nil; + + NSError *parseError = nil; + + CXMLDocument *document = [[CXMLDocument alloc] initWithData:data + options:0 + error:&parseError]; + + xmlErrorPtr xmlError = nil; + if (document) + xmlError = xmlCtxtGetLastError(document->xmlCtxt); + + if (!parseError && xmlError) { + + NSString *errorDescription = @(xmlError->message); + parseError = [JFFRestKitParseInvalidXMLError newErrorWithDescription:errorDescription]; + document = nil; } - - [ parseError_ setToPointer: outError_ ]; - - return document_; + + [parseError setToPointer:outError]; + + return document; } diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest.xcodeproj/project.pbxproj b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest.xcodeproj/project.pbxproj index 8b3c206..4c92dd8 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest.xcodeproj/project.pbxproj +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest.xcodeproj/project.pbxproj @@ -26,9 +26,8 @@ 1BEE3AFF15EFA9D40024D249 /* CachedAsyncOperationsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 65977F8014A6731000AB83AE /* CachedAsyncOperationsTest.m */; }; 1BEE3B0015EFA9D40024D249 /* AsyncOperationBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B7A10A314C036D900F37C95 /* AsyncOperationBinder.m */; }; 1BEE3B0115EFA9D40024D249 /* AsyncOperationWithDelayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 65359B4D151A6DB90099D6FE /* AsyncOperationWithDelayTest.m */; }; - 7E12F4B817FAA43C00ABE54E /* SequenceWithAllResultTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E12F4B717FAA43C00ABE54E /* SequenceWithAllResultTest.m */; }; - 7E3884D017FBED8100399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E3884CF17FBED8100399329 /* QuartzCore.framework */; }; - 7E95E46317FB11B2001961B4 /* SequenceWithSuccessfullResultTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E95E46217FB11B2001961B4 /* SequenceWithSuccessfullResultTest.m */; }; + 4CCA7DFE17FEE7A300D85F5B /* SequenceWithAllResultTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCA7DFD17FEE7A300D85F5B /* SequenceWithAllResultTest.m */; }; + 4CCA7E0117FEEA6100D85F5B /* SequenceWithSuccessfullResultTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCA7E0017FEEA6100D85F5B /* SequenceWithSuccessfullResultTest.m */; }; 8D29EF8D13BE066900041B6A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D29EF8C13BE066900041B6A /* UIKit.framework */; }; 8D29EF8F13BE066900041B6A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D29EF8E13BE066900041B6A /* Foundation.framework */; }; 8D29EF9113BE066900041B6A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D29EF9013BE066900041B6A /* CoreGraphics.framework */; }; @@ -152,13 +151,6 @@ remoteGlobalIDString = 65802A5B148BF2930040A93A; remoteInfo = JFFUtilsMacOS; }; - 7E12F4C317FAA43D00ABE54E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 1B835A0E142C8BAB00FC004C /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CE28A105161793F40029BE05 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 1B835A0E142C8BAB00FC004C /* JFFUtils.xcodeproj */; @@ -185,13 +177,12 @@ 1BA2551F1443114300C9B2BE /* SequenceOfAsyncOperationsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequenceOfAsyncOperationsTest.m; sourceTree = ""; }; 1BA27738144D9B1B00774C8E /* TrySequenceOfAsyncOperationsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TrySequenceOfAsyncOperationsTest.m; sourceTree = ""; }; 1BED04FF144EBF2800B8DC2A /* GroupOfAsyncOperationsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupOfAsyncOperationsTest.m; sourceTree = ""; }; + 4CCA7DFD17FEE7A300D85F5B /* SequenceWithAllResultTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequenceWithAllResultTest.m; sourceTree = ""; }; + 4CCA7E0017FEEA6100D85F5B /* SequenceWithSuccessfullResultTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequenceWithSuccessfullResultTest.m; sourceTree = ""; }; 5357CDF914A9F5130046EA34 /* libstdc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.dylib"; path = "usr/lib/libstdc++.dylib"; sourceTree = SDKROOT; }; 65359B4D151A6DB90099D6FE /* AsyncOperationWithDelayTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncOperationWithDelayTest.m; sourceTree = ""; }; 65359BD5151A81C40099D6FE /* ParalelBlockTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParalelBlockTest.m; sourceTree = ""; }; 65977F8014A6731000AB83AE /* CachedAsyncOperationsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CachedAsyncOperationsTest.m; sourceTree = ""; }; - 7E12F4B717FAA43C00ABE54E /* SequenceWithAllResultTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequenceWithAllResultTest.m; sourceTree = ""; }; - 7E3884CF17FBED8100399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 7E95E46217FB11B2001961B4 /* SequenceWithSuccessfullResultTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequenceWithSuccessfullResultTest.m; sourceTree = ""; }; 8D29EF8813BE066900041B6A /* JFFAsyncOperationsTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JFFAsyncOperationsTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D29EF8C13BE066900041B6A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 8D29EF8E13BE066900041B6A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -211,7 +202,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E3884D017FBED8100399329 /* QuartzCore.framework in Frameworks */, 1BEC48A4156A27660099DA6D /* libstdc++.dylib in Frameworks */, 1B0E89DF1563FB1100825E3C /* libc++.dylib in Frameworks */, 1B2D8C49154BFE7300360296 /* libJFFTestTools.a in Frameworks */, @@ -255,7 +245,6 @@ 5357CE0514A9F5130046EA34 /* libJFFUtils-clang.a */, 6500345C151A646D008F16E7 /* JFFUtilsFW.framework */, CE28A106161793F40029BE05 /* JFFUtilsTest.octest */, - 7E12F4C417FAA43D00ABE54E /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -303,7 +292,6 @@ 8D29EF8B13BE066900041B6A /* Frameworks */ = { isa = PBXGroup; children = ( - 7E3884CF17FBED8100399329 /* QuartzCore.framework */, 1B0E89DE1563FB1100825E3C /* libc++.dylib */, 5357CDF914A9F5130046EA34 /* libstdc++.dylib */, 8D29EFB213BE070F00041B6A /* GHUnitIOS.framework */, @@ -323,8 +311,6 @@ 1B2A680C143F514C00BC284F /* JFFCancelAyncOperationBlockHolderTest.m */, 1B793B32142C851C00B43DC8 /* WeakAsyncOperationTest.m */, 1BA2551F1443114300C9B2BE /* SequenceOfAsyncOperationsTest.m */, - 7E12F4B717FAA43C00ABE54E /* SequenceWithAllResultTest.m */, - 7E95E46217FB11B2001961B4 /* SequenceWithSuccessfullResultTest.m */, 1BA27738144D9B1B00774C8E /* TrySequenceOfAsyncOperationsTest.m */, 1BED04FF144EBF2800B8DC2A /* GroupOfAsyncOperationsTest.m */, 1B0857D014516076001DDE0A /* FailOnFirstErrorGroupOfAsyncOperationsTest.m */, @@ -334,6 +320,8 @@ 65359BD5151A81C40099D6FE /* ParalelBlockTest.m */, 1B93690515650A5A00F8A394 /* JFFAsyncOperationUtilsTest.m */, CEBCFC1D163D42AB0009772F /* JFFLimitedLoadersQueueTest.m */, + 4CCA7DFD17FEE7A300D85F5B /* SequenceWithAllResultTest.m */, + 4CCA7E0017FEEA6100D85F5B /* SequenceWithSuccessfullResultTest.m */, ); path = JFFAsyncOperationsTest; sourceTree = ""; @@ -382,7 +370,7 @@ 8D29EF7F13BE066900041B6A /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0500; }; buildConfigurationList = 8D29EF8213BE066900041B6A /* Build configuration list for PBXProject "JFFAsyncOperationsTest" */; compatibilityVersion = "Xcode 3.2"; @@ -504,13 +492,6 @@ remoteRef = 65D8B6C5148C025900C02FA4 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7E12F4C417FAA43D00ABE54E /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E12F4C317FAA43D00ABE54E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE28A106161793F40029BE05 /* JFFUtilsTest.octest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; @@ -555,11 +536,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 7E95E46317FB11B2001961B4 /* SequenceWithSuccessfullResultTest.m in Sources */, + 4CCA7E0117FEEA6100D85F5B /* SequenceWithSuccessfullResultTest.m in Sources */, 8D29EF9913BE066900041B6A /* main.m in Sources */, 1B12CB3B144D5C5900DFE2B1 /* JFFAsyncOperationManager.m in Sources */, 1BEE3AF115EFA9850024D249 /* TrySequenceOfAsyncOperationsTest.m in Sources */, - 7E12F4B817FAA43C00ABE54E /* SequenceWithAllResultTest.m in Sources */, + 4CCA7DFE17FEE7A300D85F5B /* SequenceWithAllResultTest.m in Sources */, 1BEE3AF715EFA9A40024D249 /* ParalelBlockTest.m in Sources */, 1BEE3AF815EFA9A40024D249 /* JFFAsyncOperationUtilsTest.m in Sources */, 1BEE3AF915EFA9D40024D249 /* JFFDidFinishAsyncOperationBlockHolderTest.m in Sources */, @@ -616,9 +597,10 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -635,15 +617,19 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../../lib, ../../lib/JFFTestTools, ); IPHONEOS_DEPLOYMENT_TARGET = 3.2; + ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = ( "-ObjC", "-all_load", @@ -658,9 +644,10 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -670,9 +657,12 @@ GCC_GENERATE_TEST_COVERAGE_FILES = YES; GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../../lib, diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationBinder.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationBinder.m index 46f46fd..d5c6447 100755 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationBinder.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationBinder.m @@ -61,40 +61,39 @@ -(void)testNormalFinish GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); } --(void)testFailFirstLoader +- (void)testFailFirstLoader { @autoreleasepool { - JFFAsyncOperationManager* firstLoader_ = [JFFAsyncOperationManager new]; - JFFAsyncOperationManager* secondLoader_ = [JFFAsyncOperationManager new]; - JFFAsyncOperation secondLoaderBlock_ = secondLoader_.loader; + JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; + JFFAsyncOperationManager *secondLoader = [JFFAsyncOperationManager new]; + JFFAsyncOperation secondLoaderBlock = secondLoader.loader; - __block NSError* finalError_ = nil; - __block BOOL binderCalled_ = NO; + __block NSError *finalError = nil; + __block BOOL binderCalled = NO; - JFFAsyncOperationBinder secondLoaderBinder_ = ^JFFAsyncOperation( id firstResult_ ) { - binderCalled_ = YES; - return secondLoaderBlock_; + JFFAsyncOperationBinder secondLoaderBinder = ^JFFAsyncOperation( id firstResult_ ) { + binderCalled = YES; + return secondLoaderBlock; }; - JFFAsyncOperation asyncOp_ = bindSequenceOfAsyncOperations( firstLoader_.loader - , secondLoaderBinder_ - , nil ); - - asyncOp_( nil, nil, ^( id result_, NSError* error_ ) - { - finalError_ = error_; - } ); - - NSError* failError_ = [ JFFError newErrorWithDescription: @"error1" ]; - firstLoader_.loaderFinishBlock.didFinishBlock( nil, failError_ ); - - GHAssertFalse( binderCalled_, @"OK" ); - GHAssertTrue( failError_ == finalError_, @"OK" ); + JFFAsyncOperation asyncOp = bindSequenceOfAsyncOperations(firstLoader.loader, + secondLoaderBinder, + nil ); + + asyncOp(nil, nil, ^(id result, NSError *error) { + finalError = error; + }); + + NSError* failError = [JFFError newErrorWithDescription:@"error1"]; + firstLoader.loaderFinishBlock.didFinishBlock( nil, failError ); + + GHAssertFalse(binderCalled, @"OK" ); + GHAssertTrue(failError == finalError, @"OK" ); } - - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); + + GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"OK"); + GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"OK"); + GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"OK"); } @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationWithDelayTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationWithDelayTest.m index 67f5d03..3c4ea3a 100755 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationWithDelayTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/AsyncOperationWithDelayTest.m @@ -9,49 +9,53 @@ @interface AsyncOperationWithDelayTest : GHAsyncTestCase @implementation AsyncOperationWithDelayTest --(void)setUp +- (void)setUp { [JFFScheduler enableInstancesCounting]; } --(void)testCancelAsyncOperationWithDelay +- (void)testCancelAsyncOperationWithDelay { const NSUInteger initialSchedulerInstancesCount = [JFFScheduler instancesCount]; __block BOOL cancelBlockOk = NO; __block NSTimeInterval timeDifference = 0; - @autoreleasepool { - JFFAsyncOperation loader = asyncOperationWithDelay(.2); + void (^block)(JFFSimpleBlock) = ^(JFFSimpleBlock complete) { - JFFAsyncOperationProgressHandler progressCallback = ^(id data) { - [self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; - }; - JFFCancelAsyncOperationHandler cancelCallback = ^(BOOL canceled) { - cancelBlockOk = canceled; - }; - JFFDidFinishAsyncOperationHandler doneCallback = ^(id result, NSError *error) { - [self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; - }; - - JFFCancelAsyncOperation cancel = loader(progressCallback, - cancelCallback, - doneCallback); - - cancel(YES); - - NSDate *startDate = [NSDate new]; - - asyncOperationWithDelay(.3)(nil, nil, ^(id result, NSError *error) { - NSDate *finishDate = [NSDate new]; - timeDifference = [finishDate timeIntervalSinceDate:startDate]; + @autoreleasepool { + JFFAsyncOperation loader = asyncOperationWithDelay(.2, .02); + + JFFAsyncOperationProgressHandler progressCallback = ^(id data) { + complete(); + }; + JFFCancelAsyncOperationHandler cancelCallback = ^(BOOL canceled) { + cancelBlockOk = canceled; + }; + JFFDidFinishAsyncOperationHandler doneCallback = ^(id result, NSError *error) { + complete(); + }; + + JFFCancelAsyncOperation cancel = loader(progressCallback, + cancelCallback, + doneCallback); - [self notify:kGHUnitWaitStatusSuccess forSelector:_cmd]; - }); - } + cancel(YES); + + NSDate *startDate = [NSDate new]; + + asyncOperationWithDelay(.3, .03)(nil, nil, ^(id result, NSError *error) { + NSDate *finishDate = [NSDate new]; + timeDifference = [finishDate timeIntervalSinceDate:startDate]; + + complete(); + }); + } + }; - [self prepare]; - [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.]; + [self performAsyncRequestOnMainThreadWithBlock:block + selector:_cmd + timeout:1.]; GHAssertTrue(initialSchedulerInstancesCount == [JFFScheduler instancesCount], @"OK"); @@ -59,33 +63,37 @@ -(void)testCancelAsyncOperationWithDelay GHAssertTrue(timeDifference >= 0.3, @"OK"); } --(void)testAsyncOperationWithDelayTwiceCall +- (void)testAsyncOperationWithDelayTwiceCall { const NSUInteger initialSchedulerInstancesCount = [JFFScheduler instancesCount]; __block NSUInteger callsCount = 0; - @autoreleasepool { - JFFAsyncOperation loader = asyncOperationWithDelay(.2); - - JFFAsyncOperationProgressHandler progressCallback = ^(id data) { - [self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; - }; - JFFCancelAsyncOperationHandler cancelCallback = ^(BOOL canceled) { - [self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; - }; - JFFDidFinishAsyncOperationHandler doneCallback = ^(id result, NSError *error) { - ++callsCount; - if (callsCount == 2) - [self notify:kGHUnitWaitStatusSuccess forSelector:_cmd]; - }; + void (^block)(JFFSimpleBlock) = ^(JFFSimpleBlock complete) { - loader(progressCallback, cancelCallback, doneCallback); - loader(progressCallback, cancelCallback, doneCallback); - } + @autoreleasepool { + JFFAsyncOperation loader = asyncOperationWithDelay(.2, .02); + + JFFAsyncOperationProgressHandler progressCallback = ^(id data) { + complete(); + }; + JFFCancelAsyncOperationHandler cancelCallback = ^(BOOL canceled) { + complete(); + }; + JFFDidFinishAsyncOperationHandler doneCallback = ^(id result, NSError *error) { + ++callsCount; + if (callsCount == 2) + complete(); + }; + + loader(progressCallback, cancelCallback, doneCallback); + loader(progressCallback, cancelCallback, doneCallback); + } + }; - [self prepare]; - [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.]; + [self performAsyncRequestOnMainThreadWithBlock:block + selector:_cmd + timeout:1.]; GHAssertTrue(initialSchedulerInstancesCount == [JFFScheduler instancesCount], @"OK"); diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationManager.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationManager.m index 3b158f7..4244a0d 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationManager.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationManager.m @@ -17,33 +17,41 @@ @interface JFFAsyncOperationManager () @implementation JFFAsyncOperationManager -- (id)init +- (JFFDidFinishAsyncOperationBlockHolder *)loaderFinishBlock { - self = [super init]; + if (!_loaderFinishBlock) { + + _loaderFinishBlock = [JFFDidFinishAsyncOperationBlockHolder new]; + } - if (self) { - self->_loaderFinishBlock = [JFFDidFinishAsyncOperationBlockHolder new]; - self->_loaderCancelBlock = [JFFCancelAsyncOperationBlockHolder new]; + return _loaderFinishBlock; +} + +- (JFFCancelAsyncOperationBlockHolder *)loaderCancelBlock +{ + if (!_loaderCancelBlock) { + + _loaderCancelBlock = [JFFCancelAsyncOperationBlockHolder new]; } - return self; + return _loaderCancelBlock; } - (void)clear { - self.loaderFinishBlock = nil; - self.loaderCancelBlock = nil; - self.finished = NO; + _loaderFinishBlock = nil; + _loaderCancelBlock = nil; + _finished = NO; } - (JFFAsyncOperation)loader { - __weak JFFAsyncOperationManager *weakSelf = self; - return [^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progress_callback, JFFCancelAsyncOperationHandler cancelCallback, JFFDidFinishAsyncOperationHandler doneCallback) { + __weak JFFAsyncOperationManager *weakSelf = self; + self.loadingCount += 1; if (self.cancelAtLoading > JFFDoNotCancelAsyncOperationManager) { @@ -82,7 +90,7 @@ - (JFFAsyncOperation)loader cancelCallback(canceled); }; return self.loaderCancelBlock.onceCancelBlock; - } copy ]; + } copy]; } @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationUtilsTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationUtilsTest.m index f2a0011..83aeeaa 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationUtilsTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationUtilsTest.m @@ -6,40 +6,43 @@ @implementation JFFAsyncOperationUtilsTest -(void)testCallingOfPregressBlock { - NSObject *resultObject = [NSObject new]; - - JFFSyncOperation loadDataBlock = ^id(NSError **error) { - return resultObject; - }; - - JFFAsyncOperation loader = asyncOperationWithSyncOperationAndQueue(loadDataBlock, "com.test"); - - __block BOOL resultCalled = NO; - - JFFDidFinishAsyncOperationHandler doneCallback_ = ^(id result, NSError *error) { - resultCalled = YES; - [ self notify: kGHUnitWaitStatusSuccess forSelector: _cmd ]; - }; - - __block BOOL progressCalled_ = NO; + __block BOOL progressCalled = NO; __block NSUInteger progressCallsCount = 0; __block BOOL progressCalledBeforeResult = NO; - JFFAsyncOperationProgressHandler progressCallback_ = ^(id info) { - progressCalled_ = (info == resultObject); - ++progressCallsCount; - progressCalledBeforeResult = !resultCalled; + void (^block)(JFFSimpleBlock) = ^(JFFSimpleBlock complete) { + + NSObject *resultObject = [NSObject new]; + + JFFSyncOperation loadDataBlock = ^id(NSError **error) { + return resultObject; + }; + + JFFAsyncOperation loader = asyncOperationWithSyncOperationAndQueue(loadDataBlock, "com.test"); + + __block BOOL resultCalled = NO; + + JFFDidFinishAsyncOperationHandler doneCallback = ^(id result, NSError *error) { + resultCalled = YES; + complete(); + }; + + JFFAsyncOperationProgressHandler progressCallback = ^(id info) { + progressCalled = (info == resultObject); + ++progressCallsCount; + progressCalledBeforeResult = !resultCalled; + }; + + loader(progressCallback, nil, doneCallback); }; - - loader(progressCallback_, nil, doneCallback_); - //TODO sometimes fails - fix !!! - [self prepare]; - [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.]; - - GHAssertTrue( progressCalled_, @"ok" ); - GHAssertTrue( progressCallsCount == 1, @"ok" ); - GHAssertTrue( progressCalledBeforeResult, @"ok" ); + [self performAsyncRequestOnMainThreadWithBlock:block + selector:_cmd + timeout:1.]; + + GHAssertTrue(progressCalled, @"ok"); + GHAssertTrue(progressCallsCount == 1, @"ok"); + GHAssertTrue(progressCalledBeforeResult, @"ok"); } @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationsTest-Prefix.pch b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationsTest-Prefix.pch index 43b781c..c35c93c 100755 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationsTest-Prefix.pch +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFAsyncOperationsTest-Prefix.pch @@ -13,7 +13,7 @@ #import #import #import - + #import #import #endif diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFDidFinishAsyncOperationBlockHolderTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFDidFinishAsyncOperationBlockHolderTest.m index d85ed11..454279b 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFDidFinishAsyncOperationBlockHolderTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFDidFinishAsyncOperationBlockHolderTest.m @@ -11,41 +11,41 @@ -(void)testDidFinishAsyncOperationBlockHolder @autoreleasepool { - JFFDidFinishAsyncOperationBlockHolder* holder_ = [ JFFDidFinishAsyncOperationBlockHolder new ]; - [ holder_ addOnDeallocBlock: ^void( void ) + JFFDidFinishAsyncOperationBlockHolder *holder = [JFFDidFinishAsyncOperationBlockHolder new]; + [ holder addOnDeallocBlock: ^void( void ) { holderDeallocated_ = YES; } ]; - - __block BOOL blockContextDeallocated_ = NO; - __block NSUInteger finishBlockCallsNumber_ = 0; + + __block BOOL blockContextDeallocated = NO; + __block NSUInteger finishBlockCallsNumber = 0; @autoreleasepool { - NSObject* blockContext_ = [ NSObject new ]; - [ blockContext_ addOnDeallocBlock: ^void( void ) - { - blockContextDeallocated_ = YES; - } ]; - - holder_.didFinishBlock = ^( id result_, NSError* error_ ) - { - if ( [ blockContext_ class ] ) - ++finishBlockCallsNumber_; + NSObject *blockContext = [NSObject new]; + [blockContext addOnDeallocBlock:^void(void) { + + blockContextDeallocated = YES; + }]; + + holder.didFinishBlock = ^(id result, NSError *error) { + + if ([blockContext class]) + ++finishBlockCallsNumber; }; } + + GHAssertFalse( blockContextDeallocated, @"context not deallocated" ); - GHAssertFalse( blockContextDeallocated_, @"context not deallocated" ); - - holder_.onceDidFinishBlock( nil, nil ); + holder.onceDidFinishBlock( nil, nil ); - GHAssertTrue( nil == holder_.didFinishBlock, @"finish block empty" ); - GHAssertTrue( blockContextDeallocated_, @"context deallocated" ); - GHAssertTrue( 1 == finishBlockCallsNumber_, @"block once was called" ); + GHAssertTrue( nil == holder.didFinishBlock, @"finish block empty" ); + GHAssertTrue( blockContextDeallocated, @"context deallocated" ); + GHAssertTrue( 1 == finishBlockCallsNumber, @"block once was called" ); - holder_.onceDidFinishBlock( nil, nil ); + holder.onceDidFinishBlock( nil, nil ); - GHAssertTrue( 1 == finishBlockCallsNumber_, @"block still once was called" ); + GHAssertTrue( 1 == finishBlockCallsNumber, @"block still once was called" ); } GHAssertTrue( holderDeallocated_, @"holder deallocated" ); diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFLimitedLoadersQueueTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFLimitedLoadersQueueTest.m index 837c6d3..96872b7 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFLimitedLoadersQueueTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/JFFLimitedLoadersQueueTest.m @@ -3,7 +3,7 @@ #import -#import +#import @interface JFFLimitedLoadersQueueTest : GHAsyncTestCase @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/ParalelBlockTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/ParalelBlockTest.m index 3443c95..9604cf1 100755 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/ParalelBlockTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/ParalelBlockTest.m @@ -9,123 +9,129 @@ @implementation ParalelBlockTest -(void)setUp { - [ JFFBlockOperation enableInstancesCounting ]; + [JFFBlockOperation enableInstancesCounting]; } -(void)testParalelTask { const NSUInteger initialSchedulerInstancesCount = [JFFBlockOperation instancesCount]; - - __block BOOL theSameThread_ = NO; - __block BOOL theProgressOk_ = NO; - - @autoreleasepool - { - dispatch_queue_t currentQueue_ = dispatch_get_current_queue(); - - JFFSyncOperationWithProgress progressLoadDataBlock_ = ^id( NSError** error_ - , JFFAsyncOperationProgressHandler progressCallback_ ) - { - if ( progressCallback_ ) - progressCallback_( [ NSNull null ] ); - return [ NSNull null ]; - }; - JFFAsyncOperation loader_ = asyncOperationWithSyncOperationWithProgressBlock( progressLoadDataBlock_ ); - - JFFDidFinishAsyncOperationHandler doneCallback_ = ^( id result_, NSError* error_ ) + + __block BOOL theSameThread = NO; + __block BOOL theProgressOk = NO; + + void (^block)(JFFSimpleBlock) = ^(JFFSimpleBlock complete) { + @autoreleasepool { - theSameThread_ = ( currentQueue_ == dispatch_get_current_queue() ); - - if ( result_ && theSameThread_ ) + dispatch_queue_t currentQueue = dispatch_get_current_queue(); + + JFFSyncOperationWithProgress progressLoadDataBlock_ = ^id(NSError** error, + JFFAsyncOperationProgressHandler progressCallback) { - [ self notify: kGHUnitWaitStatusSuccess forSelector: _cmd ]; - } - else + if (progressCallback) + progressCallback([NSNull null]); + return [NSNull null]; + }; + JFFAsyncOperation loader = asyncOperationWithSyncOperationWithProgressBlock( progressLoadDataBlock_ ); + + JFFDidFinishAsyncOperationHandler doneCallback = ^( id result_, NSError* error_ ) { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; - } - }; - - JFFAsyncOperationProgressHandler progressCallback_ = ^( id data_ ) - { - theProgressOk_ = YES; - - theSameThread_ = ( currentQueue_ == dispatch_get_current_queue() ); - - if ( !theSameThread_ ) + theSameThread = ( currentQueue == dispatch_get_current_queue() ); + + if ( result_ && theSameThread ) + { + complete(); + } + else + { + complete(); + } + }; + + JFFAsyncOperationProgressHandler progressCallback = ^(id data) { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; - } - }; - - loader_( progressCallback_, nil, doneCallback_ ); - } - - [ self prepare ]; - [ self waitForStatus: kGHUnitWaitStatusSuccess timeout: 1. ]; - + theProgressOk = YES; + + theSameThread = (currentQueue == dispatch_get_current_queue()); + + if (!theSameThread) { + + complete(); + } + }; + + loader(progressCallback, nil, doneCallback); + } + }; + + [self performAsyncRequestOnMainThreadWithBlock:block + selector:_cmd + timeout:1.]; + GHAssertTrue(initialSchedulerInstancesCount == [JFFBlockOperation instancesCount], @"OK"); - - GHAssertTrue( theSameThread_, @"OK" ); - GHAssertTrue( theProgressOk_, @"OK" ); + + GHAssertTrue(theSameThread, @"OK"); + GHAssertTrue(theProgressOk, @"OK"); } --(void)testCancelParalelTask +- (void)testCancelParalelTask { - const NSUInteger initialSchedulerInstancesCount_ = [ JFFBlockOperation instancesCount ]; - - __block BOOL theSameThread_ = NO; - - @autoreleasepool - { - dispatch_queue_t currentQueue_ = dispatch_get_current_queue(); - - JFFSyncOperationWithProgress progressLoadDataBlock_ = ^id( NSError** error_ - , JFFAsyncOperationProgressHandler progressCallback_ ) - { - progressCallback_( [ NSNull null ] ); - return [ NSNull null ]; - }; - JFFAsyncOperation loader_ = asyncOperationWithSyncOperationWithProgressBlock( progressLoadDataBlock_ ); - - JFFCancelAsyncOperationHandler cancelCallback_ = ^( BOOL canceled_ ) + const NSUInteger initialSchedulerInstancesCount = [JFFBlockOperation instancesCount]; + + __block BOOL theSameThread = NO; + + void (^block)(JFFSimpleBlock) = ^(JFFSimpleBlock complete) { + @autoreleasepool { - theSameThread_ = ( currentQueue_ == dispatch_get_current_queue() ); - - if ( theSameThread_ && canceled_ ) + dispatch_queue_t currentQueue = dispatch_get_current_queue(); + + JFFSyncOperationWithProgress progressLoadDataBlock = ^id(NSError **error, + JFFAsyncOperationProgressHandler progressCallback) { - [ self notify: kGHUnitWaitStatusSuccess forSelector: _cmd ]; - } - else + progressCallback([ NSNull new]); + return [NSNull new]; + }; + JFFAsyncOperation loader = asyncOperationWithSyncOperationWithProgressBlock(progressLoadDataBlock); + + JFFCancelAsyncOperationHandler cancelCallback = ^(BOOL canceled) { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; - } - }; - - JFFDidFinishAsyncOperationHandler doneCallback_ = ^( id result_, NSError* error_ ) - { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; - }; - - JFFAsyncOperationProgressHandler progressCallback_ = ^( id data_ ) - { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; - }; - - asyncOperationWithDelay( 0.1 )( nil, nil, ^( id result_, NSError* error_ ) - { - loader_( progressCallback_ - , cancelCallback_ - , doneCallback_ )( YES ); - } ); - } - - [ self prepare ]; - [ self waitForStatus: kGHUnitWaitStatusSuccess timeout: 1. ]; + theSameThread = ( currentQueue == dispatch_get_current_queue() ); + + if (theSameThread && canceled) + { + complete(); + } + else + { + complete(); + } + }; + + JFFDidFinishAsyncOperationHandler doneCallback = ^(id result, NSError *error) + { + complete(); + }; + + JFFAsyncOperationProgressHandler progressCallback = ^(id data) + { + complete(); + }; + + asyncOperationWithDelay(0.1, 0.01)(nil, nil, ^(id result, NSError *error) + { + loader(progressCallback, + cancelCallback, + doneCallback)(YES); + } ); + } + }; - GHAssertTrue( initialSchedulerInstancesCount_ == [ JFFBlockOperation instancesCount ], @"OK" ); + [self performAsyncRequestOnMainThreadWithBlock:block + selector:_cmd + timeout:1.]; + + GHAssertTrue(initialSchedulerInstancesCount == [JFFBlockOperation instancesCount], @"OK"); - GHAssertTrue( theSameThread_, @"OK" ); + GHAssertTrue(theSameThread, @"OK"); } @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithAllResultTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithAllResultTest.m index 6722a24..134025e 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithAllResultTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithAllResultTest.m @@ -3,99 +3,113 @@ #import #import - @interface SequenceWithAllResultTest : GHTestCase @end @implementation SequenceWithAllResultTest --(void)setUp +- (void)setUp { [super setUp]; - + [JFFCancelAsyncOperationBlockHolder enableInstancesCounting]; [JFFDidFinishAsyncOperationBlockHolder enableInstancesCounting]; [JFFAsyncOperationManager enableInstancesCounting]; } --(void)tearDown -{ - // Put teardown code here; it will be run once, after the last test case. - [ super tearDown ]; -} - --(void)testBlocksAreExecutedInTurn +- (void)testBlocksAreExecutedInTurn { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; JFFAsyncOperationManager *secondLoader = [JFFAsyncOperationManager new]; JFFAsyncOperationManager *thirdLoader = [JFFAsyncOperationManager new]; - __weak JFFAsyncOperationManager* assign_first_loader_ = firstLoader; - JFFAsyncOperation loader2_ = asyncOperationWithDoneBlock( secondLoader.loader, ^() { + __weak JFFAsyncOperationManager *assignFirstLoader = firstLoader; + JFFAsyncOperation loader2 = asyncOperationWithDoneBlock(secondLoader.loader, ^() { - GHAssertTrue( assign_first_loader_.finished, @"First loader finished already" ); - } ); + GHAssertTrue(assignFirstLoader.finished, @"First loader finished already"); + }); - JFFAsyncOperation loader_ = sequenceOfAsyncOperationsWithAllResults( @[ firstLoader.loader, loader2_, thirdLoader.loader ] ); + JFFAsyncOperation loader = sequenceOfAsyncOperationsWithAllResults(@[firstLoader.loader, loader2, thirdLoader.loader]); __block id sequenceResult = nil; __block BOOL sequenceLoaderFinished = NO; - loader_( nil, nil, ^( id result_, NSError* error_ ) { + + JFFSimpleBlock test = ^() { + + sequenceResult = nil; + sequenceLoaderFinished = NO; + + [firstLoader clear]; + [secondLoader clear]; + [thirdLoader clear]; - if ( result_ && !error_ ) { + loader(nil, nil, ^(id result, NSError *error) { - sequenceResult = result_; - sequenceLoaderFinished = YES; - } - } ); - - NSNumber* firstResult = @(2.71); - NSNumber* secondResult = @(3.14); - NSString* thirdResult = @"E and Pi"; - - GHAssertFalse( firstLoader.finished, @"First loader not finished yet" ); - GHAssertFalse( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertFalse( sequenceLoaderFinished, @"Sequence loader not finished yet" ); - - firstLoader.loaderFinishBlock.didFinishBlock( firstResult, nil ); - GHAssertTrue( firstLoader.finished, @"First loader finished already" ); - GHAssertFalse( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertFalse( sequenceLoaderFinished, @"Sequence loader finished already" ); - - - secondLoader.loaderFinishBlock.didFinishBlock( secondResult, nil ); - GHAssertTrue( firstLoader.finished, @"First loader finished already" ); - GHAssertTrue( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertFalse( sequenceLoaderFinished, @"Sequence loader finished already" ); - - thirdLoader.loaderFinishBlock.didFinishBlock( thirdResult, nil ); - GHAssertTrue( firstLoader.finished, @"First loader finished already" ); - GHAssertTrue( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertTrue( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertTrue( sequenceLoaderFinished, @"Sequence loader finished already" ); + if (result && !error) { + + sequenceResult = result; + sequenceLoaderFinished = YES; + } + }); + + NSNumber *firstResult = @(2.71); + NSNumber *secondResult = @(3.14); + NSString *thirdResult = @"E and Pi"; + + GHAssertFalse(firstLoader.finished , @"First loader not finished yet"); + GHAssertFalse(secondLoader.finished , @"Second loader not finished yet"); + GHAssertFalse(thirdLoader.finished , @"Third loader not finished yet"); + GHAssertFalse(sequenceLoaderFinished, @"Sequence loader not finished yet"); + + firstLoader.loaderFinishBlock.didFinishBlock(firstResult, nil); + GHAssertTrue(firstLoader.finished , @"First loader finished already"); + GHAssertFalse(secondLoader.finished , @"Second loader not finished yet"); + GHAssertFalse(thirdLoader.finished , @"Third loader not finished yet"); + GHAssertFalse(sequenceLoaderFinished, @"Sequence loader finished already"); + + secondLoader.loaderFinishBlock.didFinishBlock(secondResult, nil); + GHAssertTrue(firstLoader.finished , @"First loader finished already"); + GHAssertTrue(secondLoader.finished , @"Second loader not finished yet"); + GHAssertFalse(thirdLoader.finished , @"Third loader not finished yet"); + GHAssertFalse(sequenceLoaderFinished, @"Sequence loader finished already"); + + thirdLoader.loaderFinishBlock.didFinishBlock(thirdResult, nil); + GHAssertTrue(firstLoader.finished , @"First loader finished already"); + GHAssertTrue(secondLoader.finished , @"Second loader not finished yet"); + GHAssertTrue(thirdLoader.finished , @"Third loader not finished yet"); + GHAssertTrue(sequenceLoaderFinished, @"Sequence loader finished already"); + + GHAssertTrue([sequenceResult isKindOfClass:[NSArray class]], @"Result type mismatch"); + GHAssertTrue(3 == [sequenceResult count], @"result count mismatch"); + + NSArray *expectedResult = @[firstResult, secondResult, thirdResult]; + GHAssertEqualObjects(expectedResult, sequenceResult, @"result object mismatch"); + }; + test(); - GHAssertTrue( [ sequenceResult isKindOfClass: [ NSArray class ] ], @"Result type mismatch" ); - GHAssertTrue( 3 == [ sequenceResult count ], @"result count mismatch" ); - - NSArray* expectedResult = @[ firstResult, secondResult, thirdResult ]; - GHAssertEqualObjects( expectedResult, sequenceResult, @"result object mismatch" ); + test();//invoke th same loader again } - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } -(void)testMultiSequenceWithEmptyArray { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { GHAssertThrows @@ -105,28 +119,31 @@ -(void)testMultiSequenceWithEmptyArray ); } - - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } --(void)testMultiSequenceWithOneLoader +- (void)testMultiSequenceWithOneLoader { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; - JFFAsyncOperation loader_ = sequenceOfAsyncOperationsWithAllResults( @[firstLoader.loader] ); + JFFAsyncOperation loader = sequenceOfAsyncOperationsWithAllResults( @[firstLoader.loader] ); __block id sequenceResult = nil; __block BOOL sequenceLoaderFinished = NO; - loader_( nil, nil, ^( id result_, NSError* error_ ) { + loader( nil, nil, ^(id result, NSError *error_ ) { - if ( result_ && !error_ ) { + if ( result && !error_ ) { - sequenceResult = result_; + sequenceResult = result; sequenceLoaderFinished = YES; } } ); @@ -145,15 +162,18 @@ -(void)testMultiSequenceWithOneLoader NSArray* expectedResult = @[ firstResult ]; GHAssertEqualObjects( expectedResult, sequenceResult, @"result object mismatch" ); } - - - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); + + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } --(void)testMultiSequenceFailsIfAnyOperationFails +- (void)testMultiSequenceFailsIfAnyOperationFails { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; @@ -177,22 +197,20 @@ -(void)testMultiSequenceFailsIfAnyOperationFails __block BOOL sequenceLoaderFinished = NO; loader_( nil, nil, ^( id result_, NSError* error_ ) { - sequenceError = error_; - sequenceResult = result_; - sequenceLoaderFinished = YES; + sequenceError = error_; + sequenceResult = result_; + sequenceLoaderFinished = YES; } ); - GHAssertFalse( firstLoader.finished, @"First loader not finished yet" ); GHAssertFalse( secondLoader.finished, @"Second loader not finished yet" ); GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); GHAssertFalse( sequenceLoaderFinished, @"Sequence loader not finished yet" ); - + NSNumber* firstResult = @(2.71); firstLoader.loaderFinishBlock.didFinishBlock( firstResult, nil ); - -// secondLoader.loaderFinishBlock.didFinishBlock( nil, secondError ); + // secondLoader.loaderFinishBlock.didFinishBlock( nil, secondError ); GHAssertTrue( firstLoader.finished, @"First loader finished already" ); GHAssertTrue( secondLoader.finished, @"Second loader not finished yet" ); GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); @@ -202,9 +220,9 @@ -(void)testMultiSequenceFailsIfAnyOperationFails GHAssertNotNil( sequenceError, @"error object mismatch" ); } - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithSuccessfullResultTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithSuccessfullResultTest.m index 7041e0d..823b125 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithSuccessfullResultTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/SequenceWithSuccessfullResultTest.m @@ -9,93 +9,108 @@ @interface SequenceWithSuccessfullResultTest : GHTestCase @implementation SequenceWithSuccessfullResultTest --(void)setUp +- (void)setUp { [super setUp]; - + [JFFCancelAsyncOperationBlockHolder enableInstancesCounting]; [JFFDidFinishAsyncOperationBlockHolder enableInstancesCounting]; [JFFAsyncOperationManager enableInstancesCounting]; } --(void)tearDown -{ - // Put teardown code here; it will be run once, after the last test case. - [ super tearDown ]; -} - --(void)testBlocksAreExecutedInTurn +- (void)testBlocksAreExecutedInTurn { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; JFFAsyncOperationManager *secondLoader = [JFFAsyncOperationManager new]; JFFAsyncOperationManager *thirdLoader = [JFFAsyncOperationManager new]; - __weak JFFAsyncOperationManager* assign_first_loader_ = firstLoader; - JFFAsyncOperation loader2_ = asyncOperationWithDoneBlock( secondLoader.loader, ^() { + __weak JFFAsyncOperationManager *assignFirstLoader = firstLoader; + JFFAsyncOperation loader2 = asyncOperationWithDoneBlock(secondLoader.loader, ^() { - GHAssertTrue( assign_first_loader_.finished, @"First loader finished already" ); - } ); + GHAssertTrue( assignFirstLoader.finished, @"First loader finished already" ); + }); - JFFAsyncOperation loader_ = sequenceOfAsyncOperationsWithSuccessfullResults( @[ firstLoader.loader, loader2_, thirdLoader.loader ] ); + JFFAsyncOperation loader = sequenceOfAsyncOperationsWithSuccessfullResults(@[firstLoader.loader, loader2, thirdLoader.loader]); __block id sequenceResult = nil; - __block BOOL sequenceLoaderFinished = NO; - loader_( nil, nil, ^( id result_, NSError* error_ ) { - - if ( result_ && !error_ ) { - - sequenceResult = result_; - sequenceLoaderFinished = YES; - } - } ); - - NSNumber* firstResult = @(2.71); - NSNumber* secondResult = @(3.14); - NSString* thirdResult = @"E and Pi"; - - GHAssertFalse( firstLoader.finished, @"First loader not finished yet" ); - GHAssertFalse( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertFalse( sequenceLoaderFinished, @"Sequence loader not finished yet" ); - - firstLoader.loaderFinishBlock.didFinishBlock( firstResult, nil ); - GHAssertTrue( firstLoader.finished, @"First loader finished already" ); - GHAssertFalse( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertFalse( sequenceLoaderFinished, @"Sequence loader finished already" ); - - - secondLoader.loaderFinishBlock.didFinishBlock( secondResult, nil ); - GHAssertTrue( firstLoader.finished, @"First loader finished already" ); - GHAssertTrue( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertFalse( sequenceLoaderFinished, @"Sequence loader finished already" ); - thirdLoader.loaderFinishBlock.didFinishBlock( thirdResult, nil ); - GHAssertTrue( firstLoader.finished, @"First loader finished already" ); - GHAssertTrue( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertTrue( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertTrue( sequenceLoaderFinished, @"Sequence loader finished already" ); + JFFSimpleBlock test = ^() { + sequenceResult = nil; + sequenceLoaderFinished = NO; + + [firstLoader clear]; + [secondLoader clear]; + [thirdLoader clear]; + + loader( nil, nil, ^(id result, NSError *error) { + + if (result && !error) { + + sequenceResult = result; + sequenceLoaderFinished = YES; + } + }); + + NSNumber *firstResult = @(2.71); + NSNumber *secondResult = @(3.14); + NSString *thirdResult = @"E and Pi"; + + GHAssertFalse(firstLoader.finished, @"First loader not finished yet" ); + GHAssertFalse(secondLoader.finished, @"Second loader not finished yet" ); + GHAssertFalse(thirdLoader.finished, @"Third loader not finished yet" ); + GHAssertFalse(sequenceLoaderFinished, @"Sequence loader not finished yet" ); + + firstLoader.loaderFinishBlock.didFinishBlock( firstResult, nil ); + GHAssertTrue(firstLoader.finished, @"First loader finished already" ); + GHAssertFalse(secondLoader.finished, @"Second loader not finished yet" ); + GHAssertFalse(thirdLoader.finished, @"Third loader not finished yet" ); + GHAssertFalse(sequenceLoaderFinished, @"Sequence loader finished already"); + + secondLoader.loaderFinishBlock.didFinishBlock( secondResult, nil ); + GHAssertTrue(firstLoader.finished, @"First loader finished already" ); + GHAssertTrue(secondLoader.finished, @"Second loader not finished yet" ); + GHAssertFalse(thirdLoader.finished, @"Third loader not finished yet" ); + GHAssertFalse(sequenceLoaderFinished, @"Sequence loader finished already" ); + + thirdLoader.loaderFinishBlock.didFinishBlock( thirdResult, nil ); + GHAssertTrue( firstLoader.finished, @"First loader finished already" ); + GHAssertTrue( secondLoader.finished, @"Second loader not finished yet" ); + GHAssertTrue( thirdLoader.finished, @"Third loader not finished yet" ); + GHAssertTrue( sequenceLoaderFinished, @"Sequence loader finished already" ); + + + GHAssertTrue( [ sequenceResult isKindOfClass: [ NSArray class ] ], @"Result type mismatch" ); + GHAssertTrue( 3 == [ sequenceResult count ], @"result count mismatch" ); + + NSArray* expectedResult = @[ firstResult, secondResult, thirdResult ]; + GHAssertEqualObjects( expectedResult, sequenceResult, @"result object mismatch" ); + }; - GHAssertTrue( [ sequenceResult isKindOfClass: [ NSArray class ] ], @"Result type mismatch" ); - GHAssertTrue( 3 == [ sequenceResult count ], @"result count mismatch" ); + test(); - NSArray* expectedResult = @[ firstResult, secondResult, thirdResult ]; - GHAssertEqualObjects( expectedResult, sequenceResult, @"result object mismatch" ); + test();//invoke th same loader again } - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"Successfull object of this class should be deSuccessfullocated"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } --(void)testMultiSequenceWithEmptyArray +- (void)testMultiSequenceWithEmptyArray { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { GHAssertThrows @@ -105,31 +120,34 @@ -(void)testMultiSequenceWithEmptyArray ); } - - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"Successfull object of this class should be deSuccessfullocated"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } --(void)testMultiSequenceWithOneLoader +- (void)testMultiSequenceWithOneLoader { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; - JFFAsyncOperation loader_ = sequenceOfAsyncOperationsWithSuccessfullResults( @[firstLoader.loader] ); + JFFAsyncOperation loader = sequenceOfAsyncOperationsWithSuccessfullResults(@[firstLoader.loader]); __block id sequenceResult = nil; __block BOOL sequenceLoaderFinished = NO; - loader_( nil, nil, ^( id result_, NSError* error_ ) { + loader(nil, nil, ^(id result, NSError *error) { - if ( result_ && !error_ ) { + if (result && !error) { - sequenceResult = result_; + sequenceResult = result; sequenceLoaderFinished = YES; } - } ); + }); NSNumber* firstResult = @(2.71); GHAssertFalse( firstLoader.finished, @"First loader not finished yet" ); @@ -145,15 +163,18 @@ -(void)testMultiSequenceWithOneLoader NSArray* expectedResult = @[ firstResult ]; GHAssertEqualObjects( expectedResult, sequenceResult, @"result object mismatch" ); } - - - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"Successfull object of this class should be deSuccessfullocated"); + + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } --(void)testFailedOperationResultsAreSkippedInMultiSequence +- (void)testFailedOperationResultsAreSkippedInMultiSequence { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; @@ -164,54 +185,52 @@ -(void)testFailedOperationResultsAreSkippedInMultiSequence JFFAsyncOperationManager *thirdLoader = [JFFAsyncOperationManager new]; thirdLoader.finishAtLoading = YES; - __weak JFFAsyncOperationManager* assign_first_loader_ = firstLoader; - JFFAsyncOperation loader2_ = asyncOperationWithDoneBlock( secondLoader.loader, ^() { + __weak JFFAsyncOperationManager* assignFirstLoader = firstLoader; + JFFAsyncOperation loader2 = asyncOperationWithDoneBlock(secondLoader.loader, ^() { - GHAssertTrue( assign_first_loader_.finished, @"First loader finished already" ); - } ); + GHAssertTrue( assignFirstLoader.finished, @"First loader finished already" ); + }); - JFFAsyncOperation loader_ = sequenceOfAsyncOperationsWithSuccessfullResults( @[ firstLoader.loader, loader2_, thirdLoader.loader ] ); + JFFAsyncOperation loader = sequenceOfAsyncOperationsWithSuccessfullResults(@[firstLoader.loader, loader2, thirdLoader.loader]); __block id sequenceResult = nil; - __block NSError* sequenceError = nil; + __block NSError *sequenceError = nil; __block BOOL sequenceLoaderFinished = NO; - loader_( nil, nil, ^( id result_, NSError* error_ ) { - sequenceError = error_; - sequenceResult = result_; - sequenceLoaderFinished = YES; - } ); - - - GHAssertFalse( firstLoader.finished, @"First loader not finished yet" ); - GHAssertFalse( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertFalse( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertFalse( sequenceLoaderFinished, @"Sequence loader not finished yet" ); - - NSNumber* firstResult = @(2.71); - NSNull* thirdResult = [ NSNull null ]; + loader(nil, nil, ^( id result_, NSError* error_ ) { + sequenceError = error_; + sequenceResult = result_; + sequenceLoaderFinished = YES; + }); + + GHAssertFalse(firstLoader.finished, @"First loader not finished yet" ); + GHAssertFalse(secondLoader.finished, @"Second loader not finished yet" ); + GHAssertFalse(thirdLoader.finished, @"Third loader not finished yet" ); + GHAssertFalse(sequenceLoaderFinished, @"Sequence loader not finished yet" ); + + NSNumber *firstResult = @(2.71); + NSNull *thirdResult = [NSNull null]; firstLoader.loaderFinishBlock.didFinishBlock( firstResult, nil ); - -// secondLoader.loaderFinishBlock.didFinishBlock( nil, secondError ); - GHAssertTrue( firstLoader.finished, @"First loader finished already" ); - GHAssertTrue( secondLoader.finished, @"Second loader not finished yet" ); - GHAssertTrue( thirdLoader.finished, @"Third loader not finished yet" ); - GHAssertTrue( sequenceLoaderFinished, @"Sequence loader finished already" ); + // secondLoader.loaderFinishBlock.didFinishBlock( nil, secondError ); + GHAssertTrue(firstLoader.finished, @"First loader finished already" ); + GHAssertTrue(secondLoader.finished, @"Second loader not finished yet" ); + GHAssertTrue(thirdLoader.finished, @"Third loader not finished yet" ); + GHAssertTrue(sequenceLoaderFinished, @"Sequence loader finished already" ); - GHAssertNotNil( sequenceResult, @"Result type mismatch" ); - GHAssertNil( sequenceError, @"error object mismatch" ); + GHAssertNotNil(sequenceResult, @"Result type mismatch" ); + GHAssertNil(sequenceError, @"error object mismatch" ); - GHAssertTrue( [ sequenceResult isKindOfClass: [ NSArray class ] ], @"Result type mismatch" ); - GHAssertTrue( 2 == [ sequenceResult count ], @"result count mismatch" ); + GHAssertTrue([ sequenceResult isKindOfClass: [ NSArray class ] ], @"Result type mismatch" ); + GHAssertTrue(2 == [ sequenceResult count ], @"result count mismatch" ); NSArray* expectedResult = @[ firstResult, thirdResult ]; GHAssertEqualObjects( expectedResult, sequenceResult, @"result object mismatch" ); } - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"Successfull object of this class should be deSuccessfullocated"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"Successfull object of this class should be deSuccessfullocated"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/TrySequenceOfAsyncOperationsTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/TrySequenceOfAsyncOperationsTest.m index a623ba5..4760f0b 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/TrySequenceOfAsyncOperationsTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/TrySequenceOfAsyncOperationsTest.m @@ -18,6 +18,10 @@ -(void)setUp -(void)testTrySequenceOfAsyncOperations { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; @@ -61,13 +65,17 @@ -(void)testTrySequenceOfAsyncOperations GHAssertTrue( result_ == sequenceResult_, @"Sequence loader finished already" ); } - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } -(void)testCancelFirstLoaderOfTrySequence { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager* firstLoader_ = [ JFFAsyncOperationManager new ]; @@ -89,13 +97,17 @@ -(void)testCancelFirstLoaderOfTrySequence GHAssertFalse( secondLoader_.canceled, @"still not canceled" ); } - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } -(void)testCancelSecondLoaderOfTrySequence { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager* firstLoader_ = [ JFFAsyncOperationManager new ]; @@ -120,14 +132,18 @@ -(void)testCancelSecondLoaderOfTrySequence GHAssertTrue( secondLoader_.cancelFlag, @"canceled" ); } - - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); + + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } -(void)testCancelSecondLoaderOfTrySequenceIfFirstInstantFinish { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager* first_loader_ = [ JFFAsyncOperationManager new ]; @@ -149,14 +165,18 @@ -(void)testCancelSecondLoaderOfTrySequenceIfFirstInstantFinish GHAssertTrue( second_loader_.cancelFlag, @"canceled" ); } - - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); + + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } -(void)testFirstLoaderOkOfTrySequence { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager* first_loader_ = [ JFFAsyncOperationManager new ]; @@ -181,65 +201,75 @@ -(void)testFirstLoaderOkOfTrySequence GHAssertFalse( second_loader_.finished, @"second - not finished" ); } - - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); + + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } -(void)testTrySequenceWithOneLoader { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { - JFFAsyncOperationManager* first_loader_ = [ JFFAsyncOperationManager new ]; - - JFFAsyncOperation loader_ = trySequenceOfAsyncOperationsArray( @[ first_loader_.loader ] ); - - __block BOOL sequence_loader_finished_ = NO; - - loader_( nil, nil, ^( id result_, NSError* error_ ) - { - if ( result_ && !error_ ) - { - sequence_loader_finished_ = YES; + JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; + + JFFAsyncOperation loader = trySequenceOfAsyncOperationsArray(@[firstLoader.loader]); + + __block BOOL sequenceLoaderFinished = NO; + + loader(nil, nil, ^(id result, NSError *error) { + + if (result && !error) { + + sequenceLoaderFinished = YES; } - } ); + }); - GHAssertFalse( sequence_loader_finished_, @"sequence not finished" ); + GHAssertFalse( sequenceLoaderFinished, @"sequence not finished" ); - first_loader_.loaderFinishBlock.didFinishBlock( [ NSNull null ], nil ); + firstLoader.loaderFinishBlock.didFinishBlock([NSNull new], nil); - GHAssertTrue( sequence_loader_finished_, @"sequence finished" ); - + GHAssertTrue( sequenceLoaderFinished, @"sequence finished" ); } - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"All object of this class should be deallocated" ); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } --(void)testCriticalErrorOnFailFirstLoaderWhenTrySequenceResultCallbackIsNil +- (void)testCriticalErrorOnFailFirstLoaderWhenTrySequenceResultCallbackIsNil { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { - JFFAsyncOperationManager* firstLoader_ = [ JFFAsyncOperationManager new ]; - JFFAsyncOperationManager* secondLoader_ = [ JFFAsyncOperationManager new ]; - - JFFAsyncOperation loader_ = trySequenceOfAsyncOperations( firstLoader_.loader, secondLoader_.loader, nil ); - - loader_( nil, nil, nil ); - - firstLoader_.loaderFinishBlock.didFinishBlock( [ NSNull null ], nil ); - + JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; + JFFAsyncOperationManager *secondLoader = [JFFAsyncOperationManager new]; + + JFFAsyncOperation loader = trySequenceOfAsyncOperations(firstLoader.loader, secondLoader.loader, nil); + + loader(nil, nil, nil); + + firstLoader.loaderFinishBlock.didFinishBlock( [ NSNull null ], nil ); } - - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationManager instancesCount ], @"OK" ); + + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } - (void)testImmediatelyCancelCallbackOfFirstLoader { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; @@ -276,13 +306,17 @@ - (void)testImmediatelyCancelCallbackOfFirstLoader GHAssertEquals((NSUInteger)0, secondLoader.loadingCount, nil); } - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"OK"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"OK"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"OK"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } - (void)testImmediatelyCancelCallbackOfSecondLoader { + NSUInteger originalInstanceCount1 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationManager instancesCount]; + @autoreleasepool { JFFAsyncOperationManager *firstLoader = [JFFAsyncOperationManager new]; @@ -319,9 +353,9 @@ - (void)testImmediatelyCancelCallbackOfSecondLoader GHAssertFalse(doneCallbackCalled, nil); } - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"OK"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"OK"); - GHAssertTrue(0 == [JFFAsyncOperationManager instancesCount], @"OK"); + GHAssertTrue(originalInstanceCount1 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationManager instancesCount], @"All object of this class should be deallocated"); } @end diff --git a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/WeakAsyncOperationTest.m b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/WeakAsyncOperationTest.m index d80f935..a52e8b5 100644 --- a/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/WeakAsyncOperationTest.m +++ b/test/JFFAsyncOperationsTest/JFFAsyncOperationsTest/WeakAsyncOperationTest.m @@ -8,16 +8,21 @@ @interface WeakAsyncOperationTest : GHTestCase @implementation WeakAsyncOperationTest --(void)setUp +- (void)setUp { - [ JFFSimpleBlockHolder enableInstancesCounting ]; - [ JFFCancelAsyncOperationBlockHolder enableInstancesCounting ]; - [ JFFAsyncOperationProgressBlockHolder enableInstancesCounting ]; - [ JFFDidFinishAsyncOperationBlockHolder enableInstancesCounting ]; + [JFFSimpleBlockHolder enableInstancesCounting]; + [JFFCancelAsyncOperationBlockHolder enableInstancesCounting]; + [JFFAsyncOperationProgressBlockHolder enableInstancesCounting]; + [JFFDidFinishAsyncOperationBlockHolder enableInstancesCounting]; } --(void)testCancelActionAfterUnsubscribeOnDealloc +- (void)testCancelActionAfterUnsubscribeOnDealloc { + NSUInteger originalInstanceCount1 = [JFFSimpleBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationProgressBlockHolder instancesCount]; + NSUInteger originalInstanceCount4 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + @autoreleasepool { __block BOOL cancelCallbackCalled_ = NO; JFFCancelAsyncOperation cancel_; @@ -28,80 +33,90 @@ -(void)testCancelActionAfterUnsubscribeOnDealloc @autoreleasepool { - JFFAsyncOperation operation_ = ^JFFCancelAsyncOperation( JFFAsyncOperationProgressHandler progress_callback_ - , JFFCancelAsyncOperationHandler cancelCallback_ - , JFFDidFinishAsyncOperationHandler done_callback_ ) + JFFAsyncOperation operation_ = ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { - cancelCallback_ = [ cancelCallback_ copy ]; + cancelCallback = [ cancelCallback copy ]; return [ ^void( BOOL cancel_ ) { - if ( cancelCallback_ ) - cancelCallback_( cancel_ ); + if ( cancelCallback ) + cancelCallback( cancel_ ); } copy ]; }; - + operation_ = [ obj_ autoUnsubsribeOnDeallocAsyncOperation: operation_ ]; - + cancel_ = operation_( nil, ^( BOOL canceled_ ) { cancelCallbackCalled_ = YES; }, nil ); } } - + GHAssertTrue( cancelCallbackCalled_, @"Cancel callback should be called" ); cancelCallbackCalled_ = NO; - + cancel_( YES ); - + GHAssertFalse( cancelCallbackCalled_, @"Cancel callback should not be called after dealloc" ); } - - GHAssertTrue( 0 == [ JFFSimpleBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFAsyncOperationProgressBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"All object of this class should be deallocated" ); + + GHAssertTrue(originalInstanceCount1 == [JFFSimpleBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationProgressBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount4 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); } --(void)testOnceCancelBlockCallingOnDealloc +- (void)testOnceCancelBlockCallingOnDealloc { + NSUInteger originalInstanceCount1 = [JFFSimpleBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationProgressBlockHolder instancesCount]; + NSUInteger originalInstanceCount4 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + @autoreleasepool { - __block NSUInteger cancelCallbackCallCount_ = 0; + __block NSUInteger cancelCallbackCallCount = 0; @autoreleasepool { - NSObject* obj_ = [ NSObject new ]; + NSObject *obj = [NSObject new]; - JFFAsyncOperation operation_ = ^JFFCancelAsyncOperation( JFFAsyncOperationProgressHandler progressCallback_ - , JFFCancelAsyncOperationHandler cancelCallback_ - , JFFDidFinishAsyncOperationHandler doneCallback_ ) + JFFAsyncOperation operation = ^JFFCancelAsyncOperation(JFFAsyncOperationProgressHandler progressCallback, + JFFCancelAsyncOperationHandler cancelCallback, + JFFDidFinishAsyncOperationHandler doneCallback) { - cancelCallback_ = [ cancelCallback_ copy ]; + cancelCallback = [cancelCallback copy]; return [ ^void( BOOL cancel_ ) { - ++cancelCallbackCallCount_; - if ( cancelCallback_ ) - cancelCallback_( cancel_ ); + ++cancelCallbackCallCount; + if (cancelCallback) + cancelCallback( cancel_ ); } copy ]; }; - - operation_ = [ obj_ autoUnsubsribeOnDeallocAsyncOperation: operation_ ]; - - operation_( nil, nil, nil ); + + operation = [obj autoUnsubsribeOnDeallocAsyncOperation:operation]; + + operation(nil, nil, nil); } - - GHAssertTrue( 1 == cancelCallbackCallCount_, @"Cancel callback should not be called after dealloc" ); + + GHAssertTrue(1 == cancelCallbackCallCount, @"Cancel callback should not be called after dealloc" ); } - - GHAssertTrue( 0 == [ JFFSimpleBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFAsyncOperationProgressBlockHolder instancesCount ], @"All object of this class should be deallocated" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"All object of this class should be deallocated" ); + + GHAssertTrue(originalInstanceCount1 == [JFFSimpleBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationProgressBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount4 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); } - (void)testCancelCallbackCallingOnCancelBlock { + NSUInteger originalInstanceCount1 = [JFFSimpleBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationProgressBlockHolder instancesCount]; + NSUInteger originalInstanceCount4 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + @autoreleasepool { NSObject *obj = [NSObject new]; @@ -132,18 +147,23 @@ - (void)testCancelCallbackCallingOnCancelBlock GHAssertTrue(cancelBlockCalled, @"Cancel callback should not be called after dealloc"); } - GHAssertTrue(0 == [JFFSimpleBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFAsyncOperationProgressBlockHolder instancesCount], @"All object of this class should be deallocated"); - GHAssertTrue(0 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount1 == [JFFSimpleBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationProgressBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount4 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); } // When unsubscribe from autoCancelAsyncOperation -> native should not be canceled -(void)testUnsubscribeFromAutoCancel { + NSUInteger originalInstanceCount1 = [JFFSimpleBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationProgressBlockHolder instancesCount]; + NSUInteger originalInstanceCount4 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + @autoreleasepool { - NSObject* operationOwner_ = [ NSObject new ]; + NSObject *operationOwner_ = [ NSObject new ]; __block BOOL nativeCancelBlockCalled_ = NO; @@ -204,15 +224,20 @@ -(void)testUnsubscribeFromAutoCancel GHAssertTrue( deallocated_, @"owned_by_callbacks_ objet should be deallocated" ); GHAssertTrue( cancelCallbackCalled_, @"cancel callback should ba called" ); } - - GHAssertTrue( 0 == [ JFFSimpleBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationProgressBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); + + GHAssertTrue(originalInstanceCount1 == [JFFSimpleBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationProgressBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount4 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); } -(void)testCancelCallbackCallingForNativeLoaderWhenWeekDelegateRemove { + NSUInteger originalInstanceCount1 = [JFFSimpleBlockHolder instancesCount]; + NSUInteger originalInstanceCount2 = [JFFCancelAsyncOperationBlockHolder instancesCount]; + NSUInteger originalInstanceCount3 = [JFFAsyncOperationProgressBlockHolder instancesCount]; + NSUInteger originalInstanceCount4 = [JFFDidFinishAsyncOperationBlockHolder instancesCount]; + @autoreleasepool { __block BOOL nativeCancelBlockCalled_ = NO; @@ -266,7 +291,7 @@ -(void)testCancelCallbackCallingForNativeLoaderWhenWeekDelegateRemove } ); } } - + GHAssertTrue( delegateDeallocated_ , @"OK" ); GHAssertTrue( nativeCancelBlockCalled_ , @"OK" ); GHAssertTrue( unsibscribeCancelBlockCalled_, @"OK" ); @@ -275,11 +300,11 @@ -(void)testCancelCallbackCallingForNativeLoaderWhenWeekDelegateRemove GHAssertFalse( nativeCancelBlockCalled_, @"operation_ should be canceled here" ); } - - GHAssertTrue( 0 == [ JFFSimpleBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFCancelAsyncOperationBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFAsyncOperationProgressBlockHolder instancesCount ], @"OK" ); - GHAssertTrue( 0 == [ JFFDidFinishAsyncOperationBlockHolder instancesCount ], @"OK" ); + + GHAssertTrue(originalInstanceCount1 == [JFFSimpleBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount2 == [JFFCancelAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount3 == [JFFAsyncOperationProgressBlockHolder instancesCount], @"All object of this class should be deallocated"); + GHAssertTrue(originalInstanceCount4 == [JFFDidFinishAsyncOperationBlockHolder instancesCount], @"All object of this class should be deallocated"); } @end diff --git a/test/JFFCachesTest/JFFCachesTest.xcodeproj/project.pbxproj b/test/JFFCachesTest/JFFCachesTest.xcodeproj/project.pbxproj index ef31f24..9f6b966 100644 --- a/test/JFFCachesTest/JFFCachesTest.xcodeproj/project.pbxproj +++ b/test/JFFCachesTest/JFFCachesTest.xcodeproj/project.pbxproj @@ -22,7 +22,6 @@ 0617255B152B33BD00549265 /* JFFCacheDBInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 0617255A152B33BD00549265 /* JFFCacheDBInfo.plist */; }; 1B0E89BC1563FAEC00825E3C /* libc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B0E89BB1563FAEC00825E3C /* libc++.dylib */; }; 1BEC4882156A27460099DA6D /* libstdc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BEC4881156A27460099DA6D /* libstdc++.dylib */; }; - 7E3884EB17FBED9900399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E3884EA17FBED9900399329 /* QuartzCore.framework */; }; CED001FA1619914F00368E7D /* libJFFRestKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CED001F91619914F00368E7D /* libJFFRestKit.a */; }; /* End PBXBuildFile section */ @@ -118,13 +117,6 @@ remoteGlobalIDString = 7E8F20C914F94BDF00588C7D; remoteInfo = JFFAsyncOperationsFW; }; - 7E3884F917FBED9900399329 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 061724CF152B30C200549265 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CED001D116198FB200368E7D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 061724CF152B30C200549265 /* JFFUtils.xcodeproj */; @@ -167,9 +159,8 @@ 0617255A152B33BD00549265 /* JFFCacheDBInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = JFFCacheDBInfo.plist; sourceTree = ""; }; 1B0E89BB1563FAEC00825E3C /* libc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libc++.dylib"; path = "usr/lib/libc++.dylib"; sourceTree = SDKROOT; }; 1BEC4881156A27460099DA6D /* libstdc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.dylib"; path = "usr/lib/libstdc++.dylib"; sourceTree = SDKROOT; }; - 7E3884EA17FBED9900399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; CED001D41619912B00368E7D /* JFFRestKitTest.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFRestKitTest.xcodeproj; path = ../JFFRestKitTest/JFFRestKitTest.xcodeproj; sourceTree = ""; }; - CED001F91619914F00368E7D /* libJFFRestKit.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libJFFRestKit.a; path = "../../lib/JFFRestKit/build/Release-iphoneos/libJFFRestKit.a"; sourceTree = ""; }; + CED001F91619914F00368E7D /* libJFFRestKit.a */ = {isa = PBXFileReference; lastKnownFileType = file; name = libJFFRestKit.a; path = "../../lib/JFFRestKit/build/Release-iphoneos/libJFFRestKit.a"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -177,7 +168,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E3884EB17FBED9900399329 /* QuartzCore.framework in Frameworks */, 1BEC4882156A27460099DA6D /* libstdc++.dylib in Frameworks */, 1B0E89BC1563FAEC00825E3C /* libc++.dylib in Frameworks */, 0617250C152B310000549265 /* libJFFAsyncOperations.a in Frameworks */, @@ -217,7 +207,6 @@ 06172484152B2B6100549265 /* Frameworks */ = { isa = PBXGroup; children = ( - 7E3884EA17FBED9900399329 /* QuartzCore.framework */, CED001F91619914F00368E7D /* libJFFRestKit.a */, 1BEC4881156A27460099DA6D /* libstdc++.dylib */, 1B0E89BB1563FAEC00825E3C /* libc++.dylib */, @@ -278,7 +267,6 @@ 061724DB152B30C300549265 /* libJFFUtils-clang.a */, 061724DD152B30C300549265 /* JFFUtilsFW.framework */, CED001D216198FB200368E7D /* JFFUtilsTest.octest */, - 7E3884FA17FBED9900399329 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -467,13 +455,6 @@ remoteRef = 06172509152B30F900549265 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7E3884FA17FBED9900399329 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E3884F917FBED9900399329 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CED001D216198FB200368E7D /* JFFUtilsTest.octest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; diff --git a/test/JFFContactsTest/Default-568h@2x.png b/test/JFFContactsTest/Default-568h@2x.png new file mode 100644 index 0000000..0891b7a Binary files /dev/null and b/test/JFFContactsTest/Default-568h@2x.png differ diff --git a/test/JFFContactsTest/JFFContactsTest.xcodeproj/project.pbxproj b/test/JFFContactsTest/JFFContactsTest.xcodeproj/project.pbxproj index 29c2864..1f7e249 100644 --- a/test/JFFContactsTest/JFFContactsTest.xcodeproj/project.pbxproj +++ b/test/JFFContactsTest/JFFContactsTest.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 7E38851B17FBEE8700399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E38851A17FBEE8700399329 /* QuartzCore.framework */; }; + 4CC52F2A1729786900BB7637 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CC52F291729786900BB7637 /* Default-568h@2x.png */; }; CE91A8E315F61233002B220B /* libJFFContacts.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CEDBB8FA15F60E8E0093FE95 /* libJFFContacts.a */; }; CE91A8E415F61233002B220B /* libJFFTestTools.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CEDBB8E015F60E7C0093FE95 /* libJFFTestTools.a */; }; CE91A8E515F61233002B220B /* libJFFUtils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CEDBB8E915F60E840093FE95 /* libJFFUtils.a */; }; @@ -27,13 +27,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 7E38852717FBEE8700399329 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEDBB8E115F60E840093FE95 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CE91A8DD15F6122C002B220B /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CEDBB8E115F60E840093FE95 /* JFFUtils.xcodeproj */; @@ -177,7 +170,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7E38851A17FBEE8700399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 4CC52F291729786900BB7637 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; CE91A8E615F61292002B220B /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; }; CE91A8EA15F612B4002B220B /* libc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libc++.dylib"; path = "usr/lib/libc++.dylib"; sourceTree = SDKROOT; }; CE91A8EC15F612D1002B220B /* libstdc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.dylib"; path = "usr/lib/libstdc++.dylib"; sourceTree = SDKROOT; }; @@ -204,7 +197,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E38851B17FBEE8700399329 /* QuartzCore.framework in Frameworks */, CE91AA3715F64F7A002B220B /* libJFFScheduler.a in Frameworks */, CE91AA2215F64F5A002B220B /* libJFFAsyncOperations.a in Frameworks */, CE91A8ED15F612D1002B220B /* libstdc++.dylib in Frameworks */, @@ -255,6 +247,7 @@ CEDBB8AB15F60E2F0093FE95 = { isa = PBXGroup; children = ( + 4CC52F291729786900BB7637 /* Default-568h@2x.png */, CEDBB8C015F60E300093FE95 /* JFFContactsTest */, CEDBB8B915F60E300093FE95 /* Frameworks */, CEDBB8B715F60E300093FE95 /* Products */, @@ -274,7 +267,6 @@ CEDBB8B915F60E300093FE95 /* Frameworks */ = { isa = PBXGroup; children = ( - 7E38851A17FBEE8700399329 /* QuartzCore.framework */, CE91A8EC15F612D1002B220B /* libstdc++.dylib */, CE91A8EA15F612B4002B220B /* libc++.dylib */, CE91A8E615F61292002B220B /* AddressBook.framework */, @@ -334,7 +326,6 @@ CEDBB8ED15F60E840093FE95 /* libJFFUtils-clang.a */, CEDBB8EF15F60E840093FE95 /* JFFUtilsFW.framework */, CED001A716198EAD00368E7D /* JFFUtilsTest.octest */, - 7E38852817FBEE8700399329 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -379,7 +370,7 @@ CEDBB8AD15F60E2F0093FE95 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0440; + LastUpgradeCheck = 0460; ORGANIZATIONNAME = EmbeddedSources; }; buildConfigurationList = CEDBB8B015F60E2F0093FE95 /* Build configuration list for PBXProject "JFFContactsTest" */; @@ -422,13 +413,6 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 7E38852817FBEE8700399329 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E38852717FBEE8700399329 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE91AA1A15F64C67002B220B /* libJFFAsyncOperations.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -543,6 +527,7 @@ files = ( CEDBB8C515F60E300093FE95 /* InfoPlist.strings in Resources */, CE91AA0415F63390002B220B /* avator.png in Resources */, + 4CC52F2A1729786900BB7637 /* Default-568h@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -607,6 +592,9 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; @@ -640,6 +628,9 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; diff --git a/test/JFFContactsTest/JFFContactsTest/JFFContactsTest.m b/test/JFFContactsTest/JFFContactsTest/JFFContactsTest.m index e940abf..bea32ab 100644 --- a/test/JFFContactsTest/JFFContactsTest/JFFContactsTest.m +++ b/test/JFFContactsTest/JFFContactsTest/JFFContactsTest.m @@ -4,29 +4,30 @@ @interface JFFContactsTest : GHAsyncTestCase @implementation JFFContactsTest --(void)testCreateFindAndRemoveContact +- (void)testCreateFindAndRemoveContact { - [ self prepare ]; - - __block JFFContact* savedContact_; - + [self prepare]; + + __block JFFContact *savedContact; + __block ABRecordID contactInternalId = 0; + static NSString* const contactFirstName_ = @"First Name"; static NSString* const contactLastName_ = @"Last Name"; NSArray* contactEmails_ = @[ @"vlg@wishdates.com", @"usstass1@gmail.com" ]; NSArray* contactPhones_ = @[ @"+380684453923" , @"+380679758477" ]; UIImage* contactImage_ = [ UIImage imageNamed: @"avator" ]; - + NSArray* contactAddresses_ = @[ @{ JFFContactAddresseStreetKey () : @"address street" , JFFContactAddresseCityKey () : @"address city" , JFFContactAddresseStateKey () : @"address state" , JFFContactAddresseZIPKey () : @"address zip" , JFFContactAddresseCountryKey() : @"address country", - } ]; - - JFFAddressBookSuccessCallback onSuccess_ = ^( JFFAddressBook* book_ ) + }]; + + JFFAddressBookSuccessCallback onSuccess = ^(JFFAddressBook *book) { - NSDictionary* contactFields_ = @{ + NSDictionary *contactFields = @{ JFFContactFirstName : contactFirstName_, JFFContactLastName : contactLastName_ , JFFContactPhoto : contactImage_ , @@ -34,56 +35,65 @@ -(void)testCreateFindAndRemoveContact JFFContactPhones : contactPhones_ , JFFContactAddresses : contactAddresses_, }; - - ABRecordID contactInternalId_ = 0; + + { - JFFContact* newContact_ = [ [ JFFContact alloc ] initWithFieldsDict: contactFields_ - addressBook: book_ ]; - - if ( ![ newContact_ save ] ) + JFFContact *newContact = [[JFFContact alloc] initWithFieldsDict:contactFields + addressBook:book]; + + if ( ![ newContact save ] ) { [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; return; } - - contactInternalId_ = newContact_.contactInternalId; + + contactInternalId = newContact.contactInternalId; } - + { - savedContact_ = [ JFFContact findContactWithContactInternalId: contactInternalId_ - addressBook: book_ ]; - - if ( !savedContact_ ) + savedContact = [JFFContact findContactWithContactInternalId:contactInternalId + addressBook:book]; + + if ( !savedContact ) { [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; return; } } - if ( ![ savedContact_ remove ] ) - { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; - return; - } - - [ self notify: kGHUnitWaitStatusSuccess forSelector: _cmd ]; + [self notify: kGHUnitWaitStatusSuccess forSelector: _cmd ]; }; - JFFAddressBookErrorCallback onFailure_ = ^( ABAuthorizationStatus status_, NSError* error_ ) + JFFAddressBookErrorCallback onFailure = ^( ABAuthorizationStatus status_, NSError* error_ ) { [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; }; - [ JFFAddressBookFactory asyncAddressBookWithSuccessBlock: onSuccess_ - errorCallback: onFailure_ ]; + [JFFAddressBookFactory asyncAddressBookWithSuccessBlock:onSuccess + errorCallback:onFailure]; [ self waitForStatus: kGHUnitWaitStatusSuccess timeout: 10000. ]; - GHAssertEqualObjects( savedContact_.firstName, contactFirstName_, @"contact fields values mismatch" ); - GHAssertEqualObjects( savedContact_.lastName , contactLastName_ , @"contact fields values mismatch" ); - GHAssertEqualObjects( savedContact_.emails , contactEmails_ , @"contact fields values mismatch" ); - GHAssertEqualObjects( savedContact_.phones , contactPhones_ , @"contact fields values mismatch" ); - GHAssertEqualObjects( savedContact_.addresses, contactAddresses_, @"contact fields values mismatch" ); - GHAssertNotNil( savedContact_.photo, @"contact fields values mismatch" ); + GHAssertEqualObjects( savedContact.firstName, contactFirstName_, @"contact fields values mismatch" ); + GHAssertEqualObjects( savedContact.lastName , contactLastName_ , @"contact fields values mismatch" ); + GHAssertEqualObjects( savedContact.emails , contactEmails_ , @"contact fields values mismatch" ); + GHAssertEqualObjects( savedContact.phones , contactPhones_ , @"contact fields values mismatch" ); + GHAssertEqualObjects( savedContact.addresses, contactAddresses_, @"contact fields values mismatch" ); + GHAssertNotNil( savedContact.photo, @"contact fields values mismatch" ); + + onSuccess = ^(JFFAddressBook *book) + { + savedContact = [JFFContact findContactWithContactInternalId:contactInternalId + addressBook:book]; + + if (![savedContact remove]) { + + [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; + return; + } + }; + + [JFFAddressBookFactory asyncAddressBookWithSuccessBlock:onSuccess + errorCallback:onFailure]; } -(void)testEnumerateAllContacts @@ -102,7 +112,7 @@ -(void)testEnumerateAllContacts NSUInteger contactsCount_ = 5; - JFFAddressBookSuccessCallback onSuccess_ = ^( JFFAddressBook* book_ ) + JFFAddressBookSuccessCallback onSuccess = ^( JFFAddressBook* book_ ) { NSDictionary* contactFields_ = @{ JFFContactFirstName : contactFirstName_, @@ -142,39 +152,29 @@ -(void)testEnumerateAllContacts addressBook: book_ ]; } ]; - if ( [ savedContacts_ count ] < contactsCount_ ) - { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; + if ( [ savedContacts_ count ] < contactsCount_ ) { + + [self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; return; } } - - asyncAllContactsLoader()( nil, nil, ^( NSArray* result_, NSError* error_ ) + + asyncAllContactsLoader()(nil, nil, ^(NSArray *result, NSError *error) { - allContacts_ = result_; - - for ( JFFContact* contact_ in savedContacts_ ) - { - if ( ![ contact_ remove ] ) - { - [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; - return; - } - } - - [ self notify: kGHUnitWaitStatusSuccess forSelector: _cmd ]; - } ); + allContacts_ = result; + [self notify:kGHUnitWaitStatusSuccess forSelector:_cmd]; + }); }; - JFFAddressBookErrorCallback onFailure_ = ^( ABAuthorizationStatus status_, NSError* error_ ) + JFFAddressBookErrorCallback onFailure = ^( ABAuthorizationStatus status_, NSError* error_ ) { [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; }; - [ JFFAddressBookFactory asyncAddressBookWithSuccessBlock: onSuccess_ - errorCallback: onFailure_ ]; - - [ self waitForStatus: kGHUnitWaitStatusSuccess timeout: 10000. ]; - + [JFFAddressBookFactory asyncAddressBookWithSuccessBlock:onSuccess + errorCallback:onFailure]; + + [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10000.]; + for ( JFFContact* contact_ in savedContacts_ ) { GHAssertEqualObjects( contact_.firstName, contactFirstName_, @"contact fields values mismatch" ); @@ -201,6 +201,26 @@ -(void)testEnumerateAllContacts GHAssertEqualObjects( contact_.phones , contactPhones_ , @"contact fields values mismatch" ); GHAssertNotNil( contact_.photo, @"contact fields values mismatch" ); } + + onSuccess = ^(JFFAddressBook *book) + { + NSArray *savedContacts = [contactIds_ forceMap: ^id(NSNumber *contactId) { + return [JFFContact findContactWithContactInternalId:[contactId longLongValue] + addressBook:book]; + }]; + + [savedContacts enumerateObjectsUsingBlock:^(JFFContact *removedContact, NSUInteger idx, BOOL *stop) { + + if (![removedContact remove]) { + + [ self notify: kGHUnitWaitStatusFailure forSelector: _cmd ]; + return; + } + }]; + }; + + [JFFAddressBookFactory asyncAddressBookWithSuccessBlock:onSuccess + errorCallback:onFailure]; } @end diff --git a/test/JFFCoreLocationTest/JFFCoreLocationTest.xcodeproj/project.pbxproj b/test/JFFCoreLocationTest/JFFCoreLocationTest.xcodeproj/project.pbxproj index e057e0e..66048dd 100644 --- a/test/JFFCoreLocationTest/JFFCoreLocationTest.xcodeproj/project.pbxproj +++ b/test/JFFCoreLocationTest/JFFCoreLocationTest.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 7E38853217FBEE9800399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E38853117FBEE9800399329 /* QuartzCore.framework */; }; CE206E2B16414CFF002476FD /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE206E2A16414CFF002476FD /* UIKit.framework */; }; CE206E2D16414CFF002476FD /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE206E2C16414CFF002476FD /* Foundation.framework */; }; CE206E2F16414CFF002476FD /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE206E2E16414CFF002476FD /* CoreGraphics.framework */; }; @@ -29,13 +28,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 7E38853E17FBEE9800399329 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE206E8A16414EEB002476FD /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CE206E7216414EDE002476FD /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CE206E6A16414EDE002476FD /* JFFCoreLocation.xcodeproj */; @@ -179,7 +171,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7E38853117FBEE9800399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; CE206E2616414CFF002476FD /* JFFCoreLocationTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JFFCoreLocationTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; CE206E2A16414CFF002476FD /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; CE206E2C16414CFF002476FD /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -208,7 +199,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E38853217FBEE9800399329 /* QuartzCore.framework in Frameworks */, CE206FC116415677002476FD /* CoreLocation.framework in Frameworks */, CE206EF516414FE7002476FD /* libJFFScheduler.a in Frameworks */, CE206EF616414FE7002476FD /* libJFFTestTools.a in Frameworks */, @@ -248,7 +238,6 @@ CE206E2916414CFF002476FD /* Frameworks */ = { isa = PBXGroup; children = ( - 7E38853117FBEE9800399329 /* QuartzCore.framework */, CE206EDD16414FC0002476FD /* libc++.dylib */, CE206EDB16414FB9002476FD /* libstdc++.dylib */, CE206FC016415677002476FD /* CoreLocation.framework */, @@ -322,7 +311,6 @@ CE206E9E16414EEB002476FD /* libJFFUtils-clang.a */, CE206EA016414EEB002476FD /* JFFUtilsFW.framework */, CE206EA216414EEB002476FD /* JFFUtilsTest.octest */, - 7E38853F17FBEE9800399329 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -420,13 +408,6 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 7E38853F17FBEE9800399329 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E38853E17FBEE9800399329 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE206E7316414EDE002476FD /* libJFFCoreLocation.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/test/JFFNetworkTest/Classes/ConnectionsFactoryTest.m b/test/JFFNetworkTest/Classes/ConnectionsFactoryTest.m index 785015f..5c364b2 100755 --- a/test/JFFNetworkTest/Classes/ConnectionsFactoryTest.m +++ b/test/JFFNetworkTest/Classes/ConnectionsFactoryTest.m @@ -1,103 +1,101 @@ @interface ConnectionsFactoryTest : GHTestCase - @end - @implementation ConnectionsFactoryTest --(void)testUrlIsRequired +- (void)testUrlIsRequired { - char hello_[] = "Hello"; - NSData* stub_data_ = [ NSData dataWithBytesNoCopy: hello_ - length: sizeof( hello_ ) - freeWhenDone: NO ]; - - NSDictionary* headers_ = [ NSDictionary dictionary ]; - + char hello[] = "Hello"; + NSData *stubData = [NSData dataWithBytesNoCopy:hello + length:sizeof(hello) + freeWhenDone:NO]; + + NSDictionary *headers = @{}; + GHAssertThrows ( { - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.httpBody = stub_data_; - params_.headers = headers_; - id res_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; - NSLog( @"res: %@", res_ ); + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.httpBody = stubData; + params.headers = headers; + id res = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + NSLog(@"res: %@", res); } , @"NSAssert expected" - ); + ); } --(void)testHeadersAndDataAreOptional +- (void)testHeadersAndDataAreOptional { - NSURL* google_url_ = [ NSURL URLWithString: @"www.google.com" ]; - - char hello_[] = "Hello"; - NSData* stub_data_ = [ NSData dataWithBytesNoCopy: hello_ - length: sizeof( hello_ ) - freeWhenDone: NO ]; - NSDictionary* headers_ = [ NSDictionary dictionary ]; - + NSURL *googleURL = [@"www.google.com" toURL]; + + char hello[] = "Hello"; + NSData *stubData = [NSData dataWithBytesNoCopy:hello + length:sizeof(hello) + freeWhenDone:NO]; + NSDictionary *headers = @{}; + GHAssertNoThrow ( { - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = google_url_; - params_.headers = headers_; - id res_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; - NSLog( @"res: %@", res_ ); + JFFURLConnectionParams* params = [JFFURLConnectionParams new]; + params.url = googleURL; + params.headers = headers; + id res = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + NSLog(@"res: %@", res); } - , @"NSAssert expected" - ); - + , @"NSAssert expected" + ); + GHAssertNoThrow ( { - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = google_url_; - params_.httpBody = stub_data_; - id res_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; - NSLog( @"res: %@", res_ ); + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = googleURL; + params.httpBody = stubData; + id res = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + NSLog(@"res: %@", res); } , @"NSAssert expected" ); } --(void)testInitNotSupported +- (void)testInitNotSupported { - GHAssertThrows - ( - { - id res_ = [ [ JNConnectionsFactory alloc ] init ]; - NSLog( @"res: %@", res_ ); - } - , @"NSAssert expected" - ); + GHAssertThrows + ( + { + id res = [JNConnectionsFactory new]; + NSLog(@"res: %@", res); + } + , @"NSAssert expected" + ); } --(void)testFactoryReturnsCorrectClasses +- (void)testFactoryReturnsCorrectClasses { - NSURL* google_url_ = [ NSURL URLWithString: @"www.yahoo.com" ]; - - char hello_[] = "Abrakadabra"; - NSData* stub_data_ = [ NSData dataWithBytesNoCopy: hello_ - length: sizeof( hello_ ) - freeWhenDone: NO ]; - - NSDictionary* headers_ = [ NSDictionary dictionary ]; - - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = google_url_; - params_.httpBody = stub_data_; - params_.headers = headers_; - JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; - - id< JNUrlConnection > connection_ = nil; - - connection_ = [ factory_ createFastConnection ]; - GHAssertTrue( [ connection_ isMemberOfClass: [ JFFURLConnection class ] ], @"Custom connection class mismatch" ); - - connection_ = [ factory_ createStandardConnection ]; - GHAssertTrue( [ connection_ isMemberOfClass: [ JNNsUrlConnection class ] ], @"Standard connection class mismatch" ); + NSURL *googleURL = [@"www.yahoo.com" toURL]; + + char hello[] = "Abrakadabra"; + NSData *stubData = [NSData dataWithBytesNoCopy:hello + length:sizeof(hello) + freeWhenDone:NO ]; + + NSDictionary *headers = @{}; + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = googleURL; + params.httpBody = stubData; + params.headers = headers; + JNConnectionsFactory *factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + + id< JNUrlConnection > connection = nil; + + connection = [factory createFastConnection]; + GHAssertTrue([connection isMemberOfClass:[JFFURLConnection class]], @"Custom connection class mismatch"); + + connection = [factory createStandardConnection ]; + GHAssertTrue([connection isMemberOfClass:[JNNsUrlConnection class]], @"Standard connection class mismatch"); } @end diff --git a/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.h b/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.h index 7f743fb..57c0f97 100755 --- a/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.h +++ b/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.h @@ -2,7 +2,7 @@ @interface NSHTTPCookie (HTTPCookieWithHeader) -+(id)HTTPCookieWithHeader:( NSString* )header_ - url:( NSURL* )url_; ++ (instancetype)HTTPCookieWithHeader:(NSString *)header + url:(NSURL *)url; @end diff --git a/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.m b/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.m index 4c390e0..e1a8dbd 100755 --- a/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.m +++ b/test/JFFNetworkTest/Classes/Details/NSHTTPCookie+HTTPCookieWithHeader.m @@ -2,19 +2,18 @@ @implementation NSHTTPCookie (HTTPCookieWithHeader) -+(id)HTTPCookieWithHeader:( NSString* )header_ - url:( NSURL* )url_ ++ (instancetype)HTTPCookieWithHeader:(NSString *)header + url:(NSURL *)url { - if ( [ header_ length ] == 0 ) + if ([header length] == 0) return nil; - NSDictionary* headers_ = [ NSDictionary dictionaryWithObject: header_ - forKey: @"Set-Cookie" ]; + NSDictionary *headers = @{ @"Set-Cookie" : header }; - NSArray* cookies_ = [ NSHTTPCookie cookiesWithResponseHeaderFields: headers_ - forURL: url_ ]; + NSArray *cookies = [ NSHTTPCookie cookiesWithResponseHeaderFields:headers + forURL:url]; - return [ cookies_ lastObject ]; + return [cookies lastObject]; } @end diff --git a/test/JFFNetworkTest/Classes/EncodingsFactoryTest.m b/test/JFFNetworkTest/Classes/EncodingsFactoryTest.m index 6a821e0..952e379 100755 --- a/test/JFFNetworkTest/Classes/EncodingsFactoryTest.m +++ b/test/JFFNetworkTest/Classes/EncodingsFactoryTest.m @@ -1,4 +1,6 @@ +#import + @interface EncodingsFactoryTest : GHTestCase @end @@ -7,62 +9,62 @@ @implementation EncodingsFactoryTest JNHttpEncodingsFactory* _factory; } --(void)setUp +- (void)setUp { - self->_factory = [ [ JNHttpEncodingsFactory alloc ] initWithContentLength: 0 ]; + _factory = [[JNHttpEncodingsFactory alloc] initWithContentLength:0]; } --(void)testFactoryProducesValidDecoders +- (void)testFactoryProducesValidDecoders { - id decoder_ = nil; - - { - decoder_ = [ self->_factory gzipDecoder ]; - GHAssertNotNil( decoder_, @"NOT nil data Expected" ); - GHAssertTrue( [ decoder_ conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); - GHAssertTrue( [ decoder_ isMemberOfClass : [ JNGzipDecoder class ] ], @"This should be JNGzipDecoder class" ); - } - - { - decoder_ = [ self->_factory decoderForHeaderString: @"gzip" ]; - GHAssertNotNil( decoder_, @"NOT nil data Expected" ); - GHAssertTrue( [ decoder_ conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); - GHAssertTrue( [ decoder_ isMemberOfClass : [ JNGzipDecoder class ] ], @"This should be JNGzipDecoder class" ); - } + id decoder = nil; + + { + decoder = [ _factory gzipDecoder ]; + GHAssertNotNil( decoder, @"NOT nil data Expected" ); + GHAssertTrue( [ decoder conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); + GHAssertTrue( [ decoder isMemberOfClass : [ JNGzipDecoder class ] ], @"This should be JNGzipDecoder class" ); + } + + { + decoder = [ _factory decoderForHeaderString: @"gzip" ]; + GHAssertNotNil( decoder, @"NOT nil data Expected" ); + GHAssertTrue( [ decoder conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); + GHAssertTrue( [ decoder isMemberOfClass : [ JNGzipDecoder class ] ], @"This should be JNGzipDecoder class" ); + } } --(void)testFactoryProducesStubDecoderForUnexpectedCases +- (void)testFactoryProducesStubDecoderForUnexpectedCases { - id decoder_ = nil; - - { - decoder_ = [ self->_factory stubDecoder ]; - GHAssertNotNil( decoder_, @"NOT nil data Expected" ); - GHAssertTrue( [ decoder_ conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); - GHAssertTrue( [ decoder_ isMemberOfClass : [ JNStubDecoder class ] ], @"This should be JNGzipDecoder class" ); - } - - { - decoder_ = [ self->_factory decoderForHeaderString: @"" ]; - - GHAssertNotNil( decoder_, @"NOT nil data Expected" ); - GHAssertTrue( [ decoder_ conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); - GHAssertTrue( [ decoder_ isMemberOfClass : [ JNStubDecoder class ] ], @"This should be JNStubDecoder class" ); - } - - { - decoder_ = [ self->_factory decoderForHeaderString: nil ]; - GHAssertNotNil( decoder_, @"NOT nil data Expected" ); - GHAssertTrue( [ decoder_ conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); - GHAssertTrue( [ decoder_ isMemberOfClass : [ JNStubDecoder class ] ], @"This should be JNStubDecoder class" ); - } - - { - decoder_ = [ self->_factory decoderForHeaderString: @"abrakadabra" ]; - GHAssertNotNil( decoder_, @"NOT nil data Expected" ); - GHAssertTrue( [ decoder_ conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); - GHAssertTrue( [ decoder_ isMemberOfClass : [ JNStubDecoder class ] ], @"This should be JNStubDecoder class" ); - } + id decoder = nil; + + { + decoder = [ _factory stubDecoder ]; + GHAssertNotNil(decoder, @"NOT nil data Expected" ); + GHAssertTrue([decoder conformsToProtocol: @protocol(JNHttpDecoder)], @"This class should conform protocol"); + GHAssertTrue([decoder isMemberOfClass : [JNStubDecoder class]], @"This should be JNGzipDecoder class"); + } + + { + decoder = [ _factory decoderForHeaderString: @"" ]; + + GHAssertNotNil( decoder, @"NOT nil data Expected" ); + GHAssertTrue( [ decoder conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); + GHAssertTrue( [ decoder isMemberOfClass : [ JNStubDecoder class ] ], @"This should be JNStubDecoder class" ); + } + + { + decoder = [ _factory decoderForHeaderString: nil ]; + GHAssertNotNil( decoder, @"NOT nil data Expected" ); + GHAssertTrue( [ decoder conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); + GHAssertTrue( [ decoder isMemberOfClass : [ JNStubDecoder class ] ], @"This should be JNStubDecoder class" ); + } + + { + decoder = [ _factory decoderForHeaderString: @"abrakadabra" ]; + GHAssertNotNil( decoder, @"NOT nil data Expected" ); + GHAssertTrue( [ decoder conformsToProtocol: @protocol(JNHttpDecoder) ], @"This class should conform protocol" ); + GHAssertTrue( [ decoder isMemberOfClass : [ JNStubDecoder class ] ], @"This should be JNStubDecoder class" ); + } } @end diff --git a/test/JFFNetworkTest/Classes/GzipDecoderTest.m b/test/JFFNetworkTest/Classes/GzipDecoderTest.m index 5528ea0..4db63f9 100755 --- a/test/JFFNetworkTest/Classes/GzipDecoderTest.m +++ b/test/JFFNetworkTest/Classes/GzipDecoderTest.m @@ -4,83 +4,82 @@ @interface GzipDecoderTest : GHTestCase @implementation GzipDecoderTest --(void)testErrorParameterIsRequired +- (void)testErrorParameterIsRequired { - NSData* gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1" ]; - - JNGzipDecoder* decoder_ = [ [ JNGzipDecoder alloc ] initWithContentLength: 100500 ]; - - GHAssertThrows - ( - [ decoder_ decodeData: gzip_data_ - error: NULL ] - , @"NULL error should produce assert" - ); + NSData *gzipData = [JNTestBundleManager loadZipFileNamed:@"1"]; + + JNGzipDecoder* decoder = [[JNGzipDecoder alloc] initWithContentLength:100500]; + + GHAssertThrows + ( + [decoder decodeData:gzipData + error:NULL] + , @"NULL error should produce assert" + ); } --(void)testNilDataProducesNilResult +- (void)testNilDataProducesNilResult { NSError* error_ = nil; - - JNGzipDecoder* decoder_ = [ [ JNGzipDecoder alloc ] initWithContentLength: 100500 ]; - NSData* received_data_ = [ decoder_ decodeData: nil - error: &error_ ]; - - GHAssertNil( received_data_, @"Nil output expected" ); - GHAssertNil( error_ , @"No errors are expected" ); + + JNGzipDecoder* decoder_ = [ [ JNGzipDecoder alloc ] initWithContentLength: 100500 ]; + NSData *received_data_ = [decoder_ decodeData:nil + error:&error_]; + + GHAssertNil(received_data_, @"Nil output expected" ); + GHAssertNil(error_ , @"No errors are expected"); } --(void)testGzipFromBackEndExtractedCorrectly +- (void)testGzipFromBackEndExtractedCorrectly { NSError* error_ = nil; - + NSData* gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1" ]; NSString* expected_ = [ JNTestBundleManager loadTextFileNamed: @"1" ]; - - JNGzipDecoder* decoder_ = [ [ JNGzipDecoder alloc ] initWithContentLength: 1 ]; + + JNGzipDecoder* decoder_ = [ [ JNGzipDecoder alloc ] initWithContentLength: 1 ]; NSData* received_data_ = [ decoder_ decodeData: gzip_data_ error: &error_ ]; GHAssertNil( error_, @"Unexpected decode error - %@", error_ ); - - NSString* received_ = [ [ NSString alloc ] initWithData: received_data_ - encoding: NSUTF8StringEncoding ]; - + + NSString* received_ = [ [ NSString alloc ] initWithData: received_data_ + encoding: NSUTF8StringEncoding ]; + GHAssertTrue( [ received_ isEqualToString: expected_ ], @"Wrong decoding result" ); } --(void)testBadDataProducesCorrectError +- (void)testBadDataProducesCorrectError { - NSError* error_ = nil; - NSData* gzip_data_ = nil; - NSData* received_data_ = nil; - JNGzipDecoder* decoder_ = nil; - - { - //compressed with zip instead of gzip - gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1.1" ]; - decoder_ = [ [ JNGzipDecoder alloc ] initWithContentLength: [ gzip_data_ length ] ]; - - - received_data_ = [ decoder_ decodeData: gzip_data_ - error: &error_ ]; - - GHAssertNil( received_data_, @"nil data in error Expected" ); - - GHAssertTrue( [ error_.domain isEqualToString: kGzipErrorDomain ], @"Unexpected error domain" ); - GHAssertTrue( error_.code == Z_DATA_ERROR, @"Unexpected error code" ); - } - - { - //compressed with zip instead of gzip - gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1-Incomplete" ]; - decoder_ = [ [ JNGzipDecoder alloc ] initWithContentLength: [ gzip_data_ length ] ]; - - received_data_ = [ decoder_ decodeData: gzip_data_ - error: &error_ ]; - - GHAssertNotNil( received_data_, @"nil data in error Expected" ); - GHAssertNil( error_, @"No error expected since on-the-fly unpacking was introduced " ); - } + NSError* error = nil; + NSData* gzipData = nil; + NSData* receivedData = nil; + JNGzipDecoder* decoder = nil; + + { + //compressed with zip instead of gzip + gzipData = [ JNTestBundleManager loadZipFileNamed : @"1.1" ]; + decoder = [ [ JNGzipDecoder alloc ] initWithContentLength: [ gzipData length ] ]; + + receivedData = [ decoder decodeData: gzipData + error: &error ]; + + GHAssertNil( receivedData, @"nil data in error Expected" ); + + GHAssertTrue( [ error.domain isEqualToString: kGzipErrorDomain ], @"Unexpected error domain" ); + GHAssertTrue( error.code == Z_DATA_ERROR, @"Unexpected error code" ); + } + + { + //compressed with zip instead of gzip + gzipData = [ JNTestBundleManager loadZipFileNamed : @"1-Incomplete" ]; + decoder = [ [ JNGzipDecoder alloc ] initWithContentLength: [ gzipData length ] ]; + + receivedData = [ decoder decodeData: gzipData + error: &error ]; + + GHAssertNotNil( receivedData, @"nil data in error Expected" ); + GHAssertNil( error, @"No error expected since on-the-fly unpacking was introduced " ); + } } @end diff --git a/test/JFFNetworkTest/Classes/GzipErrorsLoggerTest.m b/test/JFFNetworkTest/Classes/GzipErrorsLoggerTest.m index dfbd878..1c1e17b 100755 --- a/test/JFFNetworkTest/Classes/GzipErrorsLoggerTest.m +++ b/test/JFFNetworkTest/Classes/GzipErrorsLoggerTest.m @@ -4,73 +4,72 @@ @interface GzipErrorsLoggerTest : GHTestCase @implementation GzipErrorsLoggerTest --(void)testGzipLoggerDoesNotAcceptValuesOutOf_minus1_minus6 +- (void)testGzipLoggerDoesNotAcceptValuesOutOf_minus1_minus6 { - NSString* received_ = nil; - NSString* expected_ = nil; - - { - expected_ = @"Z_UnknownError"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: 0 ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } - - { - expected_ = @"Z_UnknownError"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: -7 ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } + NSString* received_ = nil; + NSString* expected_ = nil; + + { + expected_ = @"Z_UnknownError"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: 0 ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } + + { + expected_ = @"Z_UnknownError"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: -7 ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } } - --(void)testGzipLoggerProducesCorrectStrings +- (void)testGzipLoggerProducesCorrectStrings { - NSString* received_ = nil; - NSString* expected_ = nil; - - { - expected_ = @"Z_ERRNO"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_ERRNO ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } - - { - expected_ = @"Z_STREAM_ERROR"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_STREAM_ERROR ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } - - { - expected_ = @"Z_DATA_ERROR"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_DATA_ERROR ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } - - { - expected_ = @"Z_MEM_ERROR"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_MEM_ERROR ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } - - { - expected_ = @"Z_BUF_ERROR"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_BUF_ERROR ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } - - { - expected_ = @"Z_VERSION_ERROR"; - received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_VERSION_ERROR ]; - - GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); - } + NSString* received_ = nil; + NSString* expected_ = nil; + + { + expected_ = @"Z_ERRNO"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_ERRNO ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } + + { + expected_ = @"Z_STREAM_ERROR"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_STREAM_ERROR ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } + + { + expected_ = @"Z_DATA_ERROR"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_DATA_ERROR ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } + + { + expected_ = @"Z_MEM_ERROR"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_MEM_ERROR ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } + + { + expected_ = @"Z_BUF_ERROR"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_BUF_ERROR ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } + + { + expected_ = @"Z_VERSION_ERROR"; + received_ = [ JNGzipErrorsLogger zipErrorMessageFromCode: Z_VERSION_ERROR ]; + + GHAssertTrue( [ expected_ isEqualToString: received_ ], @"Wrong description" ); + } } @end diff --git a/test/JFFNetworkTest/Classes/InvalidPathForJConnectionTest.m b/test/JFFNetworkTest/Classes/InvalidPathForJConnectionTest.m index 3c8cab9..54e58d2 100755 --- a/test/JFFNetworkTest/Classes/InvalidPathForJConnectionTest.m +++ b/test/JFFNetworkTest/Classes/InvalidPathForJConnectionTest.m @@ -1,66 +1,61 @@ #import "BadHeadersMockNetwork.h" -static const NSTimeInterval TIMEOUT = 10.f; - @interface InvalidPathForJConnectionTest : GHAsyncTestCase< NSURLConnectionDelegate > @end @implementation InvalidPathForJConnectionTest --(void)setUp +- (void)setUp { - [ NSURLProtocol registerClass: [ BadHeadersMockNetwork class ] ]; + [NSURLProtocol registerClass:[BadHeadersMockNetwork class]]; + [JNNsUrlConnection enableInstancesCounting]; } --(void)tearDown +- (void)tearDown { - [ NSURLProtocol unregisterClass: [ BadHeadersMockNetwork class ] ]; + [NSURLProtocol unregisterClass:[BadHeadersMockNetwork class]]; } --(void)testInvalidLocationDoesNotCauseCrash +- (void)testInvalidLocationDoesNotCauseCrash { - __weak GHAsyncTestCase* weakSelf_ = self; - SEL testSelector_ = _cmd; - - [ self prepare: _cmd ]; + NSUInteger initialInstancesCount = [JFFURLConnection instancesCount]; - JFFURLConnection* connection_ = nil; - JFFURLConnectionParams* params_ = nil; + @autoreleasepool { - { - params_ = [ JFFURLConnectionParams new ]; - params_.useLiveConnection = NO; - params_.url = [ NSURL URLWithString: @"http://abrakadabra.com" ]; - - connection_ = [ [ JFFURLConnection alloc ] initWithURLConnectionParams: params_ ]; - connection_.didFinishLoadingBlock = ^( NSError* blockError_) + __weak GHAsyncTestCase *weakSelf = self; + SEL testSelector = _cmd; + + [self prepare:testSelector]; + { - [ weakSelf_ notify: kGHUnitWaitStatusSuccess - forSelector: testSelector_ ]; - }; + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.useLiveConnection = NO; + params.url = [@"http://abrakadabra.com" toURL]; + + JFFURLConnection *connection = [[JFFURLConnection alloc] initWithURLConnectionParams:params]; + connection.didFinishLoadingBlock = ^(NSError *blockError) + { + [weakSelf notify:kGHUnitWaitStatusSuccess + forSelector:testSelector]; + }; + + [connection start]; + } - [ connection_ start ]; + [self waitForStatus:kGHUnitWaitStatusSuccess + timeout:61.]; } - - [ self waitForStatus: kGHUnitWaitStatusSuccess - timeout: TIMEOUT ]; + GHAssertEquals(initialInstancesCount, [JFFURLConnection instancesCount], @"packet mismatch"); } --(void)_testMockIsAvailableOnlyForNSUrlConnection +- (void)_testMockIsAvailableOnlyForNSUrlConnection { - [ self prepare: _cmd ]; + [self prepare:_cmd]; - NSURLRequest* request_ = [ NSURLRequest requestWithURL: [ NSURL URLWithString: @"http://abrakadabra.com" ] ]; - NSURLConnection* conn_ = [ [ NSURLConnection alloc ] initWithRequest: request_ - delegate: self ]; - [ conn_ start ]; -} - -- (void)connection:(NSURLConnection *)connection_ -didReceiveResponse:(NSURLResponse *)response_ -{ - [ self notify: kGHUnitWaitStatusSuccess - forSelector: @selector(testInvalidLocationDoesNotCauseCrash) ]; + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://abrakadabra.com"]]; + NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request + delegate:self]; + [conn start]; } @end diff --git a/test/JFFNetworkTest/Classes/JFFConectionTest.m b/test/JFFNetworkTest/Classes/JFFConectionTest.m index 1445639..7710ecd 100755 --- a/test/JFFNetworkTest/Classes/JFFConectionTest.m +++ b/test/JFFNetworkTest/Classes/JFFConectionTest.m @@ -1,173 +1,173 @@ @interface JFFConectionTest : GHAsyncTestCase - @end @implementation JFFConectionTest //TODO test leaks --(void)setUp +- (void)setUp { - [ JFFURLConnection enableInstancesCounting ];//JTODO test + [JFFURLConnection enableInstancesCounting];//JTODO test } //http://jigsaw.w3.org/HTTP/negbad --(void)testHttp406NotAcceptableCode +- (void)testHttp406NotAcceptableCode { - NSUInteger initialInstancesCount_ = [JFFURLConnection instancesCount]; - - [ self prepare ]; - - __block NSError* didFinishLoadingBlockError; - - NSURL* dataUrl = [NSURL URLWithString: @"http://jigsaw.w3.org/HTTP/negbad"]; - NSData* expectedData = [[NSData alloc] initWithContentsOfURL:dataUrl]; - - __block NSMutableData* totalData; - - @autoreleasepool - { - JFFAsyncOperationProgressHandler progress = ^(NSData *dataChunk) - { - if (!totalData) - totalData = [NSMutableData new]; - [totalData appendData:dataChunk]; - }; - - JFFDidFinishAsyncOperationHandler finish = ^(id result, NSError *error) - { - didFinishLoadingBlockError = error; - [ self notify: kGHUnitWaitStatusSuccess - forSelector: _cmd ]; + NSUInteger initialInstancesCount = [JFFURLConnection instancesCount]; + + @autoreleasepool { + __block NSError *didFinishLoadingBlockError; + + NSURL *dataUrl = [@"http://jigsaw.w3.org/HTTP/negbad" toURL]; + NSData *expectedData = [[NSData alloc] initWithContentsOfURL:dataUrl]; + + __block NSMutableData *totalData; + + void (^testBlock)(JFFSimpleBlock) = ^(JFFSimpleBlock finishTest) { + + JFFAsyncOperationProgressHandler progress = ^(NSData *dataChunk) + { + if (!totalData) + totalData = [NSMutableData new]; + [totalData appendData:dataChunk]; + }; + + JFFDidFinishAsyncOperationHandler finish = ^(id result, NSError *error) + { + didFinishLoadingBlockError = error; + finishTest(); + }; + + JFFAsyncOperation loader = liveChunkedURLResponseLoader(dataUrl, nil, nil); + loader(progress, nil, finish); }; - - liveChunkedURLResponseLoader(dataUrl, nil, nil)(progress, nil, finish); - - [self waitForStatus: kGHUnitWaitStatusSuccess - timeout: 61.]; + + [self performAsyncRequestOnMainThreadWithBlock:testBlock + selector:_cmd + timeout:61.]; + + GHAssertTrue([didFinishLoadingBlockError isKindOfClass:[JHttpError class]], @"Expected error with class - %@", [JHttpError class] ); + GHAssertNil(expectedData, @"packet mismatch"); + GHAssertNil(totalData , @"packet mismatch"); } - - GHAssertTrue( [didFinishLoadingBlockError isKindOfClass:[JHttpError class]], @"Expected error with class - %@", [JHttpError class] ); - GHAssertNil( expectedData, @"packet mismatch" ); - GHAssertNil( totalData , @"packet mismatch" ); - - GHAssertTrue( initialInstancesCount_ == [ JFFURLConnection instancesCount ], @"packet mismatch" ); + + GHAssertEquals(initialInstancesCount, [JFFURLConnection instancesCount], @"packet mismatch"); } //http://jigsaw.w3.org/HTTP/300/Go_301 --(void)testRedirectOnHttp301Code +- (void)testRedirectOnHttp301Code { - NSUInteger initialInstancesCount_ = [JFFURLConnection instancesCount]; - - [ self prepare ]; - - __block NSError* didFinishLoadingBlockError_; - - NSURL* dataUrl_ = [ NSURL URLWithString: @"http://jigsaw.w3.org/HTTP/300/301.html" ]; - NSData* expectedData_ = [[NSData alloc] initWithContentsOfURL:dataUrl_]; - - NSMutableData* totalData_ = [ NSMutableData new ]; - - @autoreleasepool - { - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = dataUrl_; - - JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; + NSUInteger initialInstancesCount = [JFFURLConnection instancesCount]; + + @autoreleasepool { + + __block NSError *didFinishLoadingBlockError; - id< JNUrlConnection > connection_ = [ factory_ createFastConnection ]; + NSURL *dataUrl = [@"http://jigsaw.w3.org/HTTP/300/301.html" toURL]; + NSData *expectedData = [[NSData alloc] initWithContentsOfURL:dataUrl]; - connection_.didReceiveResponseBlock = ^( id response_ ) - { - //IDLE - }; - connection_.didReceiveDataBlock = ^( NSData* dataChunk_ ) - { - [ totalData_ appendData: dataChunk_ ]; - }; - - connection_.didFinishLoadingBlock = ^( NSError* error_ ) - { - didFinishLoadingBlockError_ = error_; - [ self notify: kGHUnitWaitStatusSuccess - forSelector: _cmd ]; + NSMutableData *totalData = [NSMutableData new]; + + void (^testBlock)(JFFSimpleBlock) = ^(JFFSimpleBlock finishTest) { + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = dataUrl; + + JNConnectionsFactory *factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + + id connection = [factory createFastConnection]; + + connection.didReceiveResponseBlock = ^(id response) + { + //IDLE + }; + connection.didReceiveDataBlock = ^(NSData *dataChunk) + { + [totalData appendData:dataChunk]; + }; + + connection.didFinishLoadingBlock = ^(NSError *error) + { + didFinishLoadingBlockError = error; + finishTest(); + }; + + [connection start]; }; - [ connection_ start ]; - [ self waitForStatus: kGHUnitWaitStatusSuccess - timeout: 61. ]; + [self performAsyncRequestOnMainThreadWithBlock:testBlock + selector:_cmd + timeout:61.]; + + GHAssertNil(didFinishLoadingBlockError, @"Unexpected error - %@", didFinishLoadingBlockError); + GHAssertTrue([expectedData length] == [totalData length], @"packet mismatch" ); } - GHAssertNil( didFinishLoadingBlockError_, @"Unexpected error - %@", didFinishLoadingBlockError_ ); - GHAssertTrue( [ expectedData_ length ] == [ totalData_ length ], @"packet mismatch" ); - - GHAssertTrue( initialInstancesCount_ == [ JFFURLConnection instancesCount ], @"packet mismatch" ); + GHAssertEquals(initialInstancesCount, [JFFURLConnection instancesCount], @"packet mismatch"); } // http://jigsaw.w3.org/HTTP/300/Overview.html --(void)testRedirectOnHttp302Code +- (void)testRedirectOnHttp302Code { - NSUInteger initialInstancesCount_ = [ JFFURLConnection instancesCount ]; - - [ self prepare ]; - - __block NSError* didFinishLoadingBlockError_; - - NSURL* dataUrl_ = [ NSURL URLWithString: @"http://jigsaw.w3.org/HTTP/300/302.html" ]; - NSData* expectedData_ = [ [ NSData alloc ] initWithContentsOfURL: dataUrl_ ]; - - NSMutableData* totalData_ = [ NSMutableData new ]; - - @autoreleasepool - { - - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = dataUrl_; - JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; + NSUInteger initialInstancesCount = [JFFURLConnection instancesCount]; + + __block NSError *didFinishLoadingBlockError; + + NSURL* dataUrl = [@"http://jigsaw.w3.org/HTTP/300/302.html" toURL]; + NSData* expectedData = [[NSData alloc] initWithContentsOfURL:dataUrl]; - id< JNUrlConnection > connection_ = [ factory_ createFastConnection ]; + NSMutableData* totalData = [NSMutableData new]; - connection_.didReceiveResponseBlock = ^( id response_ ) + void (^testBlock)(JFFSimpleBlock) = ^(JFFSimpleBlock finishTest) { + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = dataUrl; + JNConnectionsFactory *factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + + id connection = [factory createFastConnection]; + + connection.didReceiveResponseBlock = ^(id response) { //IDLE }; - connection_.didReceiveDataBlock = ^( NSData* dataChunk_ ) + connection.didReceiveDataBlock = ^(NSData *dataChunk) { - [ totalData_ appendData: dataChunk_ ]; + [totalData appendData:dataChunk]; }; - - connection_.didFinishLoadingBlock = ^( NSError* error_ ) + + connection.didFinishLoadingBlock = ^(NSError *error) { - didFinishLoadingBlockError_ = error_; - [ self notify: kGHUnitWaitStatusSuccess - forSelector: _cmd ]; + didFinishLoadingBlockError = error; + finishTest(); }; - - [ connection_ start ]; - [ self waitForStatus: kGHUnitWaitStatusSuccess - timeout: 61. ]; - } - - GHAssertNil( didFinishLoadingBlockError_, @"Unexpected error - %@", didFinishLoadingBlockError_ ); - GHAssertTrue( [ expectedData_ length ] == [ totalData_ length ], @"packet mismatch" ); - - GHAssertTrue( initialInstancesCount_ == [ JFFURLConnection instancesCount ], @"packet mismatch" ); + + [connection start]; + }; + + [self performAsyncRequestOnMainThreadWithBlock:testBlock + selector:_cmd + timeout:61.]; + + GHAssertNil(didFinishLoadingBlockError, @"Unexpected error - %@", didFinishLoadingBlockError ); + GHAssertTrue([expectedData length] == [totalData length], @"packet mismatch" ); + + GHAssertEquals(initialInstancesCount, [JFFURLConnection instancesCount], @"packet mismatch"); } //JTODO add file - http://10.28.9.57:9000/about/ --(void)RtestValidDownloadCompletesCorrectly +- (void)RtestValidDownloadCompletesCorrectly { - [ self prepare ]; - - NSURL* dataUrl_ = [ NSURL URLWithString: @"http://10.28.9.57:9000/about/" ]; - - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = dataUrl_; - JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; + [self prepare]; + + NSURL *dataUrl = [ NSURL URLWithString: @"http://10.28.9.57:9000/about/" ]; + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = dataUrl; + JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params ]; id< JNUrlConnection > connection_ = [ factory_ createFastConnection ]; NSMutableData* totalData_ = [ NSMutableData new ]; - NSData* expectedData_ = [ NSData dataWithContentsOfURL: dataUrl_ ]; + NSData* expectedData_ = [ NSData dataWithContentsOfURL: dataUrl ]; connection_.didReceiveResponseBlock = ^( id response_ ) { @@ -192,42 +192,41 @@ -(void)RtestValidDownloadCompletesCorrectly } //now http://kdjsfhjkfhsdfjkdhfjkds.com redirected --(void)RtestInValidDownloadCompletesWithError +- (void)RtestInValidDownloadCompletesWithError { - [ self prepare ]; - - NSURL* dataUrl_ = [ NSURL URLWithString: @"http://kdjsfhjkfhsdfjkdhfjkds.com" ]; - - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = dataUrl_; - JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; - - id< JNUrlConnection > connection_ = [ factory_ createFastConnection ]; + [self prepare]; + + NSURL *dataUrl = [ NSURL URLWithString: @"http://kdjsfhjkfhsdfjkdhfjkds.com" ]; + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = dataUrl; + JNConnectionsFactory *factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + + id< JNUrlConnection > connection_ = [factory createFastConnection]; - connection_.didReceiveResponseBlock = ^( id response_ ) + connection_.didReceiveResponseBlock = ^(id response) { //IDLE }; - connection_.didReceiveDataBlock = ^( NSData* dataChunk_ ) + connection_.didReceiveDataBlock = ^(NSData *dataChunk) { }; - connection_.didFinishLoadingBlock = ^( NSError* error_ ) + connection_.didFinishLoadingBlock = ^(NSError *error) { - if ( nil != error_ ) + if (nil != error) { - [ self notify: kGHUnitWaitStatusSuccess - forSelector: _cmd ]; + [self notify:kGHUnitWaitStatusSuccess + forSelector:_cmd]; return; } - - [ self notify: kGHUnitWaitStatusFailure - forSelector: _cmd ]; + + [self notify:kGHUnitWaitStatusFailure + forSelector:_cmd]; }; - - [ connection_ start ]; - [ self waitForStatus: kGHUnitWaitStatusSuccess - timeout: 61. ]; + + [connection_ start]; + [self waitForStatus:kGHUnitWaitStatusSuccess + timeout:61.]; } - @end diff --git a/test/JFFNetworkTest/Classes/JFFLocalCookiesStorageTest.m b/test/JFFNetworkTest/Classes/JFFLocalCookiesStorageTest.m index 451ffc3..d03ded0 100755 --- a/test/JFFNetworkTest/Classes/JFFLocalCookiesStorageTest.m +++ b/test/JFFNetworkTest/Classes/JFFLocalCookiesStorageTest.m @@ -8,7 +8,7 @@ @interface JFFLocalCookiesStorageTest : GHTestCase @implementation JFFLocalCookiesStorageTest --(void)setUp +- (void)setUp { NSHTTPCookieStorage* storage_ = [ NSHTTPCookieStorage sharedHTTPCookieStorage ]; NSArray* cookies_ = [ [ storage_ cookies ] copy ]; @@ -18,7 +18,7 @@ -(void)setUp } } --(void)testHTTPCookieExparationDate +- (void)testHTTPCookieExparationDate { NSString* header_ = @"ws-alr1.dk.sitecore.net80_sitecore_username=NOhnomXlt2B691wsxQMcKxsi6rXR2bqSc4mtScMHQWpeVVLhgvKrF91imx_37FEP0vWkKJ6X78VEl5Gx3gXPYA2; expires=Wed, 05-Aug-2012 07:21:54 GMT; path=/sitecore/login"; @@ -45,7 +45,7 @@ -(void)testHTTPCookieExparationDate } } --(void)testHTTPCookiePathMatchWithSameDomain +- (void)testHTTPCookiePathMatchWithSameDomain { NSDate* now_ = [NSDate distantFuture]; @@ -112,7 +112,7 @@ -(void)testHTTPCookiePathMatchWithSameDomain } } --(void)testHTTPCookieDotDomainMatch +- (void)testHTTPCookieDotDomainMatch { NSDate *now = [NSDate distantFuture]; @@ -179,7 +179,7 @@ -(void)testHTTPCookieDotDomainMatch } } --(void)testHTTPCookieNoDotDomainMatch +- (void)testHTTPCookieNoDotDomainMatch { NSDate* now_ = [NSDate distantFuture]; diff --git a/test/JFFNetworkTest/Classes/JFFURLConnectionTest.m b/test/JFFNetworkTest/Classes/JFFURLConnectionTest.m index 1602669..3a89691 100755 --- a/test/JFFNetworkTest/Classes/JFFURLConnectionTest.m +++ b/test/JFFNetworkTest/Classes/JFFURLConnectionTest.m @@ -4,75 +4,65 @@ @interface JFFURLConnectionTest : GHAsyncTestCase @implementation JFFURLConnectionTest --(void)setUp +- (void)setUp { - [ JFFURLConnection enableInstancesCounting ]; - [ JFFURLConnectionParams enableInstancesCounting ]; + [JFFURLConnection enableInstancesCounting]; + [JFFURLConnectionParams enableInstancesCounting]; } --(void)testValidDownloadCompletesCorrectly +- (void)testValidDownloadCompletesCorrectly { - const NSUInteger initialCount_ = [ JFFURLConnection instancesCount ]; + const NSUInteger initialCount = [JFFURLConnection instancesCount]; + const NSUInteger initialParamsCount = [JFFURLConnectionParams instancesCount]; - __weak id< JNUrlConnection > wealConnection_ = nil; + __block __weak id< JNUrlConnection > wealConnection = nil; + @autoreleasepool { - @autoreleasepool + TestAsyncRequestBlock starterBlock = ^void(JFFSimpleBlock stopTest) { - NSURL* dataUrl_ = [ NSURL URLWithString: @"http://www.ietf.org/rfc/rfc4180.txt" ]; - - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = dataUrl_; - JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; - - NSObject< JNUrlConnection >* connection_ = [ factory_ createFastConnection ]; - - NSUInteger currentCount_ = [ JFFURLConnection instancesCount ]; - - currentCount_ = [ JFFURLConnectionParams instancesCount ]; - - NSMutableData* totalData_ = [ NSMutableData data ]; - NSData* expectedData_ = [ NSData dataWithContentsOfURL: dataUrl_ ]; - - wealConnection_ = connection_; - connection_.didReceiveResponseBlock = ^( id response_ ) + NSURL *dataUrl = [@"http://www.ietf.org/rfc/rfc4180.txt" toURL]; + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = dataUrl; + JNConnectionsFactory* factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + + NSObject< JNUrlConnection > *connection = [factory createFastConnection]; + + NSMutableData *totalData = [NSMutableData data]; + NSData *expectedData = [NSData dataWithContentsOfURL:dataUrl]; + + wealConnection = connection; + connection.didReceiveResponseBlock = ^(id response) { - NSLog( @"[JFFURLConnectionTest] didReceiveResponseBlock: %@ ", response_ ); + NSLog(@"[JFFURLConnectionTest] didReceiveResponseBlock: %@ ", response); }; - connection_.didReceiveDataBlock = ^( NSData* data_chunk_ ) + connection.didReceiveDataBlock = ^(NSData *dataChunk) { - NSLog( @"[JFFURLConnectionTest] didReceiveDataBlock: %d ", [ data_chunk_ length ] ); - [ totalData_ appendData: data_chunk_ ]; + NSLog(@"[JFFURLConnectionTest] didReceiveDataBlock: %d ", [dataChunk length]); + [totalData appendData:dataChunk]; }; - - TestAsyncRequestBlock starterBlock_ = ^void( JFFSimpleBlock stopTest_ ) - { - connection_.didFinishLoadingBlock = ^( NSError* error_ ) - { - NSLog( @"[JFFURLConnectionTest] didFinishLoadingBlock: %@ ", error_ ); - - stopTest_(); - GHAssertTrue( [ expectedData_ isEqualToData: totalData_ ], @"packet mismatch" ); - }; + connection.didFinishLoadingBlock = ^(NSError *error) { - [ connection_ start ]; + NSLog(@"[JFFURLConnectionTest] didFinishLoadingBlock: %@ ", error); + stopTest(); + GHAssertTrue([expectedData isEqualToData:totalData], @"packet mismatch" ); }; - [ self performAsyncRequestOnMainThreadWithBlock: starterBlock_ - selector: _cmd - timeout: 61.0 ]; - } + [connection start]; + }; + + [self performAsyncRequestOnMainThreadWithBlock:starterBlock + selector:_cmd + timeout:61.0]; } - - GHAssertTrue( wealConnection_ == nil, @"OK" ); - - NSUInteger currentCount_ = [ JFFURLConnection instancesCount ]; - GHAssertTrue( initialCount_ == currentCount_, @"packet mismatch" ); - - NSUInteger currentParamsCount_ = [ JFFURLConnectionParams instancesCount ]; - GHAssertTrue( initialCount_ == currentParamsCount_, @"packet mismatch" ); + + GHAssertTrue(wealConnection == nil, @"OK"); + + GHAssertEquals(initialCount, [JFFURLConnection instancesCount], @"JFFURLConnection instancesCount mismatch"); + GHAssertEquals(initialParamsCount, [JFFURLConnectionParams instancesCount], @"JFFURLConnectionParams instancesCount mismatch"); } @end diff --git a/test/JFFNetworkTest/Classes/JNLiveLoaderTest.m b/test/JFFNetworkTest/Classes/JNLiveLoaderTest.m index 163f824..676f75b 100755 --- a/test/JFFNetworkTest/Classes/JNLiveLoaderTest.m +++ b/test/JFFNetworkTest/Classes/JNLiveLoaderTest.m @@ -10,9 +10,9 @@ -(void)TtestValidBlockDownloadCompletesCorrectly //Our build server NSURL* data_url_ = [ NSURL URLWithString: @"http://10.28.9.57:9000/about/" ]; NSData* expected_data_ = [ NSData dataWithContentsOfURL: data_url_ ]; - + JFFAsyncOperation loader_ = liveDataURLResponseLoader( data_url_, nil, nil ); - + loader_( nil, nil, ^void( id result_, NSError* error_ ) { GHAssertNil ( error_, @"Unexpected error : %@", error_ ); diff --git a/test/JFFNetworkTest/Classes/JNTestBundleManager.m b/test/JFFNetworkTest/Classes/JNTestBundleManager.m index 23a5465..95ae0e9 100755 --- a/test/JFFNetworkTest/Classes/JNTestBundleManager.m +++ b/test/JFFNetworkTest/Classes/JNTestBundleManager.m @@ -2,7 +2,7 @@ @implementation JNTestBundleManager -+(NSBundle*)decodersDataBundle ++ (NSBundle *)decodersDataBundle { NSBundle* main_bundle_ = [ NSBundle bundleForClass: [ self class ] ]; @@ -12,7 +12,7 @@ +(NSBundle*)decodersDataBundle return [ NSBundle bundleWithPath: result_path_ ]; } -+(NSData*)loadZipFileNamed:( NSString* )file_name_ ++ (NSData *)loadZipFileNamed:(NSString *)file_name_ { NSString* result_path_ = [ [ self decodersDataBundle ] pathForResource: file_name_ ofType: @"zip" ]; @@ -20,22 +20,22 @@ +(NSData*)loadZipFileNamed:( NSString* )file_name_ return [ NSData dataWithContentsOfFile: result_path_ ]; } -+(NSString*)loadTextFileNamed:( NSString* )file_name_ ++ (NSString *)loadTextFileNamed:(NSString *)fileName { - NSString* result_path_ = [ [ self decodersDataBundle ] pathForResource: file_name_ - ofType: @"txt" ]; - - NSError* error_ = nil; - - NSString* result_ = [ NSString stringWithContentsOfFile: result_path_ - encoding: NSUTF8StringEncoding - error: &error_ ]; - if ( nil != error_ ) - { - NSLog( @"[!!! ERROR !!!] : wrong resource type at '%@' ", result_path_ ); + NSString *resultPath = [[self decodersDataBundle] pathForResource:fileName + ofType:@"txt"]; + + NSError *error = nil; + + NSString *result = [NSString stringWithContentsOfFile:resultPath + encoding:NSUTF8StringEncoding + error:&error]; + if (nil != error) { + + NSLog(@"[!!! ERROR !!!] : wrong resource type at '%@' ", resultPath); } - - return result_; + + return result; } @end diff --git a/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.h b/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.h index 4078c5c..048637c 100755 --- a/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.h +++ b/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.h @@ -1,5 +1,4 @@ #import @interface BadHeadersMockNetwork : NSURLProtocol - @end diff --git a/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.m b/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.m index 43dc786..b8548b5 100755 --- a/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.m +++ b/test/JFFNetworkTest/Classes/Mock/BadHeadersMockNetwork.m @@ -2,15 +2,14 @@ @implementation BadHeadersMockNetwork - -+(NSURLRequest*)canonicalRequestForRequest:(NSURLRequest *)request_ ++ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request { - return request_; + return request; } -+(BOOL)canInitWithRequest:( NSURLRequest* )request_ ++ (BOOL)canInitWithRequest:(NSURLRequest *)request { - return [ request_.URL.absoluteString hasPrefix: @"http://abrakadabra.com" ]; + return [request.URL.absoluteString hasPrefix:@"http://abrakadabra.com"]; } + (BOOL)requestIsCacheEquivalent:(NSURLRequest *)aRequest toRequest:(NSURLRequest *)bRequest @@ -20,32 +19,30 @@ + (BOOL)requestIsCacheEquivalent:(NSURLRequest *)aRequest toRequest:(NSURLReques -(void)startLoading { - NSURL* url_ = [ NSURL URLWithString: @"http://abrakadabra.com" ]; - NSDictionary* headers_ = [ NSDictionary dictionaryWithObjectsAndKeys: - @"close", @"Connection", - @"0", @"Content-Length", - @"text/html", @"Content-Type", - @"Tue, 05 Jun 2012 08:15:16 GMT", @"Date" - @"http://abrakadabra.com/?f", @"Location", - @"Apache/2.2.17 (Ubuntu)", @"Server" - @"WEB=W2; path=/", @"Set-Cookie", - @"Accept-Encoding", @"Vary" - @"PHP/5.3.5-1ubuntu7.8", @"X-Powered-By" - , nil ]; + NSURL *url = [@"http://abrakadabra.com" toURL]; + NSDictionary *headers = + @{ + @"Connection" : @"close" , + @"Content-Length" : @"0" , + @"Content-Type" : @"text/html" , + @"Date" : @"Tue, 05 Jun 2012 08:15:16 GMT", + @"Location" : @"http://abrakadabra.com/?f" , + @"Server" : @"Apache/2.2.17 (Ubuntu)" , + @"Set-Cookie" : @"WEB=W2; path=/" , + @"Vary" : @"Accept-Encoding" , + @"X-Powered-By" : @"PHP/5.3.5-1ubuntu7.8" , + }; - NSHTTPURLResponse* response_ = [ [ NSHTTPURLResponse alloc ] initWithURL: url_ - statusCode: 302 - HTTPVersion: @"HTTP/1.1" - headerFields: headers_ ]; + NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:url + statusCode:302 + HTTPVersion:@"HTTP/1.1" + headerFields:headers]; + [[self client] URLProtocol:self + didReceiveResponse:response + cacheStoragePolicy:NSURLCacheStorageNotAllowed]; - [ [ self client ] URLProtocol: self - didReceiveResponse: response_ - cacheStoragePolicy: NSURLCacheStorageNotAllowed ]; - - - - [ [ self client ] URLProtocolDidFinishLoading: self ]; + [[self client] URLProtocolDidFinishLoading:self]; } @end diff --git a/test/JFFNetworkTest/Classes/NSConnectionTest.m b/test/JFFNetworkTest/Classes/NSConnectionTest.m index 0933095..e033a52 100644 --- a/test/JFFNetworkTest/Classes/NSConnectionTest.m +++ b/test/JFFNetworkTest/Classes/NSConnectionTest.m @@ -4,116 +4,110 @@ @interface NSConnectionTest : GHAsyncTestCase @implementation NSConnectionTest --(void)setUp +- (void)setUp { - [ JNNsUrlConnection enableInstancesCounting ]; + [JNNsUrlConnection enableInstancesCounting]; } --(void)testValidDownloadCompletesLocalFileCorrectly +- (void)testValidDownloadCompletesLocalFileCorrectly { - const NSUInteger initialCount_ = [ JNNsUrlConnection instancesCount ]; - + const NSUInteger initialCount = [JNNsUrlConnection instancesCount]; + @autoreleasepool { - [ self prepare ]; - - NSURL* dataUrl_ = [ [ JNTestBundleManager decodersDataBundle ] URLForResource: @"1" - withExtension: @"txt" ]; - - JFFURLConnectionParams* params_ = [ JFFURLConnectionParams new ]; - params_.url = dataUrl_; - JNConnectionsFactory* factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams: params_ ]; - - id< JNUrlConnection > connection_ = [ factory_ createStandardConnection ]; - + [self prepare]; + + NSURL *dataUrl = [[JNTestBundleManager decodersDataBundle] URLForResource:@"1" + withExtension:@"txt"]; + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = dataUrl; + JNConnectionsFactory *factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + + id< JNUrlConnection > connection = [factory createStandardConnection]; + NSMutableData* totalData_ = [ NSMutableData new ]; - NSData* expectedData_ = [ [ NSData alloc ] initWithContentsOfURL: dataUrl_ ]; - - connection_.didReceiveResponseBlock = ^( id response_ ) + NSData* expectedData_ = [ [ NSData alloc ] initWithContentsOfURL:dataUrl]; + + connection.didReceiveResponseBlock = ^( id response_ ) { //IDLE }; - connection_.didReceiveDataBlock = ^( NSData* dataChunk_ ) + connection.didReceiveDataBlock = ^( NSData* dataChunk_ ) { [ totalData_ appendData: dataChunk_ ]; }; - connection_.didFinishLoadingBlock = ^( NSError* error_ ) + connection.didFinishLoadingBlock = ^(NSError *error) { - if ( nil != error_ ) - { - [ self notify: kGHUnitWaitStatusFailure - forSelector: _cmd ]; + if (nil != error) { + + [self notify:kGHUnitWaitStatusFailure + forSelector:_cmd]; return; } - - GHAssertTrue( [ expectedData_ isEqualToData: totalData_ ], @"packet mismatch" ); - [ self notify: kGHUnitWaitStatusSuccess - forSelector: _cmd ]; + + GHAssertTrue([expectedData_ isEqualToData:totalData_], @"packet mismatch"); + [self notify:kGHUnitWaitStatusSuccess + forSelector:_cmd]; }; - - [ connection_ start ]; - [ self waitForStatus: kGHUnitWaitStatusSuccess - timeout: 61. ]; + + [connection start]; + [self waitForStatus:kGHUnitWaitStatusSuccess + timeout:61.]; } - - NSUInteger currentCount_ = [ JNNsUrlConnection instancesCount ]; - GHAssertTrue( initialCount_ == currentCount_, @"packet mismatch" ); + + GHAssertEquals(initialCount, [JNNsUrlConnection instancesCount], @"packet mismatch"); } --(void)testValidDownloadCompletesCorrectly +- (void)testValidDownloadCompletesCorrectly { - const NSUInteger initialCount_ = [ JNNsUrlConnection instancesCount ]; + const NSUInteger initialCount = [JNNsUrlConnection instancesCount]; __block BOOL dataReceived_ = NO; __block BOOL isDownloadExecuted = NO; - - @autoreleasepool { - [self prepare]; - - NSURL* dataUrl_ = [ [ NSURL alloc ] initWithString: @"http://www.ietf.org/rfc/rfc4180.txt" ]; - - JFFURLConnectionParams *params = [JFFURLConnectionParams new]; - params.url = dataUrl_; - JNConnectionsFactory *factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; - - id< JNUrlConnection > connection = [factory createStandardConnection]; - - connection.didReceiveResponseBlock = ^(id response) { - NSLog( @"[testValidDownloadCompletesCorrectly] - didReceiveResponseBlock : %@", response ); - }; - - connection.didReceiveDataBlock = ^(NSData *dataChunk) { - dataReceived_ = YES; - }; - - TestAsyncRequestBlock starterBlock_ = ^void(JFFSimpleBlock stopTest_) + TestAsyncRequestBlock starterBlock = ^void(JFFSimpleBlock stopTest) { + NSURL *dataUrl = [@"http://www.ietf.org/rfc/rfc4180.txt" toURL]; + + JFFURLConnectionParams *params = [JFFURLConnectionParams new]; + params.url = dataUrl; + JNConnectionsFactory *factory = [[JNConnectionsFactory alloc] initWithURLConnectionParams:params]; + + id< JNUrlConnection > connection = [factory createStandardConnection]; + + connection.didReceiveResponseBlock = ^(id response) { + NSLog( @"[testValidDownloadCompletesCorrectly] - didReceiveResponseBlock : %@", response ); + }; + + connection.didReceiveDataBlock = ^(NSData *dataChunk) { + dataReceived_ = YES; + }; + connection.didFinishLoadingBlock = ^(NSError *error) { NSLog( @"[testValidDownloadCompletesCorrectly] - connectionDidFinishLoading" ); isDownloadExecuted = YES; - stopTest_(); + stopTest(); }; [connection start]; }; - [ self performAsyncRequestOnMainThreadWithBlock: starterBlock_ - selector: _cmd - timeout: 61.0 ]; + [self performAsyncRequestOnMainThreadWithBlock:starterBlock + selector:_cmd + timeout:61.0]; } - GHAssertTrue( dataReceived_, @"packet mismatch" ); + GHAssertTrue(dataReceived_, @"packet mismatch" ); - NSUInteger currentCount = [JNNsUrlConnection instancesCount]; - GHAssertTrue(initialCount_ == currentCount, @"packet mismatch"); + GHAssertEquals(initialCount, [JNNsUrlConnection instancesCount], @"packet mismatch"); } --(void)RtestInValidDownloadCompletesWithError +- (void)RtestInValidDownloadCompletesWithError { [self prepare]; @@ -121,18 +115,18 @@ -(void)RtestInValidDownloadCompletesWithError JFFURLConnectionParams *params = [JFFURLConnectionParams new]; params.url = dataUrl; - JNConnectionsFactory *factory_ = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams:params]; + JNConnectionsFactory *factory = [ [ JNConnectionsFactory alloc ] initWithURLConnectionParams:params]; - id< JNUrlConnection > connection_ = [ factory_ createStandardConnection ]; - - connection_.didReceiveResponseBlock = ^( id response_ ) + id< JNUrlConnection > connection = [ factory createStandardConnection ]; + + connection.didReceiveResponseBlock = ^( id response_ ) { //IDLE }; - connection_.didReceiveDataBlock = ^( NSData* data_chunk_ ) + connection.didReceiveDataBlock = ^( NSData* data_chunk_ ) { }; - connection_.didFinishLoadingBlock = ^( NSError* error_ ) + connection.didFinishLoadingBlock = ^( NSError* error_ ) { if ( nil != error_ ) { @@ -145,9 +139,9 @@ -(void)RtestInValidDownloadCompletesWithError forSelector: _cmd ]; }; - [ connection_ start ]; - [ self waitForStatus: kGHUnitWaitStatusSuccess - timeout: 61. ]; + [connection start]; + [self waitForStatus:kGHUnitWaitStatusSuccess + timeout:61.]; } @end diff --git a/test/JFFNetworkTest/Classes/NSHTTPCookieMatchesURLTest.m b/test/JFFNetworkTest/Classes/NSHTTPCookieMatchesURLTest.m index 904cde4..3942d14 100755 --- a/test/JFFNetworkTest/Classes/NSHTTPCookieMatchesURLTest.m +++ b/test/JFFNetworkTest/Classes/NSHTTPCookieMatchesURLTest.m @@ -1,5 +1,5 @@ -#import +#import #import "NSHTTPCookie+HTTPCookieWithHeader.h" @@ -8,32 +8,32 @@ @interface NSHTTPCookieMatchesURLTest : GHTestCase @implementation NSHTTPCookieMatchesURLTest --(void)testHTTPCookiematchesWithEmptyUrl +- (void)testHTTPCookiematchesWithEmptyUrl { NSString* header_ = @"ws-alr1.dk.sitecore.net80_sitecore_username=NOhnomXlt2B691wsxQMcKxsi6rXR2bqSc4mtScMHQWpeVVLhgvKrF91imx_37FEP0vWkKJ6X78VEl5Gx3gXPYA2; expires=Wed, 25-Jul-2012 07:21:54 GMT; path=/sitecore/login"; - + NSHTTPCookie* cookie_ = [ NSHTTPCookie HTTPCookieWithHeader: header_ url: nil ]; - + GHAssertNil( cookie_, @"OK" ); } --(void)testHTTPCookiematchesWithEmptyUrlAndDomain +- (void)testHTTPCookiematchesWithEmptyUrlAndDomain { NSString* header_ = @"ws-alr1.dk.sitecore.net80_sitecore_username=NOhnomXlt2B691wsxQMcKxsi6rXR2bqSc4mtScMHQWpeVVLhgvKrF91imx_37FEP0vWkKJ6X78VEl5Gx3gXPYA2; expires=Wed, 25-Jul-2012 07:21:54 GMT; Domain=ws-alr1.dk.sitecore.net; path=/sitecore/login"; - + NSHTTPCookie* cookie_ = [ NSHTTPCookie HTTPCookieWithHeader: header_ url: nil ]; - + GHAssertNil( cookie_, @"OK" ); } --(void)testHTTPCookiePathMatchWithSameDomain +- (void)testHTTPCookiePathMatchWithSameDomain { - NSString* header_ = @"ws-alr1.dk.sitecore.net80_sitecore_username=NOhnomXlt2B691wsxQMcKxsi6rXR2bqSc4mtScMHQWpeVVLhgvKrF91imx_37FEP0vWkKJ6X78VEl5Gx3gXPYA2; expires=Wed, 25-Jul-2012 07:21:54 GMT; path=/sitecore/login"; - - NSURL* url_ = [ NSURL URLWithString: @"http://ws-alr1.dk.sitecore.net/sitecore/login" ]; - - NSHTTPCookie* cookie_ = [ NSHTTPCookie HTTPCookieWithHeader: header_ url: url_ ]; - + NSString *header_ = @"ws-alr1.dk.sitecore.net80_sitecore_username=NOhnomXlt2B691wsxQMcKxsi6rXR2bqSc4mtScMHQWpeVVLhgvKrF91imx_37FEP0vWkKJ6X78VEl5Gx3gXPYA2; expires=Wed, 25-Jul-2012 07:21:54 GMT; path=/sitecore/login"; + + NSURL *url_ = [ NSURL URLWithString: @"http://ws-alr1.dk.sitecore.net/sitecore/login" ]; + + NSHTTPCookie *cookie_ = [NSHTTPCookie HTTPCookieWithHeader:header_ url:url_]; + GHAssertTrue ( [ cookie_.domain isEqualToString: @"ws-alr1.dk.sitecore.net" ], @"OK" ); GHAssertTrue ( [ cookie_.path isEqualToString: @"/sitecore/login" ], @"OK" ); @@ -49,7 +49,7 @@ -(void)testHTTPCookiePathMatchWithSameDomain GHAssertFalse( [ cookie_ matchesURL: rootUrl_ ], @"OK" ); } --(void)testHTTPCookieDotDomainMatch +- (void)testHTTPCookieDotDomainMatch { NSString* header_ = @"ws-alr1.dk.sitecore.net80_sitecore_username=NOhnomXlt2B691wsxQMcKxsi6rXR2bqSc4mtScMHQWpeVVLhgvKrF91imx_37FEP0vWkKJ6X78VEl5Gx3gXPYA2; expires=Wed, 25-Jul-2012 07:21:54 GMT; Domain=sitecore.net; path=/"; @@ -72,7 +72,7 @@ -(void)testHTTPCookieDotDomainMatch GHAssertTrue( [ cookie_ matchesURL: rootUrl_ ], @"OK" ); } --(void)testHTTPCookieNoDotDomainMatch +- (void)testHTTPCookieNoDotDomainMatch { NSString* header_ = @"sitecore.net80_sitecore_username=NOhnomXlt2B691wsxQMcKxsi6rXR2bqSc4mtScMHQWpeVVLhgvKrF91imx_37FEP0vWkKJ6X78VEl5Gx3gXPYA2; expires=Wed, 25-Jul-2012 07:21:54 GMT; path=/"; diff --git a/test/JFFNetworkTest/Classes/NSStringRFC_2965Test.m b/test/JFFNetworkTest/Classes/NSStringRFC_2965Test.m index 65d9c1c..a8b6ef3 100755 --- a/test/JFFNetworkTest/Classes/NSStringRFC_2965Test.m +++ b/test/JFFNetworkTest/Classes/NSStringRFC_2965Test.m @@ -7,7 +7,7 @@ @interface NSStringRFC_2965Test : GHTestCase @implementation NSStringRFC_2965Test // http://tools.ietf.org/html/rfc2965 --(void)testNSStringRFC_2965Domain +- (void)testNSStringRFC_2965Domain { GHAssertTrue ( [ @"x.y.com" domainMatchesCookiesDomain: @".Y.com" ], @"OK" ); //domain-match is not a commutative @@ -17,21 +17,21 @@ -(void)testNSStringRFC_2965Domain GHAssertTrue ( [ @"y.com" domainMatchesCookiesDomain: @".y.com" ], @"OK" ); } --(void)testNSStringRFC_2965Path +- (void)testNSStringRFC_2965Path { - GHAssertFalse( [ @"/a/d/v" pathMatchesCookiesPath: @"" ], @"OK" ); - GHAssertFalse( [ @"" pathMatchesCookiesPath: @"" ], @"OK" ); + GHAssertFalse([@"/a/d/v" pathMatchesCookiesPath: @"" ], @"OK" ); + GHAssertFalse([@"" pathMatchesCookiesPath: @"" ], @"OK" ); - GHAssertTrue( [ @"/" pathMatchesCookiesPath: @"/" ], @"OK" ); - GHAssertTrue( [ @"" pathMatchesCookiesPath: @"/" ], @"OK" ); - GHAssertTrue( [ @"asdsdsd" pathMatchesCookiesPath: @"/" ], @"OK" ); - GHAssertTrue( [ @"/a/d/v" pathMatchesCookiesPath: @"/" ], @"OK" ); + GHAssertTrue([@"/" pathMatchesCookiesPath: @"/" ], @"OK" ); + GHAssertTrue([@"" pathMatchesCookiesPath: @"/" ], @"OK" ); + GHAssertTrue([@"asdsdsd" pathMatchesCookiesPath: @"/" ], @"OK" ); + GHAssertTrue([@"/a/d/v" pathMatchesCookiesPath: @"/" ], @"OK" ); - GHAssertTrue ( [ @"/a/d/v" pathMatchesCookiesPath: @"/a" ], @"OK" ); - GHAssertFalse( [ @"/s/d/v" pathMatchesCookiesPath: @"/a" ], @"OK" ); + GHAssertTrue ([@"/a/d/v" pathMatchesCookiesPath: @"/a" ], @"OK" ); + GHAssertFalse([@"/s/d/v" pathMatchesCookiesPath: @"/a" ], @"OK" ); - GHAssertTrue ( [ @"/a/B/v" pathMatchesCookiesPath: @"/a/b" ], @"OK" ); - GHAssertFalse( [ @"/a/c/v" pathMatchesCookiesPath: @"/a/b" ], @"OK" ); + GHAssertTrue ([@"/a/B/v" pathMatchesCookiesPath: @"/a/b" ], @"OK" ); + GHAssertFalse([@"/a/c/v" pathMatchesCookiesPath: @"/a/b" ], @"OK" ); } @end diff --git a/test/JFFNetworkTest/Classes/StringFromQueryComponentsTest.m b/test/JFFNetworkTest/Classes/StringFromQueryComponentsTest.m index c99408c..04baa21 100755 --- a/test/JFFNetworkTest/Classes/StringFromQueryComponentsTest.m +++ b/test/JFFNetworkTest/Classes/StringFromQueryComponentsTest.m @@ -4,7 +4,7 @@ @interface StringFromQueryComponentsTest : GHTestCase @implementation StringFromQueryComponentsTest --(void)testStringFromQueryComponentsTest +- (void)testStringFromQueryComponentsTest { NSString* key1_ = @"a"; NSString* key2_ = @"a b"; @@ -12,28 +12,26 @@ -(void)testStringFromQueryComponentsTest NSString* valueA_ = @"valueA"; - NSDictionary* dict_ = [ [ NSDictionary alloc ] initWithObjectsAndKeys: - valueA_, key1_ - , [ NSArray arrayWithObjects: @"a", @"b", nil ], key2_ - , [ NSArray array ], key3_ - , nil ]; - + NSDictionary* dict_ = @{key1_: valueA_ + , key2_: @[@"a", @"b"] + , key3_: @[]}; + NSString* str_ = [ dict_ stringFromQueryComponents ]; + + NSDictionary *newDict_ = [ str_ dictionaryFromQueryComponents ]; - NSDictionary* newDict_ = [ str_ dictionaryFromQueryComponents ]; - - GHAssertTrue( [ newDict_ count ] == 2, @"OK" ); + GHAssertTrue([newDict_ count ] == 2, @"OK" ); NSString* argValueA_ = [ newDict_ firstValueIfExsistsForKey: key1_ ]; - GHAssertTrue( [ valueA_ isEqualToString: argValueA_ ], @"OK" ); + GHAssertTrue([valueA_ isEqualToString: argValueA_ ], @"OK" ); - NSArray* ABvalues_ = [ newDict_ objectForKey: key2_ ]; + NSArray* ABvalues_ = newDict_[key2_]; - GHAssertTrue( [ ABvalues_ count ] == 2, @"OK" ); + GHAssertTrue([ABvalues_ count ] == 2, @"OK" ); - GHAssertTrue( [ ABvalues_ containsObject: @"a" ], @"OK" ); - GHAssertTrue( [ ABvalues_ containsObject: @"b" ], @"OK" ); + GHAssertTrue([ ABvalues_ containsObject: @"a" ], @"OK" ); + GHAssertTrue([ ABvalues_ containsObject: @"b" ], @"OK" ); } @end diff --git a/test/JFFNetworkTest/Classes/StubDecoderTest.m b/test/JFFNetworkTest/Classes/StubDecoderTest.m index 5dd5835..31a5d0b 100755 --- a/test/JFFNetworkTest/Classes/StubDecoderTest.m +++ b/test/JFFNetworkTest/Classes/StubDecoderTest.m @@ -4,12 +4,12 @@ @interface StubDecoderTest : GHTestCase @implementation StubDecoderTest --(void)testErrorParameterIsRequired +- (void)RtestErrorParameterIsRequired { - NSData* gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1" ]; - + NSData *gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1" ]; + JNStubDecoder* decoder_ = [ JNStubDecoder new ]; - + GHAssertThrows ( [ decoder_ decodeData: gzip_data_ @@ -18,7 +18,7 @@ -(void)testErrorParameterIsRequired ); } --(void)testStubDecoderReturnsTheSameVariable +- (void)testStubDecoderReturnsTheSameVariable { NSError* error_ = nil; JNStubDecoder* decoder_ = nil; diff --git a/test/JFFNetworkTest/Classes/ZipDecoderTest.m b/test/JFFNetworkTest/Classes/ZipDecoderTest.m index 1e01f23..125be19 100755 --- a/test/JFFNetworkTest/Classes/ZipDecoderTest.m +++ b/test/JFFNetworkTest/Classes/ZipDecoderTest.m @@ -4,12 +4,12 @@ @interface ZipDecoderTest : GHTestCase @implementation ZipDecoderTest --(void)testErrorParameterIsRequired +- (void)testErrorParameterIsRequired { - NSData* gzipData_ = [ JNTestBundleManager loadZipFileNamed : @"1.1" ]; - + NSData* gzipData_ = [ JNTestBundleManager loadZipFileNamed : @"1.1" ]; + JNZipDecoder* decoder_ = [ JNZipDecoder new ]; - + GHAssertThrows ( [ decoder_ decodeData: gzipData_ @@ -18,50 +18,50 @@ -(void)testErrorParameterIsRequired ); } --(void)testNilDataProducesNilResult +- (void)testNilDataProducesNilResult { - NSError* error_ = nil; + NSError *error = nil; - JNZipDecoder* decoder_ = [ JNZipDecoder new ]; - NSData* received_data_ = [ decoder_ decodeData: nil - error: &error_ ]; - - GHAssertNil( received_data_, @"Nil output expected" ); - GHAssertNil( error_ , @"No errors are expected" ); + JNZipDecoder *decoder = [JNZipDecoder new]; + NSData *receivedData = [decoder decodeData:nil + error:&error]; + + GHAssertNil(receivedData, @"Nil output expected" ); + GHAssertNil(error , @"No errors are expected"); } //!! dodikk -- TODO : uncomment this once an appropriate test case is created --(void)_testZipFromBackEndExtractedCorrectly +- (void)_testZipFromBackEndExtractedCorrectly { NSError* error_ = nil; - + NSData* gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1.1" ]; NSString* expected_ = [ JNTestBundleManager loadTextFileNamed: @"1.1" ]; - + JNZipDecoder* decoder_ = [ JNZipDecoder new ]; NSData* received_data_ = [ decoder_ decodeData: gzip_data_ error: &error_ ]; GHAssertNil( error_, @"Unexpected decode error - %@", error_ ); - + NSString* received_ = [ [ NSString alloc ] initWithData: received_data_ encoding: NSUTF8StringEncoding ]; - + GHAssertNil( error_, @"Unexpected encoding error - %@", error_ ); - + GHAssertTrue( [ received_ isEqualToString: expected_ ], @"Wrong decoding result" ); } --(void)testBadDataProducesCorrectError +- (void)testBadDataProducesCorrectError { NSError* error_ = nil; - + NSData* gzip_data_ = [ JNTestBundleManager loadZipFileNamed : @"1.1" ]; - + JNZipDecoder* decoder_ = [ JNZipDecoder new ]; NSData* received_data_ = [ decoder_ decodeData: gzip_data_ error: &error_ ]; - + GHAssertNil( received_data_, @"nil data in error Expected" ); GHAssertTrue( [ error_.domain isEqualToString: @"gzip.error" ], @"Unexpected error domain" ); GHAssertTrue( error_.code == Z_DATA_ERROR, @"Unexpected error code" ); diff --git a/test/JFFNetworkTest/JFFNetworkTest.xcodeproj/project.pbxproj b/test/JFFNetworkTest/JFFNetworkTest.xcodeproj/project.pbxproj index def285b..c5e0fe1 100755 --- a/test/JFFNetworkTest/JFFNetworkTest.xcodeproj/project.pbxproj +++ b/test/JFFNetworkTest/JFFNetworkTest.xcodeproj/project.pbxproj @@ -29,7 +29,6 @@ 53A33F2E141F69EB00469DAA /* 1.1.txt in Resources */ = {isa = PBXBuildFile; fileRef = 53A33F2C141F69EB00469DAA /* 1.1.txt */; }; 53A33F2F141F69EB00469DAA /* 1.1.zip in Resources */ = {isa = PBXBuildFile; fileRef = 53A33F2D141F69EB00469DAA /* 1.1.zip */; }; 53A33F4A141F9AA000469DAA /* 1-Incomplete.zip in Resources */ = {isa = PBXBuildFile; fileRef = 53A33F49141F9A9F00469DAA /* 1-Incomplete.zip */; }; - 7E38854A17FBEEAF00399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E38854917FBEEAF00399329 /* QuartzCore.framework */; }; 7E6AF9A0157E105600CA8ED4 /* BadHeadersMockNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E6AF99F157E105600CA8ED4 /* BadHeadersMockNetwork.m */; }; 7EBCDA6316E5E76E0095EE39 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EBCDA6216E5E76E0095EE39 /* Default-568h@2x.png */; }; CE29B5E915F5E984000A05B8 /* URLWithLocationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CE29B5E815F5E983000A05B8 /* URLWithLocationTest.m */; }; @@ -207,13 +206,6 @@ remoteGlobalIDString = 7E57F42414F93738002D139B; remoteInfo = JFFUtilsFW; }; - 7ED1F4CD17DF65EB0003CDD4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5310BA8D141F51AD00A3E2B1 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CE433772160A1A5800C2279F /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 5310BA8D141F51AD00A3E2B1 /* JFFUtils.xcodeproj */; @@ -266,7 +258,6 @@ 53A33F49141F9A9F00469DAA /* 1-Incomplete.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "1-Incomplete.zip"; sourceTree = ""; }; 65C1D70A1539BE950092F5E6 /* JFFURLConnectionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFURLConnectionTest.m; sourceTree = ""; }; 65F47AC41539A33500D8C865 /* StringFromQueryComponentsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StringFromQueryComponentsTest.m; sourceTree = ""; }; - 7E38854917FBEEAF00399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 7E6AF99B157E0BF100CA8ED4 /* InvalidPathForJConnectionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InvalidPathForJConnectionTest.m; sourceTree = ""; }; 7E6AF99E157E105600CA8ED4 /* BadHeadersMockNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BadHeadersMockNetwork.h; sourceTree = ""; }; 7E6AF99F157E105600CA8ED4 /* BadHeadersMockNetwork.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BadHeadersMockNetwork.m; sourceTree = ""; }; @@ -281,7 +272,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E38854A17FBEEAF00399329 /* QuartzCore.framework in Frameworks */, 1BEC485C156A27270099DA6D /* libstdc++.dylib in Frameworks */, 1B0E89961563FAC800825E3C /* libc++.dylib in Frameworks */, 1B2669E615623FBD0054E183 /* libJFFTestTools.a in Frameworks */, @@ -403,7 +393,6 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( - 7E38854917FBEEAF00399329 /* QuartzCore.framework */, 1BEC485B156A27270099DA6D /* libstdc++.dylib */, 1B0E89951563FAC800825E3C /* libc++.dylib */, 53A33F2A141F65F700469DAA /* CFNetwork.framework */, @@ -456,7 +445,6 @@ 5357CDF514A9F4F80046EA34 /* libJFFUtils-clang.a */, 65B1F94A151A8B74000A1736 /* JFFUtilsFW.framework */, CE433773160A1A5800C2279F /* JFFUtilsTest.octest */, - 7ED1F4CE17DF65EB0003CDD4 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -540,7 +528,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0500; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "JFFNetworkTest" */; compatibilityVersion = "Xcode 3.2"; @@ -697,13 +685,6 @@ remoteRef = 65B1F949151A8B74000A1736 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7ED1F4CE17DF65EB0003CDD4 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7ED1F4CD17DF65EB0003CDD4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE433773160A1A5800C2279F /* JFFUtilsTest.octest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; @@ -920,7 +901,6 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = c99; GCC_GENERATE_TEST_COVERAGE_FILES = YES; @@ -931,6 +911,7 @@ ../../lib, ../../lib/JFFTestTools, ); + ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-all_load"; SDKROOT = iphoneos; }; @@ -939,7 +920,6 @@ C01FCF5008A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = c99; GCC_GENERATE_TEST_COVERAGE_FILES = YES; diff --git a/test/JFFNetworkTest/NoArc/NSConnectionTestNoArc.m b/test/JFFNetworkTest/NoArc/NSConnectionTestNoArc.m index 1dbff23..4f41b89 100644 --- a/test/JFFNetworkTest/NoArc/NSConnectionTestNoArc.m +++ b/test/JFFNetworkTest/NoArc/NSConnectionTestNoArc.m @@ -4,7 +4,7 @@ @interface NSConnectionTestNoArc : GHAsyncTestCase @implementation NSConnectionTestNoArc --(void)setUp +- (void)setUp { [JNNsUrlConnection enableInstancesCounting]; } @@ -15,6 +15,7 @@ - (void)testValidDownloadCompletesCorrectly id< JNUrlConnection > connection = nil; __block BOOL executed = NO; __block BOOL isDownloadSuccessfull = NO; + __unsafe_unretained id unretainedConnection = connection; NSAutoreleasePool *pool = [NSAutoreleasePool new]; [self prepare]; @@ -33,19 +34,17 @@ - (void)testValidDownloadCompletesCorrectly connection.didReceiveResponseBlock = ^(id response) { - NSLog( @"[testValidDownloadCompletesCorrectly] - didReceiveResponseBlock : %@", response ); + NSLog(@"[testValidDownloadCompletesCorrectly] - didReceiveResponseBlock : %@", response ); }; connection.didReceiveDataBlock = ^(NSData *dataChunk) { [totalData appendData:dataChunk]; }; - connection.didFinishLoadingBlock = ^(NSError *error) - { + connection.didFinishLoadingBlock = ^(NSError *error) { executed = YES; - if (nil != error) - { + if (nil != error) { [self notify:kGHUnitWaitStatusFailure forSelector:_cmd]; return; @@ -56,21 +55,22 @@ - (void)testValidDownloadCompletesCorrectly [self notify:kGHUnitWaitStatusSuccess forSelector:_cmd]; + + [unretainedConnection cancel]; }; [connection start]; } - if ( !executed ) - { + if (!executed) { + [self waitForStatus:kGHUnitWaitStatusSuccess timeout:61.]; } [pool drain]; - - GHAssertTrue( isDownloadSuccessfull, @"Unexpected download failure" ); - NSUInteger currentCount = [JNNsUrlConnection instancesCount]; - GHAssertTrue(initialCount == currentCount, @"packet mismatch"); + GHAssertTrue(isDownloadSuccessfull, @"Unexpected download failure"); + + GHAssertEquals(initialCount, [JNNsUrlConnection instancesCount], @"packet mismatch"); } @end diff --git a/test/JFFNetworkTest/main.m b/test/JFFNetworkTest/main.m index 973da59..323b9a0 100755 --- a/test/JFFNetworkTest/main.m +++ b/test/JFFNetworkTest/main.m @@ -26,9 +26,9 @@ int main(int argc, char *argv[]) For malloc debugging see: http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html */ - setenv( "GHUNIT_AUTORUN" , "YES", 1 ); - setenv( "WRITE_JUNIT_XML", "YES", 1 ); - setenv( "GHUNIT_AUTOEXIT" , "YES", 1 ); + setenv("GHUNIT_AUTORUN" , "YES", 1); + setenv("WRITE_JUNIT_XML", "YES", 1); + setenv("GHUNIT_AUTOEXIT", "YES", 1); @autoreleasepool { // Register any special test case classes diff --git a/test/JFFRestKitTest/JFFRestKitTest.xcodeproj/project.pbxproj b/test/JFFRestKitTest/JFFRestKitTest.xcodeproj/project.pbxproj index bf0ee99..9b7951e 100644 --- a/test/JFFRestKitTest/JFFRestKitTest.xcodeproj/project.pbxproj +++ b/test/JFFRestKitTest/JFFRestKitTest.xcodeproj/project.pbxproj @@ -23,7 +23,6 @@ 65E308B61531F1C000E0B781 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E308B51531F1C000E0B781 /* CFNetwork.framework */; }; 65E308B81531F1CD00E0B781 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E308B71531F1CD00E0B781 /* libsqlite3.dylib */; }; 65E308CD1531F1FA00E0B781 /* libJFFScheduler.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E308C41531F1E900E0B781 /* libJFFScheduler.a */; }; - 7E38856317FBEEC300399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E38856217FBEEC300399329 /* QuartzCore.framework */; }; CE19F66A16AED8A5005B15B4 /* libJFFNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE19F66316AED89A005B15B4 /* libJFFNetwork.a */; }; CE19F66E16AED8C7005B15B4 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CE19F66D16AED8C7005B15B4 /* libz.dylib */; }; CED0014C16198DDF00368E7D /* SmartDataLoaderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 65E308671531EF0000E0B781 /* SmartDataLoaderTest.m */; }; @@ -157,13 +156,6 @@ remoteGlobalIDString = D2AAC07D0554694100DB518D; remoteInfo = JFFScheduler; }; - 7E38857117FBEEC300399329 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 65E3083F1531EEC500E0B781 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CE19F66216AED89A005B15B4 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CE19F65716AED89A005B15B4 /* JFFNetwork.xcodeproj */; @@ -230,7 +222,6 @@ 65E308B51531F1C000E0B781 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; 65E308B71531F1CD00E0B781 /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; 65E308B91531F1E800E0B781 /* JFFScheduler.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFScheduler.xcodeproj; path = ../../lib/JFFScheduler/JFFScheduler.xcodeproj; sourceTree = ""; }; - 7E38856217FBEEC300399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; CE19F65716AED89A005B15B4 /* JFFNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFNetwork.xcodeproj; path = ../../lib/JFFNetwork/JFFNetwork.xcodeproj; sourceTree = ""; }; CE19F66D16AED8C7005B15B4 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; CED85DB3161C61F300F28EBC /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; @@ -241,7 +232,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E38856317FBEEC300399329 /* QuartzCore.framework in Frameworks */, CE19F66E16AED8C7005B15B4 /* libz.dylib in Frameworks */, CE19F66A16AED8A5005B15B4 /* libJFFNetwork.a in Frameworks */, 1BEC4832156A27060099DA6D /* libstdc++.dylib in Frameworks */, @@ -286,7 +276,6 @@ 65E3081E1531EE1B00E0B781 /* Frameworks */ = { isa = PBXGroup; children = ( - 7E38856217FBEEC300399329 /* QuartzCore.framework */, CE19F66D16AED8C7005B15B4 /* libz.dylib */, 1BEC4831156A27060099DA6D /* libstdc++.dylib */, 1B0E896B1563FA9C00825E3C /* libc++.dylib */, @@ -343,7 +332,6 @@ 65E3084B1531EEC500E0B781 /* libJFFUtils-clang.a */, 65E3084D1531EEC500E0B781 /* JFFUtilsFW.framework */, CED0014A16198CE200368E7D /* JFFUtilsTest.octest */, - 7E38857217FBEEC300399329 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -565,13 +553,6 @@ remoteRef = 65E308C91531F1E900E0B781 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7E38857217FBEEC300399329 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E38857117FBEEC300399329 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE19F66316AED89A005B15B4 /* libJFFNetwork.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/test/JFFSchedulerTest/JFFSchedulerTest.xcodeproj/project.pbxproj b/test/JFFSchedulerTest/JFFSchedulerTest.xcodeproj/project.pbxproj index 1f30dc1..42c01a3 100644 --- a/test/JFFSchedulerTest/JFFSchedulerTest.xcodeproj/project.pbxproj +++ b/test/JFFSchedulerTest/JFFSchedulerTest.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ 1B41AD65151CD1EE00566B1B /* libJFFUtils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B41AD5C151CD1E000566B1B /* libJFFUtils.a */; }; 1BEC47F7156A26B80099DA6D /* libstdc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BEC47F6156A26B80099DA6D /* libstdc++.dylib */; }; 1BEE3D2615EFB43E0024D249 /* PerformSelectorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BEE3D2515EFB43E0024D249 /* PerformSelectorTest.m */; }; - 7E38858317FBEF9C00399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E38858217FBEF9C00399329 /* QuartzCore.framework */; }; CE1BC2DB161B2E81007DEC95 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = CE1BC2DA161B2E81007DEC95 /* Default-568h@2x.png */; }; /* End PBXBuildFile section */ @@ -109,13 +108,6 @@ remoteGlobalIDString = D2AAC07D0554694100DB518D; remoteInfo = JFFUtils; }; - 7E38858C17FBEF9D00399329 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 1B41AD51151CD1E000566B1B /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CED0011616198BE900368E7D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 1B41AD51151CD1E000566B1B /* JFFUtils.xcodeproj */; @@ -142,7 +134,6 @@ 1B41AD51151CD1E000566B1B /* JFFUtils.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFUtils.xcodeproj; path = ../../lib/JFFUtils/JFFUtils.xcodeproj; sourceTree = ""; }; 1BEC47F6156A26B80099DA6D /* libstdc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.dylib"; path = "usr/lib/libstdc++.dylib"; sourceTree = SDKROOT; }; 1BEE3D2515EFB43E0024D249 /* PerformSelectorTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PerformSelectorTest.m; sourceTree = ""; }; - 7E38858217FBEF9C00399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; CE1BC2DA161B2E81007DEC95 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -151,7 +142,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E38858317FBEF9C00399329 /* QuartzCore.framework in Frameworks */, 1BEC47F7156A26B80099DA6D /* libstdc++.dylib in Frameworks */, 1B0E89441563FA7900825E3C /* libc++.dylib in Frameworks */, 1B266A2E156245360054E183 /* libJFFTestTools.a in Frameworks */, @@ -197,7 +187,6 @@ 1B41ACF8151CCF7100566B1B /* Frameworks */ = { isa = PBXGroup; children = ( - 7E38858217FBEF9C00399329 /* QuartzCore.framework */, 1B0E89431563FA7900825E3C /* libc++.dylib */, 1BEC47F6156A26B80099DA6D /* libstdc++.dylib */, 1B41AD19151CCF9300566B1B /* GHUnitIOS.framework */, @@ -258,7 +247,6 @@ 1B41AD60151CD1E000566B1B /* libJFFUtils-clang.a */, 1B41AD62151CD1E000566B1B /* JFFUtilsFW.framework */, CED0011716198BE900368E7D /* JFFUtilsTest.octest */, - 7E38858D17FBEF9D00399329 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -389,13 +377,6 @@ remoteRef = 1B41AD61151CD1E000566B1B /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7E38858D17FBEF9D00399329 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E38858C17FBEF9D00399329 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CED0011716198BE900368E7D /* JFFUtilsTest.octest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; diff --git a/test/JFFSecureStorageTest/JFFSecureStorageTest.xcodeproj/project.pbxproj b/test/JFFSecureStorageTest/JFFSecureStorageTest.xcodeproj/project.pbxproj index d4d14b5..af5d4ce 100644 --- a/test/JFFSecureStorageTest/JFFSecureStorageTest.xcodeproj/project.pbxproj +++ b/test/JFFSecureStorageTest/JFFSecureStorageTest.xcodeproj/project.pbxproj @@ -16,7 +16,6 @@ 1BE99A3015459AB40028F395 /* JFFSecureStorageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE99A2F15459AB40028F395 /* JFFSecureStorageTest.m */; }; 1BE99A4015459BCC0028F395 /* libJFFSecureStorage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BE99A3B15459BC20028F395 /* libJFFSecureStorage.a */; }; 1BE99A4215459BDB0028F395 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BE99A4115459BDB0028F395 /* Security.framework */; }; - 7E38859017FBEFAB00399329 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E38858F17FBEFAB00399329 /* QuartzCore.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -56,7 +55,6 @@ 1BE99A2F15459AB40028F395 /* JFFSecureStorageTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFSecureStorageTest.m; sourceTree = ""; }; 1BE99A3215459BC20028F395 /* JFFSecureStorage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFSecureStorage.xcodeproj; path = ../../lib/JFFSecureStorage/JFFSecureStorage.xcodeproj; sourceTree = ""; }; 1BE99A4115459BDB0028F395 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; - 7E38858F17FBEFAB00399329 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -64,7 +62,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E38859017FBEFAB00399329 /* QuartzCore.framework in Frameworks */, 1BE99A4215459BDB0028F395 /* Security.framework in Frameworks */, 1BE99A4015459BCC0028F395 /* libJFFSecureStorage.a in Frameworks */, 1BE99A04154599490028F395 /* UIKit.framework in Frameworks */, @@ -98,7 +95,6 @@ 1BE99A02154599490028F395 /* Frameworks */ = { isa = PBXGroup; children = ( - 7E38858F17FBEFAB00399329 /* QuartzCore.framework */, 1BE99A4115459BDB0028F395 /* Security.framework */, 1BE99A2C154599CD0028F395 /* GHUnitIOS.framework */, 1BE99A03154599490028F395 /* UIKit.framework */, diff --git a/test/JFFSecureStorageTest/JFFSecureStorageTest/JFFSecureStorageTest.m b/test/JFFSecureStorageTest/JFFSecureStorageTest/JFFSecureStorageTest.m index 5137913..f7e40b6 100644 --- a/test/JFFSecureStorageTest/JFFSecureStorageTest/JFFSecureStorageTest.m +++ b/test/JFFSecureStorageTest/JFFSecureStorageTest/JFFSecureStorageTest.m @@ -20,7 +20,7 @@ -(void)testSecureStorage GHAssertTrue( [ login_ isEqualToString: outLogin_ ], @"OK" ); GHAssertTrue( [ password_ isEqualToString: outPassword_ ], @"OK" ); } - + { NSString* login_ = @"llll2"; NSString* password_ = @"ppp2"; diff --git a/test/JFFSocialTest/JFFSocialTest.xcodeproj/project.pbxproj b/test/JFFSocialTest/JFFSocialTest.xcodeproj/project.pbxproj index 429dad6..87b178c 100644 --- a/test/JFFSocialTest/JFFSocialTest.xcodeproj/project.pbxproj +++ b/test/JFFSocialTest/JFFSocialTest.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 373035A2165E579D00540258 /* FoursquareApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 371D861515FF34DA001C1C2C /* FoursquareApiTest.m */; }; 374980AC1602185A00AF0C29 /* test-img1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 374980AB1602185A00AF0C29 /* test-img1.jpg */; }; - 7E72C9C917FBEFC80081F306 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E72C9C817FBEFC80081F306 /* QuartzCore.framework */; }; CE4F60AA15F8BD1600271035 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE4F60A915F8BD1600271035 /* UIKit.framework */; }; CE4F60AC15F8BD1600271035 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE4F60AB15F8BD1600271035 /* Foundation.framework */; }; CE4F60AE15F8BD1600271035 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE4F60AD15F8BD1600271035 /* CoreGraphics.framework */; }; @@ -40,13 +39,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 7E72C9DB17FBEFC80081F306 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CE4F60E015F8BD7C00271035 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CE4F60E715F8BD7C00271035 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CE4F60E015F8BD7C00271035 /* JFFUtils.xcodeproj */; @@ -283,7 +275,6 @@ /* Begin PBXFileReference section */ 371D861515FF34DA001C1C2C /* FoursquareApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FoursquareApiTest.m; sourceTree = ""; }; 374980AB1602185A00AF0C29 /* test-img1.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "test-img1.jpg"; sourceTree = ""; }; - 7E72C9C817FBEFC80081F306 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; CE4F60A515F8BD1600271035 /* JFFSocialTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JFFSocialTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; CE4F60A915F8BD1600271035 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; CE4F60AB15F8BD1600271035 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -323,7 +314,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E72C9C917FBEFC80081F306 /* QuartzCore.framework in Frameworks */, CE78FF1C1609BA7D005CE392 /* libsqlite3.dylib in Frameworks */, CE78FF1A1609BA6F005CE392 /* libJFFRestKit.a in Frameworks */, CE78FF071609BA54005CE392 /* libJFFCache.a in Frameworks */, @@ -383,7 +373,6 @@ CE4F60A815F8BD1600271035 /* Frameworks */ = { isa = PBXGroup; children = ( - 7E72C9C817FBEFC80081F306 /* QuartzCore.framework */, CE78FF1B1609BA7D005CE392 /* libsqlite3.dylib */, CE5A01CA15F9F17D005CC01A /* libz.dylib */, CE4F613015F8BDFB00271035 /* libc++.dylib */, @@ -448,7 +437,6 @@ CE4F60EC15F8BD7C00271035 /* libJFFUtils-clang.a */, CE4F60EE15F8BD7C00271035 /* JFFUtilsFW.framework */, CE8C2C1F160879AA006E9C6C /* JFFUtilsTest.octest */, - 7E72C9DC17FBEFC80081F306 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -642,13 +630,6 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 7E72C9DC17FBEFC80081F306 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E72C9DB17FBEFC80081F306 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CE4F60E815F8BD7C00271035 /* libJFFUtils.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -785,6 +766,7 @@ CEB2347515FF61EC005E5CF5 /* libJFFUI copy.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; + name = "libJFFUI copy.a"; path = "libJFFUI-clang.a"; remoteRef = CEB2347415FF61EC005E5CF5 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; diff --git a/test/JFFStoreKitTest/JFFStoreKitTest.xcodeproj/project.pbxproj b/test/JFFStoreKitTest/JFFStoreKitTest.xcodeproj/project.pbxproj index 978697a..72d8ad7 100644 --- a/test/JFFStoreKitTest/JFFStoreKitTest.xcodeproj/project.pbxproj +++ b/test/JFFStoreKitTest/JFFStoreKitTest.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 7E72C9E817FBEFDB0081F306 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E72C9E717FBEFDB0081F306 /* QuartzCore.framework */; }; CEBCBE6D1619C923007F805F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEBCBE6C1619C923007F805F /* UIKit.framework */; }; CEBCBE6F1619C923007F805F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEBCBE6E1619C923007F805F /* Foundation.framework */; }; CEBCBE711619C923007F805F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEBCBE701619C923007F805F /* CoreGraphics.framework */; }; @@ -28,13 +27,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 7E72C9F417FBEFDB0081F306 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CEBCBEA11619CC83007F805F /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CEBCBE9F1619CC7D007F805F /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CEBCBE981619CC7D007F805F /* JFFTestTools.xcodeproj */; @@ -178,7 +170,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7E72C9E717FBEFDB0081F306 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; CEBCBE681619C923007F805F /* JFFStoreKitTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JFFStoreKitTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; CEBCBE6C1619C923007F805F /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; CEBCBE6E1619C923007F805F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -206,7 +197,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E72C9E817FBEFDB0081F306 /* QuartzCore.framework in Frameworks */, CEBCBEFD1619CF7A007F805F /* StoreKit.framework in Frameworks */, CEBCBEFB1619CF6B007F805F /* libJFFStoreKit.a in Frameworks */, CEBCBEEA1619CCC2007F805F /* libstdc++.dylib in Frameworks */, @@ -245,7 +235,6 @@ CEBCBE6B1619C923007F805F /* Frameworks */ = { isa = PBXGroup; children = ( - 7E72C9E717FBEFDB0081F306 /* QuartzCore.framework */, CEBCBEE91619CCC2007F805F /* libstdc++.dylib */, CEBCBEFC1619CF7A007F805F /* StoreKit.framework */, CEBCBE921619CB36007F805F /* GHUnitIOS.framework */, @@ -307,7 +296,6 @@ CEBCBEB21619CC83007F805F /* libJFFUtils-clang.a */, CEBCBEB41619CC83007F805F /* JFFUtilsFW.framework */, CEBCBEB61619CC83007F805F /* JFFUtilsTest.octest */, - 7E72C9F517FBEFDB0081F306 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -416,13 +404,6 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 7E72C9F517FBEFDB0081F306 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E72C9F417FBEFDB0081F306 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CEBCBEA01619CC7D007F805F /* libJFFTestTools.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/test/JFFUITest/JFFUITest.xcodeproj/project.pbxproj b/test/JFFUITest/JFFUITest.xcodeproj/project.pbxproj index bdba69c..575afbe 100644 --- a/test/JFFUITest/JFFUITest.xcodeproj/project.pbxproj +++ b/test/JFFUITest/JFFUITest.xcodeproj/project.pbxproj @@ -20,15 +20,9 @@ 1BE054DE154829FB00270B58 /* libJFFTestTools.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BE054DB154829F000270B58 /* libJFFTestTools.a */; }; 1BE054E115482A5400270B58 /* JFFActionSheetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE054E015482A5400270B58 /* JFFActionSheetTest.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; 1BEC47D4156A26950099DA6D /* libstdc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 538C141014A9F33B0097645A /* libstdc++.dylib */; }; - 7E72CA0317FBEFEA0081F306 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E72CA0217FBEFEA0081F306 /* QuartzCore.framework */; }; - 7E79474316E5DCF500219958 /* libJFFNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E79473416E5DCEE00219958 /* libJFFNetwork.a */; }; - 7E79474716E5DD0200219958 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E79474616E5DD0200219958 /* CFNetwork.framework */; }; - 7E79474916E5DD0600219958 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E79474816E5DD0600219958 /* libz.dylib */; }; CEA097F715FF52010080DEF7 /* libJFFAsyncOperations.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA097EF15FF51F20080DEF7 /* libJFFAsyncOperations.a */; }; CEA097FA15FF540C0080DEF7 /* OpenApplicationAsyncOpTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA097F915FF540C0080DEF7 /* OpenApplicationAsyncOpTest.m */; }; CEA0980F15FF55950080DEF7 /* libJFFScheduler.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CEA0980615FF55840080DEF7 /* libJFFScheduler.a */; }; - CED0008316198A5C00368E7D /* libJFFCache.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CED0008016198A4D00368E7D /* libJFFCache.a */; }; - CED0009616198A8B00368E7D /* libJFFRestKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CED0009116198A7300368E7D /* libJFFRestKit.a */; }; CED0009816198AA200368E7D /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CED0009716198AA200368E7D /* libsqlite3.dylib */; }; /* End PBXBuildFile section */ @@ -103,48 +97,6 @@ remoteGlobalIDString = 5391044314A88C04007315A3; remoteInfo = "JFFUtils-clang"; }; - 7E79473316E5DCEE00219958 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 8D5AE6DB13F3E6C600EB6143; - remoteInfo = JFFNetwork; - }; - 7E79473516E5DCEE00219958 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 65802B22148BFC230040A93A; - remoteInfo = JFFNetworkMacOS; - }; - 7E79473716E5DCEE00219958 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 539103B714A88BCA007315A3; - remoteInfo = "JFFNetwork-clang"; - }; - 7E79473916E5DCEE00219958 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7E8F204314F9494300588C7D; - remoteInfo = JFFNetworkFW; - }; - 7E79474416E5DCFD00219958 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 8D5AE6DA13F3E6C600EB6143; - remoteInfo = JFFNetwork; - }; - 7ED1F4B017DF65940003CDD4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 1B295564143DCCAE00532BD7 /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; CEA097EE15FF51F20080DEF7 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = CEA097E115FF51F20080DEF7 /* JFFAsyncOperations.xcodeproj */; @@ -215,34 +167,6 @@ remoteGlobalIDString = CE444A1C1608609100DD85B0; remoteInfo = JFFUtilsTest; }; - CED0007F16198A4D00368E7D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CED0007816198A4D00368E7D /* JFFCache.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 65168477144F4ECD0014670E; - remoteInfo = JFFCache; - }; - CED0008116198A5700368E7D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CED0007816198A4D00368E7D /* JFFCache.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 65168476144F4ECD0014670E; - remoteInfo = JFFCache; - }; - CED0009016198A7300368E7D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CED0008416198A7300368E7D /* JFFRestKit.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1B7ABA81152D973A005DD4CA; - remoteInfo = JFFRestKit; - }; - CED0009416198A8700368E7D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = CED0008416198A7300368E7D /* JFFRestKit.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 1B7ABA80152D973A005DD4CA; - remoteInfo = JFFRestKit; - }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -262,15 +186,9 @@ 1BE054D3154829F000270B58 /* JFFTestTools.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFTestTools.xcodeproj; path = ../../lib/JFFTestTools/JFFTestTools.xcodeproj; sourceTree = ""; }; 1BE054E015482A5400270B58 /* JFFActionSheetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFFActionSheetTest.m; sourceTree = ""; }; 538C141014A9F33B0097645A /* libstdc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.dylib"; path = "usr/lib/libstdc++.dylib"; sourceTree = SDKROOT; }; - 7E72CA0217FBEFEA0081F306 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFNetwork.xcodeproj; path = ../../lib/JFFNetwork/JFFNetwork.xcodeproj; sourceTree = ""; }; - 7E79474616E5DD0200219958 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; - 7E79474816E5DD0600219958 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; CEA097E115FF51F20080DEF7 /* JFFAsyncOperations.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFAsyncOperations.xcodeproj; path = ../../lib/JFFAsyncOperations/JFFAsyncOperations.xcodeproj; sourceTree = ""; }; CEA097F915FF540C0080DEF7 /* OpenApplicationAsyncOpTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OpenApplicationAsyncOpTest.m; sourceTree = ""; }; CEA097FB15FF55840080DEF7 /* JFFScheduler.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFScheduler.xcodeproj; path = ../../lib/JFFScheduler/JFFScheduler.xcodeproj; sourceTree = ""; }; - CED0007816198A4D00368E7D /* JFFCache.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFCache.xcodeproj; path = ../../lib/JFFCache/JFFCache.xcodeproj; sourceTree = ""; }; - CED0008416198A7300368E7D /* JFFRestKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JFFRestKit.xcodeproj; path = ../../lib/JFFRestKit/JFFRestKit.xcodeproj; sourceTree = ""; }; CED0009716198AA200368E7D /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -279,13 +197,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E72CA0317FBEFEA0081F306 /* QuartzCore.framework in Frameworks */, - 7E79474916E5DD0600219958 /* libz.dylib in Frameworks */, - 7E79474716E5DD0200219958 /* CFNetwork.framework in Frameworks */, - 7E79474316E5DCF500219958 /* libJFFNetwork.a in Frameworks */, CED0009816198AA200368E7D /* libsqlite3.dylib in Frameworks */, - CED0009616198A8B00368E7D /* libJFFRestKit.a in Frameworks */, - CED0008316198A5C00368E7D /* libJFFCache.a in Frameworks */, CEA0980F15FF55950080DEF7 /* libJFFScheduler.a in Frameworks */, CEA097F715FF52010080DEF7 /* libJFFAsyncOperations.a in Frameworks */, 1BEC47D4156A26950099DA6D /* libstdc++.dylib in Frameworks */, @@ -306,6 +218,7 @@ 1B29550F143DC94B00532BD7 = { isa = PBXGroup; children = ( + CED0009716198AA200368E7D /* libsqlite3.dylib */, 1BE054D2154829AA00270B58 /* Dependencies */, 1B295524143DC94B00532BD7 /* JFFUITest */, 1B29551D143DC94B00532BD7 /* Frameworks */, @@ -324,10 +237,6 @@ 1B29551D143DC94B00532BD7 /* Frameworks */ = { isa = PBXGroup; children = ( - 7E72CA0217FBEFEA0081F306 /* QuartzCore.framework */, - 7E79474816E5DD0600219958 /* libz.dylib */, - 7E79474616E5DD0200219958 /* CFNetwork.framework */, - CED0009716198AA200368E7D /* libsqlite3.dylib */, 1B0E890E1563FA2A00825E3C /* libc++.dylib */, 538C141014A9F33B0097645A /* libstdc++.dylib */, 1B295547143DC9BC00532BD7 /* GHUnitIOS.framework */, @@ -372,7 +281,7 @@ isa = PBXGroup; children = ( 1B295555143DCA8300532BD7 /* libJFFUI.a */, - 538C140814A9F3200097645A /* libJFFUI-clang.a */, + 538C140814A9F3200097645A /* libJFFUI copy.a */, ); name = Products; sourceTree = ""; @@ -385,7 +294,6 @@ 538C140E14A9F3200097645A /* libJFFUtils-clang.a */, 1BE054D01548298A00270B58 /* JFFUtilsFW.framework */, CED00076161989F000368E7D /* JFFUtilsTest.octest */, - 7ED1F4B117DF65940003CDD4 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -393,9 +301,6 @@ 1BE054D2154829AA00270B58 /* Dependencies */ = { isa = PBXGroup; children = ( - 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */, - CED0008416198A7300368E7D /* JFFRestKit.xcodeproj */, - CED0007816198A4D00368E7D /* JFFCache.xcodeproj */, CEA097FB15FF55840080DEF7 /* JFFScheduler.xcodeproj */, CEA097E115FF51F20080DEF7 /* JFFAsyncOperations.xcodeproj */, 1BE054D3154829F000270B58 /* JFFTestTools.xcodeproj */, @@ -413,17 +318,6 @@ name = Products; sourceTree = ""; }; - 7E79472A16E5DCED00219958 /* Products */ = { - isa = PBXGroup; - children = ( - 7E79473416E5DCEE00219958 /* libJFFNetwork.a */, - 7E79473616E5DCEE00219958 /* libJFFNetworkMacOS.a */, - 7E79473816E5DCEE00219958 /* libJFFNetwork-clang.a */, - 7E79473A16E5DCEE00219958 /* JFFNetworkFW.framework */, - ); - name = Products; - sourceTree = ""; - }; CEA097E215FF51F20080DEF7 /* Products */ = { isa = PBXGroup; children = ( @@ -445,22 +339,6 @@ name = Products; sourceTree = ""; }; - CED0007916198A4D00368E7D /* Products */ = { - isa = PBXGroup; - children = ( - CED0008016198A4D00368E7D /* libJFFCache.a */, - ); - name = Products; - sourceTree = ""; - }; - CED0008516198A7300368E7D /* Products */ = { - isa = PBXGroup; - children = ( - CED0009116198A7300368E7D /* libJFFRestKit.a */, - ); - name = Products; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -476,9 +354,6 @@ buildRules = ( ); dependencies = ( - 7E79474516E5DCFD00219958 /* PBXTargetDependency */, - CED0009516198A8700368E7D /* PBXTargetDependency */, - CED0008216198A5700368E7D /* PBXTargetDependency */, CEA0980E15FF558F0080DEF7 /* PBXTargetDependency */, CEA097F615FF51FC0080DEF7 /* PBXTargetDependency */, 1BE054DD154829F600270B58 /* PBXTargetDependency */, @@ -513,18 +388,6 @@ ProductGroup = CEA097E215FF51F20080DEF7 /* Products */; ProjectRef = CEA097E115FF51F20080DEF7 /* JFFAsyncOperations.xcodeproj */; }, - { - ProductGroup = CED0007916198A4D00368E7D /* Products */; - ProjectRef = CED0007816198A4D00368E7D /* JFFCache.xcodeproj */; - }, - { - ProductGroup = 7E79472A16E5DCED00219958 /* Products */; - ProjectRef = 7E79472916E5DCED00219958 /* JFFNetwork.xcodeproj */; - }, - { - ProductGroup = CED0008516198A7300368E7D /* Products */; - ProjectRef = CED0008416198A7300368E7D /* JFFRestKit.xcodeproj */; - }, { ProductGroup = CEA097FC15FF55840080DEF7 /* Products */; ProjectRef = CEA097FB15FF55840080DEF7 /* JFFScheduler.xcodeproj */; @@ -578,9 +441,10 @@ remoteRef = 1BE054DA154829F000270B58 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 538C140814A9F3200097645A /* libJFFUI-clang.a */ = { + 538C140814A9F3200097645A /* libJFFUI copy.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; + name = "libJFFUI copy.a"; path = "libJFFUI-clang.a"; remoteRef = 538C140714A9F3200097645A /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; @@ -599,41 +463,6 @@ remoteRef = 538C140D14A9F3200097645A /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7E79473416E5DCEE00219958 /* libJFFNetwork.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFNetwork.a; - remoteRef = 7E79473316E5DCEE00219958 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 7E79473616E5DCEE00219958 /* libJFFNetworkMacOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFNetworkMacOS.a; - remoteRef = 7E79473516E5DCEE00219958 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 7E79473816E5DCEE00219958 /* libJFFNetwork-clang.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libJFFNetwork-clang.a"; - remoteRef = 7E79473716E5DCEE00219958 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 7E79473A16E5DCEE00219958 /* JFFNetworkFW.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework.static; - path = JFFNetworkFW.framework; - remoteRef = 7E79473916E5DCEE00219958 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 7ED1F4B117DF65940003CDD4 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7ED1F4B017DF65940003CDD4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; CEA097EF15FF51F20080DEF7 /* libJFFAsyncOperations.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -690,20 +519,6 @@ remoteRef = CED00075161989F000368E7D /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - CED0008016198A4D00368E7D /* libJFFCache.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFCache.a; - remoteRef = CED0007F16198A4D00368E7D /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - CED0009116198A7300368E7D /* libJFFRestKit.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libJFFRestKit.a; - remoteRef = CED0009016198A7300368E7D /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ @@ -765,11 +580,6 @@ name = JFFTestTools; targetProxy = 1BE054DC154829F600270B58 /* PBXContainerItemProxy */; }; - 7E79474516E5DCFD00219958 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFNetwork; - targetProxy = 7E79474416E5DCFD00219958 /* PBXContainerItemProxy */; - }; CEA097F615FF51FC0080DEF7 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = JFFAsyncOperations; @@ -780,16 +590,6 @@ name = JFFScheduler; targetProxy = CEA0980D15FF558F0080DEF7 /* PBXContainerItemProxy */; }; - CED0008216198A5700368E7D /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFCache; - targetProxy = CED0008116198A5700368E7D /* PBXContainerItemProxy */; - }; - CED0009516198A8700368E7D /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = JFFRestKit; - targetProxy = CED0009416198A8700368E7D /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ diff --git a/test/JFFUtilsTest/JFFUtilsTest.xcodeproj/project.pbxproj b/test/JFFUtilsTest/JFFUtilsTest.xcodeproj/project.pbxproj index 2caed0a..01f21ff 100644 --- a/test/JFFUtilsTest/JFFUtilsTest.xcodeproj/project.pbxproj +++ b/test/JFFUtilsTest/JFFUtilsTest.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 1B2D8B6C154BF37C00360296 /* libJFFTestTools.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B2D8B69154BF36C00360296 /* libJFFTestTools.a */; }; 534CDFDE14A8CAAC0068F4DF /* JMStringHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 534CDFDD14A8CAAC0068F4DF /* JMStringHolder.m */; }; 7E7225DE1588891400210CBE /* DevNullTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7225DD1588891400210CBE /* DevNullTest.m */; }; - 7E72CA1717FBEFF80081F306 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E72CA1617FBEFF80081F306 /* QuartzCore.framework */; }; B69483EC1429C88400B8247E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B69483EB1429C88400B8247E /* UIKit.framework */; }; B69483EE1429C88400B8247E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B69483ED1429C88400B8247E /* Foundation.framework */; }; B69483F01429C88400B8247E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B69483EF1429C88400B8247E /* CoreGraphics.framework */; }; @@ -62,13 +61,6 @@ remoteGlobalIDString = 7E57F42414F93738002D139B; remoteInfo = JFFUtilsFW; }; - 7E72CA1D17FBEFF80081F306 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = B694845D1429E24B00B8247E /* JFFUtils.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7ED3CB1516E6387B00E5A00F; - remoteInfo = "JFFUtilsTest-CI"; - }; B69484641429E24B00B8247E /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = B694845D1429E24B00B8247E /* JFFUtils.xcodeproj */; @@ -99,7 +91,6 @@ 534CDFDC14A8CAAC0068F4DF /* JMStringHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMStringHolder.h; sourceTree = ""; }; 534CDFDD14A8CAAC0068F4DF /* JMStringHolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JMStringHolder.m; sourceTree = ""; }; 7E7225DD1588891400210CBE /* DevNullTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DevNullTest.m; sourceTree = ""; }; - 7E72CA1617FBEFF80081F306 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; B69483E71429C88400B8247E /* JFFUtilsTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JFFUtilsTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; B69483EB1429C88400B8247E /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; B69483ED1429C88400B8247E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -121,7 +112,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7E72CA1717FBEFF80081F306 /* QuartzCore.framework in Frameworks */, CE57FBE11611FA0900124D90 /* libstdc++.dylib in Frameworks */, 1B0E89211563FA5200825E3C /* libc++.dylib in Frameworks */, 1B2D8B6C154BF37C00360296 /* libJFFTestTools.a in Frameworks */, @@ -184,7 +174,6 @@ B69483EA1429C88400B8247E /* Frameworks */ = { isa = PBXGroup; children = ( - 7E72CA1617FBEFF80081F306 /* QuartzCore.framework */, 1B0E89201563FA5200825E3C /* libc++.dylib */, 534CDFD914A8CA290068F4DF /* libstdc++.dylib */, B69484021429D3D300B8247E /* GHUnitIOS.framework */, @@ -235,7 +224,6 @@ 534CDFD414A8C7E00068F4DF /* libJFFUtils-clang.a */, 6515B960152B726E00518996 /* JFFUtilsFW.framework */, CE444A3F160860B500DD85B0 /* JFFUtilsTest.octest */, - 7E72CA1E17FBEFF80081F306 /* JFFUtilsTest-CI.octest */, ); name = Products; sourceTree = ""; @@ -269,7 +257,7 @@ B69483DE1429C88400B8247E /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0420; + LastUpgradeCheck = 0460; }; buildConfigurationList = B69483E11429C88400B8247E /* Build configuration list for PBXProject "JFFUtilsTest" */; compatibilityVersion = "Xcode 3.2"; @@ -327,13 +315,6 @@ remoteRef = 6515B95F152B726E00518996 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7E72CA1E17FBEFF80081F306 /* JFFUtilsTest-CI.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "JFFUtilsTest-CI.octest"; - remoteRef = 7E72CA1D17FBEFF80081F306 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; B69484651429E24B00B8247E /* libJFFUtils.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -426,7 +407,6 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = NO; - CLANG_WARN_OBJCPP_ARC_ABI = NO; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -460,7 +440,6 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = NO; - CLANG_WARN_OBJCPP_ARC_ABI = NO; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = YES; GCC_C_LANGUAGE_STANDARD = gnu99;