示例#1
0
//------------------------------------------------------------
VIREO_EXPORT Int32 EggShell_PokeMemory(TypeManagerRef tm,
        const char* viName, const char* eltName, Int32 bufferSize, char* buffer)
{
    void *pData = nullptr;

    SubString objectName(viName);
    SubString path(eltName);
    TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true);
    if (actualType == nullptr)
        return -1;

    TypeManagerScope scope(tm);
    SubBinaryBuffer subBuffer(reinterpret_cast<UInt8*>(buffer), reinterpret_cast<UInt8*>(buffer)+bufferSize);

    // Write unflattened data to the element
    if (UnflattenData(&subBuffer, true, 0, nullptr, actualType, pData) == -1) {
        return -1;
    } else {
        return bufferSize;
    }
}
示例#2
0
void sub_clear_test(skiatest::Reporter* reporter, GrContext* context, GrPixelConfig config) {
    const int width = 10;
    const int height = 10;
    const int subWidth = width/2;
    const int subHeight = height/2;
    GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu());
    gpu->discard(NULL);
    SkAutoTMalloc<GrColor> buffer(width * height);
    SkAutoTMalloc<GrColor> subBuffer(subWidth * subHeight);

    GrSurfaceDesc surfDesc;
    surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
    surfDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
    surfDesc.fWidth = width;
    surfDesc.fHeight = height;
    surfDesc.fConfig = config;
    surfDesc.fSampleCnt = 0;
    GrTexture* tex = gpu->createTexture(surfDesc, false, nullptr, 0);
    SkASSERT(tex);
    SkASSERT(tex->asRenderTarget());

    SkIRect fullRect = SkIRect::MakeWH(10, 10);
    gpu->clear(fullRect, GrColor_TRANSPARENT_BLACK, tex->asRenderTarget());

    gpu->readPixels(tex, 0, 0, width, height, config, (void*)buffer.get(), 0);

    REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
                                                                     GrColor_TRANSPARENT_BLACK,
                                                                     config,
                                                                     width,
                                                                     height));
    SkIRect rect;
    rect = SkIRect::MakeXYWH(0, 0, subWidth, subHeight);
    gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
    rect = SkIRect::MakeXYWH(subWidth, 0, subWidth, subHeight);
    gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
    rect = SkIRect::MakeXYWH(0, subHeight, subWidth, subHeight);
    gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());

    // Should fail since bottom right sub area has not been cleared to white
    gpu->readPixels(tex, 0, 0, width, height, config, (void*)buffer.get(), 0);
    REPORTER_ASSERT(reporter, !does_full_buffer_contain_correct_color(buffer.get(),
                                                                      GrColor_WHITE,
                                                                      config,
                                                                      width,
                                                                      height));

    rect = SkIRect::MakeXYWH(subWidth, subHeight, subWidth, subHeight);
    gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());

    gpu->readPixels(tex, 0, 0, width, height, config, (void*)buffer.get(), 0);
    REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
                                                                     GrColor_WHITE,
                                                                     config,
                                                                     width,
                                                                     height));

    // Try different colors and that each sub area has correct color
    GrColor subColor1 = GrColorPackRGBA(0xFF, 0x00, 0x00, 0xFF);
    GrColor subColor2 = GrColorPackRGBA(0x00, 0xFF, 0x00, 0xFF);
    GrColor subColor3 = GrColorPackRGBA(0x00, 0x00, 0xFF, 0xFF);
    GrColor subColor4 = GrColorPackRGBA(0xFF, 0xFF, 0x00, 0xFF);

    rect = SkIRect::MakeXYWH(0, 0, subWidth, subHeight);
    gpu->clear(rect, subColor1, tex->asRenderTarget());
    rect = SkIRect::MakeXYWH(subWidth, 0, subWidth, subHeight);
    gpu->clear(rect, subColor2, tex->asRenderTarget());
    rect = SkIRect::MakeXYWH(0, subHeight, subWidth, subHeight);
    gpu->clear(rect, subColor3, tex->asRenderTarget());
    rect = SkIRect::MakeXYWH(subWidth, subHeight, subWidth, subHeight);
    gpu->clear(rect, subColor4, tex->asRenderTarget());

    gpu->readPixels(tex, 0, 0, subWidth, subHeight, config, (void*)subBuffer.get(), 0);
    REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
                                                                     subColor1,
                                                                     config,
                                                                     subWidth,
                                                                     subHeight));
    gpu->readPixels(tex, subWidth, 0, subWidth, subHeight, config, (void*)subBuffer.get(), 0);
    REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
                                                                     subColor2,
                                                                     config,
                                                                     subWidth,
                                                                     subHeight));
    gpu->readPixels(tex, 0, subHeight, subWidth, subHeight, config, (void*)subBuffer.get(), 0);
    REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
                                                                     subColor3,
                                                                     config,
                                                                     subWidth,
                                                                     subHeight));
    gpu->readPixels(tex, subWidth, subHeight, subWidth, subHeight,
                    config, (void*)subBuffer.get(), 0);
    REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(subBuffer.get(),
                                                                     subColor4,
                                                                     config,
                                                                     subWidth,
                                                                     subHeight));
}
示例#3
0
 inline Framebuffer* subBuffer(const Scalar& x1, const Scalar& y1, const Scalar& width, const Scalar& height)
 {
     return subBuffer(FBRectangle(x1,y1,x1 + width - 1, y1 + height - 1));
 };
