Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3445008
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:59:16+00:00 2026-05-18T08:59:16+00:00

I wrote a simple loop to aid in billboarding that will check if a

  • 0

I wrote a simple loop to aid in billboarding that will check if a pixel is white. if so, it will set it to 100% transparency. i wrote it in native code because the java equivalent of this loop took 19 seconds to run for a 256×256 bitmap, too slow.

when compiling:

#include "org_me_renderscene_Billboard.h"

#include <stdio.h>
#include <stdlib.h>

JNIEXPORT jintArray JNICALL Java_org_me_renderscene_Billboard_NativeSetAlphaWhereWhite
  (JNIEnv *envptr, jclass jClass, jintArray pixels, jint length)
{
    int *mPixels = (*int)malloc(length * 4);

    static int currentcolor;
    static int writecolor;
    static int red, green, blue;

    for(int x = 0; x < length; x++)
    {
        currentcolor = pixels[x];

        red = currentcolor << 16;
        green = currentcolor << 8;
        blue = currentcolor;
        if((red == 0) && (green == 0) && (blue == 0))
        {
            mPixels[x] = 0x00000000;
        }
        else
        {
            mPixels[x] = currentcolor;
        }
    }

    return mPixels;

}

the auto-generated stub for which is:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_me_renderscene_Billboard */

#ifndef _Included_org_me_renderscene_Billboard
#define _Included_org_me_renderscene_Billboard
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     org_me_renderscene_Billboard
 * Method:    NativeSetAlphaWhereWhite
 * Signature: ([II)[I
 */
JNIEXPORT jintArray JNICALL Java_org_me_renderscene_Billboard_NativeSetAlphaWhereWhite
  (JNIEnv *, jclass, jintArray, jint);

#ifdef __cplusplus
}
#endif
#endif

i get these errors:

thomas@THOMASDESKLINUX:~/Documents/LinuxProgramming/EclipseWorkspace/RenderScene$ /home/thomas/Documents/LinuxProgramming/AndroidSDKs/android-ndk-r4b/ndk-build
Compile thumb  : Billboardlib <= /home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c: In function 'Java_org_me_renderscene_Billboard_NativeSetAlphaWhereWhite':
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:9: error: expected expression before 'int'
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:9: error: expected ',' or ';' before 'malloc'
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:15: error: 'for' loop initial declarations are only allowed in C99 mode
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:15: note: use option -std=c99 or -std=gnu99 to compile your code
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:17: warning: dereferencing 'void *' pointer
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:17: error: void value not ignored as it ought to be
make: *** [/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/obj/local/armeabi/objs/Billboardlib/org_me_renderscene_Billboard.o] Error 1

why is this happening? my C code should be fine, and these errors dont make much sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:59:16+00:00Added an answer on May 18, 2026 at 8:59 am
    int *mPixels = (*int)malloc(length * 4);
    

    should be

    int *mPixels = (int*)malloc(length * 4);
    

    or even better

    int *mPixels = (int*)malloc(length * sizeof(int));
    

    and also note that this will not properly separate red, green, and blue:

    red = currentcolor << 16;
    green = currentcolor << 8;
    blue = currentcolor;
    

    Given that you’re just checking for zero, and you don’t really care about the individual RGB values, you can probably just get away with:

    if ( (currentcolor & 0x00FFFFFF) == 0)
    

    This will zero out the Alpha from the pixel, leaving behind just the RGB portion. If that whole thing is zero, each color must be zero, so there’s no need to check each color individually.

    Final thought:

    I haven’t done much with Android specifically, but isn’t 0x000000 black and 0xFFFFFF white? So you’re actually matching on black instead of white here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple tool to generate a DBUnit XML dataset using queries that
I needed some simple string encryption, so I wrote the following code (with a
I have a simple Google App Engine app, that I wrote using ordinary strings.
I wrote a simple batch file as a PowerShell script, and I am getting
I wrote a simple Windows Forms program in C#. I want to be able
I wrote a simple web service in C# using SharpDevelop (which I just got
I wrote a simple javascript image rotator which picks a random image on each
I am trying to write simple Visual Studio Add-In for code generation. In my
I wrote a sample program at http://codepad.org/ko8vVCDF that uses a template function. How do
I need to write a 'simple' util to convert from ASCII to EBCDIC? The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.