53 if (ps1->
h > ps2->
h) {
56 if (ps1->
h < ps2->
h) {
61 if (ps1->
s > ps2->
s) {
64 if (ps1->
s < ps2->
s) {
69 if (1.0f - ps1->
v > 1.0f - ps2->
v) {
72 if (1.0f - ps1->
v < 1.0f - ps2->
v) {
90 if (ps1->
s > ps2->
s) {
93 if (ps1->
s < ps2->
s) {
98 if (1.0f - ps1->
v > 1.0f - ps2->
v) {
101 if (1.0f - ps1->
v < 1.0f - ps2->
v) {
106 if (ps1->
h > ps2->
h) {
109 if (ps1->
h < ps2->
h) {
127 if (1.0f - ps1->
v > 1.0f - ps2->
v) {
130 if (1.0f - ps1->
v < 1.0f - ps2->
v) {
135 if (ps1->
h > ps2->
h) {
138 if (ps1->
h < ps2->
h) {
143 if (ps1->
s > ps2->
s) {
146 if (ps1->
s < ps2->
s) {
163 float lumi1 = (ps1->
rgb[0] + ps1->
rgb[1] + ps1->
rgb[2]) / 3.0f;
164 float lumi2 = (ps2->
rgb[0] + ps2->
rgb[1] + ps2->
rgb[2]) / 3.0f;
191 for (
uint col : color_table) {
196 color_array[
index++] = pal_col;
232 ot->
name =
"Add New Palette";
234 ot->
idname =
"PALETTE_OT_new";
291 ot->
name =
"New Palette Color";
292 ot->
description =
"Add new color to active palette";
293 ot->
idname =
"PALETTE_OT_color_add";
319 ot->
name =
"Delete Palette Color";
320 ot->
description =
"Remove active color from palette";
321 ot->
idname =
"PALETTE_OT_color_delete";
360 const int range = int(
pow(10.0f, threshold));
363 for (
uchar4 pix : byte_buffer) {
369 for (
int i = 0; i < 3; i++) {
373 color_table.
add(key);
393 ot->
name =
"Extract Palette from Image";
394 ot->
idname =
"PALETTE_OT_extract_from_image";
395 ot->
description =
"Extract all colors used in Image and create a Palette";
405 prop =
RNA_def_int(ot->
srna,
"threshold", 1, 1, 1,
"Threshold",
"", 1, 1);
417 if (palette ==
nullptr) {
424 const int totcol = palette->
colors.count();
427 color_array = MEM_new_array<PaletteColorHSV>(totcol, __func__);
433 col_elm = &color_array[t];
445 else if (type == 2) {
448 else if (type == 3) {
461 for (
int i = 0; i < totcol; i++) {
462 col_elm = &color_array[i];
472 MEM_SAFE_DELETE(color_array);
483 {1,
"HSV", 0,
"Hue, Saturation, Value",
""},
484 {2,
"SVH", 0,
"Saturation, Value, Hue",
""},
485 {3,
"VHS", 0,
"Value, Hue, Saturation",
""},
486 {4,
"LUMINANCE", 0,
"Luminance",
""},
487 {0,
nullptr, 0,
nullptr,
nullptr},
491 ot->
name =
"Sort Palette";
492 ot->
idname =
"PALETTE_OT_sort";
513 if (palcolor ==
nullptr) {
531 {-1,
"UP", 0,
"Up",
""},
532 {1,
"DOWN", 0,
"Down",
""},
533 {0,
nullptr, 0,
nullptr,
nullptr},
537 ot->
name =
"Move Palette Color";
538 ot->
idname =
"PALETTE_OT_color_move";
539 ot->
description =
"Move the active Color up/down in the list";
557 Palette *palette_join =
nullptr;
563 if ((palette ==
nullptr) || (name[0] ==
'\0')) {
568 if (palette_join ==
nullptr) {
572 const int totcol = palette_join->
colors.count();
601 ot->
name =
"Join Palette Swatches";
602 ot->
idname =
"PALETTE_OT_join";
#define ID_IS_EDITABLE(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
VecBase< uint8_t, 4 > uchar4
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE void copy_v3_v3(float r[3], const float a[3])
static bool palette_poll(bContext *C)
void cpack_to_rgb(unsigned int col, float *r_r, float *r_g, float *r_b)
static wmOperatorStatus palette_color_add_exec(bContext *C, wmOperator *)
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
static void palette_sort_hsv(PaletteColorHSV *color_array, const int totcol)
void PALETTE_OT_new(wmOperatorType *ot)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static bool palette_extract_img_poll(bContext *C)
unsigned int rgb_to_cpack(float r, float g, float b)
static int palettecolor_compare_vhs(const void *a1, const void *a2)
void PALETTE_OT_extract_from_image(wmOperatorType *ot)
static wmOperatorStatus palette_sort_exec(bContext *C, wmOperator *op)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], const ColorSpace *colorspace)
static wmOperatorStatus palette_join_exec(bContext *C, wmOperator *op)
static void palette_sort_luminance(PaletteColorHSV *color_array, const int totcol)
BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3])
static int palettecolor_compare_hsv(const void *a1, const void *a2)
static int palettecolor_compare_luminance(const void *a1, const void *a2)
static wmOperatorStatus palette_color_delete_exec(bContext *C, wmOperator *)
static wmOperatorStatus palette_new_exec(bContext *C, wmOperator *)
static wmOperatorStatus palette_extract_img_exec(bContext *C, wmOperator *op)
MINLINE void zero_v3(float r[3])
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void BKE_palette_color_remove(Palette *palette, PaletteColor *color)
PaletteColor * BKE_palette_color_add(Palette *palette)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
SpaceImage * CTX_wm_space_image(const bContext *C)
SpaceLink * CTX_wm_space_data(const bContext *C)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void PALETTE_OT_sort(wmOperatorType *ot)
Main * CTX_data_main(const bContext *C)
void PALETTE_OT_color_add(wmOperatorType *ot)
Paint * BKE_paint_get_active_from_context(const bContext *C)
void PALETTE_OT_color_move(wmOperatorType *ot)
static bool palette_from_hash(Main *bmain, const Set< uint > &color_table, const char *name)
bool BKE_image_has_ibuf(Image *ima, ImageUser *iuser)
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
static void palette_sort_vhs(PaletteColorHSV *color_array, const int totcol)
void PALETTE_OT_join(wmOperatorType *ot)
float3 BKE_brush_color_get(const Paint *paint, const Brush *brush)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3])
void PALETTE_OT_color_delete(wmOperatorType *ot)
static wmOperatorStatus palette_color_move_exec(bContext *C, wmOperator *op)
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
void BKE_paint_palette_set(Paint *paint, Palette *palette)
static int palettecolor_compare_svh(const void *a1, const void *a2)
void void void bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL()
Palette * BKE_palette_add(Main *bmain, const char *name)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
static void palette_sort_svh(PaletteColorHSV *color_array, const int totcol)
const ColorSpace * colorspace
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
ListBaseT< PaletteColor > colors
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports