Skip to content

colorized effect does not work in hexa, but fine in rgb #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mrbbp opened this issue Apr 30, 2025 · 4 comments
Closed

colorized effect does not work in hexa, but fine in rgb #1070

mrbbp opened this issue Apr 30, 2025 · 4 comments

Comments

@mrbbp
Copy link

mrbbp commented Apr 30, 2025

i was working on a 1bit sprite sheet sketch with color effect to tint() black pixel.
sorry i do not code my self, it's ia coded.

by filling the screen with sprites, some "hole" in the filling appearing.
i was looking for a beat to understand that the problem was coming from the way i define color for the custom blendMode.
in the example, nothing is show (all is white) in hexa color, and color is shown in rgb.
on my project the result is a more weird. i have some sprite displayed, and some white hole.

if think it's a bug
i can purpose my all script if this does not convince you (but it's the mess)

// Démonstration du bug de couleur avec remplissage complet d'écran
PImage spriteSheet;      // Feuille de sprites
PImage colorizedSprite;  // Sprite colorisé
int SPRITE_SIZE = 8;     // Taille d'un sprite
int DISPLAY_SIZE = 16;   // Taille d'affichage
boolean useHexadecimal = true;  // Mode de couleur

void setup() {
  size(400, 400);
  noSmooth();  // Désactiver l'anti-aliasing
  
  // Charger la spritesheet
  spriteSheet = loadImage("trame_90deg_5.png");  // Remplacez par votre fichier
  
  // Extraire et coloriser le sprite initial
  updateColorizedSprite();
}

void draw() {
  background(255);
  
  // Remplir l'écran avec le sprite colorisé
  for (int y = 0; y < height; y += DISPLAY_SIZE) {
    for (int x = 0; x < width; x += DISPLAY_SIZE) {
      image(colorizedSprite, x, y, DISPLAY_SIZE, DISPLAY_SIZE);
    }
  }
  
  // Afficher le mode actuel et la valeur de couleur
  fill(0);
  textSize(14);
  if (useHexadecimal) {
    text("Mode: HEXADECIMAL (0x88FF88)", 10, 20);
  } else {
    text("Mode: RGB (128, 255, 128)", 10, 20);
  }
  text("Appuyez sur ESPACE pour basculer", 10, 40);
}

// Mettre à jour le sprite selon le mode de couleur actuel
void updateColorizedSprite() {
  color spriteColor;
  
  if (useHexadecimal) {
    // Mode hexadécimal
    spriteColor = color(0x88FF88);  // Bleu foncé en hexadécimal
  } else {
    // Mode RGB
    spriteColor = color(128, 255, 128);  // Même bleu foncé en RGB
  }
  
  // Extraire et coloriser un sprite
  int index = 0;  // Premier sprite, vous pouvez changer ça
  
  // Calculer la position dans la spritesheet
  int cols = spriteSheet.width / SPRITE_SIZE;
  int col = index % cols;
  int row = index / cols;
  
  // Extraire le sprite original
  PImage originalSprite = spriteSheet.get(col * SPRITE_SIZE, row * SPRITE_SIZE, SPRITE_SIZE, SPRITE_SIZE);
  
  // Créer une nouvelle image pour le sprite colorisé
  colorizedSprite = createImage(SPRITE_SIZE, SPRITE_SIZE, ARGB);
  
  // Appliquer la couleur
  originalSprite.loadPixels();
  colorizedSprite.loadPixels();
  
  for (int i = 0; i < originalSprite.pixels.length; i++) {
    color c = originalSprite.pixels[i];
    
    // Si le pixel est noir ou foncé (motif)
    if (brightness(c) < 50) {
      colorizedSprite.pixels[i] = spriteColor;  // Appliquer la couleur souhaitée
    } else {
      colorizedSprite.pixels[i] = color(255);  // Pixel blanc
    }
  }
  
  colorizedSprite.updatePixels();
}

void keyPressed() {
  if (key == ' ') {
    // Basculer entre les modes
    useHexadecimal = !useHexadecimal;
    // Mettre à jour le sprite avec la nouvelle couleur
    updateColorizedSprite();
  }
}

on this image, there is only few hole in the blue area and more in the green area... but it is more hasardous
Image

MacOs 14.7.3
Processing 4.3.1 and 4.4.1
macbook pro 14" M1 2020

@SableRaf
Copy link
Collaborator

SableRaf commented May 2, 2025

Hi @mrbbp and thanks for sharing your example. From what I understand, the issue you’re seeing might be related to how the colors and blending are handled in your sketch, rather than a bug in Processing itself.

If you would like support, I recommend posting on the Processing forum. When you do, it would be important to create a minimal example: a very small sketch that shows the unexpected behavior without anything extra. This makes it much easier for others to reproduce and investigate the issue.

You also mentioned that you don’t code yourself and use AI-generated code. In that case, learning a bit more about coding could make it easier for you to troubleshoot problems and communicate what you’re trying to achieve. The Processing tutorials page is a good place to start learning :)

