January 22, 2020, 12:31:48 PM

Author Topic: WritePixel Issue  (Read 214 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 369
WritePixel Issue
« on: December 11, 2019, 08:05:33 PM »
Can anyone explain me why do i get an error when I created a large pixmap (3840,500)

WritePixel(PixMap,X + ImageCounter * Image.width, Y, PixelValue)

what im trying to do is write a series of  Pixmaps onto a Single big Pixmap to create an Image Strip..

I only manage to write the first Image and than I get an Error..

Code: [Select]
Local Image:TImage = LoadGif("GifToLoad.Gif")
Local PixMap:TPixmap = CreatePixmap(image.width * (Image.pixmaps.Length - 1), image.height, PF_RGBA8888)

Local S, J, K

For S = 0 To Image.pixmaps.Length - 1

For J = 0 To Image.width
For K = 0 To Image.height
Local Pixel = ReadPixel(Image.pixmaps[S], J, K)
WritePixel(PixMap, J + S * Image.width, K, Pixel)
Next
Next

Next

SavePixmapPNG(PixMap, "Test.png")



* Another thing that puzzels me that is unrelated..
This guy who wrote this LoadGif Code didnt use Strict State.

so in his code you see this..

Code: [Select]
dib=GIFLoad(filename$) 'Load the next frame
  If dib=0 'Avoid errors
   'FreeImage graphic 'Free the graphic''hierX
   ResetGlobals()
   Return image 'Return the image
  EndIf
  bpp=PeekShort(dib,14) 'biBitCount
  bits=40+(PeekInt(dib,32)*4) 'biSize+(biClrUsed*4)

the variable dib starts as an int, and than used as a TBank on the command PeekShort..
how come something that began as an Int suddenly can be used as a Tbank without an Error?



Happy New Year

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 369
Re: WritePixel Issue
« Reply #1 on: December 11, 2019, 08:18:04 PM »
Ok, While writing this question ive managed to solve the write pixel Issue..
I just needed to add -1 to the length and the height.. on the write pixel process..

Whats weird is.. that I remember trying it, and now suddenly it works..  ::)
Happy New Year

Online Derron

  • Hero Member
  • *****
  • Posts: 2673
Re: WritePixel Issue
« Reply #2 on: December 11, 2019, 08:50:31 PM »
I saw your code - and I saw odd filenames - make sure that passed "filename" and actual filename are exactly the same  - once you moved on from Xors3D you might want to compile for Mac and Linux and this will result in issues if you mixup "myFILE.gIF" and "myfile.gif"


Also it can help to write more superstrict code (your variables "Local S, J, K" would become "Local S:Int, J:Int, K:Int").

This would then lead to some more insights on what happens with your "dib" (It is surely passing back a Byte Ptr ...). Where are these GIF-functions defined, and how?


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 369
Re: WritePixel Issue
« Reply #3 on: December 11, 2019, 09:27:16 PM »
Like Ive said.. Its not my code.
I would never write code without Strict..
About Super Strict.. I find no use for it, Ive concidered it as an over doing.
I dont like Variables that has the same name but with uppser case diffrences..
Ive always found that rather stupid Since we have enough Words to use..
But.. Maybe in a more professional Level, Super strict is essential, I dont know..

I was forced to work without Strict because when I put Strict on this guy code it producess Errors..
Thats why I asked about the how come an Integer can also be used as a TBank..

Anyway.. All Going better now, Im managin to achieve my Goal with all the difficulties.
Happy New Year

Online Derron

  • Hero Member
  • *****
  • Posts: 2673
Re: WritePixel Issue
« Reply #4 on: December 11, 2019, 09:44:21 PM »
Quote
I dont like Variables that has the same name but with uppser case diffrences..

SuperStrict does not allow multiple variables just differing by case differences. BlitzMax is case insensitive.
What  was talking about is that Linux/Mac can have multiple files in a directory:
file.txt
File.txt
filE.tXT

while for Windows they are all the same. So when loading a file on Linux or Mac with "LoadImage()" you need to write the filename exactly how it is in the directory.


@ SuperStrict
Read more about this: https://blitzmax.org/docs/en/language/basic_compatibility/

If adding "strict" created errors then you might be using variables which you did not plan to use (eg you spelled them incorrectly). So "strict" at least makes sure you cannot do that. If SuperStrict creates errors for you, then you most probably mix up "Int" and "Byte Ptr".


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 369
Re: WritePixel Issue
« Reply #5 on: December 12, 2019, 04:42:50 AM »
Im not using Mac or Linux.
I told you Derron, I added strict to a code that is not mine.
I didnt mix anything. I tried to Edit a code that isnt mine, in addition, adding my own code.

Thanks for the explantions btw about the linux and mac File reading Issue. I didnt know

About Typos.. Well I do have lots of Typos.. if my speller doesnt work properly, as english is not my language.
Happy New Year

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1458
Re: WritePixel Issue
« Reply #6 on: December 12, 2019, 07:53:24 AM »
strict is good, but SuperStrict is even better :) But only at the start of a project. adding it later would be a nightmare

Online Derron

  • Hero Member
  • *****
  • Posts: 2673
Re: WritePixel Issue
« Reply #7 on: December 12, 2019, 09:06:47 AM »
I am not talking about spelling issues in comments or variable names.

I do not care if you have a variable "eneeemies:TList". The problem is pretty simple - and explained in the link I gave above. Without strict you can write this:

Code: [Select]
Framework Brl.StandardIO

Type TEnemy
  Field id:int
End Type

For local personsIndex:Int = 0 until 5
  local enemy:TEnemy = new TEnemy
  enemy.id = personIndex + 1
  print enemy.id
Next

So what do you think is printed?

1
1
1
1
1

This is because you did not pay attention and added a little spelling mistake (there is an "s" missing). With "strict" it would blame that "personIndex" is undefined. Such mistakes can and most probably will lead to serious issues.


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 369
Re: WritePixel Issue
« Reply #8 on: December 12, 2019, 10:12:57 AM »
Lol. Nice example ..
That's why im using strict!
I had to fix this guy code last night..
It was horrible..
But i made it!

Strict is good enough for Me
I don't need super duper strict 😁

Yet, You have to be careful when you're using strict as the default of a variable is an int and not a float..
When you do so, you suppose to be ok..
As long as im not planning anything to linux/mac it's fine by me 👌

If anyone will ever edit my code, i won't mind if he will turn it into a super strict code
Happy New Year

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2173
  • elgol developer
Re: WritePixel Issue
« Reply #9 on: December 12, 2019, 12:17:26 PM »
Jees what a mess, Mark should never have made variable type definition optional, then compounded the problem with varying degrees of definition.
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Catalina, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.2, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
Raspberry pi 3 and 4

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 369
Re: WritePixel Issue
« Reply #10 on: December 12, 2019, 12:41:51 PM »
I agree..
Mark is a genius, but he had done some bad moves..
- For example, not promoting his blitzmax properly..
- Spreading into many engines instead of concentrating on one.

But I guess he is an Artist. Money is not his first priority, and I value it deeply.. :)
Happy New Year