Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nokia 6100 Library

Status
Not open for further replies.
this is very frustrating heh .. in my mind it should be working but in reality it isnt..

My screen is setup to write from

LEFT to Right then top to bottom like:
wrap-jpg.34920


So in VB im reading from left to right and top to bottom .. placing the data into a listbox and looping through the listbox (visual array)

I divide each pixel RGB by 17 so 255 == 15 (aka 0x0F) which is the max for each RGB (0xFFF)

Now i get black pretty good but i get sukish results with the rest... here is my 50x50 image i want to convert: (i had to convert to jpg to place here)
colors-jpg.34922


VB Code:
Code:
Private OnBits(0 To 31) As Long

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, _
    ByVal y As Long) As Long


    Dim Red As Byte
   Dim Green As Byte
   Dim Blue As Byte
    Dim Color As Long

Public Function LShiftLong(ByVal Value As Long, _
    ByVal Shift As Integer) As Long
  
    MakeOnBits
  
    If (Value And (2 ^ (31 - Shift))) Then GoTo OverFlow
  
    LShiftLong = ((Value And OnBits(31 - Shift)) * (2 ^ Shift))
  
    Exit Function

OverFlow:
  
    LShiftLong = ((Value And OnBits(31 - (Shift + 1))) * _
       (2 ^ (Shift))) Or &H80000000
  
End Function

Public Function RShiftLong(ByVal Value As Long, _
   ByVal Shift As Integer) As Long
    Dim hi As Long
    MakeOnBits
    If (Value And &H80000000) Then hi = &H40000000
  
    RShiftLong = (Value And &H7FFFFFFE) \ (2 ^ Shift)
    RShiftLong = (RShiftLong Or (hi \ (2 ^ (Shift - 1))))
End Function
 


Private Sub MakeOnBits()
    Dim j As Integer, _
        v As Long
  
    For j = 0 To 30
  
        v = v + (2 ^ j)
        OnBits(j) = v
  
    Next j
  
    OnBits(j) = v + &H80000000

End Sub

Private Sub Command1_Click()
'The following code example counts the number of red pixels on the active form:
' assumes that form's ScaleMode
' is set to 3 - Pixels
Text2 = ""
Text4 = ""
Text3 = ""
Dim x As Long, y As Long
Dim h As Long, count As Long
Dim q As Long, w As Long
Dim tmp As Integer
Dim tmpf As Integer
' cache form's hDC property
h = Picture1.hdc

'For y = 0 To Picture1.ScaleHeight - 1
'    For x = 0 To Picture1.ScaleWidth - 1
Dim hMax As Integer, wMax As Integer
hMax = Picture1.ScaleHeight - 1
wMax = Picture1.ScaleWidth - 1

For y = 0 To hMax
    For x = 0 To wMax
        Color = GetPixel(h, x, y)
        Red = Color And &HFF&                    'mind the ampersand at the end of constant
        Green = (Color And &HFF00&) / 256        'bit masking and "shift"
        Blue = (Color And &HFF0000) / 65535      'bit masking and "shift"

        Red = Red / 17
        Green = Green / 17
        Blue = Blue / 17
                
        List1.AddItem Red
        List1.AddItem Green
        List1.AddItem Blue
        
        Text2.Text = Text2.Text & Red & "-" & Green & "-" & Blue & ", "
    Next
Next

h = List1.ListCount - 1
If h Mod 2 = 1 Then List1.AddItem 0
count = List1.ListCount / 2

h = List1.ListCount - 1


For y = 0 To List1.ListCount - 1
    tmpf = 0
    
    For x = 0 To 1
        tmpf = tmpf Or Val(List1.List(y + x))
              
        If tmpf > 9 Then
            Select Case List1.List(y + x)
                Case 10
                    tmpf = tmpf Or &HA
                Case 11
                    tmpf = tmpf Or &HB
                Case 12
                    tmpf = tmpf Or &HC
                Case 13
                    tmpf = tmpf Or &HD
                Case 14
                    tmpf = tmpf Or &HE
                Case 15
                    tmpf = tmpf Or &HF
            End Select
        End If
        If x = 0 Then
            tmpf = LShiftLong(tmpf, 4)
        End If
    Next x
    y = y + 2
    List2.AddItem tmpf
Next y
Text3 = Str(List1.ListCount - 1)
Text4 = Str(List2.ListCount - 1)
End Sub

Private Sub List1_Click()
Dim x As Integer, y As Integer
Text2.Text = ""
For x = 0 To List1.ListCount - 1
    Text2.Text = Text2.Text & List1.List(x) & ","
        y = y + 1
        If y = 40 Then
            y = 0
            Text2.Text = Text2.Text & vbNewLine
        End If
Next x

Text2.Text = Mid$(Text2.Text, 1, (Len(Text2.Text) - 1))

End Sub

Private Sub List2_Click()
Dim x As Integer, y As Integer
Text2.Text = ""
For x = 0 To List2.ListCount - 1
    Text2.Text = Text2.Text & List2.List(x) & ","
    y = y + 1
        If y = 40 Then
            y = 0
            Text2.Text = Text2.Text & vbNewLine
        End If
Next x

Text2.Text = Mid$(Text2.Text, 1, (Len(Text2.Text) - 1))

End Sub

Private Sub Picture1_Click()
Picture1.Picture = LoadPicture("d:\colors.bmp")
End Sub
 

Attachments

  • wrap.jpg
    wrap.jpg
    68.7 KB · Views: 538
  • colors.jpg
    colors.jpg
    798 bytes · Views: 559
...

I divide each pixel RGB by 17 so 255 == 15 (aka 0x0F) which is the max for each RGB (0xFFF)
...

To convert the pixel properly from 0-255 range down to 0-15 range, use this;
Code:
unsigned char newpixel;   // 8bit var is ok
unsigned int temp;    // must be 16bit var!

  temp = (pixel + 8);
  newpixel = (temp / 16);

The operation of adding half the divisor then dividing will give you the best colour match (ie least possible error).
 
Top line looks ok, then you get a 45 degree angle so you have a 1 pixel error on each line.

Check your line length values, and for loops etc. Could be a -1 in the wrong spot... ;)
 
The main program... can someone test it out for me to see if it works well on other computers. Like does it seem to work well heh

Tiny Version (NO VB6 RUNTIME FILES INCLUDED) (9kb ZIP)
**broken link removed**

Full Version (VB6 RUNTIME FILES INCLUDED) (1,179kb ZIP)
**broken link removed**



EDIT: Just noticed they were making txt files instead of h (headers) so i just fixed it and re-uploaded it

heh was bored....

yay-jpg.34929



Looks way better live
 

Attachments

  • yay.jpg
    yay.jpg
    352.8 KB · Views: 647
Last edited:
I am currently Cleaning up the code and will post a full source and schematic and VB program all in one. This way people can use it.

The VB source will not be shared until i fix it up more...

Also i will be adding the ability to select between 8, 12 and 16 bit color for LCD image conversion and code soon.
 
so if i needed to make a RGB pixel to 8 bit LCD which is RRRGGGBB can i simply
Code:
unsigned char newpixel;   // 8bit var is ok
unsigned int temp;    // must be 16bit var!

  temp = (RED);
  newRED = (temp / (255/7));

  temp = (GREEN);
  newGREEN = (temp / (255/7));

  temp = (BLUE);
  newBLUE = (temp / (255/3));

//NewPixel 8 Bit would be shifted like:

newpixel= (NewRED<<4) | (NewGREEN<<2) | NewBLUE;

Would it be something like that?
 
Last edited:
That makes even less sense atom....
RGB....
All 00s == black. All FFs == white. There should be no separate bytes other than R G and B.

White made of R=255 + G=255 + B=255 / 8bit+8bit+8bit= 24 bit
Each color has 256 level, 0=off, 127 on 50%, 255 on 100%
He use half of it R max 15+ G max 15+ B max 15 / 4bit+4bit+4bit=12 bit
FF white only if you change all 3 channel "RGB" to FF

Csaba
 
Ok too much work for 16 bit and will waste to much space on pic to be usefull i think heh

Here is a pic of the new version of the VB6 program.

6100conv-jpg.34982


working on adding the 8 bit stuff to pic code. Should be easy
 

Attachments

  • 6100Conv.jpg
    6100Conv.jpg
    207.4 KB · Views: 581
Last edited:
for now i will leave this as is 12bit and PIC only. I have no need to make it otherwise...

I will be working on storage needs now. SD+FAT... New idea and stuff comes to mind.
 
Hey guys this is eating up quite a bit of my time so i am omitting the 16bit part but the 8 and 12 bit works 100% and i also made a Color conversion part to this so you can convert colors from RGB to 8, 12 and 16 bit version based on this LCD of course


v3-jpg.35008
 

Attachments

  • v3.jpg
    v3.jpg
    170.8 KB · Views: 539
You can get around bit depth in some specific applications by using a palleted image format, does the display support pallets? It's the simplest form of compression.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top