We need to get these all on the wiki one of these days. Smile Ashbad, speak to me at some point about this if you'd be willing to help me organize them onto it.
KermMartian wrote:
We need to get these all on the wiki one of these days. Smile Ashbad, speak to me at some point about this if you'd be willing to help me organize them onto it.


Okay, sounds good Smile just PM some link to this wiki, and I can start adding my stuff to it.
I think I should publish my routines...
Where is my HDD?...
/me goes to sleep, then 'll think to publish him routines, there are a lot of useful graphics functions!
Eiyeron, that's great! Be sure to do so, and I'll have to give you a wiki link too. Ashbad, check your PMS.
CopySpriteMaskedAlpha: takes the same params as CopySpriteMasked, but with an alpha transparency channel between 0-31.


Code:
void CopySpriteMaskedAlpha(const void*datar, int x, int y, int width, int height, int maskcolor, int alpha) {
   color_t*data = (color_t*) datar;
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += LCD_WIDTH_PX*y + x;
   alpha %= 32;
   for(int j=y; j<y+height; j++) {
      for(int i=x; i<x+width;  i++) {
         if (*(data) != maskcolor) {
         *(VRAM) = (color_t)((((int)(*data & 0xf81f) * alpha + (int)(*VRAM & 0xf81f) * (32-alpha) + 0x8010) >> 5) & 0xf81f) |
                (color_t)((((int)(*data & 0x07e0) * alpha + (int)(*VRAM & 0x07e0) * (32-alpha) + 0x0400) >> 6) & 0x07e0);
           VRAM++; data++;
         } else { VRAM++; data++; }
      }
      VRAM += LCD_WIDTH_PX-width;
   }
}
Awesome! Sounds like I need to get you to add the ability for SourceCoder to generate this format, or just do it myself.
KermMartian wrote:
Awesome! Sounds like I need to get you to add the ability for SourceCoder to generate this format, or just do it myself.


Well, actually, this routine doesn't take a built-in channel Sad (edit: the whole image is taken as opaque and masked, and then the entire thing is alpha blended at the same level, which is given as a paramter) but because you prompted, I just whipped together a new format (RGBAX 56553, where X, for those few who don't know, is unused by the routine and can be used for something entirely else if wanted -- in this case, it's only 3 bits large per pixel) that uses a new type color_t_rgbax, which is 24 bits large instead of the original 565 color_t which is 16 bits. *Now* there's something to add to SC2.5 Smile


Code:
typedef struct {
   union {
      unsigned int : 24;
      struct {
         unsigned int r : 5;
         unsigned int g : 6;
         unsigned int b : 5;
         unsigned int a : 5;
         unsigned int x : 3;
      };
   };
} color_t_rgbax;

void CopySpriteMasked5655(const void*datar, int x, int y, int width, int height, int maskcolor) {
   color_t_rgbax*data = (color_t*) datar;
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += LCD_WIDTH_PX*y + x;
   for(int j=y; j<y+height; j++) {
      for(int i=x; i<x+width;  i++) {
         if ((color_t)*(data) != maskcolor) {
         int alpha = *data & 0x0000F8;
         *(VRAM) = (color_t)((((int)((*data>>8) & 0xf81f) * alpha + (int)(*VRAM & 0xf81f) * (32-alpha) + 0x8010) >> 5) & 0xf81f) |
                (color_t)((((int)((*data>>8) & 0x07e0) * alpha + (int)(*VRAM & 0x07e0) * (32-alpha) + 0x0400) >> 6) & 0x07e0);
           VRAM++; data++;
         } else { VRAM++; data++; }
      }
      VRAM += LCD_WIDTH_PX-width;
   }
}


Should work, untested, but only really minor additions made to my original routine.
So, I have looked at compression on GlassOS before, but SDCC just couldn't compile the library I was using. So, the prizm has more memory, so here it is:

Basic Compression Library

It impliments
  • RLE
  • Huffman
  • LZ77
  • SF - Shannon-Fano
  • rice8/8s/16/16s/32/32s

For example, I took a 40320 byte image and compressed and uncompressed on the prizm successfully using huffman compression. The compressed size is 15789 for this particular image, 39% of the actual size! So, how do you compress? Get that archive and build the compressor for your PC. Take your raw image data and save it to a file, such as fun.raw. use ./bfc.exe c huff fun.raw fun.huff to make a compressed image with header data. Remove the first 96 bits of that file as it was added by the bfc.exe and isn't part of the compression. Done! Add that data to your source file (you can use okteta from KDE to convert the binary file to a C array).

On the calculator, you need to malloc a buffer of the same size as the uncompressed data. Use Huffman_Uncompresss(compresseddata, outbuffer, compressedsize, uncompressedsize) to get the data from it, done!

Now, using this for a large background may be useful as you would only have 1 background malloc'd at a time, and you don't have the memory for multiple malloc'd at once. Decompressing isn't lightning fast as a PC as the prizm is under 60 Hz Razz For me, decompressing is about 0.5 sec. for the 40320 image.

I know that the LZ77 method allows for much better compression ratios, but compressing on-calc isn't reasonable as the method is a brute-force compressor and can be slow, but decompression should be fine.
Is there anything that prevents you from using the VRAM or some offset thereof directly for the outbuffer? Can you (or me, of course) add an optional "step" argument to that command so that you can skip M pixels copying an SxT patch to outbuffer, allowing you to copy a patch of S<A, T<=B onto a screen buffer of AxB = (S+M)xB = 384x216 pixels to VRAM?
You can write directly to the VRAM, yes. Just have *out as the start of the VRAM and it will work. The buffer needs to be at max the size of the uncompressed data. However, if you want to do compression on files, such as if you make a game with levels, you can compress them to save on space as speed isn't an issue. Which goes back to the the VRAM. Once you decompress to the VRAM, you have to reserve it or else you must uncompress it again, taking up a lot of time.
What about the step option? Also, did you happen to upload this to the archives anyway, or is it a simple build-from-source with no modifications needed?
Just modify the uncompressor. It simply is a for loop that writes to pointer and inc's it. I didn't upload it as I just gave the url to the source Wink
Here's a function that wraps around the sys calls and stuff for printing little text:

