Skip to content

Commit

Permalink
めっちゃ速くなって新登場
Browse files Browse the repository at this point in the history
  • Loading branch information
todashuta committed Jul 5, 2022
1 parent 3891640 commit 732e404
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions black_to_alpha_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@


import bpy
import numpy as np


bl_info = {
"name": "Black to Alpha Zero",
"author": "todashuta",
"version": (1, 1, 3),
"version": (1, 2, 0),
"blender": (2, 80, 0),
"location": "Image Editor > Sidebar > Tool > Black to Alpha Zero",
"description": "",
Expand Down Expand Up @@ -73,17 +74,22 @@ def execute(self, context):
mask_source_image = target_image

width, height = target_image.size
target_image_pxs = list(target_image.pixels[:])
mask_source_image_pxs = list(mask_source_image.pixels[:])
target_image_pixel_data = np.zeros((width, height, 4), "f")
mask_source_pixel_data = np.zeros((width, height, 4), "f")

for i in range(0, width*height*4, 4):
r = mask_source_image_pxs[i+0]
g = mask_source_image_pxs[i+1]
b = mask_source_image_pxs[i+2]
if r == 0 and g == 0 and b == 0:
target_image_pxs[i+3] = 0 # Alpha
target_image.pixels.foreach_get(target_image_pixel_data.ravel())
mask_source_image.pixels.foreach_get(mask_source_pixel_data.ravel())

target_image.pixels = target_image_pxs
R = mask_source_pixel_data[:,:,0]
G = mask_source_pixel_data[:,:,1]
B = mask_source_pixel_data[:,:,2]
A = mask_source_pixel_data[:,:,3]

A[np.where((R == 0) & (G == 0) & (B == 0))] = 0

target_image_pixel_data[:,:,3] = A

target_image.pixels.foreach_set(target_image_pixel_data.ravel())
target_image.update()

return {"FINISHED"}
Expand Down

0 comments on commit 732e404

Please sign in to comment.