summaryrefslogtreecommitdiff
path: root/tests/image_data_ycbcr601pl_wide_stride.lua
blob: f15ffe41865c099b85ddacb3b3bd108888f68199 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
local ffi = require("ffi")
local ffi_cast = ffi.cast
local util = require("util")
local C = ffi.C
local levas = util.get_lib("evas")

ffi.cdef [[
    void  *fopen(const char *fname, const char *mode);
    int   fclose(void *stream);
    size_t fread(void *ptr, size_t size, size_t n, void *stream);
]]

local band, bnot = bit.band, bit.bnot

return function(ui)
    return "data.png", "Image Data YCbCr 601 Pointer List Wide Stride",
    36.5261, function()
        local image, yp, up, vp
        local win_w, win_h = ui.win_w, ui.win_h
        ui.func_set(function() levas.evas_object_del(image) end, function(t, f)
            local w = 640
            local h = 480
            local x = (win_w / 2) - (w / 2)
            local y = (win_h / 2) - (h / 2)
            levas.evas_object_move(image, x, y)
            levas.evas_object_resize(image, w, h)
            levas.evas_object_image_fill_set(image, 0, 0, w, h)

            w = 320 - 16 + f
            if w < 1 then w = 1
            elseif w > 640 then w = 640 end
            w = band(w, bnot(0x1))
            levas.evas_object_image_size_set(image, w, 480)
            local data = ffi_cast("unsigned char**",
                levas.evas_object_image_data_get(image, 1))
            local lp
            if data ~= nil then
                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)
                levas.evas_object_image_data_update_add(image, 0, 0, w, 480)
            end
        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, 320, 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_show(image)
        local f = C.fopen(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)
        C.fclose(f)
        local data = ffi_cast("unsigned char**",
            levas.evas_object_image_data_get(image, 1))
        local lp
        if data ~= nil then
            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)
            levas.evas_object_image_data_update_add(image, 0, 0, 320, 480)
        end
    end
end