Code:
int PrintMiniFix( int x, int y, const char*Msg, const int flags, const short color, const short bcolor ){
int i = 0, dx;
unsigned short width;
void*p;

   while ( Msg[ i ] ){
      p = GetMiniGlyphPtr( Msg[ i ], &width );
      dx = ( 12 - width ) / 2;
      if ( dx > 0 ) {
         PrintMiniGlyph( x, y, (void*)empty, flags, dx, 0, 0, 0, 0, color, bcolor, 0 );
      }else dx = 0;
      PrintMiniGlyph( x+dx, y, p, flags, width, 0, 0, 0, 0, color, bcolor, 0 );
      if ( width+dx < 12 ){
         PrintMiniGlyph( x+width+dx, y, (void*)empty, flags, 12-width-dx, 0, 0, 0, 0, color, bcolor, 0 );
      }
      x += 12;
      i++;
   }
   return x;
}

Use it like:

Code:
PrintMiniFix(0, 175,
         "Oh look a string at the bottom of the screen.",
         0, COLOR_WHITE, COLOR_BLACK);

Empty is defined as:

Code:
const short empty[18] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
I don't know very much about C/ASM, but Kerm asked me to post this here:

http://www.top-progcasio.com/programme-216.html

It includes source code for the on-unload routine.

This is the same routine that eActivities uses for the Save dialog.
Oh well. The program fxLock flyingfisch posted includes source code, and I seem to understand how SetQuitHandler(void(*callback)(void)) works (it's described in the fx9860 SDK), the problem is that I'd like to use it on my screen locker (at least just as an experiment) but the PrizmSDK doesn't seem to have that function implemented. Any ideas?
Likely hasn't been exposed yet. You should bug Jonimus.
This is more of a generally-useful C routine or even general algorithm, but it takes a value z between z_min and z_max and converts it to a color. When z=z_max, the output color is dark blue; when z=z_min, it's maroon. The colors pass through bright red #F00) to yellow (#FF0) to bright green (#0F0) to aqua (#0FF) to bright blue (#00F) along the way. Enjoy, and I of course wouldn't mind a little attribution, but not necessary.

Code:

short unsigned int heightcolor(float z, float z_min, float z_max) {
         float frac = ((z-z_min)/(z_max-z_min));
         
         //color!
         float r = (0.25f)-frac;
         float g = (0.5f)-frac;
         float b = (0.75f)-frac;

         //calculate the R/G/B values
         r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b;   //absolute value
         r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b;   //invert
         r = (r>0.f)?(6.f*r):0.f; g = (g>0.f)?(6.f*g):0.f; b = (b>0.f)?(6.f*b):0.f;   //scale the chromatic triangles
         r = (r>1.f)?1.f:r; g = (g>1.f)?1.f:g; b = (b>1.f)?1.f:b;   //clip the top of the chromatic triangles
         if (frac < 0.25f) r = (r+1.f)/2.f;   //adjust the bottom end of the scale so that z_min is red, not black
         if (frac > 0.75f) b = (b+1.f)/2.f;   //adjust the top end of the scale so that z_max is blue, not black
         return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b))));   //put the bits together
}
Thank you, Kerm! Very Happy It fit into my program really well and I barely had to change anything: https://img.ourl.ca/rfg/mandelbrot-kerm-color.png
Neat! It looks like you might need to be a little more specific with your maximum z value, though?
Indeed, I changed it to a fixed amount, rather than the changing maxIteration value, and it looks a lot more vibrant: https://img.ourl.ca/rfg/mandelbrot-kerm-color-max-changed.png FWIW, here is the only part of the code that I changed (Pretty much just styling and making it use a Java function header):
Code:
  /* Awesome color routine from Kerm!! */
  private Color getColor(float z, float z_min, float z_max) {
    float frac = ((z-z_min)/(z_max-z_min));
   
    //color!
    float r = (0.25f)-frac;
    float g = (0.5f)-frac;
    float b = (0.75f)-frac;
   
    //calculate the R/G/B values
    r = (r>0.f)?r:-r;            g = (g>0.f)?g:-g;          b = (b>0.f)?b:-b;              //absolute value
    r = (0.25f)-r;               g = (1.f/3.f)-g;           b = (0.25f)-b;                 //invert
    r = (r>0.f)?(6.f*r):0.f;     g = (g>0.f)?(6.f*g):0.f;   b = (b>0.f)?(6.f*b):0.f;       //scale the chromatic triangles
    r = (r>1.f)?1.f:r;           g = (g>1.f)?1.f:g;         b = (b>1.f)?1.f:b;             //clip the top of the chromatic triangles
    if (frac < 0.25f) r = (r+1.f)/2.f;   //adjust the bottom end of the scale so that z_min is red, not black
    if (frac > 0.75f) b = (b+1.f)/2.f;   //adjust the top end of the scale so that z_max is blue, not black
    return new Color(r, g, b);
    //return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b))));   //put the bits together
  }
And here's the code that calls it (iteration is a variable for how many iterations it was able to do before it reached infinity):
Code:
return getColor((float)iteration, (float)0, 200.0f);
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3 ... 6, 7, 8 ... 10, 11, 12  Next
» View previous topic :: View next topic  
Page 7 of 12
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement