Skip to content

Commit

Permalink
Solve issue with CMYK and CMYK255
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Mar 9, 2017
1 parent e722626 commit ddd907e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,59 @@
*/
public class CMYK implements AbstractColorMode {

protected int MAX_VALUE;

public CMYK() {
MAX_VALUE = 100;
}

private double fraction() {
return 255 / (double) MAX_VALUE;
}

@Override
public List<Channel> getChannels() {
List<Channel> list = new ArrayList<>();

list.add(new Channel(R.string.channel_cyan, 0, 100, new Channel.ColorExtractor() {
list.add(new Channel(R.string.channel_cyan, 0, MAX_VALUE, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 100 - (int) (Color.red((int) (color * 2.55)) / 2.55);
// C = (1-R'-K) / (1-K)
return (int) (MAX_VALUE * ((MAX_VALUE - (Color.red(color)/fraction()) - black(color) ) / (MAX_VALUE - black(color))));
}
}));

list.add(new Channel(R.string.channel_magenta, 0, 100, new Channel.ColorExtractor() {
list.add(new Channel(R.string.channel_magenta, 0, MAX_VALUE, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 100 - (int) (Color.green((int) (color * 2.55)) / 2.55);
// M = (1-G'-K) / (1-K)
return (int) (MAX_VALUE * ((MAX_VALUE - (Color.green(color)/fraction()) - black(color) ) / (MAX_VALUE - black(color))));
}
}));

list.add(new Channel(R.string.channel_yellow, 0, 100, new Channel.ColorExtractor() {
list.add(new Channel(R.string.channel_yellow, 0, MAX_VALUE, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 100 - (int) (Color.blue((int) (color * 2.55)) / 2.55);
// M = (1-Y'-K) / (1-K)
return (int) (MAX_VALUE * ((MAX_VALUE - (Color.blue(color)/fraction()) - black(color) ) / (MAX_VALUE - black(color))));
}
}));

list.add(new Channel(R.string.channel_black, 0, 100, new Channel.ColorExtractor() {
list.add(new Channel(R.string.channel_black, 0, MAX_VALUE, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 100 - (int) (Color.alpha((int) (color * 2.55)) / 2.55);
return (int) black(color);
}
}));

return list;
}

// K = 1-max(R', G', B')
private double black(int color) {
return MAX_VALUE - Math.max(Math.max(Color.red(color)/fraction(), Color.green(color)/fraction()), Color.blue(color)/fraction());
}

@Override
public int evaluateColor(List<Channel> channels) {
return Color.rgb(
Expand All @@ -57,6 +75,6 @@ public int evaluateColor(List<Channel> channels) {
}

private int convertToRGB(Channel colorChan, Channel blackChan) {
return (int)((255 - colorChan.getProgress() * 2.55) * (255 - blackChan.getProgress() * 2.55)) / 255;
return (int)((255 - colorChan.getProgress() * fraction()) * (255 - blackChan.getProgress() * fraction())) / 255;
}
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,11 @@
package com.kunzisoft.androidclearchroma.colormode.mode;

import android.graphics.Color;

import com.kunzisoft.androidclearchroma.R;
import com.kunzisoft.androidclearchroma.colormode.Channel;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Pavel Sikun on 01.04.16.
*/
public class CMYK255 implements AbstractColorMode {

@Override
public List<Channel> getChannels() {
List<Channel> list = new ArrayList<>();

list.add(new Channel(R.string.channel_cyan, 0, 255, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 255 - Color.red(color);
}
}));

list.add(new Channel(R.string.channel_magenta, 0, 255, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 255 - Color.green(color);
}
}));

list.add(new Channel(R.string.channel_yellow, 0, 255, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 255 - Color.blue(color);
}
}));

list.add(new Channel(R.string.channel_black, 0, 255, new Channel.ColorExtractor() {
@Override
public int extract(int color) {
return 255 - Color.alpha(color);
}
}));

return list;
}

@Override
public int evaluateColor(List<Channel> channels) {
return Color.rgb(
convertToRGB(channels.get(0), channels.get(3)),
convertToRGB(channels.get(1), channels.get(3)),
convertToRGB(channels.get(2), channels.get(3)));
}
public class CMYK255 extends CMYK {

private int convertToRGB(Channel colorChan, Channel blackChan) {
return ((255 - colorChan.getProgress()) * (255 - blackChan.getProgress())) / 255;
public CMYK255() {
MAX_VALUE = 255;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.kunzisoft.androidclearchroma.colormode.Channel;
import com.kunzisoft.androidclearchroma.colormode.ColorMode;
import com.kunzisoft.androidclearchroma.listener.OnColorChangedListener;
import com.kunzisoft.androidclearchroma.listener.OnColorSelectedListener;
import com.kunzisoft.androidclearchroma.view.ChannelView;

import java.util.ArrayList;
Expand All @@ -39,9 +38,7 @@ public class ChromaColorFragment extends Fragment {
public final static String ARG_COLOR_MODE = "arg_color_mode";
public final static String ARG_INDICATOR_MODE = "arg_indicator_mode";

private
@ColorInt
int currentColor;
private @ColorInt int currentColor;
private ColorMode colorMode;
private IndicatorMode indicatorMode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public ChannelView(Channel channel, @ColorInt int color, IndicatorMode indicator
channel.setProgress(channel.getExtractor().extract(color));
if(channel.getProgress() < channel.getMin() || channel.getProgress() > channel.getMax()) {
throw new IllegalArgumentException(
"Initial progress for channel: " + channel.getClass().getSimpleName()
"Initial progress " + channel.getProgress()
+ " for channel: " + channel.getClass().getSimpleName()
+ " must be between " + channel.getMin() + " and " + channel.getMax());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ private void setupSpinner() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
colorMode = ColorMode.values()[position];
switch(colorMode) {
case CMYK:
case CMYK255:
indicatorMode = IndicatorMode.DECIMAL;
}
chromaDialog = null;
}

Expand Down

0 comments on commit ddd907e

Please sign in to comment.