@mrbbp
Copy link
Author

mrbbp commented May 2, 2025

Hi @mrbbp and thanks for sharing your example. From what I understand, the issue you’re seeing might be related to how the colors and blending are handled in your sketch, rather than a bug in Processing itself.

If you would like support, I recommend posting on the Processing forum. When you do, it would be important to create a minimal example: a very small sketch that shows the unexpected behavior without anything extra. This makes it much easier for others to reproduce and investigate the issue.

@SableRaf Not agree with your point of view!
In the picture, you see white "hole" in the pattern, who does not exist if i declare my color in rgb(), but appear sometime (more or less) if my colors are declared in hexa. it take me sometime to analyze the prob.
i call it a bug! because it is.
We should see a regular pattern in hexa or rgb or see nothing in hexa....the "holes" appear only in hexa. if i declare color in rgb, it "paint" without hole in the pattern!

the minimal exemple is not good because it works (rgb) or not(hexa). In my own sketch (more complexe with a lot of useless things in it and don't have time to clean my code, the mess is not the point) the pb is weird because there is no logical way about the hole!

Thanks for the advice about learning code... "c'est l'histoire de la paille et de la poutre."
Sans être expert... assisté ou pas, j'appelle ça un bug parce que le comportement est erratique!

@SableRaf
Copy link
Collaborator

SableRaf commented May 2, 2025

Thanks for sharing more details. To better understand the issue, could you please also share the sprite image you are using trame_90deg_5.png? Without the image, it’s difficult to fully reproduce what you are describing.

I also want to kindly remind you that we follow a Code of Conduct, which asks everyone to communicate with respect and care, even when there are misunderstandings or disagreements. Gardons en tête que ce projet est developé par des êtres humains, qui font de leur mieux 😌

I appreciate your contribution and the time you spent analyzing this.

@mrbbp
Copy link
Author

mrbbp commented May 2, 2025

i'm going nuts! i am unable to reproduce the bug.

// Couleurs pour les différents types de cellules
//color blueColor = color(128, 128, 204);//color(0x3333CC);
color greenColor = color(0, 255, 136);//color(0x00FF88);
//color magentaColor = color(0, 255, 153);//color(0x00FF99);

color blueColor = color(0x3333CC);
//color greenColor = color(0x00FF88);
color magentaColor = color(#00FF00);

with color defined with 0xRRGGBB it produce white sprite.
with color defined with #RRGGBB it does not blend, just black and white pix as my spritesheet
with color defined with rgb() it work fine.

i would put my hand on fire (sorry literal translation from a french idiomatic), i lost 2 hours with this strange behaviour of hole and worked with Claude to test different attempts to solve the prob!
in hexa it was produce blend sprite white with an incomplete pattern in a very variable and uncontrollable way!
we tried to change the spritesheet from bmp to png, verified that all the cell of the grid was filled with a pattern (a sprite number) but nothing was wrong, nothing change in the result.
After many attempts, I tried to change the color encoding out of spite. and the problem disappeared.

Looking back, I think that Processing and the Mac were behaving abnormally.
And i'm unsure to understand what the prob?

I do not restart my mac
i just restart few time Processing, tried 4.3.1 and 4.4.1
leave the prob resolved with an rgb declaration and quit Processing!
I restart today to try an other example more probant.

i do not understand what the difference between yesterday and today but now the behaviour is totally different.

at a time when i attempted to open a file by doubleclicking file, it was not lauching the last version of Processing but the 4.3.1 and no file was opened! and i said to myself "oh they push the ability to open distant files but it break local link..."
but today it's working well.

So there was a stange behaviour but i'am enable to reproduce it's... a ghost bug...

finaly i lost some time to find an other way but the prob is unsolved for me...

@mrbbp mrbbp closed this as completed May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants