Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,493,288
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 04-27-24 03:37 PM
Guest: Register | Login

0 users currently in Computing | 1 guest

Main - Computing - GBA graphics, VB help New thread | New reply


interdpth
Posted on 07-21-07 08:32 AM Link | Quote | ID: 56529


Buzzy Beetle
Level: 44

Posts: 93/383
EXP: 593722
Next: 17563

Since: 02-22-07

Last post: 4100 days
Last view: 4073 days
Alright, so i'm working on a graphics editor and i've hit a snag, it seems I can't turn my new images pixels back into bytes!


This is really hurting me!

I'm currently doing this

Pix = MiniMapGraphics(Tile * 32 + (actualpixel) + 1)
MiniMapGraphics(Tile * 32 + (actualpixel)) = ((Pix * 16) And 15) + palslot

It slightly works

The formula I used to decode the bytes into pixels originally was

Color = (GraphicArray(Tile * 32 + (pixel \ 2))) And 15
If (pixel And 1) Then Color = (GraphicArray(Tile * 32 + (pixel \ 2))) \ 16 And 15

So, any help?

____________________
lawl blog

http://interdpths.blogspot.com/

Xeon
Posted on 07-21-07 11:45 AM Link | Quote | ID: 56555


Red Paratroopa
Level: 31

Posts: 106/174
EXP: 181591
Next: 3772

Since: 03-09-07

Last post: 6021 days
Last view: 3223 days
When I made my overworld editor for the Pokémon advance games I decoded each 4 bits to a byte. And then when re-saving I would simply combine two 4 bit segments back into one and just save that way.

Private Sub LoadSprite(FilePath As String, SpriteOffset As Long, PaletteOffset As Long, Height As Long, Width As Long)
'Set the global image properties
m_lngGraphicHeightBlocks = Height
m_lngGraphicWidthBlocks = Width
'Gets us a new file handle.
iFreeFile = FreeFile
'Current position in decoding
Dim lngCurrentPosition As Long
'Resizes the buffers for the required space.
ReDim Buffer(0 To ((m_lngGraphicHeightBlocks * 8) * (m_lngGraphicWidthBlocks * 8)))
ReDim EditBuffer(0 To ((m_lngGraphicHeightBlocks * 8) * (m_lngGraphicWidthBlocks * 8)))
'Resize the Sprite View (Double-Size mode!)
picViewSprite.Width = (m_lngGraphicWidthBlocks * 8) * 2
picViewSprite.Height = (m_lngGraphicHeightBlocks * 8) * 2
'Reset current tile
m_lngCurrentTile = 0
shpSelectedTile.Top = 0
shpSelectedTile.Left = 0
'Set offsets
m_lngGraphicStartOffset = SpriteOffset
'Opens the ROM
Open FilePath For Binary As #iFreeFile
'Goto the offset of the Palette
Seek #iFreeFile, PaletteOffset
'Load the Palette up
Get #iFreeFile, , PaletteData
'Goto offset of sprite
Seek #iFreeFile, SpriteOffset
'The Y-Line is the row of blocks we are reading
For YLine = 0 To m_lngGraphicHeightBlocks - 1
'The X-Line is the column of blocks we are reading
For XLine = 0 To m_lngGraphicWidthBlocks - 1
For Y = 0 To 7
'We are reading the data in chunks of DWORD's! HOW EFFECIENT OF ME!
'I MUST BE GAWD!
Get #iFreeFile, , Data1
Get #iFreeFile, , Data2
Get #iFreeFile, , Data3
Get #iFreeFile, , Data4
'4BPP graphics are 4-bits per pixel, so 4 bytes is 8 pixels or 1 row.
'they are in reverse order. XXXXRRRR
'RRRR = First Pixel
'XXXX = Second Pixel
'Below ...that could probely be shortend to a loop.
EditBuffer(lngCurrentPosition + 0) = (Data1 And &HF) 'High Nibble
EditBuffer(lngCurrentPosition + 1) = (Data1 \ 16) 'Low Nibble
EditBuffer(lngCurrentPosition + 2) = (Data2 And &HF) 'High Nibble
EditBuffer(lngCurrentPosition + 3) = (Data2 \ 16) 'Low Nibble
EditBuffer(lngCurrentPosition + 4) = (Data3 And &HF) 'High Nibble
EditBuffer(lngCurrentPosition + 5) = (Data3 \ 16) 'Low Nibble
EditBuffer(lngCurrentPosition + 6) = (Data4 And &HF) 'High Nibble
EditBuffer(lngCurrentPosition + 7) = (Data4 \ 16) 'Low Nibble
'Increase current position by 8
lngCurrentPosition = lngCurrentPosition + 8
Next Y
Next XLine
Next YLine
Close #iFreeFile
End Sub

Private Sub SaveSprite(FilePath As String, SpriteOffset As Long, Height As Long, Width As Long)
'Current position in decoding
Dim lngCurrentPosition As Long
Dim bytTempBuffer() As Byte
On Error GoTo ErrSaveSprite
ReDim bytTempBuffer((UBound(EditBuffer) \ 2) - 1)
'Make sure file is open
If Len(m_strCurrentROM) <= 0 Or m_blnROMOpened = False Then Exit Sub
'Gets us a new file handle.
iFreeFile = FreeFile
'Opens the ROM
Open m_strCurrentROM For Binary As #iFreeFile
'Goto offset of sprite
Seek #iFreeFile, SpriteOffset
For i = 0 To UBound(EditBuffer) - 1 Step 2
bytTempBuffer(lngCurrentPosition) = EditBuffer(i) Or (EditBuffer(i + 1) * 16)
lngCurrentPosition = lngCurrentPosition + 1
Next i
Put #iFreeFile, , bytTempBuffer
Close #iFreeFile

On Error GoTo 0
Exit Sub

ErrSaveSprite:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SaveSprite of frmOverworldEditor", vbCritical


End Sub

Main - Computing - GBA graphics, VB help New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.018 seconds. (323KB of memory used)
MySQL - queries: 42, rows: 52/53, time: 0.014 seconds.