mirror of
https://github.com/dborth/vbagx.git
synced 2024-12-26 10:41:50 +01:00
optimizations (dcn)
This commit is contained in:
parent
058ac87b86
commit
fee8667d9e
@ -28,8 +28,6 @@
|
||||
CtrlrMap ctrlr_def[5] = {
|
||||
// Gamecube controller btn def
|
||||
{
|
||||
CTRLR_GCPAD,
|
||||
13,
|
||||
{
|
||||
{PAD_BUTTON_DOWN, "DOWN"},
|
||||
{PAD_BUTTON_UP, "UP"},
|
||||
@ -46,12 +44,12 @@ CtrlrMap ctrlr_def[5] = {
|
||||
{PAD_TRIGGER_Z, "Z"},
|
||||
{0, ""},
|
||||
{0, ""}
|
||||
}
|
||||
},
|
||||
13,
|
||||
CTRLR_GCPAD
|
||||
},
|
||||
// Wiimote btn def
|
||||
{
|
||||
CTRLR_WIIMOTE,
|
||||
11,
|
||||
{
|
||||
{WPAD_BUTTON_DOWN, "DOWN"},
|
||||
{WPAD_BUTTON_UP, "UP"},
|
||||
@ -68,12 +66,12 @@ CtrlrMap ctrlr_def[5] = {
|
||||
{0, ""},
|
||||
{0, ""},
|
||||
{0, ""}
|
||||
}
|
||||
},
|
||||
11,
|
||||
CTRLR_WIIMOTE
|
||||
},
|
||||
// Nunchuk btn def
|
||||
{
|
||||
CTRLR_NUNCHUK,
|
||||
13,
|
||||
{
|
||||
{WPAD_BUTTON_DOWN, "DOWN"},
|
||||
{WPAD_BUTTON_UP, "UP"},
|
||||
@ -90,12 +88,12 @@ CtrlrMap ctrlr_def[5] = {
|
||||
{WPAD_NUNCHUK_BUTTON_C, "C"},
|
||||
{0, ""},
|
||||
{0, ""}
|
||||
}
|
||||
},
|
||||
13,
|
||||
CTRLR_NUNCHUK
|
||||
},
|
||||
// Classic btn def
|
||||
{
|
||||
CTRLR_CLASSIC,
|
||||
15,
|
||||
{
|
||||
{WPAD_CLASSIC_BUTTON_DOWN, "DOWN"},
|
||||
{WPAD_CLASSIC_BUTTON_UP, "UP"},
|
||||
@ -112,12 +110,12 @@ CtrlrMap ctrlr_def[5] = {
|
||||
{WPAD_CLASSIC_BUTTON_FULL_R, "R"},
|
||||
{WPAD_CLASSIC_BUTTON_ZL, "ZL"},
|
||||
{WPAD_CLASSIC_BUTTON_ZR, "ZR"}
|
||||
}
|
||||
},
|
||||
15,
|
||||
CTRLR_CLASSIC
|
||||
},
|
||||
// Keyboard btn def
|
||||
{
|
||||
CTRLR_KEYBOARD,
|
||||
66,
|
||||
{
|
||||
{KS_A, "A"},
|
||||
{KS_B, "B"},
|
||||
@ -185,6 +183,8 @@ CtrlrMap ctrlr_def[5] = {
|
||||
{MOUSEL, "MOUSEL"},
|
||||
{MOUSER, "MOUSER"},
|
||||
{MOUSEM, "MOUSEM"}
|
||||
}
|
||||
},
|
||||
66,
|
||||
CTRLR_KEYBOARD
|
||||
}
|
||||
};
|
||||
|
@ -29,9 +29,9 @@ typedef struct _btn_map {
|
||||
} BtnMap;
|
||||
|
||||
typedef struct _ctrlr_map {
|
||||
u16 type; // controller type
|
||||
BtnMap map[150]; // controller button map
|
||||
int num_btns; // number of buttons on the controller
|
||||
BtnMap map[150]; // controller button map
|
||||
u16 type; // controller type
|
||||
} CtrlrMap;
|
||||
|
||||
// externs:
|
||||
|
@ -223,11 +223,11 @@ class GuiTrigger
|
||||
//!\return true if selection should be moved down, false otherwise
|
||||
bool Down();
|
||||
|
||||
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
|
||||
s32 chan; //!< Trigger controller channel (0-3, -1 for all)
|
||||
WPADData * wpad; //!< Wii controller trigger
|
||||
WPADData wpaddata; //!< Wii controller trigger data
|
||||
PADData pad; //!< GameCube controller trigger data
|
||||
WPADData * wpad; //!< Wii controller trigger
|
||||
s32 chan; //!< Trigger controller channel (0-3, -1 for all)
|
||||
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
|
||||
};
|
||||
|
||||
extern GuiTrigger userInput[4];
|
||||
@ -399,7 +399,9 @@ class GuiElement
|
||||
//!Called constantly to redraw the element
|
||||
virtual void Draw();
|
||||
protected:
|
||||
bool visible; //!< Visibility of the element. If false, Draw() is skipped
|
||||
GuiTrigger * trigger[2]; //!< GuiTriggers (input actions) that this element responds to
|
||||
UpdateCallback updateCB; //!< Callback function to call when this element is updated
|
||||
GuiElement * parentElement; //!< Parent element
|
||||
int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
|
||||
int width; //!< Element width
|
||||
int height; //!< Element height
|
||||
@ -412,10 +414,9 @@ class GuiElement
|
||||
int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects)
|
||||
int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects)
|
||||
int alpha; //!< Element alpha value (0-255)
|
||||
f32 scale; //!< Element scale (1 = 100%)
|
||||
int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
|
||||
f32 scale; //!< Element scale (1 = 100%)
|
||||
f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects)
|
||||
bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event
|
||||
int effects; //!< Currently enabled effect(s). 0 when no effects are enabled
|
||||
int effectAmount; //!< Effect amount. Used by different effects for different purposes
|
||||
int effectTarget; //!< Effect target amount. Used by different effects for different purposes
|
||||
@ -429,9 +430,8 @@ class GuiElement
|
||||
bool selectable; //!< Whether or not this element selectable (can change to SELECTED state)
|
||||
bool clickable; //!< Whether or not this element is clickable (can change to CLICKED state)
|
||||
bool holdable; //!< Whether or not this element is holdable (can change to HELD state)
|
||||
GuiTrigger * trigger[2]; //!< GuiTriggers (input actions) that this element responds to
|
||||
GuiElement * parentElement; //!< Parent element
|
||||
UpdateCallback updateCB; //!< Callback function to call when this element is updated
|
||||
bool visible; //!< Visibility of the element. If false, Draw() is skipped
|
||||
bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event
|
||||
};
|
||||
|
||||
//!Allows GuiElements to be grouped together into a "window"
|
||||
@ -650,18 +650,18 @@ class GuiText : public GuiElement
|
||||
//!Constantly called to draw the text
|
||||
void Draw();
|
||||
protected:
|
||||
char * origText; //!< Original text data
|
||||
GXColor color; //!< Font color
|
||||
wchar_t* text; //!< Unicode text value
|
||||
wchar_t* textDyn; //!< Wrapped text value
|
||||
char * origText; //!< Original text data
|
||||
int size; //!< Font size
|
||||
int maxWidth; //!< Maximum width of the generated text object (for text wrapping)
|
||||
bool wrap; //!< Wrapping toggle
|
||||
wchar_t* textDyn; //!< Wrapped text value
|
||||
int textScroll; //!< Scrolling toggle
|
||||
int textScrollPos; //!< Current starting index of text string for scrolling
|
||||
int textScrollInitialDelay; //!< Delay to wait before starting to scroll
|
||||
int textScrollDelay; //!< Scrolling speed
|
||||
u16 style; //!< FreeTypeGX style attributes
|
||||
GXColor color; //!< Font color
|
||||
bool wrap; //!< Wrapping toggle
|
||||
};
|
||||
|
||||
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
|
||||
@ -760,7 +760,6 @@ class GuiKeyboard : public GuiWindow
|
||||
char kbtextstr[256];
|
||||
protected:
|
||||
u32 kbtextmaxlen;
|
||||
Key keys[4][11];
|
||||
int shift;
|
||||
int caps;
|
||||
GuiText * kbText;
|
||||
@ -794,6 +793,7 @@ class GuiKeyboard : public GuiWindow
|
||||
GuiSound * keySoundOver;
|
||||
GuiSound * keySoundClick;
|
||||
GuiTrigger * trigA;
|
||||
Key keys[4][11]; // two chars = less space than one pointer
|
||||
};
|
||||
|
||||
typedef struct _optionlist {
|
||||
@ -818,16 +818,15 @@ class GuiOptionBrowser : public GuiElement
|
||||
void Update(GuiTrigger * t);
|
||||
GuiText * optionVal[PAGESIZE];
|
||||
protected:
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
bool listChanged;
|
||||
|
||||
OptionList * options;
|
||||
int optionIndex[PAGESIZE];
|
||||
GuiButton * optionBtn[PAGESIZE];
|
||||
GuiText * optionTxt[PAGESIZE];
|
||||
GuiImage * optionBg[PAGESIZE];
|
||||
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
OptionList * options;
|
||||
|
||||
GuiButton * arrowUpBtn;
|
||||
GuiButton * arrowDownBtn;
|
||||
|
||||
@ -849,6 +848,8 @@ class GuiOptionBrowser : public GuiElement
|
||||
GuiSound * btnSoundOver;
|
||||
GuiSound * btnSoundClick;
|
||||
GuiTrigger * trigA;
|
||||
|
||||
bool listChanged;
|
||||
};
|
||||
|
||||
typedef struct _savelist {
|
||||
@ -874,10 +875,8 @@ class GuiSaveBrowser : public GuiElement
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int action;
|
||||
bool saveBtnLastOver[SAVELISTSIZE];
|
||||
|
||||
int listOffset;
|
||||
SaveList * saves;
|
||||
GuiButton * saveBtn[SAVELISTSIZE];
|
||||
GuiText * saveDate[SAVELISTSIZE];
|
||||
@ -909,6 +908,8 @@ class GuiSaveBrowser : public GuiElement
|
||||
GuiSound * btnSoundOver;
|
||||
GuiSound * btnSoundClick;
|
||||
GuiTrigger * trigA;
|
||||
|
||||
bool saveBtnLastOver[SAVELISTSIZE];
|
||||
};
|
||||
|
||||
//!Display a list of files
|
||||
@ -924,10 +925,6 @@ class GuiFileBrowser : public GuiElement
|
||||
void Update(GuiTrigger * t);
|
||||
GuiButton * fileList[FILE_PAGESIZE];
|
||||
protected:
|
||||
int selectedItem;
|
||||
int numEntries;
|
||||
bool listChanged;
|
||||
|
||||
GuiText * fileListText[FILE_PAGESIZE];
|
||||
GuiImage * fileListBg[FILE_PAGESIZE];
|
||||
GuiImage * fileListIcon[FILE_PAGESIZE];
|
||||
@ -964,6 +961,10 @@ class GuiFileBrowser : public GuiElement
|
||||
GuiSound * btnSoundClick;
|
||||
GuiTrigger * trigA;
|
||||
GuiTrigger * trigHeldA;
|
||||
|
||||
int selectedItem;
|
||||
int numEntries;
|
||||
bool listChanged;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -130,23 +130,48 @@ void GuiButton::Draw()
|
||||
if(!this->IsVisible())
|
||||
return;
|
||||
|
||||
// draw image
|
||||
if((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
|
||||
imageOver->Draw();
|
||||
else if(image)
|
||||
image->Draw();
|
||||
// draw icon
|
||||
if((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
|
||||
iconOver->Draw();
|
||||
else if(icon)
|
||||
icon->Draw();
|
||||
// draw text
|
||||
for(int i=0; i<3; i++)
|
||||
if(state == STATE_SELECTED || state == STATE_HELD)
|
||||
{
|
||||
if((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i])
|
||||
labelOver[i]->Draw();
|
||||
else if(label[i])
|
||||
label[i]->Draw();
|
||||
if(imageOver)
|
||||
imageOver->Draw();
|
||||
else if(image) // draw image
|
||||
image->Draw();
|
||||
|
||||
if(iconOver)
|
||||
iconOver->Draw();
|
||||
else if(icon) // draw icon
|
||||
icon->Draw();
|
||||
|
||||
// draw text
|
||||
if(labelOver[0])
|
||||
labelOver[0]->Draw();
|
||||
else if(label[0])
|
||||
label[0]->Draw();
|
||||
|
||||
if(labelOver[1])
|
||||
labelOver[1]->Draw();
|
||||
else if(label[1])
|
||||
label[1]->Draw();
|
||||
|
||||
if(labelOver[2])
|
||||
labelOver[2]->Draw();
|
||||
else if(label[2])
|
||||
label[2]->Draw();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(image) // draw image
|
||||
image->Draw();
|
||||
if(icon) // draw icon
|
||||
icon->Draw();
|
||||
|
||||
// draw text
|
||||
if(label[0])
|
||||
label[0]->Draw();
|
||||
if(label[1])
|
||||
label[1]->Draw();
|
||||
if(label[2])
|
||||
label[2]->Draw();
|
||||
}
|
||||
|
||||
this->UpdateEffects();
|
||||
|
@ -91,7 +91,7 @@ int GuiElement::GetLeft()
|
||||
x = pLeft;
|
||||
break;
|
||||
case ALIGN_CENTRE:
|
||||
x = pLeft + (pWidth/2) - (width/2);
|
||||
x = pLeft + (pWidth>>1) - (width>>1);
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
x = pLeft + pWidth - width;
|
||||
@ -121,7 +121,7 @@ int GuiElement::GetTop()
|
||||
y = pTop;
|
||||
break;
|
||||
case ALIGN_MIDDLE:
|
||||
y = pTop + (pHeight/2) - (height/2);
|
||||
y = pTop + (pHeight>>1) - (height>>1);
|
||||
break;
|
||||
case ALIGN_BOTTOM:
|
||||
y = pTop + pHeight - height;
|
||||
@ -204,15 +204,13 @@ void GuiElement::SetAlpha(int a)
|
||||
|
||||
int GuiElement::GetAlpha()
|
||||
{
|
||||
int a;
|
||||
int a = alpha;
|
||||
|
||||
if(alphaDyn >= 0)
|
||||
a = alphaDyn;
|
||||
else
|
||||
a = alpha;
|
||||
|
||||
if(parentElement)
|
||||
a *= parentElement->GetAlpha()/255.0;
|
||||
a *= float(parentElement->GetAlpha())/255.0f;
|
||||
|
||||
return a;
|
||||
}
|
||||
@ -352,13 +350,12 @@ void GuiElement::SetEffect(int eff, int amount, int target)
|
||||
else if(eff & EFFECT_SLIDE_RIGHT)
|
||||
xoffsetDyn = screenwidth;
|
||||
}
|
||||
if(eff & EFFECT_FADE && amount > 0)
|
||||
if(eff & EFFECT_FADE)
|
||||
{
|
||||
alphaDyn = 0;
|
||||
}
|
||||
else if(eff & EFFECT_FADE && amount < 0)
|
||||
{
|
||||
alphaDyn = alpha;
|
||||
if(amount > 0)
|
||||
alphaDyn = 0;
|
||||
else if(amount < 0)
|
||||
alphaDyn = alpha;
|
||||
}
|
||||
|
||||
effects |= eff;
|
||||
@ -474,12 +471,13 @@ void GuiElement::UpdateEffects()
|
||||
}
|
||||
if(effects & EFFECT_SCALE)
|
||||
{
|
||||
scaleDyn += effectAmount/100.0;
|
||||
scaleDyn += f32(effectAmount)*0.01f;
|
||||
f32 effTar100 = f32(effectTarget)*0.01f;
|
||||
|
||||
if((effectAmount < 0 && scaleDyn <= effectTarget/100.0)
|
||||
|| (effectAmount > 0 && scaleDyn >= effectTarget/100.0))
|
||||
if((effectAmount < 0 && scaleDyn <= effTar100)
|
||||
|| (effectAmount > 0 && scaleDyn >= effTar100))
|
||||
{
|
||||
scaleDyn = effectTarget/100.0;
|
||||
scaleDyn = effTar100;
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
}
|
||||
@ -522,8 +520,8 @@ void GuiElement::Draw()
|
||||
|
||||
bool GuiElement::IsInside(int x, int y)
|
||||
{
|
||||
if(x > this->GetLeft() && x < (this->GetLeft()+width)
|
||||
&& y > this->GetTop() && y < (this->GetTop()+height))
|
||||
if(unsigned(x - this->GetLeft()) < unsigned(width)
|
||||
&& unsigned(y - this->GetTop()) < unsigned(height))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ GuiFileBrowser::GuiFileBrowser(int w, int h)
|
||||
scrollbarBoxBtn->SetHoldable(true);
|
||||
scrollbarBoxBtn->SetTrigger(trigHeldA);
|
||||
|
||||
for(int i=0; i<FILE_PAGESIZE; i++)
|
||||
for(int i=0; i<FILE_PAGESIZE; ++i)
|
||||
{
|
||||
fileListText[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
|
||||
fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
@ -211,7 +211,7 @@ void GuiFileBrowser::Draw()
|
||||
|
||||
bgFileSelectionImg->Draw();
|
||||
|
||||
for(int i=0; i<FILE_PAGESIZE; i++)
|
||||
for(u32 i=0; i<FILE_PAGESIZE; ++i)
|
||||
{
|
||||
fileList[i]->Draw();
|
||||
}
|
||||
@ -251,7 +251,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
|
||||
else if(positionWiimote > scrollbarBoxBtn->GetMaxY())
|
||||
positionWiimote = scrollbarBoxBtn->GetMaxY();
|
||||
|
||||
browser.pageIndex = (positionWiimote * browser.numEntries)/156.0 - selectedItem;
|
||||
browser.pageIndex = (positionWiimote * browser.numEntries)/156.0f - selectedItem;
|
||||
|
||||
if(browser.pageIndex <= 0)
|
||||
{
|
||||
@ -312,7 +312,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
|
||||
if(selectedItem == FILE_PAGESIZE-1)
|
||||
{
|
||||
// move list down by 1
|
||||
browser.pageIndex++;
|
||||
++browser.pageIndex;
|
||||
listChanged = true;
|
||||
}
|
||||
else if(fileList[selectedItem+1]->IsVisible())
|
||||
@ -327,7 +327,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
|
||||
if(selectedItem == 0 && browser.pageIndex + selectedItem > 0)
|
||||
{
|
||||
// move list up by 1
|
||||
browser.pageIndex--;
|
||||
--browser.pageIndex;
|
||||
listChanged = true;
|
||||
}
|
||||
else if(selectedItem > 0)
|
||||
@ -339,7 +339,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
|
||||
|
||||
endNavigation:
|
||||
|
||||
for(int i=0; i<FILE_PAGESIZE; i++)
|
||||
for(int i=0; i<FILE_PAGESIZE; ++i)
|
||||
{
|
||||
if(listChanged || numEntries != browser.numEntries)
|
||||
{
|
||||
@ -414,20 +414,24 @@ void GuiFileBrowser::Update(GuiTrigger * t)
|
||||
}
|
||||
|
||||
// update the location of the scroll box based on the position in the file list
|
||||
if(positionWiimote > 0 || listChanged || numEntries != browser.numEntries)
|
||||
if(positionWiimote > 0)
|
||||
{
|
||||
if(positionWiimote > 0)
|
||||
position = positionWiimote; // follow wiimote cursor
|
||||
scrollbarBoxBtn->SetPosition(0,position+36);
|
||||
}
|
||||
else if(listChanged || numEntries != browser.numEntries)
|
||||
{
|
||||
if(float((browser.pageIndex<<1))/(float(FILE_PAGESIZE)) < 1.0)
|
||||
{
|
||||
position = positionWiimote; // follow wiimote cursor
|
||||
position = 0;
|
||||
}
|
||||
else if(browser.pageIndex+FILE_PAGESIZE >= browser.numEntries)
|
||||
{
|
||||
position = 156;
|
||||
}
|
||||
else
|
||||
{
|
||||
position = 156*(browser.pageIndex + FILE_PAGESIZE/2.0) / (browser.numEntries*1.0);
|
||||
|
||||
if(browser.pageIndex/(FILE_PAGESIZE/2.0) < 1)
|
||||
position = 0;
|
||||
else if((browser.pageIndex+FILE_PAGESIZE)/(FILE_PAGESIZE*1.0) >= (browser.numEntries)/(FILE_PAGESIZE*1.0))
|
||||
position = 156;
|
||||
position = 156* (int((float(browser.pageIndex) + float(FILE_PAGESIZE)*0.5f) / (float(browser.numEntries))));
|
||||
}
|
||||
scrollbarBoxBtn->SetPosition(0,position+36);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ GuiImage::GuiImage(u8 * img, int w, int h)
|
||||
|
||||
GuiImage::GuiImage(int w, int h, GXColor c)
|
||||
{
|
||||
image = (u8 *)memalign (32, w * h * 4);
|
||||
image = (u8 *)memalign (32, w * h << 2);
|
||||
width = w;
|
||||
height = h;
|
||||
imageangle = 0;
|
||||
@ -66,14 +66,14 @@ GuiImage::GuiImage(int w, int h, GXColor c)
|
||||
|
||||
int x, y;
|
||||
|
||||
for(y=0; y < h; y++)
|
||||
for(y=0; y < h; ++y)
|
||||
{
|
||||
for(x=0; x < w; x++)
|
||||
for(x=0; x < w; ++x)
|
||||
{
|
||||
this->SetPixel(x, y, c);
|
||||
}
|
||||
}
|
||||
int len = w*h*4;
|
||||
int len = w * h << 2;
|
||||
if(len%32) len += (32-len%32);
|
||||
DCFlushRange(image, len);
|
||||
}
|
||||
@ -157,21 +157,24 @@ void GuiImage::SetStripe(int s)
|
||||
|
||||
void GuiImage::ColorStripe(int shift)
|
||||
{
|
||||
int x, y;
|
||||
GXColor color;
|
||||
int x, y=0;
|
||||
int alt = 0;
|
||||
|
||||
int thisHeight = this->GetHeight();
|
||||
int thisWidth = this->GetWidth();
|
||||
|
||||
for(y=0; y < this->GetHeight(); y++)
|
||||
for(; y < thisHeight; ++y)
|
||||
{
|
||||
if(y % 3 == 0)
|
||||
alt ^= 1;
|
||||
|
||||
for(x=0; x < this->GetWidth(); x++)
|
||||
if(alt)
|
||||
{
|
||||
color = GetPixel(x, y);
|
||||
|
||||
if(alt)
|
||||
for(x=0; x < thisWidth; ++x)
|
||||
{
|
||||
color = GetPixel(x, y);
|
||||
|
||||
if(color.r < 255-shift)
|
||||
color.r += shift;
|
||||
else
|
||||
@ -186,9 +189,15 @@ void GuiImage::ColorStripe(int shift)
|
||||
color.b = 255;
|
||||
|
||||
color.a = 255;
|
||||
SetPixel(x, y, color);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
for(x=0; x < thisWidth; ++x)
|
||||
{
|
||||
color = GetPixel(x, y);
|
||||
|
||||
if(color.r > shift)
|
||||
color.r -= shift;
|
||||
else
|
||||
@ -203,8 +212,8 @@ void GuiImage::ColorStripe(int shift)
|
||||
color.b = 0;
|
||||
|
||||
color.a = 255;
|
||||
SetPixel(x, y, color);
|
||||
}
|
||||
SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -219,24 +228,31 @@ void GuiImage::Draw()
|
||||
|
||||
float currScale = this->GetScale();
|
||||
int currLeft = this->GetLeft();
|
||||
int thisTop = this->GetTop();
|
||||
|
||||
if(tile > 0)
|
||||
{
|
||||
for(int i=0; i<tile; i++)
|
||||
Menu_DrawImg(currLeft+width*i, this->GetTop(), width, height, image, imageangle, currScale, currScale, this->GetAlpha());
|
||||
int alpha = this->GetAlpha();
|
||||
for(int i=0; i<tile; ++i)
|
||||
{
|
||||
Menu_DrawImg(currLeft+width*i, thisTop, width, height, image, imageangle, currScale, currScale, alpha);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// temporary (maybe), used to correct offset for scaled images
|
||||
if(scale != 1)
|
||||
currLeft = currLeft - width/2 + (width*scale)/2;
|
||||
currLeft += (width*(scale - 1))/2;
|
||||
|
||||
Menu_DrawImg(currLeft, this->GetTop(), width, height, image, imageangle, currScale, currScale, this->GetAlpha());
|
||||
Menu_DrawImg(currLeft, thisTop, width, height, image, imageangle, currScale, currScale, this->GetAlpha());
|
||||
}
|
||||
|
||||
if(stripe > 0)
|
||||
for(int y=0; y < this->GetHeight(); y+=6)
|
||||
Menu_DrawRectangle(currLeft,this->GetTop()+y,this->GetWidth(),3,(GXColor){0, 0, 0, stripe},1);
|
||||
|
||||
{
|
||||
int thisHeight = this->GetHeight();
|
||||
int thisWidth = this->GetWidth();
|
||||
for(int y=0; y < thisHeight; y+=6)
|
||||
Menu_DrawRectangle(currLeft,thisTop+y,thisWidth,3,(GXColor){0, 0, 0, stripe},1);
|
||||
}
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ GuiImageData::GuiImageData(const u8 * i)
|
||||
|
||||
if(res == PNGU_OK)
|
||||
{
|
||||
int len = imgProp.imgWidth * imgProp.imgHeight * 4;
|
||||
int len = (imgProp.imgWidth * imgProp.imgHeight) <<2;
|
||||
if(len%32) len += (32-len%32);
|
||||
data = (u8 *)memalign (32, len);
|
||||
|
||||
|
@ -211,7 +211,7 @@ void GuiOptionBrowser::Draw()
|
||||
|
||||
int next = listOffset;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
for(int i=0; i<PAGESIZE; ++i)
|
||||
{
|
||||
if(next >= 0)
|
||||
{
|
||||
@ -249,7 +249,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
|
||||
if(listChanged)
|
||||
{
|
||||
listChanged = false;
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
for(int i=0; i<PAGESIZE; ++i)
|
||||
{
|
||||
if(next >= 0)
|
||||
{
|
||||
@ -272,7 +272,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
for(int i=0; i<PAGESIZE; ++i)
|
||||
{
|
||||
if(i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
optionBtn[i]->ResetState();
|
||||
@ -311,7 +311,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
|
||||
{
|
||||
optionBtn[selectedItem]->ResetState();
|
||||
optionBtn[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
|
||||
selectedItem++;
|
||||
++selectedItem;
|
||||
}
|
||||
}
|
||||
arrowDownBtn->ResetState();
|
||||
@ -332,7 +332,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
|
||||
{
|
||||
optionBtn[selectedItem]->ResetState();
|
||||
optionBtn[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
|
||||
selectedItem--;
|
||||
--selectedItem;
|
||||
}
|
||||
}
|
||||
arrowUpBtn->ResetState();
|
||||
|
@ -107,7 +107,7 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a)
|
||||
saveBtn[i]->SetImageOver(saveBgOverImg[i]);
|
||||
saveBtn[i]->SetIcon(savePreviewImg[i]);
|
||||
saveBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
saveBtn[i]->SetPosition(257*(i % 2),87*(i/2));
|
||||
saveBtn[i]->SetPosition(257*(i % 2),87*(i>>1));
|
||||
saveBtn[i]->SetTrigger(trigA);
|
||||
saveBtn[i]->SetState(STATE_DISABLED);
|
||||
saveBtn[i]->SetEffectGrow();
|
||||
@ -257,7 +257,7 @@ void GuiSaveBrowser::Update(GuiTrigger * t)
|
||||
if(selectedItem == 0)
|
||||
{
|
||||
if((listOffset - 2 >= 0 && action == 0) ||
|
||||
(listOffset - 2 >= -2 && action == 1))
|
||||
(listOffset >= 0 && action == 1))
|
||||
{
|
||||
// move list up by 1
|
||||
listOffset -= 2;
|
||||
@ -295,7 +295,7 @@ void GuiSaveBrowser::Update(GuiTrigger * t)
|
||||
if(selectedItem < 2)
|
||||
{
|
||||
if((listOffset - 2 >= 0 && action == 0) ||
|
||||
(listOffset - 2 >= -2 && action == 1))
|
||||
(listOffset >= 0 && action == 1))
|
||||
{
|
||||
// move list up by 1
|
||||
listOffset -= 2;
|
||||
|
@ -42,7 +42,7 @@ void GuiSound::Play()
|
||||
switch(type)
|
||||
{
|
||||
case SOUND_PCM:
|
||||
vol = 255*(volume/100.0)*(GCSettings.SFXVolume/100.0);
|
||||
vol = 2.55f*(volume*GCSettings.SFXVolume);
|
||||
voice = ASND_GetFirstUnusedVoice();
|
||||
if(voice >= 0)
|
||||
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 48000, 0,
|
||||
@ -55,7 +55,7 @@ void GuiSound::Play()
|
||||
PlayOgg((char *)sound, length, 0, OGG_INFINITE_TIME);
|
||||
else
|
||||
PlayOgg((char *)sound, length, 0, OGG_ONE_TIME);
|
||||
SetVolumeOgg(255*(volume/100.0));
|
||||
SetVolumeOgg(2.55f*(volume));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@ -134,7 +134,7 @@ void GuiSound::SetVolume(int vol)
|
||||
if(voice < 0)
|
||||
return;
|
||||
|
||||
int newvol = 255*(volume/100.0)*(GCSettings.SFXVolume/100.0);
|
||||
int newvol = 2.55f*(volume*GCSettings.SFXVolume);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
@ -143,7 +143,7 @@ void GuiSound::SetVolume(int vol)
|
||||
break;
|
||||
|
||||
case SOUND_OGG:
|
||||
SetVolumeOgg(255*(volume/100.0));
|
||||
SetVolumeOgg(2.55f*(volume));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
@ -10,13 +10,13 @@
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
static GXColor presetColor = (GXColor){255, 255, 255, 255};
|
||||
static int currentSize = 0;
|
||||
static int presetSize = 0;
|
||||
static int presetMaxWidth = 0;
|
||||
static int presetAlignmentHor = 0;
|
||||
static int presetAlignmentVert = 0;
|
||||
static u16 presetStyle = 0;
|
||||
static GXColor presetColor = (GXColor){255, 255, 255, 255};
|
||||
|
||||
#define TEXT_SCROLL_DELAY 8
|
||||
#define TEXT_SCROLL_INITIAL_DELAY 6
|
||||
@ -230,7 +230,7 @@ void GuiText::Draw()
|
||||
if(maxWidth > 0)
|
||||
{
|
||||
char * tmpText = strdup(origText);
|
||||
u8 maxChar = (maxWidth*2.0) / newSize;
|
||||
u8 maxChar = int((float((maxWidth<<1))) / (float(newSize)));
|
||||
|
||||
if(!textDyn)
|
||||
{
|
||||
@ -247,11 +247,11 @@ void GuiText::Draw()
|
||||
{
|
||||
if(textScrollInitialDelay)
|
||||
{
|
||||
textScrollInitialDelay--;
|
||||
--textScrollInitialDelay;
|
||||
}
|
||||
else
|
||||
{
|
||||
textScrollPos++;
|
||||
++textScrollPos;
|
||||
if(textScrollPos > textlen-1)
|
||||
{
|
||||
textScrollPos = 0;
|
||||
@ -306,12 +306,12 @@ void GuiText::Draw()
|
||||
lastSpace = -1; // we have used this space
|
||||
lastSpaceIndex = -1;
|
||||
}
|
||||
linenum++;
|
||||
++linenum;
|
||||
i = -1;
|
||||
}
|
||||
else if(ch == txtlen-1)
|
||||
{
|
||||
linenum++;
|
||||
++linenum;
|
||||
}
|
||||
}
|
||||
if(text[ch] == ' ' && i >= 0)
|
||||
@ -319,18 +319,21 @@ void GuiText::Draw()
|
||||
lastSpace = ch;
|
||||
lastSpaceIndex = i;
|
||||
}
|
||||
ch++;
|
||||
i++;
|
||||
++ch;
|
||||
++i;
|
||||
}
|
||||
|
||||
int voffset = 0;
|
||||
|
||||
if(alignmentVert == ALIGN_MIDDLE)
|
||||
voffset = -(lineheight*linenum)/2 + lineheight/2;
|
||||
voffset = (lineheight >> 1) * (1-linenum);
|
||||
|
||||
for(i=0; i < linenum; i++)
|
||||
int left = this->GetLeft();
|
||||
int top = this->GetTop() + voffset;
|
||||
|
||||
for(i=0; i < linenum; ++i)
|
||||
{
|
||||
fontSystem[currentSize]->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, textrow[i], c, style);
|
||||
fontSystem[currentSize]->drawText(left, top+i*lineheight, textrow[i], c, style);
|
||||
delete[] textrow[i];
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,8 @@ void GuiWindow::Remove(GuiElement* e)
|
||||
if (e == NULL)
|
||||
return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
if(e == _elements.at(i))
|
||||
{
|
||||
@ -85,7 +86,8 @@ void GuiWindow::Draw()
|
||||
if(_elements.size() == 0 || !this->IsVisible())
|
||||
return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try { _elements.at(i)->Draw(); }
|
||||
catch (const std::exception& e) { }
|
||||
@ -102,7 +104,8 @@ void GuiWindow::ResetState()
|
||||
if(state != STATE_DISABLED)
|
||||
state = STATE_DEFAULT;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try { _elements.at(i)->ResetState(); }
|
||||
catch (const std::exception& e) { }
|
||||
@ -113,7 +116,8 @@ void GuiWindow::SetState(int s)
|
||||
{
|
||||
state = s;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try { _elements.at(i)->SetState(s); }
|
||||
catch (const std::exception& e) { }
|
||||
@ -124,7 +128,8 @@ void GuiWindow::SetVisible(bool v)
|
||||
{
|
||||
visible = v;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try { _elements.at(i)->SetVisible(v); }
|
||||
catch (const std::exception& e) { }
|
||||
@ -146,7 +151,8 @@ void GuiWindow::ChangeFocus(GuiElement* e)
|
||||
if(parentElement)
|
||||
return; // this is only intended for the main window
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
if(e == _elements.at(i))
|
||||
_elements.at(i)->SetFocus(1);
|
||||
@ -162,10 +168,12 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
|
||||
|
||||
int found = -1;
|
||||
int newfocus = -1;
|
||||
u8 i;
|
||||
int i;
|
||||
|
||||
int elemSize = _elements.size();
|
||||
|
||||
// look for currently in focus element
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
for (i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -181,7 +189,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
|
||||
// element with focus not found, try to give focus
|
||||
if(found == -1)
|
||||
{
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
for (i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -198,7 +206,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
|
||||
else if(t->wpad->btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)
|
||||
|| t->pad.btns_d & PAD_BUTTON_B)
|
||||
{
|
||||
for (i = found; i < _elements.size(); i++)
|
||||
for (i = found; i < elemSize; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -215,7 +223,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
|
||||
|
||||
if(newfocus == -1)
|
||||
{
|
||||
for (i = 0; i < found; i++)
|
||||
for (i = 0; i < found; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -236,13 +244,14 @@ int GuiWindow::GetSelected()
|
||||
{
|
||||
// find selected element
|
||||
int found = -1;
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->GetState() == STATE_SELECTED)
|
||||
{
|
||||
found = i;
|
||||
found = int(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -258,7 +267,8 @@ void GuiWindow::MoveSelectionHor(int dir)
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
u32 i;
|
||||
u32 elemSize = _elements.size();
|
||||
|
||||
int selected = this->GetSelected();
|
||||
|
||||
@ -268,8 +278,9 @@ void GuiWindow::MoveSelectionHor(int dir)
|
||||
top = _elements.at(selected)->GetTop();
|
||||
}
|
||||
|
||||
|
||||
// look for a button on the same row, to the left/right
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
for (i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -278,9 +289,9 @@ void GuiWindow::MoveSelectionHor(int dir)
|
||||
if(_elements.at(i)->GetLeft()*dir > left*dir && _elements.at(i)->GetTop() == top)
|
||||
{
|
||||
if(found == -1)
|
||||
found = i;
|
||||
found = int(i);
|
||||
else if(_elements.at(i)->GetLeft()*dir < _elements.at(found)->GetLeft()*dir)
|
||||
found = i; // this is a better match
|
||||
found = int(i); // this is a better match
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -290,7 +301,7 @@ void GuiWindow::MoveSelectionHor(int dir)
|
||||
goto matchfound;
|
||||
|
||||
// match still not found, let's try the first button in the next row
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
for (i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -327,7 +338,6 @@ void GuiWindow::MoveSelectionVert(int dir)
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
|
||||
int selected = this->GetSelected();
|
||||
|
||||
@ -338,7 +348,8 @@ void GuiWindow::MoveSelectionVert(int dir)
|
||||
}
|
||||
|
||||
// look for a button above/below, with the least horizontal difference
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -378,7 +389,8 @@ void GuiWindow::Update(GuiTrigger * t)
|
||||
if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement))
|
||||
return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
u32 elemSize = _elements.size();
|
||||
for (u32 i = 0; i < elemSize; ++i)
|
||||
{
|
||||
try { _elements.at(i)->Update(t); }
|
||||
catch (const std::exception& e) { }
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "gba/GBA.h"
|
||||
#include "gba/bios.h"
|
||||
#include "gba/GBAinline.h"
|
||||
#include "fastmath.h"
|
||||
|
||||
int rumbleRequest[4] = {0,0,0,0};
|
||||
GuiTrigger userInput[4];
|
||||
@ -155,8 +156,8 @@ UpdatePads()
|
||||
#endif
|
||||
PAD_ScanPads();
|
||||
|
||||
for(int i=3; i >= 0; i--)
|
||||
{
|
||||
int i = 3;
|
||||
do {
|
||||
userInput[i].pad.btns_d = PAD_ButtonsDown(i);
|
||||
userInput[i].pad.btns_u = PAD_ButtonsUp(i);
|
||||
userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
|
||||
@ -166,7 +167,8 @@ UpdatePads()
|
||||
userInput[i].pad.substickY = PAD_SubStickY(i);
|
||||
userInput[i].pad.triggerL = PAD_TriggerL(i);
|
||||
userInput[i].pad.triggerR = PAD_TriggerR(i);
|
||||
}
|
||||
--i;
|
||||
} while(i >= 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -222,20 +224,23 @@ void ShutoffRumble()
|
||||
void DoRumble(int i)
|
||||
{
|
||||
if(!GCSettings.Rumble) return;
|
||||
if(rumbleRequest[i] && rumbleCount[i] < 3)
|
||||
if(rumbleRequest[i])
|
||||
{
|
||||
WPAD_Rumble(i, 1); // rumble on
|
||||
rumbleCount[i]++;
|
||||
}
|
||||
else if(rumbleRequest[i])
|
||||
{
|
||||
rumbleCount[i] = 12;
|
||||
rumbleRequest[i] = 0;
|
||||
if(rumbleCount[i] < 3)
|
||||
{
|
||||
WPAD_Rumble(i, 1); // rumble on
|
||||
++rumbleCount[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
rumbleCount[i] = 12;
|
||||
rumbleRequest[i] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(rumbleCount[i])
|
||||
rumbleCount[i]--;
|
||||
--rumbleCount[i];
|
||||
WPAD_Rumble(i, 0); // rumble off
|
||||
}
|
||||
}
|
||||
@ -249,10 +254,18 @@ static void updateRumble()
|
||||
if (ConfigRequested) r = (menuRumbleCount > 0);
|
||||
else r = cartridgeRumble || possibleCartridgeRumble || (gameRumbleCount > 0) || (menuRumbleCount > 0);
|
||||
|
||||
if (SilenceNeeded>0) {
|
||||
if (r) SilenceNeeded = 5;
|
||||
else SilenceNeeded--;
|
||||
if (SilenceNeeded>0) r = false;
|
||||
if (SilenceNeeded > 0)
|
||||
{
|
||||
if (r)
|
||||
{
|
||||
SilenceNeeded = 5;
|
||||
// It will always be greater than 0 after that!
|
||||
r = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (--SilenceNeeded > 0) r = false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HW_RVL
|
||||
@ -269,16 +282,16 @@ void updateRumbleFrame() {
|
||||
SilenceNeeded = 5;
|
||||
rumbleCountAlready = 0;
|
||||
} else if (ConfigRequested) {
|
||||
if (menuRumbleCount>0) rumbleCountAlready++;
|
||||
if (menuRumbleCount>0) ++rumbleCountAlready;
|
||||
else rumbleCountAlready=0;
|
||||
} else {
|
||||
if (gameRumbleCount>0 || menuRumbleCount>0 || possibleCartridgeRumble)
|
||||
rumbleCountAlready++;
|
||||
++rumbleCountAlready;
|
||||
else rumbleCountAlready=0;
|
||||
}
|
||||
updateRumble();
|
||||
if (gameRumbleCount>0 && !ConfigRequested) gameRumbleCount--;
|
||||
if (menuRumbleCount>0) menuRumbleCount--;
|
||||
if (gameRumbleCount>0 && !ConfigRequested) --gameRumbleCount;
|
||||
if (menuRumbleCount>0) --menuRumbleCount;
|
||||
}
|
||||
|
||||
void systemPossibleCartridgeRumble(bool RumbleOn) {
|
||||
@ -315,22 +328,39 @@ u32 StandardMovement(unsigned short chan)
|
||||
// Is XY inside the "zone"?
|
||||
if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL)
|
||||
{
|
||||
if (pad_x > 0 && pad_y == 0) J |= VBA_RIGHT;
|
||||
if (pad_x < 0 && pad_y == 0) J |= VBA_LEFT;
|
||||
if (pad_x == 0 && pad_y > 0) J |= VBA_UP;
|
||||
if (pad_x == 0 && pad_y < 0) J |= VBA_DOWN;
|
||||
|
||||
if (pad_x != 0 && pad_y != 0)
|
||||
if (pad_y == 0)
|
||||
{
|
||||
if ((float)pad_y / pad_x >= -2.41421356237 && (float)pad_y / pad_x < 2.41421356237)
|
||||
if(pad_x > 0)
|
||||
{
|
||||
J |= VBA_RIGHT;
|
||||
}
|
||||
else if(pad_x < 0)
|
||||
{
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
}
|
||||
if (pad_x == 0)
|
||||
{
|
||||
if(pad_y > 0)
|
||||
{
|
||||
J |= VBA_UP;
|
||||
}
|
||||
else if(pad_y < 0)
|
||||
{
|
||||
J |= VBA_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if ((pad_x|pad_y) != 0)
|
||||
{
|
||||
if ((fabs((double)(pad_y) / (double)(pad_x))) < 2.41421356237)
|
||||
{
|
||||
if (pad_x >= 0)
|
||||
J |= VBA_RIGHT;
|
||||
else
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
|
||||
if ((float)pad_x / pad_y >= -2.41421356237 && (float)pad_x / pad_y < 2.41421356237)
|
||||
if ((fabs((double)(pad_x) / (double)(pad_y))) < 2.41421356237)
|
||||
{
|
||||
if (pad_y >= 0)
|
||||
J |= VBA_UP;
|
||||
@ -347,33 +377,39 @@ u32 StandardMovement(unsigned short chan)
|
||||
if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL)
|
||||
{
|
||||
/*** we don't want division by zero ***/
|
||||
if (wm_ax > 0 && wm_ay == 0)
|
||||
J |= VBA_RIGHT;
|
||||
if (wm_ax < 0 && wm_ay == 0)
|
||||
J |= VBA_LEFT;
|
||||
if (wm_ax == 0 && wm_ay > 0)
|
||||
J |= VBA_UP;
|
||||
if (wm_ax == 0 && wm_ay < 0)
|
||||
J |= VBA_DOWN;
|
||||
if (wm_ay == 0)
|
||||
{
|
||||
if(wm_ax > 0)
|
||||
{
|
||||
J |= VBA_RIGHT;
|
||||
}
|
||||
else if(pad_x < 0)
|
||||
{
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
}
|
||||
if (wm_ax == 0)
|
||||
{
|
||||
if(wm_ay > 0)
|
||||
{
|
||||
J |= VBA_UP;
|
||||
}
|
||||
else if(pad_y < 0)
|
||||
{
|
||||
J |= VBA_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if (wm_ax != 0 && wm_ay != 0)
|
||||
{
|
||||
|
||||
/*** Recalc left / right ***/
|
||||
float t;
|
||||
|
||||
t = (float) wm_ay / wm_ax;
|
||||
if (t >= -2.41421356237 && t < 2.41421356237)
|
||||
if ((fabs((double)(wm_ay) / (double)(wm_ax))) < 2.41421356237)
|
||||
{
|
||||
if (wm_ax >= 0)
|
||||
J |= VBA_RIGHT;
|
||||
else
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
|
||||
/*** Recalc up / down ***/
|
||||
t = (float) wm_ax / wm_ay;
|
||||
if (t >= -2.41421356237 && t < 2.41421356237)
|
||||
if ((fabs((double)(wm_ax) / (double)(wm_ay))) < 2.41421356237)
|
||||
{
|
||||
if (wm_ay >= 0)
|
||||
J |= VBA_UP;
|
||||
@ -605,7 +641,7 @@ u32 DecodeKeyboard(unsigned short pad)
|
||||
{
|
||||
u32 J = 0;
|
||||
#ifdef HW_RVL
|
||||
for (int i = 0; i < MAXJP; i++)
|
||||
for (u32 i = 0; i < MAXJP; ++i)
|
||||
{
|
||||
if (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) // keyboard
|
||||
J |= vbapadmap[i];
|
||||
@ -618,7 +654,7 @@ u32 DecodeGamecube(unsigned short pad)
|
||||
{
|
||||
u32 J = 0;
|
||||
u32 jp = PAD_ButtonsHeld(pad);
|
||||
for (int i = 0; i < MAXJP; i++)
|
||||
for (u32 i = 0; i < MAXJP; ++i)
|
||||
{
|
||||
if (jp & btnmap[CTRLR_GCPAD][i])
|
||||
J |= vbapadmap[i];
|
||||
@ -631,11 +667,18 @@ u32 DecodeWiimote(unsigned short pad)
|
||||
u32 J = 0;
|
||||
#ifdef HW_RVL
|
||||
WPADData * wp = WPAD_Data(pad);
|
||||
for (int i = 0; i < MAXJP; i++)
|
||||
|
||||
u32 wpad_btns_h = wp->btns_h;
|
||||
|
||||
if(wp->exp.type == WPAD_EXP_NONE)
|
||||
{
|
||||
if ( (wp->exp.type == WPAD_EXP_NONE) && (wp->btns_h & btnmap[CTRLR_WIIMOTE][i]) )
|
||||
J |= vbapadmap[i];
|
||||
for (u32 i = 0; i < MAXJP; ++i)
|
||||
{
|
||||
if (wpad_btns_h & btnmap[CTRLR_WIIMOTE][i] )
|
||||
J |= vbapadmap[i];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return J;
|
||||
}
|
||||
@ -645,10 +688,13 @@ u32 DecodeClassic(unsigned short pad)
|
||||
u32 J = 0;
|
||||
#ifdef HW_RVL
|
||||
WPADData * wp = WPAD_Data(pad);
|
||||
for (int i = 0; i < MAXJP; i++)
|
||||
{
|
||||
if ( (wp->exp.type == WPAD_EXP_CLASSIC) && (wp->btns_h & btnmap[CTRLR_CLASSIC][i]) )
|
||||
J |= vbapadmap[i];
|
||||
u32 wpad_btns_h = wp->btns_h;
|
||||
|
||||
if(wp->exp.type == WPAD_EXP_CLASSIC){
|
||||
for (u32 i = 0; i < MAXJP; ++i){
|
||||
if (wpad_btns_h & btnmap[CTRLR_CLASSIC][i] )
|
||||
J |= vbapadmap[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return J;
|
||||
@ -658,11 +704,13 @@ u32 DecodeNunchuk(unsigned short pad)
|
||||
{
|
||||
u32 J = 0;
|
||||
#ifdef HW_RVL
|
||||
for (int i = 0; i < MAXJP; i++)
|
||||
{
|
||||
if ( (userInput[pad].wpad->exp.type == WPAD_EXP_NUNCHUK) &&
|
||||
(userInput[pad].wpad->btns_h & btnmap[CTRLR_NUNCHUK][i]) )
|
||||
J |= vbapadmap[i];
|
||||
u32 wpad_btns_h = userInput[pad].wpad->btns_h;
|
||||
|
||||
if(userInput[pad].wpad->exp.type == WPAD_EXP_NUNCHUK){
|
||||
for (u32 i = 0; i < MAXJP; ++i){
|
||||
if (wpad_btns_h & btnmap[CTRLR_NUNCHUK][i] )
|
||||
J |= vbapadmap[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return J;
|
||||
@ -923,44 +971,88 @@ static u32 DecodeJoy(unsigned short pad)
|
||||
u32 J = StandardMovement(pad);
|
||||
|
||||
// Turbo feature
|
||||
if(
|
||||
userInput[0].pad.substickX > 70 ||
|
||||
userInput[0].WPAD_Stick(1,0) > 70
|
||||
)
|
||||
if(userInput[0].pad.substickX > 70 || userInput[0].WPAD_Stick(1,0) > 70)
|
||||
J |= VBA_SPEED;
|
||||
|
||||
// Report pressed buttons (gamepads)
|
||||
int i;
|
||||
u32 pad_btns_h = userInput[pad].pad.btns_h; // GCN
|
||||
|
||||
for (i = 0; i < MAXJP; i++)
|
||||
{
|
||||
if ((userInput[pad].pad.btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller
|
||||
#ifdef HW_RVL
|
||||
|| ( (userInput[pad].wpad->exp.type == WPAD_EXP_NONE) && (userInput[pad].wpad->btns_h & btnmap[CTRLR_WIIMOTE][i]) ) // wiimote
|
||||
|| ( (userInput[pad].wpad->exp.type == WPAD_EXP_CLASSIC) && (userInput[pad].wpad->btns_h & btnmap[CTRLR_CLASSIC][i]) ) // classic controller
|
||||
|| ( (userInput[pad].wpad->exp.type == WPAD_EXP_NUNCHUK) && (userInput[pad].wpad->btns_h & btnmap[CTRLR_NUNCHUK][i]) ) // nunchuk + wiimote
|
||||
|| ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) // keyboard
|
||||
#endif
|
||||
)
|
||||
#ifdef HW_RVL
|
||||
u32 wpad_btns_h = userInput[pad].wpad->btns_h;
|
||||
int wpad_exp_type = userInput[pad].wpad->exp.type;
|
||||
|
||||
if(wpad_exp_type == WPAD_EXP_NONE)
|
||||
{ // wiimote
|
||||
|
||||
for (u32 i =0; i < MAXJP; ++i)
|
||||
{
|
||||
if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller
|
||||
|| ( (wpad_btns_h & btnmap[CTRLR_WIIMOTE][i]) )
|
||||
|| ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) )// keyboard
|
||||
J |= vbapadmap[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(wpad_exp_type == WPAD_EXP_CLASSIC)
|
||||
{ // classic controller
|
||||
|
||||
for (u32 i =0; i < MAXJP; ++i)
|
||||
{
|
||||
if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller
|
||||
|| ( (wpad_btns_h & btnmap[CTRLR_CLASSIC][i]) )
|
||||
|| ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) )// keyboard
|
||||
J |= vbapadmap[i];
|
||||
}
|
||||
|
||||
}
|
||||
else if(wpad_exp_type == WPAD_EXP_NUNCHUK)
|
||||
{ // nunchuk + wiimote
|
||||
|
||||
for (u32 i =0; i < MAXJP; ++i)
|
||||
{
|
||||
if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller
|
||||
|| ( (wpad_btns_h & btnmap[CTRLR_NUNCHUK][i]) )
|
||||
|| ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) )// keyboard
|
||||
J |= vbapadmap[i];
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
// Check out this trickery!
|
||||
// If all else fails OR if HW_RVL is undefined, the result is the same
|
||||
#endif
|
||||
{
|
||||
for (u32 i = 0; i < MAXJP; ++i)
|
||||
{
|
||||
if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]))
|
||||
J |= vbapadmap[i];
|
||||
}
|
||||
}
|
||||
return J;
|
||||
}
|
||||
|
||||
bool MenuRequested()
|
||||
{
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
if (
|
||||
(userInput[i].pad.substickX < -70) ||
|
||||
(userInput[i].wpad->btns_h & WPAD_BUTTON_HOME) ||
|
||||
(userInput[i].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME) ||
|
||||
(DownUsbKeys[KS_Escape])
|
||||
if( (DownUsbKeys[KS_Escape])
|
||||
||
|
||||
(userInput[0].pad.substickX < -70) ||
|
||||
(userInput[0].wpad->btns_h & WPAD_BUTTON_HOME) ||
|
||||
(userInput[0].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME)
|
||||
||
|
||||
(userInput[1].pad.substickX < -70) ||
|
||||
(userInput[1].wpad->btns_h & WPAD_BUTTON_HOME) ||
|
||||
(userInput[1].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME)
|
||||
||
|
||||
(userInput[2].pad.substickX < -70) ||
|
||||
(userInput[2].wpad->btns_h & WPAD_BUTTON_HOME) ||
|
||||
(userInput[2].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME)
|
||||
||
|
||||
(userInput[3].pad.substickX < -70) ||
|
||||
(userInput[3].wpad->btns_h & WPAD_BUTTON_HOME) ||
|
||||
(userInput[3].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME)
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -256,19 +256,23 @@ UpdateGUI (void *arg)
|
||||
mainWindow->Draw();
|
||||
|
||||
#ifdef HW_RVL
|
||||
for(i=3; i >= 0; i--) // so that player 1's cursor appears on top!
|
||||
i = 3;
|
||||
do
|
||||
{
|
||||
if(userInput[i].wpad->ir.valid)
|
||||
Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
|
||||
96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
|
||||
DoRumble(i);
|
||||
}
|
||||
--i;
|
||||
} while(i>=0);
|
||||
#endif
|
||||
|
||||
Menu_Render();
|
||||
|
||||
for(i=3; i >= 0; i--)
|
||||
mainWindow->Update(&userInput[i]);
|
||||
mainWindow->Update(&userInput[3]);
|
||||
mainWindow->Update(&userInput[2]);
|
||||
mainWindow->Update(&userInput[1]);
|
||||
mainWindow->Update(&userInput[0]);
|
||||
|
||||
#ifdef HW_RVL
|
||||
if(updateFound)
|
||||
@ -408,12 +412,12 @@ ProgressWindow(char *title, char *msg)
|
||||
{
|
||||
if(count % 5 == 0)
|
||||
{
|
||||
angle+=45;
|
||||
if(angle >= 360)
|
||||
angle+=45.0f;
|
||||
if(angle >= 360.0f)
|
||||
angle = 0;
|
||||
throbberImg.SetAngle(angle);
|
||||
}
|
||||
count++;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,10 +483,8 @@ ShowProgress (const char *msg, int done, int total)
|
||||
|
||||
if(total < (256*1024))
|
||||
return;
|
||||
else if(done > total) // this shouldn't happen
|
||||
done = total;
|
||||
|
||||
if(done/total > 0.99)
|
||||
if(done > total) // this shouldn't happen
|
||||
done = total;
|
||||
|
||||
if(showProgress != 1)
|
||||
@ -810,22 +812,24 @@ static void WindowCredits(void * ptr)
|
||||
bgTopImg->Draw();
|
||||
creditsWindow.Draw();
|
||||
|
||||
for(i=3; i >= 0; i--)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
if(userInput[i].wpad->ir.valid)
|
||||
Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
|
||||
96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
|
||||
#ifdef HW_RVL
|
||||
i = 3;
|
||||
do {
|
||||
if(userInput[i].wpad->ir.valid)
|
||||
Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
|
||||
96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
|
||||
DoRumble(i);
|
||||
#endif
|
||||
}
|
||||
--i;
|
||||
} while(i >= 0);
|
||||
#endif
|
||||
|
||||
Menu_Render();
|
||||
|
||||
for(i=0; i < 4; i++)
|
||||
{
|
||||
if(userInput[i].wpad->btns_d || userInput[i].pad.btns_d)
|
||||
exit = true;
|
||||
if((userInput[0].wpad->btns_d || userInput[0].pad.btns_d) ||
|
||||
(userInput[1].wpad->btns_d || userInput[1].pad.btns_d) ||
|
||||
(userInput[2].wpad->btns_d || userInput[2].pad.btns_d) ||
|
||||
(userInput[3].wpad->btns_d || userInput[3].pad.btns_d)){
|
||||
exit = true;
|
||||
}
|
||||
usleep(THREAD_SLEEP);
|
||||
}
|
||||
@ -949,7 +953,7 @@ static int MenuGameSelection()
|
||||
|
||||
// update gameWindow based on arrow buttons
|
||||
// set MENU_EXIT if A button pressed on a game
|
||||
for(i=0; i < FILE_PAGESIZE; i++)
|
||||
for(i=0; i < FILE_PAGESIZE; ++i)
|
||||
{
|
||||
if(gameBrowser.fileList[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
@ -1192,7 +1196,7 @@ static int MenuGame()
|
||||
GuiImage * batteryBarImg[4];
|
||||
GuiButton * batteryBtn[4];
|
||||
|
||||
for(i=0; i < 4; i++)
|
||||
for(i=0; i < 4; ++i)
|
||||
{
|
||||
if(i == 0)
|
||||
sprintf(txt, "P %d", i+1);
|
||||
@ -1298,7 +1302,7 @@ static int MenuGame()
|
||||
if(WPAD_Probe(i, NULL) == WPAD_ERR_NONE)
|
||||
{
|
||||
newStatus = true;
|
||||
newLevel = (userInput[i].wpad->battery_level / 100.0) * 4;
|
||||
newLevel = int(userInput[i].wpad->battery_level / 100.0) << 2;
|
||||
if(newLevel > 4) newLevel = 4;
|
||||
}
|
||||
else
|
||||
@ -1334,7 +1338,7 @@ static int MenuGame()
|
||||
if (isBoktai)
|
||||
{
|
||||
if (sunBtn->GetState() == STATE_CLICKED) {
|
||||
SunBars++;
|
||||
++SunBars;
|
||||
if (SunBars>10) SunBars=0;
|
||||
menu = MENU_GAME;
|
||||
}
|
||||
@ -1415,7 +1419,7 @@ static int MenuGame()
|
||||
}
|
||||
|
||||
#ifdef HW_RVL
|
||||
for(i=0; i < 4; i++)
|
||||
for(i=0; i < 4; ++i)
|
||||
{
|
||||
delete batteryTxt[i];
|
||||
delete batteryImg[i];
|
||||
@ -1439,7 +1443,6 @@ static int FindGameSaveNum(char * savefile, int method)
|
||||
int n = -1;
|
||||
int romlen = strlen(ROMFilename);
|
||||
int savelen = strlen(savefile);
|
||||
|
||||
int diff = savelen-romlen;
|
||||
|
||||
if(strncmp(savefile, ROMFilename, romlen) != 0)
|
||||
@ -1466,16 +1469,19 @@ static int FindGameSaveNum(char * savefile, int method)
|
||||
***************************************************************************/
|
||||
static int MenuGameSaves(int action)
|
||||
{
|
||||
SaveList saves;
|
||||
struct stat filestat;
|
||||
struct tm * timeinfo;
|
||||
|
||||
int menu = MENU_NONE;
|
||||
int ret, result;
|
||||
int i, n, type, len, len2;
|
||||
int j = 0;
|
||||
SaveList saves;
|
||||
|
||||
char filepath[1024];
|
||||
char scrfile[1024];
|
||||
char tmp[MAXJOLIET];
|
||||
struct stat filestat;
|
||||
struct tm * timeinfo;
|
||||
|
||||
int method = GCSettings.SaveMethod;
|
||||
|
||||
if(method == DEVICE_AUTO)
|
||||
@ -1595,7 +1601,7 @@ static int MenuGameSaves(int action)
|
||||
strftime(saves.date[j], 20, "%a %b %d", timeinfo);
|
||||
strftime(saves.time[j], 10, "%I:%M %p", timeinfo);
|
||||
}
|
||||
j++;
|
||||
++j;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3728,12 +3734,16 @@ static void PaletteWindow(const char *name)
|
||||
}
|
||||
|
||||
GXColor GetCol(int i) {
|
||||
u32 c;
|
||||
if (i>=0 && i<=13) c = CurrentPalette.palette[i];
|
||||
else c = 0;
|
||||
u8 r = (c >> 16) & 255;
|
||||
u8 g = (c >> 8) & 255;
|
||||
u8 b = (c) & 255;
|
||||
int c = 0;
|
||||
u8 r=0, g=0, b=0;
|
||||
if (unsigned(i) <= 13)
|
||||
{
|
||||
c = CurrentPalette.palette[i];
|
||||
r = (c >> 16) & 255;
|
||||
g = (c >> 8) & 255;
|
||||
b = (c) & 255;
|
||||
|
||||
}
|
||||
return (GXColor){r,g,b,255};
|
||||
}
|
||||
|
||||
|
@ -51,14 +51,13 @@ static struct
|
||||
static int f_read(void * punt, int bytes, int blocks, int *f)
|
||||
{
|
||||
int b;
|
||||
int c;
|
||||
int c = 0;
|
||||
int d;
|
||||
|
||||
if (bytes * blocks <= 0)
|
||||
return 0;
|
||||
|
||||
blocks = bytes * blocks;
|
||||
c = 0;
|
||||
blocks *= bytes;
|
||||
|
||||
while (blocks > 0)
|
||||
{
|
||||
@ -66,9 +65,9 @@ static int f_read(void * punt, int bytes, int blocks, int *f)
|
||||
if (b > 4096)
|
||||
b = 4096;
|
||||
|
||||
if (*f >= 0x666 && *f <= 0x669)
|
||||
d = (*f) - 0x666;
|
||||
if((unsigned)(d) <= (0x669 - 0x666))
|
||||
{
|
||||
d = (*f) - 0x666;
|
||||
if (file[d].size == 0)
|
||||
return -1;
|
||||
if ((file[d].pos + b) > file[d].size)
|
||||
@ -96,11 +95,12 @@ static int f_seek(int *f, ogg_int64_t offset, int mode)
|
||||
{
|
||||
if(f==NULL) return(-1);
|
||||
|
||||
int k, d;
|
||||
int k;
|
||||
mode &= 3;
|
||||
if (*f >= 0x666 && *f <= 0x669)
|
||||
|
||||
int d = (*f) - 0x666;
|
||||
if((unsigned)(d) <= (0x669 - 0x666))
|
||||
{
|
||||
d = (*f) - 0x666;
|
||||
k = 0;
|
||||
|
||||
if (file[d].size == 0)
|
||||
@ -121,7 +121,7 @@ static int f_seek(int *f, ogg_int64_t offset, int mode)
|
||||
else
|
||||
file[d].pos = offset;
|
||||
}
|
||||
if (mode == 1)
|
||||
else if (mode == 1)
|
||||
{
|
||||
if ((file[d].pos + offset) >= file[d].size)
|
||||
{
|
||||
@ -136,7 +136,7 @@ static int f_seek(int *f, ogg_int64_t offset, int mode)
|
||||
else
|
||||
file[d].pos += offset;
|
||||
}
|
||||
if (mode == 2)
|
||||
else if (mode == 2)
|
||||
{
|
||||
|
||||
if ((file[d].size + offset) >= file[d].size)
|
||||
@ -166,10 +166,9 @@ static int f_seek(int *f, ogg_int64_t offset, int mode)
|
||||
|
||||
static int f_close(int *f)
|
||||
{
|
||||
int d;
|
||||
if (*f >= 0x666 && *f <= 0x669)
|
||||
int d = (*f) - 0x666;
|
||||
if((unsigned)(d) <= (0x669 - 0x666))
|
||||
{
|
||||
d = (*f) - 0x666;
|
||||
file[d].size = 0;
|
||||
file[d].pos = 0;
|
||||
if (file[d].mem)
|
||||
@ -185,11 +184,11 @@ static int f_close(int *f)
|
||||
|
||||
static long f_tell(int *f)
|
||||
{
|
||||
int k, d;
|
||||
int k;
|
||||
|
||||
if (*f >= 0x666 && *f <= 0x669)
|
||||
int d = (*f) - 0x666;
|
||||
if((unsigned)(d) <= (0x669 - 0x666))
|
||||
{
|
||||
d = (*f) - 0x666;
|
||||
k = file[d].pos;
|
||||
}
|
||||
else
|
||||
@ -205,8 +204,15 @@ static int mem_open(char * ogg, int size)
|
||||
if (one)
|
||||
{
|
||||
one = 0;
|
||||
for (n = 0; n < 4; n++)
|
||||
file[n].size = 0;
|
||||
|
||||
file[0].size = 0;
|
||||
file[1].size = 0;
|
||||
file[2].size = 0;
|
||||
file[3].size = 0;
|
||||
file[0].mem = ogg;
|
||||
file[0].size = size;
|
||||
file[0].pos = 0;
|
||||
return (0x666);
|
||||
}
|
||||
|
||||
for (n = 0; n < 4; n++)
|
||||
@ -224,7 +230,7 @@ static int mem_open(char * ogg, int size)
|
||||
|
||||
static int mem_close(int fd)
|
||||
{
|
||||
if (fd >= 0x666 && fd <= 0x669) // it is a memory file descriptor?
|
||||
if((unsigned)((fd) - 0x666) <= (0x669 - 0x666)) // it is a memory file descriptor?
|
||||
{
|
||||
fd -= 0x666;
|
||||
file[fd].size = 0;
|
||||
@ -353,8 +359,7 @@ static void * ogg_player_thread(private_data_ogg * priv)
|
||||
priv[0].seek_time = -1;
|
||||
}
|
||||
|
||||
ret
|
||||
= ov_read(
|
||||
ret = ov_read(
|
||||
&priv[0].vf,
|
||||
(void *) &priv[0].pcmout[priv[0].pcmout_pos][priv[0].pcm_indx],
|
||||
MAX_PCMOUT,/*0,2,1,*/&priv[0].current_section);
|
||||
@ -513,8 +518,7 @@ int StatusOgg()
|
||||
return 255; // EOF
|
||||
else if (private_ogg.flag & 128)
|
||||
return 2; // paused
|
||||
else
|
||||
return 1; // running
|
||||
return 1; // running
|
||||
}
|
||||
|
||||
void SetVolumeOgg(int volume)
|
||||
|
@ -47,7 +47,7 @@ struct _IMGCTX
|
||||
png_bytep img_data;
|
||||
};
|
||||
|
||||
// PNGU Implementation //
|
||||
// PNGU Implementation
|
||||
|
||||
IMGCTX PNGU_SelectImageFromBuffer (const void *buffer)
|
||||
{
|
||||
@ -129,436 +129,6 @@ int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *imgprop)
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride)
|
||||
{
|
||||
int result;
|
||||
PNGU_u32 x, y, buffWidth;
|
||||
|
||||
// width needs to be divisible by two
|
||||
if (width % 2)
|
||||
return PNGU_ODD_WIDTH;
|
||||
|
||||
// stride needs to be divisible by two
|
||||
if (stride % 2)
|
||||
return PNGU_ODD_STRIDE;
|
||||
|
||||
result = pngu_decode (ctx, width, height, 1);
|
||||
if (result != PNGU_OK)
|
||||
return result;
|
||||
|
||||
// Copy image to the output buffer
|
||||
buffWidth = (width + stride) >> 1;
|
||||
PNGU_u32 wid2 = width >>1;
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
for (x = 0; x < wid2; x++)
|
||||
{
|
||||
PNGU_u32 x6 = x*6;
|
||||
((PNGU_u32 *)buffer)[y*buffWidth+x] = PNGU_RGB8_TO_YCbYCr (*(ctx->row_pointers[y]+x6), *(ctx->row_pointers[y]+x6+1), *(ctx->row_pointers[y]+x6+2),
|
||||
*(ctx->row_pointers[y]+x6+3), *(ctx->row_pointers[y]+x6+4), *(ctx->row_pointers[y]+x6+5));
|
||||
}
|
||||
}
|
||||
|
||||
// Free resources
|
||||
free (ctx->img_data);
|
||||
free (ctx->row_pointers);
|
||||
|
||||
// Success
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride)
|
||||
{
|
||||
int result;
|
||||
PNGU_u32 x, y, buffWidth;
|
||||
|
||||
result = pngu_decode (ctx, width, height, 1);
|
||||
if (result != PNGU_OK)
|
||||
return result;
|
||||
|
||||
buffWidth = width + stride;
|
||||
|
||||
// Copy image to the output buffer
|
||||
for (y = 0; y < height; y++)
|
||||
for (x = 0; x < width; x++)
|
||||
((PNGU_u16 *)buffer)[y*buffWidth+x] =
|
||||
(((PNGU_u16) (ctx->row_pointers[y][x*3] & 0xF8)) << 8) |
|
||||
(((PNGU_u16) (ctx->row_pointers[y][x*3+1] & 0xFC)) << 3) |
|
||||
(((PNGU_u16) (ctx->row_pointers[y][x*3+2] & 0xF8)) >> 3);
|
||||
|
||||
// Free resources
|
||||
free (ctx->img_data);
|
||||
free (ctx->row_pointers);
|
||||
|
||||
// Success
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha)
|
||||
{
|
||||
int result;
|
||||
PNGU_u32 x, y, buffWidth;
|
||||
|
||||
result = pngu_decode (ctx, width, height, 0);
|
||||
if (result != PNGU_OK)
|
||||
return result;
|
||||
|
||||
buffWidth = width + stride;
|
||||
|
||||
// Check is source image has an alpha channel
|
||||
if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) )
|
||||
{
|
||||
// Alpha channel present, copy image to the output buffer
|
||||
for (y = 0; y < height; y++)
|
||||
memcpy (buffer + (y * buffWidth << 2), ctx->row_pointers[y], width<<2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No alpha channel present, copy image to the output buffer
|
||||
for (y = 0; y < height; y++)
|
||||
for (x = 0; x < width; x++)
|
||||
((PNGU_u32 *)buffer)[y*buffWidth+x] =
|
||||
(((PNGU_u32) ctx->row_pointers[y][x*3]) << 24) |
|
||||
(((PNGU_u32) ctx->row_pointers[y][x*3+1]) << 16) |
|
||||
(((PNGU_u32) ctx->row_pointers[y][x*3+2]) << 8) |
|
||||
((PNGU_u32) default_alpha);
|
||||
}
|
||||
|
||||
// Free resources
|
||||
free (ctx->img_data);
|
||||
free (ctx->row_pointers);
|
||||
|
||||
// Success
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer)
|
||||
{
|
||||
PNGU_u32 x, y;
|
||||
|
||||
// width and height need to be divisible by four
|
||||
if ((width % 4) || (height % 4))
|
||||
return PNGU_INVALID_WIDTH_OR_HEIGHT;
|
||||
|
||||
int result = pngu_decode (ctx, width, height, 1);
|
||||
if (result != PNGU_OK)
|
||||
return result;
|
||||
|
||||
// Copy image to the output buffer
|
||||
PNGU_u32 qwidth = width >> 2;
|
||||
PNGU_u32 qheight = height >> 2;
|
||||
|
||||
for (y = 0; y < qheight; y++)
|
||||
for (x = 0; x < qwidth; x++)
|
||||
{
|
||||
PNGU_u32 y4 = y << 2;
|
||||
PNGU_u32 x12 = x * 12;
|
||||
int blockbase = (y * qwidth + x) << 2;
|
||||
|
||||
PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y4]+x12));
|
||||
PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase] =
|
||||
(((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) |
|
||||
(((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) |
|
||||
(((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) |
|
||||
(((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3)));
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+1]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+1]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+1] =
|
||||
(((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) |
|
||||
(((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) |
|
||||
(((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) |
|
||||
(((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3)));
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+2]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+2]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+2] =
|
||||
(((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) |
|
||||
(((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) |
|
||||
(((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) |
|
||||
(((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3)));
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+3]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+3]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+3] =
|
||||
(((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) |
|
||||
(((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) |
|
||||
(((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) |
|
||||
(((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3)));
|
||||
}
|
||||
|
||||
// Free resources
|
||||
free (ctx->img_data);
|
||||
free (ctx->row_pointers);
|
||||
|
||||
// Success
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha)
|
||||
{
|
||||
int result;
|
||||
PNGU_u32 x, y, qwidth, qheight;
|
||||
PNGU_u64 alphaMask;
|
||||
|
||||
// width and height need to be divisible by four
|
||||
if ((width % 4) || (height % 4))
|
||||
return PNGU_INVALID_WIDTH_OR_HEIGHT;
|
||||
|
||||
result = pngu_decode (ctx, width, height, 0);
|
||||
if (result != PNGU_OK)
|
||||
return result;
|
||||
|
||||
// Init some vars
|
||||
qwidth = width >> 2;
|
||||
qheight = height >> 2;
|
||||
|
||||
// Check is source image has an alpha channel
|
||||
if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) )
|
||||
{
|
||||
// Alpha channel present, copy image to the output buffer
|
||||
for (y = 0; y < qheight; y++)
|
||||
for (x = 0; x < qwidth; x++)
|
||||
{
|
||||
int blockbase = (y * qwidth + x) << 2;
|
||||
|
||||
PNGU_u32 y4 = y << 2;
|
||||
PNGU_u32 x16 = x << 4;
|
||||
|
||||
PNGU_u64 tmp;
|
||||
|
||||
PNGU_u64 fieldA = *((PNGU_u64 *)(ctx->row_pointers[y4]+x16));
|
||||
PNGU_u64 fieldB = *((PNGU_u64 *)(ctx->row_pointers[y4]+x16+8));
|
||||
|
||||
// If first pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444
|
||||
if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5);
|
||||
else
|
||||
tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4);
|
||||
|
||||
// If second pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444
|
||||
if ((fieldA & 0xE0ULL) == 0xE0ULL)
|
||||
tmp |= 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21);
|
||||
else
|
||||
tmp |= ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20);
|
||||
|
||||
// If third pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444
|
||||
if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
tmp |= 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27);
|
||||
else
|
||||
tmp |= ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28);
|
||||
|
||||
// If fourth pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444
|
||||
if ((fieldB & 0xE0ULL) == 0xE0ULL)
|
||||
tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11);
|
||||
else
|
||||
tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12);
|
||||
((PNGU_u64 *) buffer)[blockbase] = tmp;
|
||||
|
||||
fieldA = *((PNGU_u64 *)(ctx->row_pointers[y4+1]+x16));
|
||||
fieldB = *((PNGU_u64 *)(ctx->row_pointers[y4+1]+x16+8));
|
||||
if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4);
|
||||
|
||||
if ((fieldA & 0xE0ULL) == 0xE0ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20);
|
||||
|
||||
if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28);
|
||||
|
||||
if ((fieldB & 0xE0ULL) == 0xE0ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12);
|
||||
((PNGU_u64 *) buffer)[blockbase+1] = tmp;
|
||||
|
||||
fieldA = *((PNGU_u64 *)(ctx->row_pointers[y4+2]+x16));
|
||||
fieldB = *((PNGU_u64 *)(ctx->row_pointers[y4+2]+x16+8));
|
||||
if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4);
|
||||
|
||||
if ((fieldA & 0xE0ULL) == 0xE0ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20);
|
||||
|
||||
if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28);
|
||||
|
||||
if ((fieldB & 0xE0ULL) == 0xE0ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12);
|
||||
((PNGU_u64 *) buffer)[blockbase+2] = tmp;
|
||||
|
||||
fieldA = *((PNGU_u64 *)(ctx->row_pointers[y4+3]+x16));
|
||||
fieldB = *((PNGU_u64 *)(ctx->row_pointers[y4+3]+x16+8));
|
||||
if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4);
|
||||
|
||||
if ((fieldA & 0xE0ULL) == 0xE0ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20);
|
||||
|
||||
if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28);
|
||||
|
||||
if ((fieldB & 0xE0ULL) == 0xE0ULL)
|
||||
// Opaque pixel, so set MSB to 1 and encode colors in RGB555
|
||||
tmp |= 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11);
|
||||
else
|
||||
// Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444
|
||||
tmp |= ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12);
|
||||
|
||||
((PNGU_u64 *) buffer)[blockbase+3] = tmp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No alpha channel present, copy image to the output buffer
|
||||
default_alpha = (default_alpha >> 5);
|
||||
if (default_alpha == 7)
|
||||
{
|
||||
// The user wants an opaque texture, so set MSB to 1 and encode colors in RGB555
|
||||
alphaMask = 0x8000800080008000ULL;
|
||||
|
||||
for (y = 0; y < qheight; y++)
|
||||
for (x = 0; x < qwidth; x++)
|
||||
{
|
||||
int blockbase = (y * qwidth + x) << 2;
|
||||
|
||||
PNGU_u32 y4 = y << 2;
|
||||
PNGU_u32 x12 = x * 12;
|
||||
|
||||
PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y4]+x12));
|
||||
PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase] =
|
||||
alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) |
|
||||
((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) |
|
||||
((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) |
|
||||
((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3);
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+1]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+1]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+1] =
|
||||
alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) |
|
||||
((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) |
|
||||
((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) |
|
||||
((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3);
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+2]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+2]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+2] =
|
||||
alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) |
|
||||
((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) |
|
||||
((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) |
|
||||
((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3);
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+3]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+3]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+3] =
|
||||
alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) |
|
||||
((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) |
|
||||
((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) |
|
||||
((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The user wants a translucid texture, so set MSB to 0 and encode colors in ARGB3444
|
||||
default_alpha = (default_alpha << 4);
|
||||
alphaMask = (((PNGU_u64) default_alpha) << 56) | (((PNGU_u64) default_alpha) << 40) |
|
||||
(((PNGU_u64) default_alpha) << 24) | (((PNGU_u64) default_alpha) << 8);
|
||||
|
||||
for (y = 0; y < qheight; y++)
|
||||
for (x = 0; x < qwidth; x++)
|
||||
{
|
||||
int blockbase = (y * qwidth + x) << 2;
|
||||
|
||||
PNGU_u32 y4 = y << 2;
|
||||
PNGU_u32 x12 = x * 12;
|
||||
|
||||
PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y4]+x12));
|
||||
PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase] =
|
||||
alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) |
|
||||
((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) |
|
||||
((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) |
|
||||
((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4);
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+1]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+1]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+1] =
|
||||
alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) |
|
||||
((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) |
|
||||
((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) |
|
||||
((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4);
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+2]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+2]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+2] =
|
||||
alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) |
|
||||
((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) |
|
||||
((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) |
|
||||
((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4);
|
||||
|
||||
field64 = *((PNGU_u64 *)(ctx->row_pointers[y4+3]+x12));
|
||||
field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y4+3]+x12+8));
|
||||
((PNGU_u64 *) buffer)[blockbase+3] =
|
||||
alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) |
|
||||
((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) |
|
||||
((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) |
|
||||
((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Free resources
|
||||
free (ctx->img_data);
|
||||
free (ctx->row_pointers);
|
||||
|
||||
// Success
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha)
|
||||
{
|
||||
int result;
|
||||
@ -694,122 +264,6 @@ int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *bu
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride)
|
||||
{
|
||||
png_uint_32 rowbytes;
|
||||
PNGU_u32 x, y, buffWidth;
|
||||
|
||||
// Erase from the context any readed info
|
||||
pngu_free_info (ctx);
|
||||
ctx->propRead = 0;
|
||||
|
||||
// Check if the user has selected a file to write the image
|
||||
if (ctx->source == PNGU_SOURCE_BUFFER);
|
||||
|
||||
else if (ctx->source == PNGU_SOURCE_DEVICE)
|
||||
{
|
||||
// Open file
|
||||
if (!(ctx->fd = fopen (ctx->filename, "wb")))
|
||||
return PNGU_CANT_OPEN_FILE;
|
||||
}
|
||||
|
||||
else
|
||||
return PNGU_NO_FILE_SELECTED;
|
||||
|
||||
// Allocation of libpng structs
|
||||
ctx->png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!(ctx->png_ptr))
|
||||
{
|
||||
if (ctx->source == PNGU_SOURCE_DEVICE)
|
||||
fclose (ctx->fd);
|
||||
return PNGU_LIB_ERROR;
|
||||
}
|
||||
|
||||
ctx->info_ptr = png_create_info_struct (ctx->png_ptr);
|
||||
if (!(ctx->info_ptr))
|
||||
{
|
||||
png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL);
|
||||
if (ctx->source == PNGU_SOURCE_DEVICE)
|
||||
fclose (ctx->fd);
|
||||
return PNGU_LIB_ERROR;
|
||||
}
|
||||
|
||||
if (ctx->source == PNGU_SOURCE_BUFFER)
|
||||
{
|
||||
// Installation of our custom data writer function
|
||||
ctx->cursor = 0;
|
||||
png_set_write_fn (ctx->png_ptr, ctx, pngu_write_data_to_buffer, pngu_flush_data_to_buffer);
|
||||
}
|
||||
else if (ctx->source == PNGU_SOURCE_DEVICE)
|
||||
{
|
||||
// Default data writer uses function fwrite, so it needs to use our FILE*
|
||||
png_init_io (ctx->png_ptr, ctx->fd);
|
||||
}
|
||||
|
||||
// Setup output file properties
|
||||
png_set_IHDR (ctx->png_ptr, ctx->info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
// Allocate memory to store the image in RGB format
|
||||
rowbytes = width * 3;
|
||||
if (rowbytes % 4)
|
||||
rowbytes = ((rowbytes >> 2) + 1) << 2;
|
||||
|
||||
ctx->img_data = malloc (rowbytes * height);
|
||||
if (!ctx->img_data)
|
||||
{
|
||||
png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL);
|
||||
if (ctx->source == PNGU_SOURCE_DEVICE)
|
||||
fclose (ctx->fd);
|
||||
return PNGU_LIB_ERROR;
|
||||
}
|
||||
|
||||
ctx->row_pointers = malloc (sizeof (png_bytep) * height);
|
||||
if (!ctx->row_pointers)
|
||||
{
|
||||
png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL);
|
||||
if (ctx->source == PNGU_SOURCE_DEVICE)
|
||||
fclose (ctx->fd);
|
||||
return PNGU_LIB_ERROR;
|
||||
}
|
||||
|
||||
// Encode YCbYCr image into RGB8 format
|
||||
buffWidth = (width + stride) >> 1;
|
||||
PNGU_u32 wid2 = width >> 1;
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
ctx->row_pointers[y] = ctx->img_data + (y * rowbytes);
|
||||
|
||||
for (x = 0; x < wid2; ++x)
|
||||
{
|
||||
PNGU_u32 x6 = x*6;
|
||||
PNGU_YCbYCr_TO_RGB8 ( ((PNGU_u32 *)buffer)[y*buffWidth+x],
|
||||
((PNGU_u8 *) ctx->row_pointers[y]+x6), ((PNGU_u8 *) ctx->row_pointers[y]+x6+1),
|
||||
((PNGU_u8 *) ctx->row_pointers[y]+x6+2), ((PNGU_u8 *) ctx->row_pointers[y]+x6+3),
|
||||
((PNGU_u8 *) ctx->row_pointers[y]+x6+4), ((PNGU_u8 *) ctx->row_pointers[y]+x6+5) );
|
||||
}
|
||||
}
|
||||
|
||||
// Tell libpng where is our image data
|
||||
png_set_rows (ctx->png_ptr, ctx->info_ptr, ctx->row_pointers);
|
||||
|
||||
// Write file header and image data
|
||||
png_write_png (ctx->png_ptr, ctx->info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
|
||||
|
||||
// Tell libpng we have no more data to write
|
||||
png_write_end (ctx->png_ptr, (png_infop) NULL);
|
||||
|
||||
// Free resources
|
||||
free (ctx->img_data);
|
||||
free (ctx->row_pointers);
|
||||
png_destroy_write_struct (&(ctx->png_ptr), &(ctx->info_ptr));
|
||||
if (ctx->source == PNGU_SOURCE_DEVICE)
|
||||
fclose (ctx->fd);
|
||||
|
||||
// Success
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
int PNGU_EncodeFromRGB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride)
|
||||
{
|
||||
png_uint_32 rowbytes;
|
||||
@ -950,46 +404,6 @@ int PNGU_EncodeFromGXTexture (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void
|
||||
return res;
|
||||
}
|
||||
|
||||
// This function is taken from a libogc example
|
||||
PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2)
|
||||
{
|
||||
PNGU_u32 y1, cb1, cr1, y2, cb2, cr2, cb, cr;
|
||||
|
||||
y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000;
|
||||
cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000;
|
||||
cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000;
|
||||
|
||||
y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000;
|
||||
cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000;
|
||||
cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000;
|
||||
|
||||
cb = (cb1 + cb2) >> 1;
|
||||
cr = (cr1 + cr2) >> 1;
|
||||
|
||||
return (PNGU_u32) ((y1 << 24) | (cb << 16) | (y2 << 8) | cr);
|
||||
}
|
||||
|
||||
void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2)
|
||||
{
|
||||
PNGU_u8 *val = (PNGU_u8 *) &ycbycr;
|
||||
|
||||
float val1 = (float)((int)(val[1]) - 128);
|
||||
float val3 = (float)((int)(val[3]) - 128);
|
||||
|
||||
int r = (int)(1.371f * val3);
|
||||
int g = (int)(- 0.698f * val3 - 0.336f * val1);
|
||||
int b = (int)(1.732f * val1);
|
||||
|
||||
*r1 = pngu_clamp (val[0] + r, 0, 255);
|
||||
*g1 = pngu_clamp (val[0] + g, 0, 255);
|
||||
*b1 = pngu_clamp (val[0] + b, 0, 255);
|
||||
|
||||
*r2 = pngu_clamp (val[2] + r, 0, 255);
|
||||
*g2 = pngu_clamp (val[2] + g, 0, 255);
|
||||
*b2 = pngu_clamp (val[2] + b, 0, 255);
|
||||
}
|
||||
|
||||
|
||||
int pngu_info (IMGCTX ctx)
|
||||
{
|
||||
png_byte magic[8];
|
||||
@ -1265,7 +679,6 @@ int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlph
|
||||
return PNGU_OK;
|
||||
}
|
||||
|
||||
|
||||
void pngu_free_info (IMGCTX ctx)
|
||||
{
|
||||
if (ctx->infoRead)
|
||||
@ -1279,7 +692,6 @@ void pngu_free_info (IMGCTX ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Custom data provider function used for reading from memory buffers.
|
||||
void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
@ -1288,7 +700,6 @@ void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t
|
||||
ctx->cursor += length;
|
||||
}
|
||||
|
||||
|
||||
// Custom data writer function used for writing to memory buffers.
|
||||
void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
@ -1297,14 +708,12 @@ void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t
|
||||
ctx->cursor += length;
|
||||
}
|
||||
|
||||
|
||||
// Custom data flusher function used for writing to memory buffers.
|
||||
void pngu_flush_data_to_buffer (png_structp png_ptr)
|
||||
{
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
|
||||
// Function used in YCbYCr to RGB decoding
|
||||
int pngu_clamp (int value, int min, int max)
|
||||
{
|
||||
|
@ -66,26 +66,6 @@ typedef struct
|
||||
struct _IMGCTX;
|
||||
typedef struct _IMGCTX *IMGCTX;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Pixel conversion *
|
||||
****************************************************************************/
|
||||
|
||||
// Macro to convert RGB8 values to RGB565
|
||||
#define PNGU_RGB8_TO_RGB565(r,g,b) ( ((((PNGU_u16) r) & 0xF8U) << 8) | ((((PNGU_u16) g) & 0xFCU) << 3) | (((PNGU_u16) b) >> 3) )
|
||||
|
||||
// Macro to convert RGBA8 values to RGB5A3
|
||||
#define PNGU_RGB8_TO_RGB5A3(r,g,b,a) (PNGU_u16) (((a & 0xE0U) == 0xE0U) ? \
|
||||
(0x8000U | ((((PNGU_u16) r) & 0xF8U) << 7) | ((((PNGU_u16) g) & 0xF8U) << 2) | (((PNGU_u16) b) >> 3)) : \
|
||||
(((((PNGU_u16) a) & 0xE0U) << 7) | ((((PNGU_u16) r) & 0xF0U) << 4) | (((PNGU_u16) g) & 0xF0U) | ((((PNGU_u16) b) & 0xF0U) >> 4)))
|
||||
|
||||
// Function to convert two RGB8 values to YCbYCr
|
||||
PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2);
|
||||
|
||||
// Function to convert an YCbYCr to two RGB8 values.
|
||||
void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Image context handling *
|
||||
****************************************************************************/
|
||||
@ -107,67 +87,17 @@ void PNGU_ReleaseImageContext (IMGCTX ctx);
|
||||
// Retrieves info from selected PNG file, including image dimensions, color format, background and transparency colors.
|
||||
int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Image conversion *
|
||||
****************************************************************************/
|
||||
|
||||
// Expands selected image into an YCbYCr buffer. You need to specify context, image dimensions,
|
||||
// destination address and stride in pixels (stride = buffer width - image width).
|
||||
int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||
|
||||
// Macro for decoding an image inside a buffer at given coordinates.
|
||||
#define PNGU_DECODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
|
||||
\
|
||||
PNGU_DecodeToYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||
(coordX) * 2, (bufferWidth) - (imgWidth))
|
||||
|
||||
// Expands selected image into a linear RGB565 buffer. You need to specify context, image dimensions,
|
||||
// destination address and stride in pixels (stride = buffer width - image width).
|
||||
int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||
|
||||
// Macro for decoding an image inside a buffer at given coordinates.
|
||||
#define PNGU_DECODE_TO_COORDS_RGB565(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
|
||||
\
|
||||
PNGU_DecodeToRGB565 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||
(coordX) * 2, (bufferWidth) - (imgWidth))
|
||||
|
||||
// Expands selected image into a linear RGBA8 buffer. You need to specify context, image dimensions,
|
||||
// destination address, stride in pixels and default alpha value, which is used if the source image
|
||||
// doesn't have an alpha channel.
|
||||
int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha);
|
||||
|
||||
// Macro for decoding an image inside a buffer at given coordinates.
|
||||
#define PNGU_DECODE_TO_COORDS_RGBA8(ctx,coordX,coordY,imgWidth,imgHeight,default_alpha,bufferWidth,bufferHeight,buffer) \
|
||||
\
|
||||
PNGU_DecodeToRGBA8 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||
(coordX) * 2, (bufferWidth) - (imgWidth), default_alpha)
|
||||
|
||||
// Expands selected image into a 4x4 tiled RGB565 buffer. You need to specify context, image dimensions
|
||||
// and destination address.
|
||||
int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer);
|
||||
|
||||
// Expands selected image into a 4x4 tiled RGB5A3 buffer. You need to specify context, image dimensions,
|
||||
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
|
||||
int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
|
||||
|
||||
// Expands selected image into a 4x4 tiled RGBA8 buffer. You need to specify context, image dimensions,
|
||||
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
|
||||
int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
|
||||
|
||||
// Encodes an YCbYCr image in PNG format and stores it in the selected device or memory buffer. You need to
|
||||
// specify context, image dimensions, destination address and stride in pixels (stride = buffer width - image width).
|
||||
int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||
|
||||
int PNGU_EncodeFromRGB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||
int PNGU_EncodeFromGXTexture (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||
|
||||
// Macro for encoding an image stored into an YCbYCr buffer at given coordinates.
|
||||
#define PNGU_ENCODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
|
||||
\
|
||||
PNGU_EncodeFromYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||
(coordX) * 2, (bufferWidth) - (imgWidth))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -44,36 +44,33 @@ enum {
|
||||
};
|
||||
|
||||
struct SGCSettings{
|
||||
int AutoLoad;
|
||||
float gbaZoomHor; // GBA horizontal zoom amount
|
||||
float gbaZoomVert; // GBA vertical zoom amount
|
||||
float gbZoomHor; // GB horizontal zoom amount
|
||||
float gbZoomVert; // GB vertical zoom amount
|
||||
int AutoLoad;
|
||||
int AutoSave;
|
||||
int LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB)
|
||||
int SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, USB, SMB
|
||||
char LoadFolder[MAXPATHLEN]; // Path to game files
|
||||
char SaveFolder[MAXPATHLEN]; // Path to save files
|
||||
char CheatFolder[MAXPATHLEN]; // Path to cheat files
|
||||
|
||||
char smbip[80];
|
||||
char smbuser[20];
|
||||
char smbpwd[20];
|
||||
char smbshare[20];
|
||||
|
||||
float gbaZoomHor; // GBA horizontal zoom amount
|
||||
float gbaZoomVert; // GBA vertical zoom amount
|
||||
float gbZoomHor; // GB horizontal zoom amount
|
||||
float gbZoomVert; // GB vertical zoom amount
|
||||
int videomode; // 0 - automatic, 1 - NTSC (480i), 2 - Progressive (480p), 3 - PAL (50Hz), 4 - PAL (60Hz)
|
||||
int scaling; // 0 - default, 1 - partial stretch, 2 - stretch to fit, 3 - widescreen correction
|
||||
int render; // 0 - original, 1 - filtered, 2 - unfiltered
|
||||
int xshift; // video output shift
|
||||
int LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB)
|
||||
int SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, USB, SMB
|
||||
int videomode; // 0 - automatic, 1 - NTSC (480i), 2 - Progressive (480p), 3 - PAL (50Hz), 4 - PAL (60Hz)
|
||||
int scaling; // 0 - default, 1 - partial stretch, 2 - stretch to fit, 3 - widescreen correction
|
||||
int render; // 0 - original, 1 - filtered, 2 - unfiltered
|
||||
int xshift; // video output shift
|
||||
int yshift;
|
||||
int colorize; // colorize Mono Gameboy games
|
||||
|
||||
int WiiControls; // Match Wii Game
|
||||
int colorize; // colorize Mono Gameboy games
|
||||
int WiiControls; // Match Wii Game
|
||||
int WiimoteOrientation;
|
||||
int ExitAction;
|
||||
int MusicVolume;
|
||||
int SFXVolume;
|
||||
int Rumble;
|
||||
char LoadFolder[MAXPATHLEN]; // Path to game files
|
||||
char SaveFolder[MAXPATHLEN]; // Path to save files
|
||||
char CheatFolder[MAXPATHLEN]; // Path to cheat files
|
||||
char smbip[80];
|
||||
char smbuser[20];
|
||||
char smbpwd[20];
|
||||
char smbshare[20];
|
||||
};
|
||||
|
||||
void ExitApp();
|
||||
|
@ -198,13 +198,11 @@ bool VMCPULoadROM()
|
||||
****************************************************************************/
|
||||
static void VMFindFree( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
vmpageno++;
|
||||
++vmpageno;
|
||||
vmpageno &= MAXVMMASK;
|
||||
if ( vmpageno == 0 ) vmpageno++;
|
||||
if ( vmpageno == 0 ) ++vmpageno;
|
||||
|
||||
for ( i = 1; i < MAXVMPAGE; i++ )
|
||||
for (unsigned i = 1; i < MAXVMPAGE; ++i )
|
||||
{
|
||||
/** Remove any other pointer to this vmpage **/
|
||||
if ( vmpage[i].pageno == vmpageno )
|
||||
@ -237,14 +235,30 @@ static void VMAllocate( int pageid )
|
||||
****************************************************************************/
|
||||
static void VMInit( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
/** Clear down pointers **/
|
||||
memset(&vmpage, 0, sizeof(VMPAGE) * MAXVMPAGE);
|
||||
for ( i = 0; i < MAXVMPAGE; i++ )
|
||||
|
||||
if(MAXVMPAGE % 4 == 0)
|
||||
{
|
||||
vmpage[i].pageno = -1;
|
||||
vmpage[i].pagetype = MEM_UN;
|
||||
for (unsigned i =0 ; i < MAXVMPAGE; i+=4 )
|
||||
{
|
||||
vmpage[i ].pageno = -1;
|
||||
vmpage[i ].pagetype = MEM_UN;
|
||||
vmpage[i+1].pageno = -1;
|
||||
vmpage[i+1].pagetype = MEM_UN;
|
||||
vmpage[i+2].pageno = -1;
|
||||
vmpage[i+2].pagetype = MEM_UN;
|
||||
vmpage[i+3].pageno = -1;
|
||||
vmpage[i+3].pagetype = MEM_UN;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned i =0 ; i < MAXVMPAGE; ++i )
|
||||
{
|
||||
vmpage[i].pageno = -1;
|
||||
vmpage[i].pagetype = MEM_UN;
|
||||
}
|
||||
}
|
||||
|
||||
/** Allocate physical **/
|
||||
@ -327,10 +341,9 @@ int VMCPULoadROM()
|
||||
****************************************************************************/
|
||||
static void VMNewPage( int pageid )
|
||||
{
|
||||
int res;
|
||||
int res = fseek( romfile, pageid << VMSHIFTBITS, SEEK_SET );
|
||||
char msg[512];
|
||||
|
||||
res = fseek( romfile, pageid << VMSHIFTBITS, SEEK_SET );
|
||||
if (res) // fseek returns non-zero on a failure
|
||||
{
|
||||
sprintf(msg, "Seek error! - Offset %d / %08x %d\n", pageid, pageid << VMSHIFTBITS, res);
|
||||
@ -351,17 +364,13 @@ static void VMNewPage( int pageid )
|
||||
****************************************************************************/
|
||||
u32 VMRead32( u32 address )
|
||||
{
|
||||
int pageid;
|
||||
u32 badaddress;
|
||||
char msg[512];
|
||||
|
||||
if ( address >= (u32)GBAROMSize )
|
||||
{
|
||||
badaddress = ( ( ( address >> 1 ) & 0xffff ) << 16 ) | ( ( ( address + 2 ) >> 1 ) & 0xffff );
|
||||
return badaddress;
|
||||
return u32(( ( ( address >> 1 ) & 0xffff ) << 16 ) | ( ( ( address + 2 ) >> 1 ) & 0xffff ));
|
||||
}
|
||||
|
||||
pageid = address >> VMSHIFTBITS;
|
||||
int pageid = address >> VMSHIFTBITS;
|
||||
char msg[512];
|
||||
|
||||
switch( vmpage[pageid].pagetype )
|
||||
{
|
||||
@ -387,14 +396,12 @@ u32 VMRead32( u32 address )
|
||||
****************************************************************************/
|
||||
u16 VMRead16( u32 address )
|
||||
{
|
||||
int pageid;
|
||||
|
||||
if ( address >= (u32)GBAROMSize )
|
||||
{
|
||||
return ( address >> 1 ) & 0xffff;
|
||||
}
|
||||
|
||||
pageid = address >> VMSHIFTBITS;
|
||||
int pageid = address >> VMSHIFTBITS;
|
||||
|
||||
switch( vmpage[pageid].pagetype )
|
||||
{
|
||||
@ -419,14 +426,12 @@ u16 VMRead16( u32 address )
|
||||
****************************************************************************/
|
||||
u8 VMRead8( u32 address )
|
||||
{
|
||||
int pageid;
|
||||
|
||||
if ( address >= (u32)GBAROMSize )
|
||||
{
|
||||
return ( address >> 1 ) & 0xff;
|
||||
}
|
||||
|
||||
pageid = address >> VMSHIFTBITS;
|
||||
int pageid = address >> VMSHIFTBITS;
|
||||
|
||||
switch( vmpage[pageid].pagetype )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user