Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libjpeg_turbo / tjunittest.c
index 89a6d1d..3bb194d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2009-2012 D. R. Commander.  All Rights Reserved.
+ * Copyright (C)2009-2012, 2014 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:
@@ -219,7 +219,6 @@ int checkBuf(unsigned char *buf, int w, int h, int pf, int subsamp,
        bailout:
        if(retval==0)
        {
-               printf("\n");
                for(row=0; row<h; row++)
                {
                        for(col=0; col<w; col++)
@@ -312,7 +311,6 @@ int checkBufYUV(unsigned char *buf, int w, int h, int subsamp)
                                printf("%.3d ", buf[ypitch*ph + uvpitch*ch + (uvpitch*row+col)]);
                        printf("\n");
                }
-               printf("\n");
        }
 
        return retval;
@@ -405,7 +403,7 @@ void _decompTest(tjhandle handle, unsigned char *jpegBuf,
        if(yuv==YUVENCODE) return;
 
        if(yuv==YUVDECODE)
-               printf("JPEG -> YUV %s ... ", subName[subsamp]);
+               printf("JPEG -> YUV %s ... ", subNameLong[subsamp]);
        else
        {
                printf("JPEG -> %s %s ", pixFormatStr[pf],
@@ -475,7 +473,7 @@ void decompTest(tjhandle handle, unsigned char *jpegBuf,
                        sf1);
 
        bailout:
-       printf("\n");
+       return;
 }
 
 
@@ -515,10 +513,15 @@ void doTest(int w, int h, const int *formats, int nformats, int subsamp,
                        decompTest(dhandle, dstBuf, size, w, h, pf, basename, subsamp,
                                flags);
                        if(pf>=TJPF_RGBX && pf<=TJPF_XRGB)
+                       {
+                               printf("\n");
                                decompTest(dhandle, dstBuf, size, w, h, pf+(TJPF_RGBA-TJPF_RGBX),
                                        basename, subsamp, flags);
+                       }
+                       printf("\n");
                }
        }
+       printf("--------------------\n\n");
 
        bailout:
        if(chandle) tjDestroy(chandle);
@@ -531,9 +534,9 @@ void doTest(int w, int h, const int *formats, int nformats, int subsamp,
 void bufSizeTest(void)
 {
        int w, h, i, subsamp;
-       unsigned char *srcBuf=NULL, *jpegBuf=NULL;
+       unsigned char *srcBuf=NULL, *dstBuf=NULL;
        tjhandle handle=NULL;
-       unsigned long jpegSize=0;
+       unsigned long dstSize=0;
 
        if((handle=tjInitCompress())==NULL) _throwtj();
 
@@ -548,12 +551,12 @@ void bufSizeTest(void)
                                if(h%100==0) printf("%.4d x %.4d\b\b\b\b\b\b\b\b\b\b\b", w, h);
                                if((srcBuf=(unsigned char *)malloc(w*h*4))==NULL)
                                        _throw("Memory allocation failure");
-                               if(!alloc)
+                               if(!alloc || yuv==YUVENCODE)
                                {
-                                       if((jpegBuf=(unsigned char *)tjAlloc(tjBufSize(w, h, subsamp)))
-                                               ==NULL)
+                                       if(yuv==YUVENCODE) dstSize=tjBufSizeYUV(w, h, subsamp);
+                                       else dstSize=tjBufSize(w, h, subsamp);
+                                       if((dstBuf=(unsigned char *)tjAlloc(dstSize))==NULL)
                                                _throw("Memory allocation failure");
-                                       jpegSize=tjBufSize(w, h, subsamp);
                                }
 
                                for(i=0; i<w*h*4; i++)
@@ -562,19 +565,27 @@ void bufSizeTest(void)
                                        else srcBuf[i]=255;
                                }
 
-                               _tj(tjCompress2(handle, srcBuf, w, 0, h, TJPF_BGRX, &jpegBuf,
-                                       &jpegSize, subsamp, 100, alloc? 0:TJFLAG_NOREALLOC));
+                               if(yuv==YUVENCODE)
+                               {
+                                       _tj(tjEncodeYUV2(handle, srcBuf, w, 0, h, TJPF_BGRX, dstBuf, subsamp,
+                                               0));
+                               }
+                               else
+                               {
+                                       _tj(tjCompress2(handle, srcBuf, w, 0, h, TJPF_BGRX, &dstBuf,
+                                               &dstSize, subsamp, 100, alloc? 0:TJFLAG_NOREALLOC));
+                               }
                                free(srcBuf);  srcBuf=NULL;
-                               tjFree(jpegBuf);  jpegBuf=NULL;
+                               tjFree(dstBuf);  dstBuf=NULL;
 
                                if((srcBuf=(unsigned char *)malloc(h*w*4))==NULL)
                                        _throw("Memory allocation failure");
-                               if(!alloc)
+                               if(!alloc || yuv==YUVENCODE)
                                {
-                                       if((jpegBuf=(unsigned char *)tjAlloc(tjBufSize(h, w, subsamp)))
-                                               ==NULL)
+                                       if(yuv==YUVENCODE) dstSize=tjBufSizeYUV(h, w, subsamp);
+                                       else dstSize=tjBufSize(h, w, subsamp);
+                                       if((dstBuf=(unsigned char *)tjAlloc(dstSize))==NULL)
                                                _throw("Memory allocation failure");
-                                       jpegSize=tjBufSize(h, w, subsamp);
                                }
 
                                for(i=0; i<h*w*4; i++)
@@ -583,10 +594,18 @@ void bufSizeTest(void)
                                        else srcBuf[i]=255;
                                }
 
-                               _tj(tjCompress2(handle, srcBuf, h, 0, w, TJPF_BGRX, &jpegBuf,
-                                       &jpegSize, subsamp, 100, alloc? 0:TJFLAG_NOREALLOC));
+                               if(yuv==YUVENCODE)
+                               {
+                                       _tj(tjEncodeYUV2(handle, srcBuf, h, 0, w, TJPF_BGRX, dstBuf, subsamp,
+                                               0));
+                               }
+                               else
+                               {
+                                       _tj(tjCompress2(handle, srcBuf, h, 0, w, TJPF_BGRX, &dstBuf,
+                                               &dstSize, subsamp, 100, alloc? 0:TJFLAG_NOREALLOC));
+                               }
                                free(srcBuf);  srcBuf=NULL;
-                               tjFree(jpegBuf);  jpegBuf=NULL;
+                               tjFree(dstBuf);  dstBuf=NULL;
                        }
                }
        }
@@ -594,7 +613,7 @@ void bufSizeTest(void)
 
        bailout:
        if(srcBuf) free(srcBuf);
-       if(jpegBuf) free(jpegBuf);
+       if(dstBuf) free(dstBuf);
        if(handle) tjDestroy(handle);
 }
 
@@ -628,9 +647,10 @@ int main(int argc, char *argv[])
        doTest(35, 39, _onlyGray, 1, TJSAMP_GRAY, "test");
        doTest(39, 41, _3byteFormats, 2, TJSAMP_GRAY, "test");
        doTest(41, 35, _4byteFormats, 4, TJSAMP_GRAY, "test");
-       if(!doyuv) bufSizeTest();
+       bufSizeTest();
        if(doyuv)
        {
+               printf("\n--------------------\n\n");
                yuv=YUVDECODE;
                doTest(48, 48, _onlyRGB, 1, TJSAMP_444, "test_yuv0");
                doTest(35, 39, _onlyRGB, 1, TJSAMP_444, "test_yuv1");