Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Fixes #1 & #3. The bg color wasn't properly being set, causing crashe…
Browse files Browse the repository at this point in the history
…s and rendering issues.
  • Loading branch information
nemosupremo committed Jul 31, 2013
1 parent a8b157b commit c58e2ec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
Binary file added assets/five.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/six.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions jni/libgifdrawable.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void drawFrame(GifFileType* gif, AndroidBitmapInfo* info, int* pixels, int fram

width = gif->SWidth;
height = gif->SHeight;
bg = &gif->SColorMap[gif->SBackGroundColor];

frame = &(gif->SavedImages[frame_no]);
frameInfo = &(frame->ImageDesc);
Expand All @@ -110,6 +109,8 @@ void drawFrame(GifFileType* gif, AndroidBitmapInfo* info, int* pixels, int fram
colorMap = gif->SColorMap;
}

bg = &colorMap->Colors[gif->SBackGroundColor];

for (j=0; j<frame->ExtensionBlockCount; j++) {
if (frame->ExtensionBlocks[j].Function == GRAPHICS_EXT_FUNC_CODE) {
ext = &(frame->ExtensionBlocks[j]);
Expand Down Expand Up @@ -147,7 +148,7 @@ void drawFrame(GifFileType* gif, AndroidBitmapInfo* info, int* pixels, int fram
}

color = (ext && frame->RasterBits[loc] == trans_index(ext)) ? bg : &colorMap->Colors[frame->RasterBits[loc]];
if (color && color->Red && color->Green && color->Blue)
if (color)
line[x] = argb(255, color->Red, color->Green, color->Blue);
}
px = (char*)px + info->stride*inc;
Expand Down Expand Up @@ -183,7 +184,8 @@ void drawFrame(GifFileType* gif, AndroidBitmapInfo* info, int* pixels, int fram
continue;
}
color = (ext && frame->RasterBits[loc] == trans_index(ext)) ? bg : &colorMap->Colors[frame->RasterBits[loc]];
line[x] = argb(255, color->Red, color->Green, color->Blue);
if (color)
line[x] = argb(255, color->Red, color->Green, color->Blue);
}
px = (char*)px + info->stride;
}
Expand Down
14 changes: 14 additions & 0 deletions res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
android:layout_height="wrap_content"
android:tag="four.gif"
android:text="Four" />

<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="five.gif"
android:text="Five" />

<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="six.gif"
android:text="Six" />

</LinearLayout>

Expand Down
2 changes: 2 additions & 0 deletions src/com/droidtools/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public void onCreate(Bundle savedInstanceState) {
((Button) findViewById(R.id.button2)).setOnClickListener(this);
((Button) findViewById(R.id.button3)).setOnClickListener(this);
((Button) findViewById(R.id.button4)).setOnClickListener(this);
((Button) findViewById(R.id.button5)).setOnClickListener(this);
((Button) findViewById(R.id.button6)).setOnClickListener(this);


/* You should always load images in the background */
Expand Down

0 comments on commit c58e2ec

Please sign in to comment.