File: mhs_snowfall.lua

package info (click to toggle)
satdump 1.2.2%2Bgb79af48-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 81,648 kB
  • sloc: cpp: 276,768; ansic: 164,598; lisp: 1,219; sh: 283; xml: 106; makefile: 7
file content (56 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (2)
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
-- Transparent snow cover using MHS

function init()
    if not has_sat_proj() then
        lerror("This composite requires projection info")
        return 0
    end

	sat_proj = get_sat_proj()
	img_landmask = image_t.new()
	image_load_jpeg(img_landmask, get_resource_path("maps/landmask.jpg"))
	image_linear_invert(img_landmask)
	equ_proj = EquirectangularProj.new()
	equ_proj:init(img_landmask:width(), img_landmask:height(), -180, 90, 180, -90)
	return 4
end

function process()
	pos = geodetic_coords_t.new()

	for x = 0, rgb_output:width() -1, 1 do
		for y = 0, rgb_output:height() -1, 1 do

			get_channel_values(x, y)

			if not sat_proj:get_position(x, y, pos) then
				x2, y2 = equ_proj:forward(pos.lon, pos.lat)

				mappos = y2 * img_landmask:width() + x2

				mval = img_landmask:get(img_landmask:width() * img_landmask:height() + mappos) / 255.0

				if mval < 0.1 then
					local cch1 = get_channel_value(0)
					local cch2 = get_channel_value(1)

					local redChannel = 1-cch1

					if cch2-cch1 < 0.1 then
						if cch1 < 0.6 then
							set_img_out(3, x, y, 1)
						else
							set_img_out(3, x, y, 0)
						end
					else
						set_img_out(3, x, y, 0)
					end

					set_img_out(0, x, y, redChannel)
					set_img_out(1, x, y, 0)
					set_img_out(2, x, y, 0)
				end
			end
		end
	end
end