animated MEGA pixels for 3D Models and SCENERY

General FreeBASIC programming questions.
Post Reply
robert8192
Posts: 35
Joined: Apr 27, 2010 15:03

animated MEGA pixels for 3D Models and SCENERY

Post by robert8192 »

Hi everyone,

I have been working on a number of games and decided,
I want to create animated MEGA pixels .

First off, what do animated MEGA pixels need to do?
I would like a animated MEGA pixels class(called A!M!P from here on) to be a draw primitive.
The idea is to make a super compressed GFX format for animation in
a game that resembles a mini-movie. I have used the LZMA functions
in another post and they are the data compression formulas I have chozen.

Not just for games, I would want the ability to stream actual video into a program, somehow and create a copy of the inported video stream converted into the A!M!P format, so a person could also make super-compressed movies , that they can load and run inside a freebasic program. This could have the possibility to make someones game look
super fantastic.

Such a thing will make some coders over at thinbasic, gameaker, and purebasic super envious.

Is such a beast possible?
Any help is appeciated.
Last edited by robert8192 on Aug 09, 2010 0:55, edited 1 time in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

You're going to have to be more specific about your implementation. What you described can be voxels, vector graphics or something else.
I would like a super pixel (called S!P from here on) to be a draw primitive. The idea is to make a super compressed video format for animation in a game that resembles a mini-movie.

...

Is such a beast possible?
I'm not sure how your first two statements are related. Are you thinking of Flash?
robert8192
Posts: 35
Joined: Apr 27, 2010 15:03

Post by robert8192 »

no not flash.

Imagine , if you will, a 15x15 box of pixels on the screen.

I want to find a way to take all relative color info out and compress it
in such a way that the result of say a small 240x200 video image file(AVI..etc)
can be recorded or saved in S!P format and take up very little memory.

Then , on command, you can play the said video to the screean anywhere
you want it.

Rob.
angros47
Posts: 2324
Joined: Jun 21, 2005 19:04

Post by angros47 »

Why don't you use variable size pixels?

Often, in an image, part of it is made of plain color (the sky, for example): you could use a big pixel to plot it.

So, you could, for each pixel, choose if you want to subdivide it into smaller pixels, or not.

Let's take a 256 * 256 image: you start with a single big pixel, with a size of 256 * 256: you will check if the area inside of this pixel is all of the same color (it could happen, if the image is blank), and if the answer is yes, you will plot the pixel: otherwise, you will split the pixel into four 128*128 pixels, and for each of them you will perform the same check (maybe, one of these pixel is a piece of sky, it's all blue, so you can plot it); then, pixels that are not plotted will be split into 64*64 pixels, and so on, until you reach 1*1 pixel (that will always be of a single colors, and can always be plotted)

With that approach, you will need much lesser pixel data, and you will keep a good detail level.
AFAIK, a similar approach is used for many image and video compression algorithms
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

@Angros

Great idea.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

@angros:

That's what I thought, which is why I asked what he was thinking - this sort of thing is fairly common in compression algorithms. It's something FB can already do if you have the right libraries.
robert8192
Posts: 35
Joined: Apr 27, 2010 15:03

Post by robert8192 »

pixels, pixels and more pixels

SUPER PIXELS

I was looking for some ASM code to help in the process.

What I need is a data format for S!P

type S1P
clrp as COLOR PALLETTE
dimension as INT ' will be DxD square
data as STRING ' possible as a string
end type

Then I would like to have an ASM function to draw the S!P

any good ideas-- maybe someone has code similiar to this already
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

The term superpixel actually refers to a segmentation method used to analyse picture data in applications such as machine vision and video analysis. It is a method to pack data into pixel groups that have the same or similar set of characteristics. That is, the data is perceptually the same across a superpixel.

http://www.cs.sfu.ca/~mori/research/superpixels/

http://www.cs.toronto.edu/~sven/Papers/turbopixels.pdf (PDF)

http://users.dickinson.edu/~jmac/public ... WMVC09.pdf (PDF)

The method isn't trivial, and I am not sure why you want to do this just to display some video on the screen. It seems to me that just utilizing the available compression codecs for video would be a better approach.
robert8192
Posts: 35
Joined: Apr 27, 2010 15:03

Post by robert8192 »

wow incredible
jumping jacked up jesus.

I did not know super pixels were already created.

I looked through some of the code on LINK#1.

It looks like hundreds of lines of speghetti code.

All these links do is complicate the matter. I believe that the
FB version of the S!P could be done in under 200 lines of code.

An effective ASM routine to draw the S!P is critical.

I think I want my S!P to operate differently as the ones in the links. All I want mine to do is create a scene.
But there are many other possibilities, imagine is a players character defined as a 3D S!P. It could render seperatly inside a scene and move as if it was an entity. Maybe Huge ships, cars and other objects could be defined as S!P and move among the scene.

