[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/arrayfire/arrayfire/feature/optional-graphics/test/imageio.cpp [Back]  [Original]

/*******************************************************
 * Copyright (c) 2014, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using af::array;
using af::cdouble;
using af::cfloat;
using af::dim4;
using std::endl;
using std::string;
using std::vector;

template
class ImageIO : public ::testing::Test {
   public:
    virtual void SetUp() {}
};

typedef ::testing::Types TestTypes;

// register the type list
TYPED_TEST_SUITE(ImageIO, TestTypes);

void loadImageTest(string pTestFile, string pImageFile, const bool isColor) {
    IMAGEIO_ENABLED_CHECK();

    vector numDims;

    vector in;
    vector tests;
    readTests(pTestFile, numDims, in, tests);
    dim4 dims = numDims[0];

    af_array imgArray = 0;
    ASSERT_SUCCESS(af_load_image(&imgArray, pImageFile.c_str(), isColor));

    // Get result
    float* imgData = new float[dims.elements()];
    ASSERT_SUCCESS(af_get_data_ptr((void*)imgData, imgArray));

    bool isJPEG = false;
    if (pImageFile.find(".jpg") != string::npos) { isJPEG = true; }

    // Compare result
    size_t nElems = in[0].size();
    for (size_t elIter = 0; elIter < nElems; ++elIter) {
        if (isJPEG)  // Allow +- 1 because of compression when testing JPG
            ASSERT_NEAR(in[0][elIter], imgData[elIter], 1)
                

Web Proxy Viewer  |  New URL  |  Original Page