H3 lib

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
User avatar
rax
Flying Officer
Posts: 193
Joined: Tue Jul 24, 2018 3:16 pm

Re: H3 lib

Post by rax »

jbperin wrote: Sat Feb 04, 2023 6:56 pm I love this lib very much.

I'm not yet using it as its best but I use it in a project I'm working on.


Belmar2023-02-04-18482268.gif
That's an amazing result :)

I made this library as a joke.
A lot of things can be optimized on it. Remove any number multiplications, need to add a few extra functions (eg to copy images from an arbitrary address in the work area), etc.

If you want I can make you a contributor to the project?
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: H3 lib

Post by jbperin »

Symoon wrote: Sun Feb 05, 2023 12:27 pm it gives a "book" feeling ;)
Yes :D that's what i was aiming.
Make as though the player was taking notes on the side of its adventure copybook.
ibisum wrote: Sun Feb 05, 2023 3:18 pm Re: AIC, couldn't you combine these techniques with H3 lib and add colour?
I'm currently not at home and don't have a computer to look carefully at what is shown in this video. But I'll analyse that in a near futur. Thanks for the link.
rax wrote: Tue Feb 07, 2023 10:53 pm I made this library as a joke.
A lot of things can be optimized on it. Remove any number multiplications, need to add a few extra functions (eg to copy images from an arbitrary address in the work area), etc.

If you want I can make you a contributor to the project?
I won't have to change this lib for my current project. But I plan to make an intense use of this lib in my next project and I will likely have to rework one or two things:
- Add trimming
- Port to asm to speed up and lighten the memory usage.
My coding practices are usually not as clean as yours so I'm not sure you will appreciate the changes I'm going to make. But I will for sure publish changes in a fork and propose a merge if the result is satisfying.

The first thing I plan to release is the Python script I wrote to help me convert allmost any image into a h3 compatible image .. so that the whole planet can create images for h3 lib.
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

IMG2H3

Post by jbperin »

Here's a little python script I wrote to convert any image file into a C buffer to use with Rax's marvellous H3OSDK lib.
img2h3.zip
(2.14 KiB) Downloaded 59 times
It relies on Python Imaging Library so most image format are handled (even animated gif).

The script is used through command line with following options:

Code: Select all

usage: img2h3 [-h] [--contrast CONTRAST] [--name NAME] [--undersample UNDERSAMPLE] [--invertin] [--invertout]
              [--output OUTPUT]
              imagefile

Image To H3lib Converter. Convert any image to C buffer tu use with rax's H3OSDK lib.
https://github.com/raxrax/oricH3OSDK

positional arguments:
  imagefile             image file to convert

optional arguments:
  -h, --help            show this help message and exit
  --contrast CONTRAST   Contrast Adjustment (positive float value). Default 1.5
  --name NAME           name of the buffer. Default 'image'
  --undersample UNDERSAMPLE
                        Number of frame to skip between two exported frames (only applies to animated gif)
  --invertin            invert input image (negative)
  --invertout           invert ouput image (negative)
  --output OUTPUT       file where to write buffer. Default ouput is stdout

For exemple: img2h3 --contrast 3.5 --name buffer_img --invertout image.bmp
Still images are converted into a C buffer looking like:

Code: Select all

unsigned char image[]= { 0x28, 0x24, 0x30, 0x20, 0x38, 0x20, 0x32, 0x29,
 0x30, 0x29, 0x9, 0x35, 0x28, 0x21, 0x31, 0x24,
...
};
that can be loaded into the H3 canvas with a fonction like:

Code: Select all

void h3LoadImage(unsigned char *image){
	memcpy((unsigned char*)(0xb800 + 32 * 8),image,640);
}
Animated gifs are stored frame by frame :

Code: Select all

unsigned char anim_00[]= {
   ...
};

unsigned char anim_01[]= {
   ...
};
...
unsigned char anim_0n[]= {
   ...
};
And a supplementary array is created that gives pointers on each frames.

Code: Select all

unsigned char* anim[] = {anim_00,
anim_01,
...
anim_0n,
};
possible results are illustrated below:
Image
User avatar
rax
Flying Officer
Posts: 193
Joined: Tue Jul 24, 2018 3:16 pm

Re: H3 lib

Post by rax »

jbperin wrote: Tue Feb 14, 2023 12:22 pm Here's a little python script I wrote to convert any image file into a C buffer to use with Rax's marvellous H3OSDK lib ..

Awesome! :)

You have full access to oricH3OSDK and can also upload stuff there.
You are free to do whatever you want in this project without restrictions.

I don't know if I will have free time soon to make any improvements to the project.

I think you did more for this project than me :)

(if there is a problem with access, write me)
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: H3 lib

Post by jbperin »

rax wrote: Tue Feb 14, 2023 1:00 pm
You have full access to oricH3OSDK and can also upload stuff there.
You are free to do whatever you want in this project without restrictions.
Hi rax

I thank you for you gave me the right to access the oricH3OSDK repository.

I've created a branch named "optim" in which:
  • I ported the h3curset function to assembly language for better performance
  • I added h3Line function in assembly language that draws a line very fast
I created the h3Line function beside the h3Draw function because, despite they both share the same prototype and do the same thing, there are the following difference:
  • the h3Line function is made to work with signed char rather than int (even through the function prototype use int (to comply with the demo program))
  • the h3Line function does not work with pattern
  • the h3Line deals with trimming
  • the h3Line goes fast
I'll keep you posted if I do some other optim .
For now I've only boosted the Line stuff because I need it for my current project.

Thanks again.
Attachments
HWSIMPLE.tap
(15.23 KiB) Downloaded 59 times
Post Reply