Hence, I have renamed super pixels in the sense of the design has changed. They are henceforth known as TERRAIN BASE PIXELS,
or non-moving (BASE) pixels, TBPm and 2D BASE PIXELS, these can be simple shapes, or images, and 3D BASE PIXELS.

Thats it for BASE PIXELS. Next I would like
TERRAIN MEGA PIXELS,
2D MEGA PIXELS
and 3D MEGA PIXELS.... the MEGA pixel units are the same framework as the BASE ones only they can be animated to move.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

@robert

This is a start. Autoscaling 3d "boxels" 2d sprite pixel data can then be interpreted/plotted ala a scalar. I'll work on translated fb images into this format and see how it comes out.

<edit>

Yet another image buffer... a "boxel image"

Code: Select all

#include once "fbgfx.bi"

Dim Shared As Integer screen_x = 800
Dim Shared As Integer screen_y = 600
Dim Shared As Integer center_x = 400
Dim Shared As Integer center_y = 300

#Define ReturnPixData( _img )     ( Cast( Ubyte Ptr, _img ) + Sizeof( FB.IMAGE ) )

#define RND_UBYTE Int(Rnd * 256)
#define RNDRGB rgb(RND_UBYTE, RND_UBYTE, RND_UBYTE)
#DEFINE RNDRGBA rgba( RND_UBYTE, RND_UBYTE, RND_UBYTE, RND_UBYTE )

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Type point3d
  As single x,y,z
  As uinteger clr
  
  declare Constructor ()
  declare Constructor ( rhs as point3d )
  declare Operator Let ( rhs as point3d )
  
  Declare Sub DrawMe (screenbuffer As fb.image Ptr )
End Type

Constructor point3d ()
    this.x = 0
    this.y = 0
    this.z = 0
    this.clr = RGBA(255,255,255,255)
end Constructor
    
Constructor point3d ( rhs as point3d )
    this.x = rhs.x
    this.y = rhs.y
    this.z = rhs.z
    this.clr = rhs.clr
end Constructor

Operator point3d.Let ( rhs as point3d )
    this.x = rhs.x
    this.y = rhs.y
    this.z = rhs.z
    this.clr = rhs.clr
end Operator

Sub point3d.DrawMe ( screenbuffer As fb.image Ptr )
  Dim As Integer xscreen = Any, yscreen = Any
  xscreen = ((x*256)/(z+1000)) + center_x
  yscreen = ((y*256)/(z+1000)) + center_y
  If xscreen < 1 Or xscreen > screen_x-1 Then Exit Sub
  If yscreen < 1 Or yscreen > screen_y-1 Then Exit Sub
  Cast (Uinteger Ptr, ReturnPixData(screenbuffer) + ( yscreen * screenbuffer->Pitch ))[ xscreen ] = clr
End Sub

type boxel
    as uinteger clr = RNDRGBA
    as point3d corners(1)
    
    declare Constructor ()
    declare Constructor (byref rhs as boxel)
    declare Operator Let (byref rhs as boxel)
    
    declare Property center () as point3d
    
    declare sub DrawMe ( screenbuffer as fb.image ptr = 0 )
    declare sub SetLoc ( x as single, y as single, z as single )
end type

Constructor boxel ()
    this.corners(0).x = 0
    this.corners(0).y = 0
    this.corners(0).z = 0
    this.corners(0).x = 1
    this.corners(0).y = 1
    this.corners(0).z = 0
end Constructor

Constructor boxel ( rhs as boxel )
    this.corners(0).x = rhs.corners(0).x
    this.corners(0).y = rhs.corners(0).y
    this.corners(0).z = rhs.corners(0).z
    this.corners(1).x = rhs.corners(0).x+1
    this.corners(1).y = rhs.corners(0).y+1
    this.corners(1).z = rhs.corners(0).z    
end Constructor

Operator boxel.Let ( rhs as boxel )
    this.corners(0).x = rhs.corners(0).x
    this.corners(0).y = rhs.corners(0).y
    this.corners(0).z = rhs.corners(0).z
    this.corners(1).x = rhs.corners(0).x+1
    this.corners(1).y = rhs.corners(0).y+1
    this.corners(1).z = rhs.corners(0).z    
end Operator

Property Boxel.Center() as point3d
    dim as point3d res
    res.x = ( corners(0).x + corners(1).x ) * .5
    res.y = ( corners(0).y + corners(1).y ) * .5
    res.z = ( corners(0).z + corners(1).z ) * .5
    return res
end Property

sub Boxel.DrawMe ( screenbuffer as fb.image ptr = 0 )
  
  Dim As Integer xscreen(1), yscreen(1)
  
  for i as integer = 0 to 1
      with corners(i)
        xscreen(i) = (.x*256)/(.z+1000) + center_x
        yscreen(i) = (.y*256)/(.z+1000) + center_y
      end with
  next
  
  if xscreen(0) < 1 or xscreen(0) > screen_x-1 then exit sub
  if yscreen(0) < 1 or yscreen(0) > screen_y-1 then exit sub
  
  line screenbuffer, ( xscreen(0), yscreen(0) ) - ( xscreen(1), yscreen(1) ), clr, bf
  
