gatech-csl / jes

The Jython Environment for Students allows students to write Jython programs that can manipulate pictures, sounds, and videos.
http://mediacomputation.org/
60 stars 38 forks source link

Incorrect colors being written back into gifs #57

Open leafstorm opened 10 years ago

leafstorm commented 10 years ago

From christop...@gmail.com on August 16, 2012 15:01:39

What steps will reproduce the problem? 1. Load a gif image

  1. select a pixel with getPixel and change its color
  2. select the same pixel with getPixel and check its color What is the expected output? What do you see instead? I would that the color at the pixel location would be the color I set on the pixel. While the color values have changed, they are not the values that I set. Here is the transcript of a sample session:

picture = makePicture(pickAFile()) # loading a gif pixel = getPixel(picture, 10, 10) print pixel Pixel red=141 green=141 blue=137 setRed(pixel, 0) print pixel # the pixel at (10,10) now has red turned off Pixel red=0 green=141 blue=137 pixel2 = getPixel(picture, 10, 10) # fetch pixel (10,10) again print pixel2 # the color values are all incorrect Pixel red=82 green=98 blue=108 What version of the product are you using? On what operating system? I am using version 4.3 on a Mac running OSX 10.6.8. Please provide any additional information below. This only seems to be the case for gifs. I though I was losing my mind until I realized I had been using a gif instead of the jpgs I had used for all of my earlier tinkering. I converted the image to a jpg and tried again, and got the correct result. Looking at the implementation, I suspect it may be a java bug, but still worth knowing about.

Original issue: http://code.google.com/p/mediacomp-jes/issues/detail?id=57

blernermhc commented 9 years ago

I also see this problem with gifs. I am running JES 5.0 on a Mac running OSX 10.10.5 and Java 1.7.0_55.

mjguzdial commented 9 years ago

I think I know what the problem is. We cache pixels, so that every pixel change doesn't change the underlying picture, since that's slow. Sounds like getPixel is sometimes accessing the underlying picture when the cache has a changed pixel. Try exploring the picture -- I'll bet that the pixel will be changed in the explorer. Exploring the picture will also push the updates to the underlying picture.

We'll put this on the to-fix queue. Thanks!

blernermhc commented 9 years ago

Thanks for the quick response! Explore shows the wrong colors. That is how we discovered it. A student wrote a very simple function to keep just the red values and it was clear looking at it in explore that it was not doing that. After much scrutinizing for some mysterious bug, re-starting JES in case there was old code that had put things in a wrong state, etc., we tried it on a different computer and happened to use a jpeg instead and it worked. I then tried it on a gif on the 2nd computer and it did not work.

Here is the code and photo.

def justRed ( picture ) :
# Loop over all pixels
   for pixel in getPixels ( picture ) :
# reduce blue & green to minimum value
     setBlue (pixel, 0)
     setGreen (pixel, 0)

def testJustRed ( ) :
# Loop over all pixels
     myFile = '/Users/blerner/Pictures/Backgrounds/SnickersAtTheBeach.gif'
     myPict = makePicture (myFile)
     explore (myPict)
     justRed (myPict)
     explore (myPict)

snickersatthebeach

mjguzdial commented 9 years ago

Interesting! I wonder if it's a GIF vs. JPEG thing. Will look into it.