summaryrefslogtreecommitdiff
path: root/tests/image_data_ycbcr601pl_map_solid_rotate.lua
blob: 60f8b587d202a0bcc66cca3b200b17c617b1447b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local ffi = require("ffi")
local util = require("util")
local C = ffi.C
local levas = util.get_lib("evas")

ffi.cdef [[ size_t fread (void *ptr, size_t size, size_t n, void *stream); ]]

local names = {
    "Image Data YCbCr 601 Pointer List Map Solid Rotate",
    "Image Data YCbCr 601 Pointer List Map Nearest Solid Rotate"
}

return function(ui, variant)
    return "data.png", names[variant], 5.0000, function()
        local image, yp, up, vp, m
        local win_w, win_h = ui.win_w, ui.win_h
        ui.func_set(function() levas.evas_object_del(image) end, function(t, f)
            if not m then m = levas.evas_map_new(4) end
            levas.evas_map_smooth_set(m, (variant == 2) and 0 or 1)
            local w = 640
            local h = 480
            local x = (win_w / 2) - (w / 2)
            local y = (win_h / 2) - (h / 2)
            levas.evas_map_util_points_populate_from_geometry(m, x, y, w,
                h, 0)
            levas.evas_map_util_rotate(m, f, x + (w / 2), y + (h / 2))
            levas.evas_object_map_enable_set(image, 1)
            levas.evas_object_map_set(image, m)
        end)
        local evas = ui.evas
        image = levas.evas_object_image_add(evas)
        levas.evas_object_image_content_hint_set(image,
            levas.EVAS_IMAGE_CONTENT_HINT_DYNAMIC)
        levas.evas_object_image_colorspace_set(image,
            levas.EVAS_COLORSPACE_YCBCR422P601_PL)
        levas.evas_object_image_size_set(image, 640, 480)
        levas.evas_object_image_alpha_set(image, 0)
        levas.evas_object_image_fill_set(image, 0, 0, 640, 480)
        levas.evas_object_resize(image, 640, 480)
        levas.evas_object_image_smooth_scale_set(image, (variant == 2)
            and 0 or 1)
        levas.evas_object_show(image)
        local f = io.open(util.build_path("tp.yuv"), "rb")
        yp = ffi.new("unsigned char[?]", 640 * 480)
        up = ffi.new("unsigned char[?]", 320 * 240)
        vp = ffi.new("unsigned char[?]", 320 * 240)
        C.fread(yp, 640 * 480, 1, f)
        C.fread(up, 320 * 240, 1, f)
        C.fread(vp, 320 * 240, 1, f)
        f:close()
        local data = ffi.cast("unsigned char**",
            levas.evas_object_image_data_get(image, 1))
        local lp = data
        for y = 0, 479 do
            lp[0] = yp + (y * 640)
            lp = lp + 1
        end
        for y = 0, 239 do
            lp[0] = up + (y * 320)
            lp = lp + 1
        end
        for y = 0, 239 do
            lp[0] = vp + (y * 320)
            lp = lp + 1
        end
        levas.evas_object_image_data_set(image, data)
    end
end