int Model_XYZ::Load(string fileName, float alfa, float* matrix) {

	TotalPoints = 0;
    std::ifstream in(fileName.c_str());
    std::stringstream buffer;
    buffer << in.rdbuf();

    string line;
    hasColor = false;
    while (getline(buffer, line, '\n')) {
        istringstream subBuffer(line);
        string point;
        for (int i = 0; i < 6 && getline(subBuffer, point, ' '); i++) {

            if (i < 3){
               float value = ::atof(point.c_str());
               Points.push_back(value);
           }
           else{
           //cout << "entro load" << endl;
               hasColor = true;
               float value = ::atof(point.c_str());
               ColorPoints.push_back(value);
           }
        }
        TotalPoints++;
    }
    in.close();

    float minX = std::numeric_limits<float>::max();
    float minY = std::numeric_limits<float>::max();
    float minZ = std::numeric_limits<float>::max();
    float maxX = std::numeric_limits<float>::min();
    float maxY = std::numeric_limits<float>::min();
    float maxZ = std::numeric_limits<float>::min();

    MinCoord = std::numeric_limits<float>::max();
    MaxCoord = std::numeric_limits<float>::min();
    for (int i = 0; i < TotalPoints * 3; i++) {
        if (Points[i] < MinCoord) {
            MinCoord = Points[i];
        }
        if (Points[i] > MaxCoord) {
            MaxCoord = Points[i];
        }
        if (i % 3 == 0) {
            if (Points[i] < minX) {
                minX = Points[i];
            }
            if (Points[i] > maxX) {
                maxX = Points[i];
            }
        }
        if (i % 3 == 1) {
            if (Points[i] < minY) {
                minY = Points[i];
            }
            if (Points[i] > maxY) {
                maxY = Points[i];
            }
        }
        if (i % 3 == 2) {
            if (Points[i] < minZ) {
                minZ = Points[i];
            }
            if (Points[i] > maxZ) {
                maxZ = Points[i];
            }
        }
    }

    if (alfa == 0) {
        AlfaCoord = std::max(std::abs(MinCoord), std::abs(MaxCoord));
    } else {
        AlfaCoord = alfa;
    }

    float deltaX = (maxX + minX) / 2;
    float deltaY = (maxY + minY) / 2;
    float deltaZ = (maxZ + minZ) / 2;
    for (int i = 0; i < TotalPoints * 3; i++) {

        if (i % 3 == 0 && i + 3 < TotalPoints * 3) {
            Convert(i / 3, matrix);
        }
        if (i == 150000) {
            //cout << "Original de Archivo: " << Points[i] << endl;
        }
        if (alfa == 0 && i % 3 == 0 && i + 3 < TotalPoints * 3) {//
            //Convert(i / 3);
        }
    }

    //cout << "alfa " << AlfaCoord << endl;

    for (int i = 0; i < TotalPoints * 3; i++) {

        Points[i] = (Points[i] / AlfaCoord) * 10;
        if (i == 150000) {
            //cout << "Dividido alfacoord " << Points[i] << endl;
        }
    }

	return TotalPoints;
}
int Model_XYZ::Load(string fileName, float alfa) {

	TotalPoints = 0;
    std::ifstream in(fileName.c_str());
    std::stringstream buffer;
    buffer << in.rdbuf();

    string line;
    while (getline(buffer, line, '\n')) {
        istringstream subBuffer(line);
        string point;
        for (int i = 0; i < 3 && getline(subBuffer, point, ' '); i++) {
            float value = ::atof(point.c_str());
            Points.push_back(value);
        }
        TotalPoints++;
    }
    in.close();

    float minX = std::numeric_limits<float>::max();
    float minY = std::numeric_limits<float>::max();
    float minZ = std::numeric_limits<float>::max();
    float maxX = std::numeric_limits<float>::min();
    float maxY = std::numeric_limits<float>::min();
    float maxZ = std::numeric_limits<float>::min();

    MinCoord = std::numeric_limits<float>::max();
    MaxCoord = std::numeric_limits<float>::min();
    for (int i = 0; i < TotalPoints * 3; i++) {
        if (Points[i] < MinCoord) {
            MinCoord = Points[i];
        }
        if (Points[i] > MaxCoord) {
            MaxCoord = Points[i];
        }
        if (i % 3 == 0) {
            if (Points[i] < minX) {
                minX = Points[i];
            }
            if (Points[i] > maxX) {
                maxX = Points[i];
            }
        }
        if (i % 3 == 1) {
            if (Points[i] < minY) {
                minY = Points[i];
            }
            if (Points[i] > maxY) {
                maxY = Points[i];
            }
        }
        if (i % 3 == 2) {
            if (Points[i] < minZ) {
                minZ = Points[i];
            }
            if (Points[i] > maxZ) {
                maxZ = Points[i];
            }
        }
    }

    if (alfa == 0) {
        AlfaCoord = std::max(std::abs(MinCoord), std::abs(MaxCoord));
    } else {
        AlfaCoord = alfa;
    }

    float deltaX = (maxX + minX) / 2;
    float deltaY = (maxY + minY) / 2;
    float deltaZ = (maxZ + minZ) / 2;
    for (int i = 0; i < TotalPoints * 3; i++) {
        if (i % 3 == 0) {
            Points[i] = Points[i] - deltaX;
        }
        if (i % 3 == 1) {
            Points[i] = Points[i] - deltaY;
        }
        if (i % 3 == 2) {
            Points[i] = Points[i] - deltaZ;
        }
        Points[i] = (Points[i] / AlfaCoord) * 10;
    }

	return TotalPoints;
}