end sub

sub Boxel.SetLoc ( x as single, y as single, z as single )
    this.corners(0).x = x
    this.corners(0).y = y
    this.corners(0).z = z
    this.corners(1).x = x+1
    this.corners(1).y = y+1
    this.corners(1).z = z
end sub

Type bImage
  As Integer       height
  As Integer       Width
  As Integer       nPixels ' !!!
  As boxel ptr     matrix

  Declare Constructor ()
  Declare Constructor ( rhs As fb.image Ptr )
  Declare Operator Let ( rhs As fb.image Ptr )

  Declare Sub bPut ( screenbuffer As fb.image Ptr = 0 )
  declare sub bSetLoc ( x as integer, y as integer, z as integer )
End Type

Constructor bImage ()
  height  = 1
  Width   = 1
  nPixels = Width*Height ' !!!
  matrix  = Callocate(nPixels, sizeof(boxel))
End Constructor

Constructor bImage ( rhs As fb.image Ptr )
  this.height  = rhs->height
  this.width   = rhs->width
  this.nPixels = Width*height ' !!!
  matrix       = Callocate(nPixels, sizeof(boxel))

  Dim As Integer i=0
  For ix As Integer = 0 To height-1
    For iy As Integer = 0 To Width - 1
      this.matrix[i].clr = Point ( ix,iy,rhs )
      this.matrix[i].corners(0).x = ix
      this.matrix[i].corners(0).y = iy
      this.matrix[i].corners(1).x = ix+1
      this.matrix[i].corners(1).y = iy+1
      i+=1
    Next
  Next
End Constructor

Operator bImage.Let ( rhs As fb.image Ptr )
  this.height  = rhs->height
  this.width   = rhs->width
  this.nPixels = Width*height ' !!!
  matrix       = Callocate(nPixels, sizeof(boxel))

  Dim As Integer i=0
  For ix As Integer = 0 To height-1
    For iy As Integer = 0 To Width - 1
      this.matrix[i].clr = Point ( ix,iy,rhs )
      this.matrix[i].corners(0).x = ix
      this.matrix[i].corners(0).y = iy
      this.matrix[i].corners(1).x = ix+1
      this.matrix[i].corners(1).y = iy+1
      i+=1
    Next
  Next
End Operator

Sub bImage.bPut ( screenbuffer As fb.image Ptr = 0 )
  Dim As Integer i=0
  'Dim As Ubyte Ptr sbpix = Cast( Ubyte Ptr, screenbuffer ) + Sizeof( FB.IMAGE )
  Dim As Integer xscreen = 0, yscreen = 0

  For ix As Integer = 0 To height-1
    For iy As Integer = 0 To Width - 1
      ' !!!
      If (matrix[i].clr And &HFF00FF)=&HFF00FF Then
        i+=1
        Continue For
      End If
      matrix[i].drawme(screenbuffer)
      i+=1
    Next
  Next
End Sub

sub bImage.bSetLoc ( x as integer, y as integer, z as integer )
    dim as integer i=0
    for ix as integer = 0 to height - 1
        for iy as integer = 0 to width-1
            matrix[i].corners(0).x = x+ix
            matrix[i].corners(0).y = y+iy
            matrix[i].corners(0).z = z
            matrix[i].corners(1).x = x+ix+1
            matrix[i].corners(1).y = y+iy+1
            matrix[i].corners(1).z = z
            i+=1
        next
    next
end sub

screen 19,32

Dim As fb.image Ptr pic = imagecreate(100,100,0)
Line   pic,(0,0)-(100,100),rgba(255,0,255,255),BF 'trans rectangle
Circle pic,(50,50),50,rgba(255,255,  0,255),,,,F
Circle pic,(25,30),12,rgba(255,255,255,255),,,,F
Circle pic,(75,30),12,rgba(255,255,255,255),,,,F
Circle pic,(25,30), 7,rgba(  0,  0,  0,255),,,,F
Circle pic,(75,30), 7,rgba(  0,  0,  0,255),,,,F
Circle pic,(50,50),28,rgba(  0,  0,  0,255),1.57*2,1.57*4

dim as bImage img = pic
img.bSetLoc(100,100,-700)
img.bPut
sleep
imagedestroy(pic)
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

Ok. Finished up boxel image with 3d rotations/translations:

http://www.freebasic.net/forum/viewtopic.php?t=16164
robert8192
Posts: 35
Joined: Apr 27, 2010 15:03

Post by robert8192 »

Boy am I late to post

Been busy on many things. I like the work your doing RB.
couldnot get stuff to work on other thread as I couldnt get vImage.bas to compile with the other demos...

hope you get it all done up good.

Rob
Post Reply